[js/ts] Feature request: In Quick Fix menu, show also a dynamic import variant
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 20/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Cần làm rõ
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- javascript, typescript
- Lĩnh vực
- developer-experience, tooling
Hướng nghiên cứu
Bắt đầu bằng cách xác định phần triển khai JS/TS Quick Fix đề xuất các static import và mọi cách xử lý hiện có cho dynamic import. Xác định các ngữ cảnh được hỗ trợ, hành vi của hàm async, việc hợp nhất các import trùng lặp và liệu có cần một flag hay không. Công việc được xem là hoàn tất khi hành vi đã thống nhất được triển khai và có coverage cho các biến thể Quick Fix được đề xuất.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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 } = ....
- Ngôn ngữ chính
- Go
- Star
- 111k
- Fork
- 14.4k
- Merge trung bình
- 1 ngày 15 giờ
- Pull request đã merge (30 ngày)
- 106
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của microsoft/TypeScript
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
microsoft/TypeScript#64322 · 2 bình luận · 1 reaction · 2 người được giao ·
-
Possible Improvement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
microsoft/TypeScript#64278 · 1 bình luận · 1 reaction ·
-
Docs
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
microsoft/TypeScript#64118 · 1 bình luận ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
microsoft/TypeScript#64094 ·
-
Docs
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
microsoft/TypeScript#63959 · 5 bình luận ·
Tất cả issue của microsoft/TypeScript
Issue tương tự
-
Type/Bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
OpenNSW/nsw-srilanka#497 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
milvus-io/birdwatcher#545 ·
-
kind/bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
kubernetes-sigs/prow#953 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
caddyserver/caddy#8046 ·