Skip to content

Commit f7823f3

Browse files
editor/code: Re-apply code format
1 parent 9d06aa5 commit f7823f3

17 files changed

+180
-175
lines changed

editors/code/src/ast_inspector.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,23 @@ export class AstInspector implements vscode.HoverProvider, vscode.DefinitionProv
3737

3838
constructor(ctx: Ctx) {
3939
ctx.pushExtCleanup(
40-
vscode.languages.registerHoverProvider({ scheme: "rust-analyzer" }, this)
40+
vscode.languages.registerHoverProvider({ scheme: "rust-analyzer" }, this),
4141
);
4242
ctx.pushExtCleanup(vscode.languages.registerDefinitionProvider({ language: "rust" }, this));
4343
vscode.workspace.onDidCloseTextDocument(
4444
this.onDidCloseTextDocument,
4545
this,
46-
ctx.subscriptions
46+
ctx.subscriptions,
4747
);
4848
vscode.workspace.onDidChangeTextDocument(
4949
this.onDidChangeTextDocument,
5050
this,
51-
ctx.subscriptions
51+
ctx.subscriptions,
5252
);
5353
vscode.window.onDidChangeVisibleTextEditors(
5454
this.onDidChangeVisibleTextEditors,
5555
this,
56-
ctx.subscriptions
56+
ctx.subscriptions,
5757
);
5858
}
5959
dispose() {
@@ -85,7 +85,7 @@ export class AstInspector implements vscode.HoverProvider, vscode.DefinitionProv
8585

8686
private findAstTextEditor(): undefined | vscode.TextEditor {
8787
return vscode.window.visibleTextEditors.find(
88-
(it) => it.document.uri.scheme === "rust-analyzer"
88+
(it) => it.document.uri.scheme === "rust-analyzer",
8989
);
9090
}
9191

@@ -100,7 +100,7 @@ export class AstInspector implements vscode.HoverProvider, vscode.DefinitionProv
100100
// additional positional params are omitted
101101
provideDefinition(
102102
doc: vscode.TextDocument,
103-
pos: vscode.Position
103+
pos: vscode.Position,
104104
): vscode.ProviderResult<vscode.DefinitionLink[]> {
105105
if (!this.rustEditor || doc.uri.toString() !== this.rustEditor.document.uri.toString()) {
106106
return;
@@ -132,7 +132,7 @@ export class AstInspector implements vscode.HoverProvider, vscode.DefinitionProv
132132
// additional positional params are omitted
133133
provideHover(
134134
doc: vscode.TextDocument,
135-
hoverPosition: vscode.Position
135+
hoverPosition: vscode.Position,
136136
): vscode.ProviderResult<vscode.Hover> {
137137
if (!this.rustEditor) return;
138138

@@ -159,7 +159,7 @@ export class AstInspector implements vscode.HoverProvider, vscode.DefinitionProv
159159

160160
private parseRustTextRange(
161161
doc: vscode.TextDocument,
162-
astLine: string
162+
astLine: string,
163163
): undefined | vscode.Range {
164164
const parsedRange = /(\d+)\.\.(\d+)/.exec(astLine);
165165
if (!parsedRange) return;

editors/code/src/bootstrap.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import { exec } from "child_process";
88
export async function bootstrap(
99
context: vscode.ExtensionContext,
1010
config: Config,
11-
state: PersistentState
11+
state: PersistentState,
1212
): Promise<string> {
1313
const path = await getServer(context, config, state);
1414
if (!path) {
1515
throw new Error(
1616
"Rust Analyzer Language Server is not available. " +
17-
"Please, ensure its [proper installation](https://rust-analyzer.github.io/manual.html#installation)."
17+
"Please, ensure its [proper installation](https://rust-analyzer.github.io/manual.html#installation).",
1818
);
1919
}
2020

@@ -34,7 +34,7 @@ export async function bootstrap(
3434
async function getServer(
3535
context: vscode.ExtensionContext,
3636
config: Config,
37-
state: PersistentState
37+
state: PersistentState,
3838
): Promise<string | undefined> {
3939
const explicitPath = process.env["__RA_LSP_SERVER_DEBUG"] ?? config.serverPath;
4040
if (explicitPath) {
@@ -49,7 +49,7 @@ async function getServer(
4949
const bundled = vscode.Uri.joinPath(context.extensionUri, "server", `rust-analyzer${ext}`);
5050
const bundledExists = await vscode.workspace.fs.stat(bundled).then(
5151
() => true,
52-
() => false
52+
() => false,
5353
);
5454
if (bundledExists) {
5555
let server = bundled;
@@ -58,7 +58,7 @@ async function getServer(
5858
const dest = vscode.Uri.joinPath(config.globalStorageUri, `rust-analyzer${ext}`);
5959
let exists = await vscode.workspace.fs.stat(dest).then(
6060
() => true,
61-
() => false
61+
() => false,
6262
);
6363
if (exists && config.package.version !== state.serverVersion) {
6464
await vscode.workspace.fs.delete(dest);
@@ -81,7 +81,7 @@ async function getServer(
8181
"run `cargo xtask install --server` to build the language server from sources. " +
8282
"If you feel that your platform should be supported, please create an issue " +
8383
"about that [here](https://github.com/rust-lang/rust-analyzer/issues) and we " +
84-
"will consider it."
84+
"will consider it.",
8585
);
8686
return undefined;
8787
}
@@ -131,14 +131,14 @@ async function patchelf(dest: vscode.Uri): Promise<void> {
131131
} else {
132132
resolve(stdout);
133133
}
134-
}
134+
},
135135
);
136136
handle.stdin?.write(expression);
137137
handle.stdin?.end();
138138
});
139139
} finally {
140140
await vscode.workspace.fs.delete(origFile);
141141
}
142-
}
142+
},
143143
);
144144
}

editors/code/src/client.ts

+35-32
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,24 @@ export const LINKED_COMMANDS = new Map<string, ra.CommandLink>();
3434
// add code to remove a target command from the map after the link is
3535
// clicked, but assuming most links in hover sheets won't be clicked anyway
3636
// this code won't change the overall memory use much.
37-
setInterval(function cleanupOlderCommandLinks() {
38-
// keys are returned in insertion order, we'll keep a few
39-
// of recent keys available, and clean the rest
40-
const keys = [...LINKED_COMMANDS.keys()];
41-
const keysToRemove = keys.slice(0, keys.length - 10);
42-
for (const key of keysToRemove) {
43-
LINKED_COMMANDS.delete(key);
44-
}
45-
}, 10 * 60 * 1000);
37+
setInterval(
38+
function cleanupOlderCommandLinks() {
39+
// keys are returned in insertion order, we'll keep a few
40+
// of recent keys available, and clean the rest
41+
const keys = [...LINKED_COMMANDS.keys()];
42+
const keysToRemove = keys.slice(0, keys.length - 10);
43+
for (const key of keysToRemove) {
44+
LINKED_COMMANDS.delete(key);
45+
}
46+
},
47+
10 * 60 * 1000,
48+
);
4649

4750
function renderCommand(cmd: ra.CommandLink): string {
4851
const commandId = randomUUID();
4952
LINKED_COMMANDS.set(commandId, cmd);
5053
return `[${cmd.title}](command:rust-analyzer.linkToCommand?${encodeURIComponent(
51-
JSON.stringify([commandId])
54+
JSON.stringify([commandId]),
5255
)} '${cmd.tooltip}')`;
5356
}
5457

@@ -57,7 +60,7 @@ function renderHoverActions(actions: ra.CommandLinkGroup[]): vscode.MarkdownStri
5760
.map(
5861
(group) =>
5962
(group.title ? group.title + " " : "") +
60-
group.commands.map(renderCommand).join(" | ")
63+
group.commands.map(renderCommand).join(" | "),
6164
)
6265
.join("___");
6366

@@ -72,7 +75,7 @@ export async function createClient(
7275
initializationOptions: vscode.WorkspaceConfiguration,
7376
serverOptions: lc.ServerOptions,
7477
config: Config,
75-
unlinkedFiles: vscode.Uri[]
78+
unlinkedFiles: vscode.Uri[],
7679
): Promise<lc.LanguageClient> {
7780
const clientOptions: lc.LanguageClientOptions = {
7881
documentSelector: [{ scheme: "file", language: "rust" }],
@@ -93,7 +96,7 @@ export async function createClient(
9396
async configuration(
9497
params: lc.ConfigurationParams,
9598
token: vscode.CancellationToken,
96-
next: lc.ConfigurationRequest.HandlerSignature
99+
next: lc.ConfigurationRequest.HandlerSignature,
97100
) {
98101
const resp = await next(params, token);
99102
if (resp && Array.isArray(resp)) {
@@ -117,7 +120,7 @@ export async function createClient(
117120
async handleDiagnostics(
118121
uri: vscode.Uri,
119122
diagnosticList: vscode.Diagnostic[],
120-
next: lc.HandleDiagnosticsSignature
123+
next: lc.HandleDiagnosticsSignature,
121124
) {
122125
const preview = config.previewRustcOutput;
123126
const errorCode = config.useRustcErrorCode;
@@ -137,20 +140,20 @@ export async function createClient(
137140
const folder = vscode.workspace.getWorkspaceFolder(uri)?.uri.fsPath;
138141
if (folder) {
139142
const parentBackslash = uri.fsPath.lastIndexOf(
140-
pathSeparator + "src"
143+
pathSeparator + "src",
141144
);
142145
const parent = uri.fsPath.substring(0, parentBackslash);
143146

144147
if (parent.startsWith(folder)) {
145148
const path = vscode.Uri.file(
146-
parent + pathSeparator + "Cargo.toml"
149+
parent + pathSeparator + "Cargo.toml",
147150
);
148151
void vscode.workspace.fs.stat(path).then(async () => {
149152
const choice = await vscode.window.showInformationMessage(
150153
`This rust file does not belong to a loaded cargo project. It looks like it might belong to the workspace at ${path.path}, do you want to add it to the linked Projects?`,
151154
"Yes",
152155
"No",
153-
"Don't show this again"
156+
"Don't show this again",
154157
);
155158
switch (choice) {
156159
case undefined:
@@ -168,14 +171,14 @@ export async function createClient(
168171
config
169172
.get<any[]>("linkedProjects")
170173
?.concat(pathToInsert),
171-
false
174+
false,
172175
);
173176
break;
174177
case "Don't show this again":
175178
await config.update(
176179
"showUnlinkedFileNotification",
177180
false,
178-
false
181+
false,
179182
);
180183
break;
181184
}
@@ -222,7 +225,7 @@ export async function createClient(
222225
document: vscode.TextDocument,
223226
position: vscode.Position,
224227
token: vscode.CancellationToken,
225-
_next: lc.ProvideHoverSignature
228+
_next: lc.ProvideHoverSignature,
226229
) {
227230
const editor = vscode.window.activeTextEditor;
228231
const positionOrRange = editor?.selection?.contains(position)
@@ -236,7 +239,7 @@ export async function createClient(
236239
client.code2ProtocolConverter.asTextDocumentIdentifier(document),
237240
position: positionOrRange,
238241
},
239-
token
242+
token,
240243
)
241244
.then(
242245
(result) => {
@@ -250,7 +253,7 @@ export async function createClient(
250253
(error) => {
251254
client.handleFailedRequest(lc.HoverRequest.type, token, error, null);
252255
return Promise.resolve(null);
253-
}
256+
},
254257
);
255258
},
256259
// Using custom handling of CodeActions to support action groups and snippet edits.
@@ -260,14 +263,14 @@ export async function createClient(
260263
range: vscode.Range,
261264
context: vscode.CodeActionContext,
262265
token: vscode.CancellationToken,
263-
_next: lc.ProvideCodeActionsSignature
266+
_next: lc.ProvideCodeActionsSignature,
264267
) {
265268
const params: lc.CodeActionParams = {
266269
textDocument: client.code2ProtocolConverter.asTextDocumentIdentifier(document),
267270
range: client.code2ProtocolConverter.asRange(range),
268271
context: await client.code2ProtocolConverter.asCodeActionContext(
269272
context,
270-
token
273+
token,
271274
),
272275
};
273276
return client.sendRequest(lc.CodeActionRequest.type, params, token).then(
@@ -283,21 +286,21 @@ export async function createClient(
283286
if (lc.CodeAction.is(item)) {
284287
assert(
285288
!item.command,
286-
"We don't expect to receive commands in CodeActions"
289+
"We don't expect to receive commands in CodeActions",
287290
);
288291
const action = await client.protocol2CodeConverter.asCodeAction(
289292
item,
290-
token
293+
token,
291294
);
292295
result.push(action);
293296
continue;
294297
}
295298
assert(
296299
isCodeActionWithoutEditsAndCommands(item),
297-
"We don't expect edits or commands here"
300+
"We don't expect edits or commands here",
298301
);
299302
const kind = client.protocol2CodeConverter.asCodeActionKind(
300-
(item as any).kind
303+
(item as any).kind,
301304
);
302305
const action = new vscode.CodeAction(item.title, kind);
303306
const group = (item as any).group;
@@ -351,7 +354,7 @@ export async function createClient(
351354
}
352355
return result;
353356
},
354-
(_error) => undefined
357+
(_error) => undefined,
355358
);
356359
},
357360
},
@@ -364,7 +367,7 @@ export async function createClient(
364367
"rust-analyzer",
365368
"Rust Analyzer Language Server",
366369
serverOptions,
367-
clientOptions
370+
clientOptions,
368371
);
369372

370373
// To turn on all proposed features use: client.registerProposedFeatures();
@@ -400,7 +403,7 @@ class ExperimentalFeatures implements lc.StaticFeature {
400403
}
401404
initialize(
402405
_capabilities: lc.ServerCapabilities,
403-
_documentSelector: lc.DocumentSelector | undefined
406+
_documentSelector: lc.DocumentSelector | undefined,
404407
): void {}
405408
dispose(): void {}
406409
}
@@ -419,7 +422,7 @@ class OverrideFeatures implements lc.StaticFeature {
419422
}
420423
initialize(
421424
_capabilities: lc.ServerCapabilities,
422-
_documentSelector: lc.DocumentSelector | undefined
425+
_documentSelector: lc.DocumentSelector | undefined,
423426
): void {}
424427
dispose(): void {}
425428
}

0 commit comments

Comments
 (0)