Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'editors/code/src/client.ts')
-rw-r--r--editors/code/src/client.ts67
1 files changed, 35 insertions, 32 deletions
diff --git a/editors/code/src/client.ts b/editors/code/src/client.ts
index 35a114fb04..ba8546763e 100644
--- a/editors/code/src/client.ts
+++ b/editors/code/src/client.ts
@@ -34,21 +34,24 @@ export const LINKED_COMMANDS = new Map<string, ra.CommandLink>();
// add code to remove a target command from the map after the link is
// clicked, but assuming most links in hover sheets won't be clicked anyway
// this code won't change the overall memory use much.
-setInterval(function cleanupOlderCommandLinks() {
- // keys are returned in insertion order, we'll keep a few
- // of recent keys available, and clean the rest
- const keys = [...LINKED_COMMANDS.keys()];
- const keysToRemove = keys.slice(0, keys.length - 10);
- for (const key of keysToRemove) {
- LINKED_COMMANDS.delete(key);
- }
-}, 10 * 60 * 1000);
+setInterval(
+ function cleanupOlderCommandLinks() {
+ // keys are returned in insertion order, we'll keep a few
+ // of recent keys available, and clean the rest
+ const keys = [...LINKED_COMMANDS.keys()];
+ const keysToRemove = keys.slice(0, keys.length - 10);
+ for (const key of keysToRemove) {
+ LINKED_COMMANDS.delete(key);
+ }
+ },
+ 10 * 60 * 1000,
+);
function renderCommand(cmd: ra.CommandLink): string {
const commandId = randomUUID();
LINKED_COMMANDS.set(commandId, cmd);
return `[${cmd.title}](command:rust-analyzer.linkToCommand?${encodeURIComponent(
- JSON.stringify([commandId])
+ JSON.stringify([commandId]),
)} '${cmd.tooltip}')`;
}
@@ -57,7 +60,7 @@ function renderHoverActions(actions: ra.CommandLinkGroup[]): vscode.MarkdownStri
.map(
(group) =>
(group.title ? group.title + " " : "") +
- group.commands.map(renderCommand).join(" | ")
+ group.commands.map(renderCommand).join(" | "),
)
.join("___");
@@ -72,7 +75,7 @@ export async function createClient(
initializationOptions: vscode.WorkspaceConfiguration,
serverOptions: lc.ServerOptions,
config: Config,
- unlinkedFiles: vscode.Uri[]
+ unlinkedFiles: vscode.Uri[],
): Promise<lc.LanguageClient> {
const clientOptions: lc.LanguageClientOptions = {
documentSelector: [{ scheme: "file", language: "rust" }],
@@ -93,7 +96,7 @@ export async function createClient(
async configuration(
params: lc.ConfigurationParams,
token: vscode.CancellationToken,
- next: lc.ConfigurationRequest.HandlerSignature
+ next: lc.ConfigurationRequest.HandlerSignature,
) {
const resp = await next(params, token);
if (resp && Array.isArray(resp)) {
@@ -117,7 +120,7 @@ export async function createClient(
async handleDiagnostics(
uri: vscode.Uri,
diagnosticList: vscode.Diagnostic[],
- next: lc.HandleDiagnosticsSignature
+ next: lc.HandleDiagnosticsSignature,
) {
const preview = config.previewRustcOutput;
const errorCode = config.useRustcErrorCode;
@@ -137,20 +140,20 @@ export async function createClient(
const folder = vscode.workspace.getWorkspaceFolder(uri)?.uri.fsPath;
if (folder) {
const parentBackslash = uri.fsPath.lastIndexOf(
- pathSeparator + "src"
+ pathSeparator + "src",
);
const parent = uri.fsPath.substring(0, parentBackslash);
if (parent.startsWith(folder)) {
const path = vscode.Uri.file(
- parent + pathSeparator + "Cargo.toml"
+ parent + pathSeparator + "Cargo.toml",
);
void vscode.workspace.fs.stat(path).then(async () => {
const choice = await vscode.window.showInformationMessage(
`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?`,
"Yes",
"No",
- "Don't show this again"
+ "Don't show this again",
);
switch (choice) {
case undefined:
@@ -168,14 +171,14 @@ export async function createClient(
config
.get<any[]>("linkedProjects")
?.concat(pathToInsert),
- false
+ false,
);
break;
case "Don't show this again":
await config.update(
"showUnlinkedFileNotification",
false,
- false
+ false,
);
break;
}
@@ -222,7 +225,7 @@ export async function createClient(
document: vscode.TextDocument,
position: vscode.Position,
token: vscode.CancellationToken,
- _next: lc.ProvideHoverSignature
+ _next: lc.ProvideHoverSignature,
) {
const editor = vscode.window.activeTextEditor;
const positionOrRange = editor?.selection?.contains(position)
@@ -236,7 +239,7 @@ export async function createClient(
client.code2ProtocolConverter.asTextDocumentIdentifier(document),
position: positionOrRange,
},
- token
+ token,
)
.then(
(result) => {
@@ -250,7 +253,7 @@ export async function createClient(
(error) => {
client.handleFailedRequest(lc.HoverRequest.type, token, error, null);
return Promise.resolve(null);
- }
+ },
);
},
// Using custom handling of CodeActions to support action groups and snippet edits.
@@ -260,14 +263,14 @@ export async function createClient(
range: vscode.Range,
context: vscode.CodeActionContext,
token: vscode.CancellationToken,
- _next: lc.ProvideCodeActionsSignature
+ _next: lc.ProvideCodeActionsSignature,
) {
const params: lc.CodeActionParams = {
textDocument: client.code2ProtocolConverter.asTextDocumentIdentifier(document),
range: client.code2ProtocolConverter.asRange(range),
context: await client.code2ProtocolConverter.asCodeActionContext(
context,
- token
+ token,
),
};
return client.sendRequest(lc.CodeActionRequest.type, params, token).then(
@@ -283,21 +286,21 @@ export async function createClient(
if (lc.CodeAction.is(item)) {
assert(
!item.command,
- "We don't expect to receive commands in CodeActions"
+ "We don't expect to receive commands in CodeActions",
);
const action = await client.protocol2CodeConverter.asCodeAction(
item,
- token
+ token,
);
result.push(action);
continue;
}
assert(
isCodeActionWithoutEditsAndCommands(item),
- "We don't expect edits or commands here"
+ "We don't expect edits or commands here",
);
const kind = client.protocol2CodeConverter.asCodeActionKind(
- (item as any).kind
+ (item as any).kind,
);
const action = new vscode.CodeAction(item.title, kind);
const group = (item as any).group;
@@ -351,7 +354,7 @@ export async function createClient(
}
return result;
},
- (_error) => undefined
+ (_error) => undefined,
);
},
},
@@ -364,7 +367,7 @@ export async function createClient(
"rust-analyzer",
"Rust Analyzer Language Server",
serverOptions,
- clientOptions
+ clientOptions,
);
// To turn on all proposed features use: client.registerProposedFeatures();
@@ -400,7 +403,7 @@ class ExperimentalFeatures implements lc.StaticFeature {
}
initialize(
_capabilities: lc.ServerCapabilities,
- _documentSelector: lc.DocumentSelector | undefined
+ _documentSelector: lc.DocumentSelector | undefined,
): void {}
dispose(): void {}
}
@@ -419,7 +422,7 @@ class OverrideFeatures implements lc.StaticFeature {
}
initialize(
_capabilities: lc.ServerCapabilities,
- _documentSelector: lc.DocumentSelector | undefined
+ _documentSelector: lc.DocumentSelector | undefined,
): void {}
dispose(): void {}
}