Merge pull request #823 from oraios/csharp-init-fix

Fix C# LS initialisation issues
This commit is contained in:
Dominik Jain authored and GitHub committed 2025-12-08 19:06:34 +01:00
commit f577ac5957
2 files changed
+11 -6

No files matched your search

@@ -532,7 +532,7 @@ class CSharpLanguageServer(SolidLanguageServer):
# Map LSP message types to Python logging levels
level_map = {1: logging.ERROR, 2: logging.WARNING, 3: logging.INFO, 4: logging.DEBUG} # Error # Warning # Info # Log
log.info(f"LSP: {message_text}", level_map.get(level, logging.DEBUG))
log.log(level_map.get(level, logging.DEBUG), f"LSP: {message_text}")
def handle_progress(params: dict) -> None:
"""Handle progress notifications from the language server."""
@@ -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)