diff options
| author | Alexander Gonzalez <alexfertel97@gmail.com> | 2021-07-25 17:26:54 -0400 |
|---|---|---|
| committer | Alexander Gonzalez <alexfertel97@gmail.com> | 2021-07-27 18:29:22 -0400 |
| commit | 18644720eb808f39545ab208370d5f705bfc54d3 (patch) | |
| tree | 098f2cdc708858b2d8cf4efd70a6273516042075 /editors/code/src/client.ts | |
| parent | 8ca3bb8fcd3c3ac8eb232086f6286eb96f4bac79 (diff) | |
| download | rust-18644720eb808f39545ab208370d5f705bfc54d3.tar.gz rust-18644720eb808f39545ab208370d5f705bfc54d3.zip | |
feat: Completed the client side implementation of rust-analyzer/hoverRange
Diffstat (limited to 'editors/code/src/client.ts')
| -rw-r--r-- | editors/code/src/client.ts | 68 |
1 files changed, 57 insertions, 11 deletions
diff --git a/editors/code/src/client.ts b/editors/code/src/client.ts index f13ae07e148..f0c10698a0c 100644 --- a/editors/code/src/client.ts +++ b/editors/code/src/client.ts @@ -56,21 +56,67 @@ export function createClient(serverPath: string, workspace: Workspace, extraEnv: traceOutputChannel, middleware: { async provideHover(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken, _next: lc.ProvideHoverSignature) { - return client.sendRequest(lc.HoverRequest.type, client.code2ProtocolConverter.asTextDocumentPositionParams(document, position), token).then( - (result) => { - const hover = client.protocol2CodeConverter.asHover(result); - if (hover) { + const editor = vscode.window.activeTextEditor; + const selection = editor?.selection; + return selection?.contains(position) + ? client + .sendRequest( + ra.hoverRange, + { + textDocument: + client.code2ProtocolConverter.asTextDocumentIdentifier( + document + ), + range: client.code2ProtocolConverter.asRange( + editor?.selection + ), + }, + token + ) + .then( + (result) => + client.protocol2CodeConverter.asHover(result), + (error) => { + client.handleFailedRequest( + lc.HoverRequest.type, + undefined, + error, + null + ); + return Promise.resolve(null); + } + ) + : client + .sendRequest( + lc.HoverRequest.type, + client.code2ProtocolConverter.asTextDocumentPositionParams( + document, + position + ), + token + ) + .then( + (result) => { + const hover = + client.protocol2CodeConverter.asHover(result); + if (hover) { const actions = (<any>result).actions; if (actions) { - hover.contents.push(renderHoverActions(actions)); + hover.contents.push(renderHoverActions(actions)); } + } + return hover; + }, + (error) => { + client.handleFailedRequest( + lc.HoverRequest.type, + token, + error, + null + ); + return Promise.resolve(null); } - return hover; - }, - (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. // Note that this means we have to re-implement lazy edit resolving ourselves as well. |
