"Organize Imports" should adjust specifiers based on preferences
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 35/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- typescript, vscode
调研方向
从 TypeScript: Sort imports 命令以及 issue 中描述的 language server quick-fix 行为开始。跟踪 typescript.preferences.importModuleSpecifier、tsconfig baseUrl 和 paths 如何影响生成的 import specifier。当 import 已排序,并且符合条件的路径已根据这些偏好进行一致调整时,即视为完成。
由索引模型根据 Issue 内容生成。
描述
🔍 Search Terms
"sort imports", "organize imports"
✅ Viability Checklist
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This isn't a request to add a new utility type: https://github.com/microsoft/TypeScript/wiki/No-New-Utility-Types
- This feature would agree with the rest of our Design Goals: https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals
⭐ Suggestion
I have a feature request for the language server / it's commands.
So I have a large project, and I have not changed tsconfig.json since the beginning of the time.
Now I "discovered" what baseUrl does, what paths does, and that there is an option in vscode - ```
"typescript.preferences.importModuleSpecifier": "non-relative", // | "project-relative" | "relative" | "shortest"`.
So I have a file, deep inside the source - which imports from a file, close to the root.
Before I added 'baseUrl' - it did
import { bar } from "../../../../../foo/bar";`
After adding "baseUrl": "./src/" in tsconfig - this could be written as
import { bar } from "foo/bar";`
bar();
If I delete the import, and go to the bar() to fix the import issue - it provides me quick fix -
Add import from "foo/bar"if I have specified"typescript.preferences.importModuleSpecifier": "shortest"in settings., orAdd import from "../../../../../foo/bar"if I have specified"typescript.preferences.importModuleSpecifier": "relative"in settings.
I really don't like those endless "../../../../../" so I would like to fix them. The only "tool" I have for now - is just to delete the import, and resolve those imports manually - so it gives me the best import paths given my settings and my tsconfig's "baseUrl" or "paths".
This is tedious. And it doesn't work where I have used import * as foo from [..].
In VSCode - there is a command Organize imports (I think this comes not from TypeScript?) (In my optionion - wasted effort. since it doesn't organize them, it just sorts them, but this is besides the point (it does not come from TypeScript))
But TypeScript does come with a command "Typescript: Sort imports"!
What I would want - after executing the command, it would not only sort the imports, but also - change the paths for those imports matching my preferences of settings.json "typescript.preferences.importModuleSpecifier" + tsconfig.json "baseUrl" and "paths".
Or it could be a new command - Typescript: Organize imports? (maybe not..)
📃 Motivating Example
This feature would help automatically shorten imports / make the satisfy project setting for a file.
💻 Use Cases
- What do you want to use this for?
To automatically organize imports - What shortcomings exist with current approaches?
You have to manually go over each import and edit them one by one - What workarounds are you using in the meantime?
Deleting the import and resolving them using quick fix.
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.4k
- 平均合并
- 1 天 19 小时
- 30 天内合并 PR
- 117
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
microsoft/TypeScript 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 88/100
microsoft/TypeScript#64322 · 2 条评论 · 1 个 reaction · 已指派 2 人 ·
-
Possible Improvement
难度 2/5 1-3 小时 新手友好度 78/100
microsoft/TypeScript#64278 · 1 条评论 · 1 个 reaction ·
-
Docs
难度 2/5 1-3 小时 新手友好度 70/100
microsoft/TypeScript#64118 · 1 条评论 ·
-
难度 1/5 1 小时以内 新手友好度 88/100
microsoft/TypeScript#64094 ·
-
Docs
难度 2/5 1-3 小时 新手友好度 76/100
microsoft/TypeScript#63959 · 5 条评论 ·
查看 microsoft/TypeScript 的全部 Issue
相似的 Issue
-
Type/Bug
难度 2/5 1-3 小时 新手友好度 78/100
OpenNSW/nsw-srilanka#497 ·
-
难度 1/5 1 小时以内 新手友好度 92/100
milvus-io/birdwatcher#545 ·
-
kind/bug
难度 2/5 1-3 小时 新手友好度 88/100
kubernetes-sigs/prow#953 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 88/100
-
难度 2/5 1-3 小时 新手友好度 88/100
caddyserver/caddy#8046 ·