-
Notifications
You must be signed in to change notification settings - Fork 8
chore: test that autocomplete works without the fallback, re-order the tests #559
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
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
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 |
---|---|---|
|
@@ -13,7 +13,7 @@ type UpdateDefinitionFunction = ( | |
newDef: Record<TypeFilename, string | boolean>, | ||
) => void; | ||
|
||
function relativeNodePath(fileName: string): string { | ||
export function relativeNodePath(fileName: string): string { | ||
const parts = fileName.split(/\/node_modules\//g); | ||
if (parts.length === 1 && fileName.endsWith('package.json')) { | ||
// special case: when it looks up this package itself it isn't going to find | ||
|
@@ -65,13 +65,14 @@ function getVirtualLanguageService( | |
return (versions[fileName] ?? 1).toString(); | ||
}, | ||
getScriptSnapshot: (fileName) => { | ||
fileName = relativeNodePath(fileName); | ||
if (fileName in codeHolder) { | ||
const relativeFileName = relativeNodePath(fileName); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was actually a bug - I was passing the relative filename to the fallback resolver and that needs the original absolute filename so it can actually load it from disk. |
||
|
||
if (relativeFileName in codeHolder) { | ||
// if its a boolean rather than code, just return a blank string if for | ||
// some reason we ever get here. | ||
const code = | ||
typeof codeHolder[fileName] === 'string' | ||
? (codeHolder[fileName] as string) | ||
typeof codeHolder[relativeFileName] === 'string' | ||
? (codeHolder[relativeFileName] as string) | ||
: ''; | ||
return ts.ScriptSnapshot.fromString(code); | ||
} | ||
|
@@ -86,8 +87,8 @@ function getVirtualLanguageService( | |
return ts.getDefaultLibFilePath(options); | ||
}, | ||
fileExists: (fileName) => { | ||
fileName = relativeNodePath(fileName); | ||
if (fileName in codeHolder) { | ||
const relativeFileName = relativeNodePath(fileName); | ||
if (relativeFileName in codeHolder) { | ||
return true; | ||
} | ||
|
||
|
@@ -98,13 +99,13 @@ function getVirtualLanguageService( | |
return false; | ||
}, | ||
readFile: (fileName) => { | ||
fileName = relativeNodePath(fileName); | ||
if (fileName in codeHolder) { | ||
const relativeFileName = relativeNodePath(fileName); | ||
if (relativeFileName in codeHolder) { | ||
// if its a boolean rather than code, just return a blank string if for | ||
// some reason we ever get here. | ||
const code = | ||
typeof codeHolder[fileName] === 'string' | ||
? (codeHolder[fileName] as string) | ||
typeof codeHolder[relativeFileName] === 'string' | ||
? (codeHolder[relativeFileName] as string) | ||
: undefined; | ||
return code; | ||
} | ||
|
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.
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.
The best way to fully test/prove this automatically (ie. that it can recreate the list) is do comment out deps in extract-types.ts to make it just an empty structure, run extract-types so none of the @types/node and lib files are in there, then run this test. It then finds the entire list.
I tried modifying extract-types to calculate the list automatically by running autocomplete, but it becomes a bit code-surgery with things passed down just for testing and a chicken and egg problem of extract-types using autocomplete which imports the extracted types which aren't generated yet... I tried to fix it with dynamic import, but then TS doesn't want to import the code from the script and it just becomes a rabbit hole.
I think this test that lists what's missing even if you start over with an empty list and the rest of the tests fail because they don't use the fallback is probably good enough.
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.
(I have now added a version of this as a comment next to the test.)