Skip to content

Commit 8495c8a

Browse files
committed
more refactorings and code cleanup
1 parent e3b7827 commit 8495c8a

File tree

6 files changed

+43
-39
lines changed

6 files changed

+43
-39
lines changed

robotcode/language_server/robotframework/parts/formatting.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,7 @@
77

88
from ....utils.logging import LoggingDescriptor
99
from ...common.language import language_id
10-
from ...common.lsp_types import (
11-
FormattingOptions,
12-
MessageType,
13-
Position,
14-
Range,
15-
TextEdit,
16-
)
10+
from ...common.lsp_types import FormattingOptions, Position, Range, TextEdit
1711
from ...common.text_document import TextDocument
1812

1913
if TYPE_CHECKING:
@@ -115,7 +109,7 @@ async def format_robot_tidy(
115109
except (SystemExit, KeyboardInterrupt, asyncio.CancelledError):
116110
raise
117111
except BaseException as e:
118-
self.parent.window.show_message(str(e), MessageType.Error)
112+
self._logger.exception(e)
119113
return None
120114

121115
async def format_internal(

robotcode/language_server/robotframework/parts/robocop_diagnostics.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ async def collect_diagnostics(self, sender: Any, document: TextDocument) -> Diag
6161
return DiagnosticsResult(self.collect_diagnostics, result)
6262
except (SystemExit, KeyboardInterrupt, asyncio.CancelledError):
6363
raise
64-
except BaseException:
65-
pass
64+
except BaseException as e:
65+
self._logger.exception(e)
6666

6767
return DiagnosticsResult(self.collect_diagnostics, [])
6868

vscode-client/extension.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,15 @@ export async function activateAsync(context: vscode.ExtensionContext): Promise<v
3232
testControllerManger,
3333

3434
vscode.window.registerTerminalLinkProvider({
35-
provideTerminalLinks(context: vscode.TerminalLinkContext, _token: vscode.CancellationToken) {
36-
if ((context.line.startsWith("Log:") || context.line.startsWith("Report:")) && context.line.endsWith("html")) {
37-
const result = /(Log|Report):\s*(?<link>\S.*)/.exec(context.line)?.groups?.link;
35+
provideTerminalLinks(terminalContext: vscode.TerminalLinkContext, _token: vscode.CancellationToken) {
36+
if (
37+
(terminalContext.line.startsWith("Log:") || terminalContext.line.startsWith("Report:")) &&
38+
terminalContext.line.endsWith("html")
39+
) {
40+
const result = /(Log|Report):\s*(?<link>\S.*)/.exec(terminalContext.line)?.groups?.link;
3841

3942
if (result) {
40-
return [new TerminalLink(result, context.line.indexOf(result), result.length, "Open report.")];
43+
return [new TerminalLink(result, terminalContext.line.indexOf(result), result.length, "Open report.")];
4144
}
4245
}
4346

@@ -79,9 +82,9 @@ function displayProgress<R>(promise: Promise<R>): Thenable<R> {
7982
}
8083

8184
export async function activate(context: vscode.ExtensionContext): Promise<void> {
82-
return await displayProgress(activateAsync(context));
85+
return displayProgress(activateAsync(context));
8386
}
8487

8588
export async function deactivate(): Promise<void> {
86-
return await languageClientManger.stopAllClients();
89+
return languageClientManger.stopAllClients();
8790
}

vscode-client/languageclientsmanger.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ export class LanguageClientsManager {
4444
public readonly outputChannel: vscode.OutputChannel
4545
) {
4646
this._disposables = vscode.Disposable.from(
47-
this.pythonManager.pythonExtension?.exports.settings.onDidChangeExecutionDetails(
48-
async (_event) => await this.refresh()
47+
this.pythonManager.pythonExtension?.exports.settings.onDidChangeExecutionDetails(async (_event) =>
48+
this.refresh()
4949
) ?? {
5050
dispose() {
5151
//empty
5252
},
5353
},
54-
vscode.workspace.onDidChangeWorkspaceFolders(async (_event) => await this.refresh()),
55-
vscode.workspace.onDidOpenTextDocument(async (document) => await this.getLanguageClientForDocument(document))
54+
vscode.workspace.onDidChangeWorkspaceFolders(async (_event) => this.refresh()),
55+
vscode.workspace.onDidOpenTextDocument(async (document) => this.getLanguageClientForDocument(document))
5656
);
5757
}
5858

@@ -70,7 +70,10 @@ export class LanguageClientsManager {
7070
}
7171

7272
dispose(): void {
73-
void this.stopAllClients().then();
73+
this.stopAllClients().then(
74+
(_) => undefined,
75+
(_) => undefined
76+
);
7477

7578
this._disposables.dispose();
7679
}
@@ -127,11 +130,11 @@ export class LanguageClientsManager {
127130
public async getLanguageClientForDocument(document: vscode.TextDocument): Promise<LanguageClient | undefined> {
128131
if (document.languageId !== "robotframework") return;
129132

130-
return await this.getLanguageClientForResource(document.uri);
133+
return this.getLanguageClientForResource(document.uri);
131134
}
132135

133136
public async getLanguageClientForResource(resource: string | vscode.Uri): Promise<LanguageClient | undefined> {
134-
return await this.clientsMutex.dispatch(async () => {
137+
return this.clientsMutex.dispatch(async () => {
135138
const uri = resource instanceof vscode.Uri ? resource : vscode.Uri.parse(resource);
136139
const workspaceFolder = vscode.workspace.getWorkspaceFolder(uri);
137140

@@ -232,25 +235,23 @@ export class LanguageClientsManager {
232235

233236
if (!client) return;
234237

235-
const result =
238+
return (
236239
(await client.sendRequest<RobotTestItem[]>("robot/discovering/getTestsFromWorkspace", {
237240
paths: paths ?? ["."],
238-
})) ?? undefined;
239-
240-
return result;
241+
})) ?? undefined
242+
);
241243
}
242244

243245
public async getTestsFromDocument(document: vscode.TextDocument, id?: string): Promise<RobotTestItem[] | undefined> {
244246
const client = await this.getLanguageClientForResource(document.uri);
245247

246248
if (!client) return;
247249

248-
const result =
250+
return (
249251
(await client.sendRequest<RobotTestItem[]>("robot/discovering/getTestsFromDocument", {
250252
textDocument: { uri: document.uri.toString() },
251253
id: id,
252-
})) ?? undefined;
253-
254-
return result;
254+
})) ?? undefined
255+
);
255256
}
256257
}

vscode-client/pythonmanger.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,17 @@ export class PythonManager {
9898
try {
9999
this._pythonExtension = vscode.extensions.getExtension("ms-python.python")!;
100100

101-
void this._pythonExtension.activate().then();
101+
this._pythonExtension.activate().then(
102+
(_) => undefined,
103+
(_) => undefined
104+
);
102105

103106
this.outputChannel.appendLine("Python Extension is active");
104107

105-
void this._pythonExtension.exports.ready.then();
108+
this._pythonExtension.exports.ready.then(
109+
(_) => undefined,
110+
(_) => undefined
111+
);
106112
} catch (ex) {
107113
this.outputChannel.appendLine("can't activate python extension");
108114
}

vscode-client/testcontrollermanager.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,21 @@ export class TestControllerManager {
6363
this.runProfile = this.testController.createRunProfile(
6464
"Run Tests",
6565
vscode.TestRunProfileKind.Run,
66-
async (request, token) => await this.runTests(request, token)
66+
async (request, token) => this.runTests(request, token)
6767
);
6868

6969
this.debugProfile = this.testController.createRunProfile(
7070
"Debug",
7171
vscode.TestRunProfileKind.Debug,
72-
async (request, token) => await this.runTests(request, token)
72+
async (request, token) => this.runTests(request, token)
7373
);
7474

75-
this.testController.resolveHandler = async (item) => await this.refresh(item);
75+
this.testController.resolveHandler = async (item) => this.refresh(item);
7676

7777
const fileWatcher = vscode.workspace.createFileSystemWatcher("**/*");
78-
fileWatcher.onDidCreate(async (uri) => await this.refreshFromUri(uri, "create"));
79-
fileWatcher.onDidDelete(async (uri) => await this.refreshFromUri(uri, "delete"));
80-
fileWatcher.onDidChange(async (uri) => await this.refreshFromUri(uri, "change"));
78+
fileWatcher.onDidCreate(async (uri) => this.refreshFromUri(uri, "create"));
79+
fileWatcher.onDidDelete(async (uri) => this.refreshFromUri(uri, "delete"));
80+
fileWatcher.onDidChange(async (uri) => this.refreshFromUri(uri, "change"));
8181

8282
this._disposables = vscode.Disposable.from(
8383
fileWatcher,

0 commit comments

Comments
 (0)