-
Notifications
You must be signed in to change notification settings - Fork 718
autoimport completions #1553
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
autoimport completions #1553
Conversation
I'm gonna closely follow this one... |
bug squashing atm :). Hopefully it'll be ready soon |
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.
Pull Request Overview
This PR implements autoimports functionality, enabling automatic import suggestions through completions in the TypeScript language server. The implementation adds the ability to suggest and automatically import symbols from other modules when typing identifiers.
Key changes include:
- Added comprehensive autoimport completion system with export info mapping and module specifier resolution
- Implemented import statement completion support for various import syntaxes
- Added text change tracking infrastructure for code modifications
Reviewed Changes
Copilot reviewed 51 out of 51 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
internal/ls/completions.go |
Main autoimport logic including export collection, module specifier resolution, and completion item generation |
internal/ls/autoimportstypes.go |
Type definitions for import/export kinds, import fixes, and related data structures |
internal/ls/changetrackerimpl.go |
Change tracking implementation for applying text edits and code modifications |
internal/printer/changetrackerwriter.go |
Writer implementation for tracking position changes during code generation |
internal/modulespecifiers/specifiers.go |
Enhanced module specifier generation with autoimport support |
internal/ls/organizeimports.go |
Import organization utilities and comparison functions |
Various utility files | Helper functions, type conversions, and API enhancements to support autoimport functionality |
return -1 | ||
} | ||
containingList := getContainingList(node, sourceFile) | ||
containingList := GetContainingList(node, sourceFile) |
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 didn't know this func existed; I wonder if it's general enough to use for sig help. (No action needed, just opining)
} | ||
|
||
func findFirstNonWhitespaceColumn(startPos int, endPos int, sourceFile *ast.SourceFile, options *FormatCodeSettings) int { | ||
func FindFirstNonWhitespaceColumn(startPos int, endPos int, sourceFile *ast.SourceFile, options *FormatCodeSettings) int { |
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 am suspicious of this function, given it appears to return the column in terms of runes? I'm not sure it walks the chars correctly either, hmm...
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.
This is what I was writing when I first went "wait, do we work in runes or in byte offsets for columns? Looks inconsistent right now". Both ways look wrong to some part of the stack around here because of that inconsistency.
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, I think we need everything to be UTF-8 byte offsets, until they hit the LS and get converted based on the client preferences.
The only exception might be symbol baselines (UTF-16 compat?), source maps, and maybe the API, and maybe printed diagnostics? (That's a lot of exceptions...)
Related, #1578
The import in the demo is inserted in a non-pretty way; is that something being worked on? |
Yes, this is a formatting bug/limitation. Strada formats with a Edit: Fixed with help from @weswigham New statements come out pretty now (haven't updated the demo vid yet tho) |
internal/fourslash/tests/gen/completionsObjectLiteralModuleExports_test.go
Outdated
Show resolved
Hide resolved
outdated/rest of changetracker formatting will be implemented in future PR
I can finally make the VS Code extension my daily driver. Thank you! |
fixes #1084
This PR implements autoimports, and allows symbols to be autoimported through completions. Also ports the basic functionalities of the changetracker (adds changes and calculates/formats the output string).
demo (note: the formatting has been fixed, see test cases)
corsa.completion.autoimports.1.mp4
Notes on implementation:
ExportInfoMap
,ImportMap
, etc) have been ported for functionality, but are not saved between server requests). After the ls is more fully implemented and perf tested, we will revisit to see what caching we need to doIncludeCompletionsForModuleExports
andIncludeCompletionsForImportStatements
in theUserPreferences
passed into any completion get/resolve request has been set totrue
to allow autoimports to work autoimport completions #1553 (comment)Related features to be implemented after this PR: