Skip to content

Add auto-import retry to getCompletionsAtPosition in API - #64133

Open
auvred wants to merge 1 commit into
microsoft:mainfrom
auvred:api-auto-import-completion-retry
Open

Add auto-import retry to getCompletionsAtPosition in API#64133
auvred wants to merge 1 commit into
microsoft:mainfrom
auvred:api-auto-import-completion-retry

Conversation

@auvred

@auvred auvred commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Fixes #64132

This PR adds a retry with (*Session).GetSnapshotWithAutoImports similar to

if errors.Is(lsErr, ls.ErrNeedsAutoImports) {
languageService, lsErr = s.session.GetLanguageServiceWithAutoImports(ctx, snapshot, params.TextDocumentURI())
if lsErr != nil {
return lsErr
}
if ctx.Err() != nil {
return ctx.Err()
}
resp, lsErr = fn(s, ctx, languageService, params)
if errors.Is(lsErr, ls.ErrNeedsAutoImports) {
panic(info.Method + " returned ErrNeedsAutoImports even after enabling auto imports")
}
}

Copilot AI balanced review requested due to automatic review settings September 2, 2026 13:34
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Sep 2, 2026
@typescript-automation typescript-automation Bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Sep 2, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The retry path must propagate cancellation after auto-import snapshot preparation.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds API completion retry support when auto-import data is required.

Changes:

  • Retries completions using an auto-import-prepared snapshot.
  • Generalizes language-service setup for alternate snapshots.
  • Adds an auto-import completion regression test.
File summaries
File Description
tsc/internal/api/session.go Implements snapshot preparation and completion retry.
tsc/internal/api/session_completion_test.go Verifies auto-import completions are returned.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Balanced

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +4032 to +4033
preparedSnapshot := s.projectSession.GetSnapshotWithAutoImports(ctx, sd.snapshot, params.File.ToURI(s.projectSession.GetCurrentDirectory()))
defer preparedSnapshot.Deref(s.projectSession)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

getCompletionsAtPosition in API throws "completion list needs auto imports"

2 participants