[js/ts] Feature request: In Quick Fix menu, show also a dynamic import variant
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Anfängerfreundlichkeit
- 20/100
- Issue-Typ
- Feature
- Klarheit
- Muss geklärt werden
- Aktivitätsstatus
- Veraltet
- Tech-Stack
- javascript, typescript
- Bereich
- developer-experience, tooling
Rechercherichtung
Beginne damit, die JS/TS Quick Fix-Implementierung zu finden, die statische Importe vorschlägt, sowie eine eventuell vorhandene Behandlung dynamischer Importe. Ermittle die unterstützten Kontexte, das Verhalten bei async-Funktionen, das Zusammenführen doppelter Importe und ob ein Flag erforderlich ist. Als erledigt gilt die Aufgabe, wenn das vereinbarte Verhalten implementiert ist und die vorgeschlagenen Quick Fix-Varianten abgedeckt sind.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Context
In JS/TS file, when using an identifier which is not found in the file, but is found somewhere else in the repo (e.g. another open file, or somewhere else), VSCode will show a Quick Fix (cmd-.) suggestion to import the file.
When followed, this will add a top-level static import
import { FOO_BAR } from 'web-ui/foobar';
Feature request
It would be useful for Quick Fix menu to also have a variant of a suggestion which would add a local, dynamic import(), which would be inserted just above the line where the identifier is first used:
So the menu would be like:
- Quick Fix
- Add import from "web-ui/foobar"
- Add dynamic import from "web-ui/foobar"
And the code would look like:
if (doSomething) {
const { FOO_BAR } = await import('web-ui/foobar');
// or, depending on how the export is defined:
// const { FOO_BAR } = (await import('web-ui/foobar')).default;
const value = FOO_BAR;
Potential drawbacks
- If for every static import suggested, there's an equivalent dynamic import, the Quick Fix list may grow substantially, especially if
FOO_BARidentifier is present in many files.
Open questions
-
To be decided if the dynamic import suggestion would show up:
- everywhere
- or only in functions?
- or only in functions and
ifblocks? etc.
-
If a dynamic import is added in a function, should the function be converted to
asyncfunction automatically? -
Perhaps the dynamic import variant could be behind a flag (enabled by default for discoverability; easy to disable if someone doesn't like it, and prefers to only have static imports in the quick fix)
Extra considerations
There might be already existing dynamic imports that could be amended. For example, say the code is:
if (doSomething) {
const { QUUX } = await import('web-ui/foobar');
const value = FOO_BAR;
In that case, all dynamic imports in scope should be analyzed, and the editor should suggest to update the existing
const { QUUX } = await import('web-ui/foobar');
with const { FOO_BAR, QUUX } = ....
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.4k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus microsoft/TypeScript
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
microsoft/TypeScript#64322 · 2 Kommentare · 1 Reaktion · 2 zugewiesene Personen ·
-
Possible Improvement
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
microsoft/TypeScript#64278 · 1 Kommentar · 1 Reaktion ·
-
Docs
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
microsoft/TypeScript#64118 · 1 Kommentar ·
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 88/100
microsoft/TypeScript#64094 ·
-
Docs
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
microsoft/TypeScript#63959 · 5 Kommentare ·
Alle Issues in microsoft/TypeScript
Ähnliche Issues
-
optimization optimization:agents-md-curator
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 86/100
githubnext/gh-aw-cao#13143 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
blinklabs-io/bursa#904 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
yanet-platform/ipfw-go#129 ·
-
bug confmap/provider/googlesecretmanagerprovider needs triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
open-telemetry/opentelemetry-collector-contrib#51273 · 2 Kommentare ·
-
bug: AI Gateway client filter lists "Unknown" twice when NULL and literal Unknown clients coexist Offenbug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 90/100