diff options
Diffstat (limited to 'editors/code/src/client.ts')
-rw-r--r-- | editors/code/src/client.ts | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/editors/code/src/client.ts b/editors/code/src/client.ts index 40ad1e3cd..9df670283 100644 --- a/editors/code/src/client.ts +++ b/editors/code/src/client.ts | |||
@@ -7,6 +7,29 @@ import { CallHierarchyFeature } from 'vscode-languageclient/lib/callHierarchy.pr | |||
7 | import { SemanticTokensFeature, DocumentSemanticsTokensSignature } from 'vscode-languageclient/lib/semanticTokens.proposed'; | 7 | import { SemanticTokensFeature, DocumentSemanticsTokensSignature } from 'vscode-languageclient/lib/semanticTokens.proposed'; |
8 | import { assert } from './util'; | 8 | import { assert } from './util'; |
9 | 9 | ||
10 | function toTrusted(obj: vscode.MarkedString): vscode.MarkedString { | ||
11 | const md = <vscode.MarkdownString>obj; | ||
12 | if (md && md.value.includes("```rust")) { | ||
13 | md.isTrusted = true; | ||
14 | return md; | ||
15 | } | ||
16 | return obj; | ||
17 | } | ||
18 | |||
19 | function renderCommand(cmd: CommandLink) { | ||
20 | return `[${cmd.title}](command:${cmd.command}?${encodeURIComponent(JSON.stringify(cmd.arguments))} '${cmd.tooltip!}')`; | ||
21 | } | ||
22 | |||
23 | function renderHoverActions(actions: CommandLinkGroup[]): vscode.MarkdownString { | ||
24 | const text = actions.map(group => | ||
25 | (group.title ? (group.title + " ") : "") + group.commands.map(renderCommand).join(' | ') | ||
26 | ).join('___'); | ||
27 | |||
28 | const result = new vscode.MarkdownString(text); | ||
29 | result.isTrusted = true; | ||
30 | return result; | ||
31 | } | ||
32 | |||
10 | export function createClient(serverPath: string, cwd: string): lc.LanguageClient { | 33 | export function createClient(serverPath: string, cwd: string): lc.LanguageClient { |
11 | // '.' Is the fallback if no folder is open | 34 | // '.' Is the fallback if no folder is open |
12 | // TODO?: Workspace folders support Uri's (eg: file://test.txt). | 35 | // TODO?: Workspace folders support Uri's (eg: file://test.txt). |
@@ -35,6 +58,27 @@ export function createClient(serverPath: string, cwd: string): lc.LanguageClient | |||
35 | if (res === undefined) throw new Error('busy'); | 58 | if (res === undefined) throw new Error('busy'); |
36 | return res; | 59 | return res; |
37 | }, | 60 | }, |
61 | async provideHover(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken, _next: lc.ProvideHoverSignature) { | ||
62 | return client.sendRequest(lc.HoverRequest.type, client.code2ProtocolConverter.asTextDocumentPositionParams(document, position), token).then( | ||
63 | (result) => { | ||
64 | const hover = client.protocol2CodeConverter.asHover(result); | ||
65 | if (hover) { | ||
66 | // Workaround to support command links (trusted vscode.MarkdownString) in hovers | ||
67 | // https://github.com/microsoft/vscode/issues/33577 | ||
68 | hover.contents = hover.contents.map(toTrusted); | ||
69 | |||
70 | const actions = (<any>result).actions; | ||
71 | if (actions) { | ||
72 | hover.contents.push(renderHoverActions(actions)); | ||
73 | } | ||
74 | } | ||
75 | return hover; | ||
76 | }, | ||
77 | (error) => { | ||
78 | client.logFailedRequest(lc.HoverRequest.type, error); | ||
79 | return Promise.resolve(null); | ||
80 | }); | ||
81 | }, | ||
38 | // Using custom handling of CodeActions where each code action is resloved lazily | 82 | // Using custom handling of CodeActions where each code action is resloved lazily |
39 | // That's why we are not waiting for any command or edits | 83 | // That's why we are not waiting for any command or edits |
40 | async provideCodeActions(document: vscode.TextDocument, range: vscode.Range, context: vscode.CodeActionContext, token: vscode.CancellationToken, _next: lc.ProvideCodeActionsSignature) { | 84 | async provideCodeActions(document: vscode.TextDocument, range: vscode.Range, context: vscode.CodeActionContext, token: vscode.CancellationToken, _next: lc.ProvideCodeActionsSignature) { |
@@ -129,6 +173,7 @@ class ExperimentalFeatures implements lc.StaticFeature { | |||
129 | caps.snippetTextEdit = true; | 173 | caps.snippetTextEdit = true; |
130 | caps.codeActionGroup = true; | 174 | caps.codeActionGroup = true; |
131 | caps.resolveCodeAction = true; | 175 | caps.resolveCodeAction = true; |
176 | caps.hoverActions = true; | ||
132 | capabilities.experimental = caps; | 177 | capabilities.experimental = caps; |
133 | } | 178 | } |
134 | initialize(_capabilities: lc.ServerCapabilities<any>, _documentSelector: lc.DocumentSelector | undefined): void { | 179 | initialize(_capabilities: lc.ServerCapabilities<any>, _documentSelector: lc.DocumentSelector | undefined): void { |