Merge commit '3b7c7f97e4' into sync-from-ra

This commit is contained in:
Laurențiu Nicola 2023-11-08 08:15:03 +02:00
parent 6eaf3f8bb2
commit d1d111d09e
177 changed files with 14930 additions and 2099 deletions

View file

@ -389,6 +389,7 @@ class ExperimentalFeatures implements lc.StaticFeature {
serverStatusNotification: true,
colorDiagnosticOutput: true,
openServerLogs: true,
localDocs: true,
commands: {
commands: [
"rust-analyzer.runSingle",

View file

@ -21,6 +21,7 @@ import type { LanguageClient } from "vscode-languageclient/node";
import { LINKED_COMMANDS } from "./client";
import type { DependencyId } from "./dependencies_provider";
import { unwrapUndefinable } from "./undefinable";
import { log } from "./util";
export * from "./ast_inspector";
export * from "./run";
@ -947,10 +948,51 @@ export function openDocs(ctx: CtxInit): Cmd {
const position = editor.selection.active;
const textDocument = { uri: editor.document.uri.toString() };
const doclink = await client.sendRequest(ra.openDocs, { position, textDocument });
const docLinks = await client.sendRequest(ra.openDocs, { position, textDocument });
log.debug(docLinks);
if (doclink != null) {
await vscode.commands.executeCommand("vscode.open", vscode.Uri.parse(doclink));
let fileType = vscode.FileType.Unknown;
if (docLinks.local !== undefined) {
try {
fileType = (await vscode.workspace.fs.stat(vscode.Uri.parse(docLinks.local))).type;
} catch (e) {
log.debug("stat() threw error. Falling back to web version", e);
}
}
let docLink = fileType & vscode.FileType.File ? docLinks.local : docLinks.web;
if (docLink) {
// instruct vscode to handle the vscode-remote link directly
if (docLink.startsWith("vscode-remote://")) {
docLink = docLink.replace("vscode-remote://", "vscode://vscode-remote/");
}
const docUri = vscode.Uri.parse(docLink);
await vscode.env.openExternal(docUri);
}
};
}
export function openExternalDocs(ctx: CtxInit): Cmd {
return async () => {
const editor = vscode.window.activeTextEditor;
if (!editor) {
return;
}
const client = ctx.client;
const position = editor.selection.active;
const textDocument = { uri: editor.document.uri.toString() };
const docLinks = await client.sendRequest(ra.openDocs, { position, textDocument });
let docLink = docLinks.web;
if (docLink) {
// instruct vscode to handle the vscode-remote link directly
if (docLink.startsWith("vscode-remote://")) {
docLink = docLink.replace("vscode-remote://", "vscode://vscode-remote/");
}
const docUri = vscode.Uri.parse(docLink);
await vscode.env.openExternal(docUri);
}
};
}

View file

@ -329,6 +329,10 @@ export class Config {
get showDependenciesExplorer() {
return this.get<boolean>("showDependenciesExplorer");
}
get statusBarClickAction() {
return this.get<string>("statusBar.clickAction");
}
}
// the optional `cb?` parameter is meant to be used to add additional

View file

@ -400,7 +400,11 @@ export class Ctx {
statusBar.tooltip.appendText(status.message ?? "Ready");
statusBar.color = undefined;
statusBar.backgroundColor = undefined;
statusBar.command = "rust-analyzer.openLogs";
if (this.config.statusBarClickAction === "stopServer") {
statusBar.command = "rust-analyzer.stopServer";
} else {
statusBar.command = "rust-analyzer.openLogs";
}
this.dependencies?.refresh();
break;
case "warning":

View file

@ -74,8 +74,8 @@ export interface FetchDependencyListParams {}
export interface FetchDependencyListResult {
crates: {
name: string | undefined;
version: string | undefined;
name?: string;
version?: string;
path: string;
}[];
}
@ -135,7 +135,11 @@ export const onEnter = new lc.RequestType<lc.TextDocumentPositionParams, lc.Text
export const openCargoToml = new lc.RequestType<OpenCargoTomlParams, lc.Location, void>(
"experimental/openCargoToml",
);
export const openDocs = new lc.RequestType<lc.TextDocumentPositionParams, string | void, void>(
export interface DocsUrls {
local?: string;
web?: string;
}
export const openDocs = new lc.RequestType<lc.TextDocumentPositionParams, DocsUrls, void>(
"experimental/externalDocs",
);
export const parentModule = new lc.RequestType<

View file

@ -170,6 +170,7 @@ function createCommands(): Record<string, CommandFactory> {
debug: { enabled: commands.debug },
newDebugConfig: { enabled: commands.newDebugConfig },
openDocs: { enabled: commands.openDocs },
openExternalDocs: { enabled: commands.openExternalDocs },
openCargoToml: { enabled: commands.openCargoToml },
peekTests: { enabled: commands.peekTests },
moveItemUp: { enabled: commands.moveItemUp },