Skip to content

Commit fbec326

Browse files
committed
refactor: some code simplifications
1 parent 39b658f commit fbec326

File tree

2 files changed

+29
-30
lines changed

2 files changed

+29
-30
lines changed

Diff for: packages/language_server/src/robotcode/language_server/common/parts/diagnostics.py

+27-30
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,19 @@ async def initialized(self, sender: Any) -> None:
146146

147147
self._workspace_diagnostics_task = create_sub_task(self.run_workspace_diagnostics(), loop=self.diagnostics_loop)
148148

149+
def extend_capabilities(self, capabilities: ServerCapabilities) -> None:
150+
if (
151+
self.parent.client_capabilities is not None
152+
and self.parent.client_capabilities.text_document is not None
153+
and self.parent.client_capabilities.text_document.diagnostic is not None
154+
):
155+
capabilities.diagnostic_provider = DiagnosticOptions(
156+
inter_file_dependencies=True,
157+
workspace_diagnostics=False,
158+
identifier=f"robotcodelsp_{uuid.uuid4()}",
159+
work_done_progress=True,
160+
)
161+
149162
@property
150163
def diagnostics_loop(self) -> asyncio.AbstractEventLoop:
151164
if self._diagnostics_loop is None:
@@ -214,19 +227,6 @@ def _ensure_diagnostics_thread_started(self) -> None:
214227
if not self._diagnostics_started.wait(10) or not self._single_diagnostics_started.wait(10):
215228
raise RuntimeError("Can't start diagnostics worker threads.")
216229

217-
def extend_capabilities(self, capabilities: ServerCapabilities) -> None:
218-
if (
219-
self.parent.client_capabilities is not None
220-
and self.parent.client_capabilities.text_document is not None
221-
and self.parent.client_capabilities.text_document.diagnostic is not None
222-
):
223-
capabilities.diagnostic_provider = DiagnosticOptions(
224-
inter_file_dependencies=True,
225-
workspace_diagnostics=False,
226-
identifier=f"robotcodelsp_{uuid.uuid4()}",
227-
work_done_progress=True,
228-
)
229-
230230
@async_tasking_event_iterator
231231
async def collect(sender, document: TextDocument) -> Optional[DiagnosticsResult]: # NOSONAR
232232
...
@@ -298,14 +298,7 @@ def done(t: asyncio.Task[Any]) -> None:
298298
await asyncio.sleep(0.001)
299299

300300
finally:
301-
self.parent.send_notification(
302-
"textDocument/publishDiagnostics",
303-
PublishDiagnosticsParams(
304-
uri=document.document_uri,
305-
version=document._version,
306-
diagnostics=[],
307-
),
308-
)
301+
self.publish_diagnostics(document, diagnostics=[])
309302

310303
async def cancel_workspace_diagnostics_task(self, sender: Any) -> None:
311304
if self._workspace_diagnostics_task is not None:
@@ -472,15 +465,9 @@ async def _get_diagnostics_for_document(
472465
collected_keys.append(result.key)
473466

474467
if data.entries and send_diagnostics:
475-
self.parent.send_notification(
476-
"textDocument/publishDiagnostics",
477-
PublishDiagnosticsParams(
478-
uri=document.document_uri,
479-
version=document._version,
480-
diagnostics=[
481-
l for l in itertools.chain(*[i for i in data.entries.values() if i is not None])
482-
],
483-
),
468+
self.publish_diagnostics(
469+
document,
470+
diagnostics=[l for l in itertools.chain(*[i for i in data.entries.values() if i is not None])],
484471
)
485472

486473
except asyncio.CancelledError:
@@ -489,6 +476,16 @@ async def _get_diagnostics_for_document(
489476
for k in set(data.entries.keys()) - set(collected_keys):
490477
data.entries.pop(k)
491478

479+
def publish_diagnostics(self, document: TextDocument, diagnostics: List[Diagnostic]) -> None:
480+
self.parent.send_notification(
481+
"textDocument/publishDiagnostics",
482+
PublishDiagnosticsParams(
483+
uri=document.document_uri,
484+
version=document.version,
485+
diagnostics=diagnostics,
486+
),
487+
)
488+
492489
@rpc_method(name="textDocument/diagnostic", param_type=DocumentDiagnosticParams)
493490
@threaded()
494491
async def _text_document_diagnostic(

Diff for: src/robotcode/cli/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
"--debugpy",
114114
is_flag=True,
115115
hidden=show_hidden_arguments(),
116+
show_envvar=True,
116117
help="Starts a debugpy session. "
117118
"**This is an internal option and should only be use if you want to debug _RobotCode_.**",
118119
)
@@ -121,6 +122,7 @@
121122
type=int,
122123
default=5678,
123124
show_default=True,
125+
show_envvar=True,
124126
hidden=show_hidden_arguments(),
125127
help="Defines the port to use for the debugpy session.",
126128
)

0 commit comments

Comments
 (0)