-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Fix ordering of module specifiers based on package.json presence #46437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/// <reference path="fourslash.ts" /> | ||
|
||
// @module: esnext | ||
// @moduleResolution: node | ||
|
||
// @Filename: /node_modules/vue/package.json | ||
//// { | ||
//// "name": "vue", | ||
//// "types": "dist/vue.d.ts" | ||
//// } | ||
|
||
// @Filename: /node_modules/vue/dist/vue.d.ts | ||
//// export * from "@vue/runtime-dom" | ||
|
||
// @Filename: /node_modules/@vue/runtime-dom/package.json | ||
//// { | ||
//// "name": "@vue/runtime-dom", | ||
//// "types": "dist/runtime-dom.d.ts" | ||
//// } | ||
|
||
// @Filename: /node_modules/@vue/runtime-dom/dist/runtime-dom.d.ts | ||
//// export * from "@vue/runtime-core"; | ||
//// export {} | ||
//// declare module '@vue/reactivity' { | ||
//// export interface RefUnwrapBailTypes { | ||
//// runtimeDOMBailTypes: any | ||
//// } | ||
//// } | ||
|
||
// @Filename: /node_modules/@vue/runtime-core/package.json | ||
//// { | ||
//// "name": "@vue/runtime-core", | ||
//// "types": "dist/runtime-core.d.ts" | ||
//// } | ||
|
||
// @Filename: /node_modules/@vue/runtime-core/dist/runtime-core.d.ts | ||
//// import { ref } from '@vue/reactivity'; | ||
//// export { ref }; | ||
//// declare module '@vue/reactivity' { | ||
//// export interface RefUnwrapBailTypes { | ||
//// runtimeCoreBailTypes: any | ||
//// } | ||
//// } | ||
|
||
// @Filename: /node_modules/@vue/reactivity/package.json | ||
//// { | ||
//// "name": "@vue/reactivity", | ||
//// "types": "dist/reactivity.d.ts" | ||
//// } | ||
|
||
// @Filename: /node_modules/@vue/reactivity/dist/reactivity.d.ts | ||
//// export declare function ref<T = any>(): T; | ||
|
||
// @Filename: /package.json | ||
//// { | ||
//// "dependencies": { | ||
//// "vue": "*" | ||
//// } | ||
//// } | ||
|
||
// @Filename: /index.ts | ||
//// import {} from "vue"; | ||
//// ref/**/ | ||
|
||
verify.completions({ | ||
marker: "", | ||
includes: [{ | ||
name: "ref", | ||
source: "vue", | ||
sourceDisplay: "vue", | ||
hasAction: true, | ||
sortText: completion.SortText.AutoImportSuggestions, | ||
}], | ||
preferences: { | ||
includeCompletionsForModuleExports: true, | ||
allowIncompleteCompletions: true, | ||
}, | ||
}); | ||
|
||
verify.applyCodeActionFromCompletion("", { | ||
name: "ref", | ||
source: "vue", | ||
description: `Add 'ref' to existing import declaration from "vue"`, | ||
data: { | ||
exportName: "ref", | ||
fileName: "/node_modules/vue/dist/vue.d.ts", | ||
}, | ||
preferences: { | ||
includeCompletionsForModuleExports: true, | ||
allowIncompleteCompletions: true, | ||
}, | ||
newFileContent: `import { ref } from "vue";\nref` | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From
compareBooleans
:So we need to reverse the order here to ensure module specifiers that are allowed are sorted
LessThan
module specifiers that aren’t.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just for my own understanding: is there a reason why you chose to reverse
a
andb
here instead of, say, changing fromComparison.LessThan
toComparison.GreaterThan
?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was simplest to leave the sort order going from
LessThan
toGreaterThan
(just like numbers are sorted), so I think the simplest two options were this andwhich would be read like “
true
is greater thanfalse
→doesn’t allow importing this specifier
is greater thanallows importing this specifier
→ ones with disallowed specifiers are sorted last.” That might be more direct reading from zero context, but when I realized I just needed to reverse the polarity of this comparison, swapping the order of the comparison was my go-to, probably because of the common analog ofThe other option that occurred to me was multiplying the comparison by
-1
, but I felt like that defeated the semi-opaque quality of theComparison
enum.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ultimately, this whole comparison abstraction makes it really nice to read at a high level what factors are considered in sorting/comparing, but very confusing to map onto the low level of what
.reduce
or.sort
is going to do. Good for understanding the big picture, bad for fixing bugs like this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for explaining your thought process! 😊