Skip to content

Commit 4586a6b

Browse files
committed
Auto merge of #15779 - Veykril:open-docs, r=Veykril
Add command for only opening external docs and attempt to fix vscode-remote issue opening URI in a remote env causes vscode to ask the OS to handle `vscode-remote` URIs as there is no handler registered for such a scheme. This attempts to instruct vscode to handle those. This is untested, as I can't figure out how to open a debug session on WSL rn.
2 parents 7f1e6fd + 4296fe5 commit 4586a6b

File tree

4 files changed

+47
-17
lines changed

4 files changed

+47
-17
lines changed

editors/code/package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,11 @@
248248
"title": "Open Docs",
249249
"category": "rust-analyzer"
250250
},
251+
{
252+
"command": "rust-analyzer.openExternalDocs",
253+
"title": "Open External Docs",
254+
"category": "rust-analyzer"
255+
},
251256
{
252257
"command": "rust-analyzer.openCargoToml",
253258
"title": "Open Cargo.toml",
@@ -260,12 +265,12 @@
260265
},
261266
{
262267
"command": "rust-analyzer.moveItemUp",
263-
"title": "Move item up",
268+
"title": "Move Item Up",
264269
"category": "rust-analyzer"
265270
},
266271
{
267272
"command": "rust-analyzer.moveItemDown",
268-
"title": "Move item down",
273+
"title": "Move Item Down",
269274
"category": "rust-analyzer"
270275
},
271276
{

editors/code/src/commands.ts

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -948,27 +948,51 @@ export function openDocs(ctx: CtxInit): Cmd {
948948
const position = editor.selection.active;
949949
const textDocument = { uri: editor.document.uri.toString() };
950950

951-
const doclinks = await client.sendRequest(ra.openDocs, { position, textDocument });
951+
const docLinks = await client.sendRequest(ra.openDocs, { position, textDocument });
952+
log.debug(docLinks);
952953

953954
let fileType = vscode.FileType.Unknown;
954-
if (typeof doclinks.local === "string") {
955+
if (docLinks.local !== undefined) {
955956
try {
956-
fileType = (await vscode.workspace.fs.stat(vscode.Uri.parse(doclinks.local))).type;
957+
fileType = (await vscode.workspace.fs.stat(vscode.Uri.parse(docLinks.local))).type;
957958
} catch (e) {
958959
log.debug("stat() threw error. Falling back to web version", e);
959960
}
960961
}
961962

962-
let doclink;
963-
if (fileType & vscode.FileType.File) {
964-
// file does exist locally
965-
doclink = doclinks.local;
966-
} else {
967-
doclink = doclinks.web;
963+
let docLink = fileType & vscode.FileType.File ? docLinks.local : docLinks.web;
964+
if (docLink) {
965+
// instruct vscode to handle the vscode-remote link directly
966+
if (docLink.startsWith("vscode-remote://")) {
967+
docLink = docLink.replace("vscode-remote://", "vscode://vscode-remote/");
968+
}
969+
const docUri = vscode.Uri.parse(docLink);
970+
await vscode.env.openExternal(docUri);
971+
}
972+
};
973+
}
974+
975+
export function openExternalDocs(ctx: CtxInit): Cmd {
976+
return async () => {
977+
const editor = vscode.window.activeTextEditor;
978+
if (!editor) {
979+
return;
968980
}
981+
const client = ctx.client;
982+
983+
const position = editor.selection.active;
984+
const textDocument = { uri: editor.document.uri.toString() };
969985

970-
if (doclink != null) {
971-
await vscode.env.openExternal(vscode.Uri.parse(doclink));
986+
const docLinks = await client.sendRequest(ra.openDocs, { position, textDocument });
987+
988+
let docLink = docLinks.web;
989+
if (docLink) {
990+
// instruct vscode to handle the vscode-remote link directly
991+
if (docLink.startsWith("vscode-remote://")) {
992+
docLink = docLink.replace("vscode-remote://", "vscode://vscode-remote/");
993+
}
994+
const docUri = vscode.Uri.parse(docLink);
995+
await vscode.env.openExternal(docUri);
972996
}
973997
};
974998
}

editors/code/src/lsp_ext.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ export interface FetchDependencyListParams {}
7474

7575
export interface FetchDependencyListResult {
7676
crates: {
77-
name: string | undefined;
78-
version: string | undefined;
77+
name?: string;
78+
version?: string;
7979
path: string;
8080
}[];
8181
}
@@ -136,8 +136,8 @@ export const openCargoToml = new lc.RequestType<OpenCargoTomlParams, lc.Location
136136
"experimental/openCargoToml",
137137
);
138138
export interface DocsUrls {
139-
local: string | void;
140-
web: string | void;
139+
local?: string;
140+
web?: string;
141141
}
142142
export const openDocs = new lc.RequestType<lc.TextDocumentPositionParams, DocsUrls, void>(
143143
"experimental/externalDocs",

editors/code/src/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ function createCommands(): Record<string, CommandFactory> {
170170
debug: { enabled: commands.debug },
171171
newDebugConfig: { enabled: commands.newDebugConfig },
172172
openDocs: { enabled: commands.openDocs },
173+
openExternalDocs: { enabled: commands.openExternalDocs },
173174
openCargoToml: { enabled: commands.openCargoToml },
174175
peekTests: { enabled: commands.peekTests },
175176
moveItemUp: { enabled: commands.moveItemUp },

0 commit comments

Comments
 (0)