Skip to content

Conversation

@jakebailey
Copy link
Member

@jakebailey jakebailey commented Nov 11, 2025

Fixes #1658

This is not perfect. It passes maybe 60 out of 160 ported fourslash tests so far. Many issues exist with import sorting or formatting, and there are other diagnostics fixed by import fixes that are not being addressed here (like swapping a non-type to a type), and there are other auto-imports that seem weird that I need to double check.

But for the typical cases of just missing an import, this seems to work.

Re-ported a bunch of code and it's now passing tests except these differences:

  • symlink tests don't work
  • import ordering sometimes differs
  • a bit of formatting weirdness in some tests
  • JSDoc @import doesn't work (we see the reparsed nodes...)

Copilot AI review requested due to automatic review settings November 11, 2025 01:15
Copilot finished reviewing on behalf of jakebailey November 11, 2025 01:16
This reverts commit 8132a8c.
Copy link
Contributor

Copilot AI left a 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 auto-import fix functionality (code actions) for the TypeScript language server port. It adds support for generating quick-fix code actions that automatically add missing import statements when identifiers cannot be found.

Key changes:

  • New code actions handler that detects import-related diagnostics and suggests fixes
  • LSP server integration for the textDocument/codeAction request
  • Enhanced test infrastructure to support fourslash tests with implicit first files
  • Utility function to check symbol meaning compatibility

Reviewed Changes

Copilot reviewed 170 out of 170 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
internal/ls/codeactions.go New file implementing code action provider with auto-import fix logic
internal/lsp/server.go Registers code action handler and advertises capability to clients
internal/ls/utilities.go Adds symbolFlagsHaveMeaning helper for filtering exports by semantic meaning
internal/testrunner/test_case_parser.go Adds support for implicit first file in fourslash tests
internal/fourslash/fourslash.go Implements VerifyImportFixAtPosition test method
internal/fourslash/test_parser.go Updates parser to use new implicit first file option
internal/fourslash/_scripts/convertFourslash.mts Adds conversion support for importFixAtPosition verification
internal/fourslash/_scripts/failingTests.txt Tracks test status (many still failing as noted in PR description)
Multiple test files Adds 160+ fourslash tests for import fix scenarios

@jakebailey
Copy link
Member Author

TestImportNameCodeFix_reExport is flaky; looking into that...

@jakebailey
Copy link
Member Author

Going to merge this now just to get this out. It's going to be no worse than the fixes that completions give, and both will improve as we fix bugs.

@jakebailey jakebailey added this pull request to the merge queue Nov 12, 2025
Merged via the queue into main with commit 336dda7 Nov 12, 2025
22 checks passed
@jakebailey jakebailey deleted the jabaile/import-fixes branch November 12, 2025 19:33
@cpojer
Copy link

cpojer commented Nov 18, 2025

@jakebailey I tried the latest tsgo from today and cmd+. in VS Code says "No code actions available". Is there any configuration needed to make this work?

@jakebailey
Copy link
Member Author

Nope, nothing special. Try moving your cursor to the end of the name and hit Ctrl+Space to trigger a completion; if the auto import shows up in that then there's definitely a bug in this PR. Otherwise, there's a more generic bug in auto imports.

In any case, you should still file a separate issue.

@cpojer
Copy link

cpojer commented Nov 18, 2025

I just updated VS Code, and now it appears to be working. That was my last blocker for fully adopting tsgo, thank you!

@cpojer
Copy link

cpojer commented Nov 18, 2025

Ah, looks like there are some issues. It only works sometimes, but I have not yet narrowed down when it works and when it doesn't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tsgo preview: autoimport quick fixes not implemented

4 participants