Resolve JS imports from html script tags#193590
Open
dpikt wants to merge 4 commits intomicrosoft:mainfrom
Open
Resolve JS imports from html script tags#193590dpikt wants to merge 4 commits intomicrosoft:mainfrom
dpikt wants to merge 4 commits intomicrosoft:mainfrom
Conversation
Author
|
@microsoft-github-policy-service agree |
dpikt
commented
Sep 20, 2023
| let text = ''; | ||
| if (fileName === currentTextDocument.uri) { | ||
| text = currentTextDocument.getText(); | ||
| } else if (isFileURI(fileName) && ts.sys.fileExists(uriToFilePath(fileName))) { |
Author
There was a problem hiding this comment.
If the requested file is on a local file system, read it with ts.sys.readFile. (Web IDE support is not possible since TS requires sync access, as discussed in #121517)
dpikt
commented
Sep 20, 2023
| return definition.filter(d => d.fileName === jsDocument.uri).map(d => { | ||
| return definition.map(d => { | ||
| const text = jsLanguageService.getProgram()!.getSourceFile(d.fileName)!.text; | ||
| const doc = TextDocument.create('tmp', 'javascript', 1, text); |
Author
There was a problem hiding this comment.
Convert source files into TextDocument objects to do text range conversion. (There may be a better way to do this).
Author
|
Update - added tests. Again based on #121517 |
dpikt
commented
Sep 23, 2023
| const list = await mode.doComplete!(document, position, context); | ||
|
|
||
| if (expected.count) { | ||
| if (expected.count !== undefined) { |
Author
There was a problem hiding this comment.
Prevent silent errors when testing for count: 0
Contributor
|
It'd be cool to get this in |
|
any way to add non module js files support? like shown in #26338 |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Partially addresses #26338 by allowing external scripts to be resolved via TSServer. This is based on the great work by @orta in #121517 - I've rearranged things a little bit for a smaller diff.
This enables display of quick info on hover, as well as jump-to-definition for JS imports. This also seems to support
//@ts-check, although I haven't tested this thoroughly.Example JS module:
Before change (no quick info):
After change (shows quick info):
Type checking example:
Current known limitations:
If the overall approach looks good I can add tests for this enhancement. Any and all feedback welcome, thanks!