Skip to content

Commit d2bd3db

Browse files
committed
fix: start diagnostics only when the language server is fully initialized
1 parent 706589a commit d2bd3db

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

robotcode/language_server/common/parts/diagnostics.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from ..lsp_types import (
2828
Diagnostic,
2929
DiagnosticOptions,
30+
DiagnosticServerCancellationData,
3031
DocumentDiagnosticParams,
3132
DocumentDiagnosticReport,
3233
ErrorCodes,
@@ -487,6 +488,11 @@ async def _text_document_diagnostic(
487488
**kwargs: Any,
488489
) -> DocumentDiagnosticReport:
489490
try:
491+
if not self.parent.is_initialized:
492+
raise JsonRPCErrorException(
493+
ErrorCodes.SERVER_CANCELLED, "Server not initialized.", DiagnosticServerCancellationData(True)
494+
)
495+
490496
document = await self.parent.documents.get(text_document.uri)
491497
if document is None:
492498
raise JsonRPCErrorException(ErrorCodes.SERVER_CANCELLED, f"Document {text_document!r} not found.")

robotcode/language_server/common/protocol.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
import asyncio
4-
from typing import Any, List, Optional, Set, Union, cast
4+
from typing import Any, List, NamedTuple, Optional, Set, Union, cast
55

66
from ...jsonrpc2.protocol import (
77
JsonRPCErrorException,
@@ -70,6 +70,12 @@ class LanguageServerException(JsonRPCException):
7070
pass
7171

7272

73+
class LanguageDefinition(NamedTuple):
74+
id: str
75+
extensions: List[str]
76+
aliases: Optional[List[str]] = None
77+
78+
7379
class LanguageServerProtocol(JsonRPCProtocol):
7480

7581
_logger = LoggingDescriptor()
@@ -103,6 +109,7 @@ class LanguageServerProtocol(JsonRPCProtocol):
103109
version: Optional[str] = None
104110

105111
file_extensions: Set[str] = set()
112+
languages: List[LanguageDefinition] = []
106113

107114
def __init__(self, server: JsonRPCServer[Any]):
108115
super().__init__()
@@ -125,6 +132,7 @@ def __init__(self, server: JsonRPCServer[Any]):
125132
)
126133

127134
self._trace = TraceValue.OFF
135+
self._is_initialized = False
128136

129137
@async_event
130138
async def on_shutdown(sender) -> None: # pragma: no cover, NOSONAR
@@ -236,6 +244,12 @@ async def on_initialize(sender, initialization_options: Optional[Any] = None) ->
236244
async def _initialized(self, params: InitializedParams, *args: Any, **kwargs: Any) -> None:
237245
await self.on_initialized(self)
238246

247+
self._is_initialized = True
248+
249+
@property
250+
def is_initialized(self) -> bool:
251+
return self._is_initialized
252+
239253
@async_event
240254
async def on_initialized(sender) -> None: # pragma: no cover, NOSONAR
241255
...

0 commit comments

Comments
 (0)