-
Notifications
You must be signed in to change notification settings - Fork 392
fix(lsp): context is singleton in vscode #4722
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -106,10 +106,13 @@ def _create_lsp_context(self, paths: t.List[Path]) -> t.Optional[LSPContext]: | |||||
| A new LSPContext instance wrapping the created context, or None if creation fails | ||||||
| """ | ||||||
| try: | ||||||
| context = self.context_class(paths=paths) | ||||||
| lsp_context = LSPContext(context) | ||||||
| self.lsp_context = lsp_context | ||||||
| return lsp_context | ||||||
| if self.lsp_context is None: | ||||||
| context = self.context_class(paths=paths) | ||||||
| else: | ||||||
| self.lsp_context.context.load() | ||||||
| context = self.lsp_context.context | ||||||
| self.lsp_context = LSPContext(context) | ||||||
| return self.lsp_context | ||||||
| except Exception as e: | ||||||
| self.server.log_trace(f"Error creating context: {e}") | ||||||
| return None | ||||||
|
|
@@ -293,8 +296,16 @@ def did_open(ls: LanguageServer, params: types.DidOpenTextDocumentParams) -> Non | |||||
|
|
||||||
| @self.server.feature(types.TEXT_DOCUMENT_DID_CHANGE) | ||||||
| def did_change(ls: LanguageServer, params: types.DidChangeTextDocumentParams) -> None: | ||||||
| if self.lsp_context is None: | ||||||
| current_path = Path.cwd() | ||||||
|
||||||
| current_path = Path.cwd() | |
| current_path = self._get_workspace_folder_or_default() |
Copilot
AI
Jun 11, 2025
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.
[nitpick] The context reinitialization logic is similar to what is done in _create_lsp_context. Consider refactoring this duplication into a helper method to ensure consistent behavior and easier maintenance.
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.
The current logic re-wraps the context in a new LSPContext even when one exists. To fully honor the singleton pattern, consider reusing the existing LSPContext instance when no state updates are required.