CSharpLanguageServer: Wait for indexing to complete

resolving issues pertaining to retrievals not working correctly initially

Fixes #814
This commit is contained in:
Dominik Jain authored and Dominik Jain committed 2025-12-08 18:27:23 +01:00
1 parent fd8bd8d064
commit b724eccde6
2 files changed
+10 -5

No files matched your search

@@ -627,10 +627,14 @@ class CSharpLanguageServer(SolidLanguageServer):
def handle_project_needs_restore(params: dict) -> None:
return
def handle_workspace_indexing_complete(params: dict) -> None:
self.completions_available.set()
# Set up notification handlers
self.server.on_notification("window/logMessage", window_log_message)
self.server.on_notification("$/progress", handle_progress)
self.server.on_notification("textDocument/publishDiagnostics", do_nothing)
self.server.on_notification("workspace/projectInitializationComplete", handle_workspace_indexing_complete)
self.server.on_request("workspace/configuration", handle_workspace_configuration)
self.server.on_request("window/workDoneProgress/create", handle_work_done_progress_create)
self.server.on_request("client/registerCapability", handle_register_capability)
@@ -679,7 +683,6 @@ class CSharpLanguageServer(SolidLanguageServer):
self._open_solution_and_projects()
self.initialization_complete.set()
self.completions_available.set()
log.info(
"Microsoft.CodeAnalysis.LanguageServer initialized and ready\n"
@@ -687,6 +690,12 @@ class CSharpLanguageServer(SolidLanguageServer):
"This may take a while for large projects"
)
if self.completions_available.wait(30): # Wait up to 30 seconds for indexing
log.info("Indexing complete")
else:
log.warning("Timeout waiting for indexing to complete, proceeding anyway")
self.completions_available.set()
def _force_pull_diagnostics(self, init_response: dict | InitializeResult) -> None:
"""
Apply the diagnostic capabilities hack.
@@ -119,13 +119,9 @@ class TestCSharpLanguageServer:
# Check that we have references from both files
assert any("Program.cs" in ref_file for ref_file in ref_files), "Should find reference in Program.cs"
# TODO: The assertion below fails randomly. Try to fix this. GitHub issue #814
# In CI, it sometimes passed; on my local machine (opcode81), it seems to fail consistently.
"""
assert any(
os.path.join("Models", "Person.cs") in ref_file for ref_file in ref_files
), "Should find reference in Models/Person.cs where Calculator.Subtract is called"
"""
# check for a second time, since the first call may trigger initialization and change the state of the LS
refs_second_call = language_server.request_references(file_path, sel_start["line"], sel_start["character"] + 1)