Skip to content

[api] Fix panic in handleGetCompletionsAtPosition#4522

Open
Vorobey31415 wants to merge 2 commits into
microsoft:mainfrom
JetBrains:fix-handleGetCompletionsAtPosition-for-inferred-projects
Open

[api] Fix panic in handleGetCompletionsAtPosition#4522
Vorobey31415 wants to merge 2 commits into
microsoft:mainfrom
JetBrains:fix-handleGetCompletionsAtPosition-for-inferred-projects

Conversation

@Vorobey31415

Copy link
Copy Markdown
Contributor

Fix panic in handleGetCompletionsAtPosition by allowing setupLanguageService for inferred projects

allowing setupLanguageService for inferred projects
Copilot AI review requested due to automatic review settings July 2, 2026 15:03

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.

Pull request overview

Fixes a panic in the API session’s completion handler path when operating on inferred (non-tsconfig) projects by avoiding a configured-project-only accessor.

Changes:

  • Update Session.setupLanguageService to key the language service with Project.ID() instead of Project.ConfigFilePath() (avoids panic on inferred projects).
  • Add a regression test that requests completions for a loose file that resolves to an inferred project.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
internal/api/session.go Avoids calling ConfigFilePath() (panics on inferred projects) by using ID() when constructing a language service.
internal/api/session_completion_test.go Adds a test covering completions on an inferred project to prevent regression.

Comment thread internal/api/session_completion_test.go Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Comment thread internal/api/session.go
return nil, fmt.Errorf("%w: project %s not found", ErrClientError, projectName)
}
return ls.NewLanguageService(proj.ConfigFilePath(), program, sd.snapshot, activeFile), nil
return ls.NewLanguageService(proj.ID(), program, sd.snapshot, activeFile), nil

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sort of confused, every caller of NewLanguageService passes in a config file path, and yes ID is that, but that seems like only by happenstance?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, this is currently the only way to get at the fake /dev/null/inferredproject path for inferred projects. I think this actually makes sense, because the language service only uses this string as a unique identifier (ultimately keying into project-specific buckets from the auto-import registry). I actually think the other usages of NewLanguageService could use .ID() and the parameter name could be renamed.

Comment thread internal/api/session.go
return nil, fmt.Errorf("%w: project %s not found", ErrClientError, projectName)
}
return ls.NewLanguageService(proj.ConfigFilePath(), program, sd.snapshot, activeFile), nil
return ls.NewLanguageService(proj.ID(), program, sd.snapshot, activeFile), nil

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, this is currently the only way to get at the fake /dev/null/inferredproject path for inferred projects. I think this actually makes sense, because the language service only uses this string as a unique identifier (ultimately keying into project-specific buckets from the auto-import registry). I actually think the other usages of NewLanguageService could use .ID() and the parameter name could be renamed.

@andrewbranch andrewbranch changed the title Fix panic in handleGetCompletionsAtPosition [api] Fix panic in handleGetCompletionsAtPosition Jul 2, 2026
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.

4 participants