diff options
| author | Lukas Wirth <lukastw97@gmail.com> | 2023-10-18 14:02:56 +0200 |
|---|---|---|
| committer | Lukas Wirth <lukastw97@gmail.com> | 2023-10-18 14:06:07 +0200 |
| commit | 4296fe52baba36de060691db9ef482b68845aeb4 (patch) | |
| tree | 7b98180f04f4bc442eda14db2544d6bf495cd808 /editors/code/src | |
| parent | 6572ec8d94c83f8cc6afe0069269abeddc37c25e (diff) | |
| download | rust-4296fe52baba36de060691db9ef482b68845aeb4.tar.gz rust-4296fe52baba36de060691db9ef482b68845aeb4.zip | |
Add command for only opening external docs and attempt to fix vscode-remote issue
Diffstat (limited to 'editors/code/src')
| -rw-r--r-- | editors/code/src/commands.ts | 46 | ||||
| -rw-r--r-- | editors/code/src/lsp_ext.ts | 8 | ||||
| -rw-r--r-- | editors/code/src/main.ts | 1 |
3 files changed, 40 insertions, 15 deletions
diff --git a/editors/code/src/commands.ts b/editors/code/src/commands.ts index 4d5c3cf4576..7e24de664e9 100644 --- a/editors/code/src/commands.ts +++ b/editors/code/src/commands.ts @@ -948,27 +948,51 @@ export function openDocs(ctx: CtxInit): Cmd { const position = editor.selection.active; const textDocument = { uri: editor.document.uri.toString() }; - const doclinks = await client.sendRequest(ra.openDocs, { position, textDocument }); + const docLinks = await client.sendRequest(ra.openDocs, { position, textDocument }); + log.debug(docLinks); let fileType = vscode.FileType.Unknown; - if (typeof doclinks.local === "string") { + if (docLinks.local !== undefined) { try { - fileType = (await vscode.workspace.fs.stat(vscode.Uri.parse(doclinks.local))).type; + 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; - if (fileType & vscode.FileType.File) { - // file does exist locally - doclink = doclinks.local; - } else { - doclink = doclinks.web; + 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() }; - if (doclink != null) { - await vscode.env.openExternal(vscode.Uri.parse(doclink)); + 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); } }; } diff --git a/editors/code/src/lsp_ext.ts b/editors/code/src/lsp_ext.ts index a1cd88b89c9..f959a76639e 100644 --- a/editors/code/src/lsp_ext.ts +++ b/editors/code/src/lsp_ext.ts @@ -74,8 +74,8 @@ export interface FetchDependencyListParams {} export interface FetchDependencyListResult { crates: { - name: string | undefined; - version: string | undefined; + name?: string; + version?: string; path: string; }[]; } @@ -136,8 +136,8 @@ export const openCargoToml = new lc.RequestType<OpenCargoTomlParams, lc.Location "experimental/openCargoToml", ); export interface DocsUrls { - local: string | void; - web: string | void; + local?: string; + web?: string; } export const openDocs = new lc.RequestType<lc.TextDocumentPositionParams, DocsUrls, void>( "experimental/externalDocs", diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index ee5e5b1b80c..5de5aabc39f 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts @@ -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 }, |
