Skip to content

Commit 76adcc4

Browse files
committed
implement cancelation of discovering requests
1 parent e30e89b commit 76adcc4

File tree

5 files changed

+181
-144
lines changed

5 files changed

+181
-144
lines changed

log.ini

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
[loggers]
2-
keys: root,server,language_server,language_server_parts,jsonrpc2,jsonrpc2_message,robotframework,debugger, debugger_launcher, asyncio, robotcode_utils
2+
#keys: root,server,language_server,language_server_parts,jsonrpc2,jsonrpc2_message,robotframework,debugger, debugger_launcher, asyncio, robotcode_utils
33
#keys: root,server,language_server,language_server_parts,robotframework,debugger, debugger_launcher, asyncio, robotcode_utils
44
#keys: root,server,robotframework,language_server,language_server_parts
55
#keys: root, asyncio, robotcode_utils
66
#keys: root, robotcode_utils
77
#keys: root, diagnostics, document, jsonrpc2, jsonrpc2_message
88
#keys: root, diagnostics, robot_diagnostics, robocop_diagnostics
9+
keys: root, discovering
910
#keys: root
1011

1112
[formatters]
@@ -125,4 +126,8 @@ level: TRACE
125126
handlers:
126127
qualname: robotcode.language_server.common.text_document
127128

129+
[logger_discovering]
130+
level: TRACE
131+
handlers:
132+
qualname: robotcode.language_server.robotframework.parts.discovering
128133

robotcode/language_server/common/parts/diagnostics.py

Lines changed: 38 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -218,54 +218,44 @@ async def start_publish_diagnostics_task(self, document: TextDocument) -> None:
218218

219219
@_logger.call(entering=True, exiting=True, exception=True)
220220
async def publish_diagnostics(self, document_uri: DocumentUri, cancelation_token: CancelationToken) -> None:
221-
self._logger.debug("start publish_diagnostics")
222-
try:
223-
document = await self.parent.documents.get(document_uri)
224-
if document is None:
225-
return
221+
document = await self.parent.documents.get(document_uri)
222+
if document is None:
223+
return
226224

227-
diagnostics: Dict[Any, List[Diagnostic]] = document.get_data(self, {})
225+
diagnostics: Dict[Any, List[Diagnostic]] = document.get_data(self, {})
228226

229-
collected_keys: List[Any] = []
227+
collected_keys: List[Any] = []
230228

231-
async for result_any in self.collect(
232-
self,
233-
document,
234-
cancelation_token,
235-
callback_filter=language_id_filter(document),
236-
return_exceptions=True,
237-
):
238-
await check_canceled()
239-
240-
result = cast(DiagnosticsResult, result_any)
241-
242-
if isinstance(result, BaseException):
243-
if not isinstance(result, asyncio.CancelledError):
244-
self._logger.exception(result, exc_info=result)
245-
else:
246-
247-
diagnostics[result.key] = result.diagnostics if result.diagnostics else []
248-
collected_keys.append(result.key)
249-
250-
asyncio.get_event_loop().call_soon(
251-
self.parent.send_notification,
252-
"textDocument/publishDiagnostics",
253-
PublishDiagnosticsParams(
254-
uri=document.document_uri,
255-
version=document._version,
256-
diagnostics=[e for e in itertools.chain(*diagnostics.values())],
257-
),
258-
)
259-
260-
for k in set(diagnostics.keys()) - set(collected_keys):
261-
diagnostics.pop(k)
262-
263-
document.set_data(self, diagnostics)
264-
except asyncio.CancelledError:
265-
self._logger.debug("canceled publish_diagnostics")
266-
raise
267-
except BaseException as e:
268-
self._logger.exception(e)
269-
raise
270-
finally:
271-
self._logger.debug("end publish_diagnostics")
229+
async for result_any in self.collect(
230+
self,
231+
document,
232+
cancelation_token,
233+
callback_filter=language_id_filter(document),
234+
return_exceptions=True,
235+
):
236+
await check_canceled()
237+
238+
result = cast(DiagnosticsResult, result_any)
239+
240+
if isinstance(result, BaseException):
241+
if not isinstance(result, asyncio.CancelledError):
242+
self._logger.exception(result, exc_info=result)
243+
else:
244+
245+
diagnostics[result.key] = result.diagnostics if result.diagnostics else []
246+
collected_keys.append(result.key)
247+
248+
asyncio.get_event_loop().call_soon(
249+
self.parent.send_notification,
250+
"textDocument/publishDiagnostics",
251+
PublishDiagnosticsParams(
252+
uri=document.document_uri,
253+
version=document._version,
254+
diagnostics=[e for e in itertools.chain(*diagnostics.values())],
255+
),
256+
)
257+
258+
for k in set(diagnostics.keys()) - set(collected_keys):
259+
diagnostics.pop(k)
260+
261+
document.set_data(self, diagnostics)

