microsoft / microsoft/TypeScript
[js/ts] Feature request: In Quick Fix menu, show also a dynamic import variant
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
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 } = ....
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、static import を提案する JS/TS Quick Fix の実装と、dynamic import に対する既存の処理があるかを特定します。サポートされるコンテキスト、async 関数の動作、重複した import のマージ、および flag が必要かどうかを確認します。合意した動作が実装され、提案された Quick Fix のバリエーションがカバーされていれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- javascript, typescript
- 領域
- developer-experience, tooling
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- 説明が足りない
- 初心者へのやさしさ
- 20/100