-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Enable path completions for node12/nodenext #47836
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
weswigham
merged 3 commits into
microsoft:main
from
weswigham:path-completions-for-nodenext
Feb 11, 2022
Merged
Changes from all commits
Commits
Show all changes
3 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
29 changes: 29 additions & 0 deletions
29
tests/baselines/reference/nodeNextPathCompletions.baseline
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,29 @@ | ||
[ | ||
{ | ||
"marker": { | ||
"fileName": "/src/foo.ts", | ||
"position": 30, | ||
"name": "" | ||
}, | ||
"completionList": { | ||
"isGlobalCompletion": false, | ||
"isMemberCompletion": false, | ||
"isNewIdentifierLocation": true, | ||
"entries": [ | ||
{ | ||
"name": "dependency", | ||
"kind": "external module name", | ||
"kindModifiers": "", | ||
"sortText": "11", | ||
"displayParts": [ | ||
{ | ||
"text": "dependency", | ||
"kind": "text" | ||
} | ||
], | ||
"tags": [] | ||
} | ||
] | ||
} | ||
} | ||
] |
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,43 @@ | ||
/// <reference path="../fourslash.ts" /> | ||
|
||
// @Filename: /node_modules/dependency/package.json | ||
//// { | ||
//// "type": "module", | ||
//// "name": "dependency", | ||
//// "version": "1.0.0", | ||
//// "exports": { | ||
//// ".": { | ||
//// "types": "./lib/index.d.ts" | ||
//// }, | ||
//// "./lol": { | ||
//// "types": "./lib/lol.d.ts" | ||
//// }, | ||
//// "./dir/*": "./lib/*" | ||
//// } | ||
//// } | ||
|
||
// @Filename: /node_modules/dependency/lib/index.d.ts | ||
//// export function fooFromIndex(): void; | ||
|
||
// @Filename: /node_modules/dependency/lib/lol.d.ts | ||
//// export function fooFromLol(): void; | ||
|
||
// @Filename: /package.json | ||
//// { | ||
//// "type": "module", | ||
//// "dependencies": { | ||
//// "dependency": "^1.0.0" | ||
//// } | ||
//// } | ||
|
||
// @Filename: /tsconfig.json | ||
//// { "compilerOptions": { "module": "nodenext" }, "files": ["./src/foo.ts"] } | ||
|
||
// @Filename: /src/foo.ts | ||
//// import { fooFromIndex } from "/**/"; | ||
|
||
verify.baselineCompletions(); | ||
edit.insert("dependency/"); | ||
verify.completions({ exact: ["lol", "dir/"], isNewIdentifierLocation: true }); | ||
edit.insert("l"); | ||
verify.completions({ exact: ["lol"], isNewIdentifierLocation: true }); |
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.
Did you know this function creates a SourceFile with parse diagnostics?? 😵
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.
Hm, I buy it - our json document parsing is more lenient than the
JSON.parse
one because we allow comments and trailing commas, so I can understand preferring to use it.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.
npm crashes on comments and trailing commas. My strong suspicion is that
readJson
leaked into package.json-reading code only because it nicely avoids the need for a try/catch and it’s totally non-obvious that it’s doing so much extra work. I’ve been meaning to rename it and use a wrappedJSON.parse
on package.jsons. It might make a little bit of a perf difference in module resolution when you have a lot of node_modules.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.
That's probably true; but I mean, it's probably most important to just use the cached package.json results where possible first 😅
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.
Yeah, definitely.