robotcode/language_server/robotframework/diagnostics/imports_manager.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,10 @@ async def get_libdoc(self) -> LibraryDoc:
363363

364364

365365
def _shutdown_process_pool(pool: ProcessPoolExecutor) -> None:
366-
pool.shutdown(True)
366+
try:
367+
pool.shutdown(True)
368+
except BaseException: # NOSONAR
369+
pass
367370

368371

369372
# we need this, because ProcessPoolExecutor is not correctly initialized if asyncio is reading from stdin

vscode-client/languageclientsmanger.ts

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -229,30 +229,53 @@ export class LanguageClientsManager {
229229

230230
public async getTestsFromWorkspace(
231231
workspaceFolder: vscode.WorkspaceFolder,
232-
paths?: Array<string>
232+
paths?: Array<string>,
233+
token?: vscode.CancellationToken
233234
): Promise<RobotTestItem[] | undefined> {
234235
const client = await this.getLanguageClientForResource(workspaceFolder.uri);
235236

236237
if (!client) return;
237238

238239
return (
239-
(await client.sendRequest<RobotTestItem[]>("robot/discovering/getTestsFromWorkspace", {
240-
workspaceFolder: workspaceFolder.uri.toString(),
241-
paths: paths ?? ["."],
242-
})) ?? undefined
240+
(token
241+
? await client.sendRequest<RobotTestItem[]>(
242+
"robot/discovering/getTestsFromWorkspace",
243+
{
244+
workspaceFolder: workspaceFolder.uri.toString(),
245+
paths: paths ?? ["."],
246+
},
247+
token
248+
)
249+
: await client.sendRequest<RobotTestItem[]>("robot/discovering/getTestsFromWorkspace", {
250+
workspaceFolder: workspaceFolder.uri.toString(),
251+
paths: paths ?? ["."],
252+
})) ?? undefined
243253
);
244254
}
245255

246-
public async getTestsFromDocument(document: vscode.TextDocument, id?: string): Promise<RobotTestItem[] | undefined> {
256+
public async getTestsFromDocument(
257+
document: vscode.TextDocument,
258+
id?: string,
259+
token?: vscode.CancellationToken
260+
): Promise<RobotTestItem[] | undefined> {
247261
const client = await this.getLanguageClientForResource(document.uri);
248262

249263
if (!client) return;
250264

251265
return (
252-
(await client.sendRequest<RobotTestItem[]>("robot/discovering/getTestsFromDocument", {
253-
textDocument: { uri: document.uri.toString() },
254-
id: id,
255-
})) ?? undefined
266+
(token
267+
? await client.sendRequest<RobotTestItem[]>(
268+
"robot/discovering/getTestsFromDocument",
269+
{
270+
textDocument: { uri: document.uri.toString() },
271+
id: id,
272+
},
273+
token
274+
)
275+
: await client.sendRequest<RobotTestItem[]>("robot/discovering/getTestsFromDocument", {
276+
textDocument: { uri: document.uri.toString() },
277+
id: id,
278+
})) ?? undefined
256279
);
257280
}
258281
}

0 commit comments

Comments
 (0)