diff --git a/src/client.ts b/src/client.ts index 4fb052f8..53f2f828 100644 --- a/src/client.ts +++ b/src/client.ts @@ -1,7 +1,8 @@ -import { CodeActionKind, Command, Executable, LanguageClient, LanguageClientOptions, ServerOptions, StaticFeature, Uri, workspace } from 'coc.nvim'; +import { CodeActionKind, Command, Executable, LanguageClient, LanguageClientOptions, Position, Range, ServerOptions, StaticFeature, Uri, workspace } from 'coc.nvim'; import { CodeAction, CodeActionParams, CodeActionRequest } from 'vscode-languageserver-protocol'; import { Env } from './config'; import { isRustDocument } from './ctx'; +import * as ra from './lsp_ext'; class ExperimentalFeatures implements StaticFeature { fillClientCapabilities(capabilities: any): void { @@ -61,6 +62,23 @@ export function createClient(bin: string, extra: Env): LanguageClient { documentSelector: [{ language: 'rust' }], initializationOptions, middleware: { + async provideHover(document, position, token) { + const doc = await workspace.document; + let positionOrRange: Range | Position | null = null; + const mode = (await workspace.nvim.call('visualmode')) as string; + if (mode) { + positionOrRange = await workspace.getSelectedRange(mode, doc); + } + if (!positionOrRange) { + const state = await workspace.getCurrentState(); + positionOrRange = state.position; + } + const param: ra.HoverParams = { + position: positionOrRange, + textDocument: { uri: doc.uri }, + }; + return await client.sendRequest(ra.hover, param, token); + }, async resolveCompletionItem(item, token, next) { if (item.data && !item.data.position) { // TODO: remove this if coc undefined item.data diff --git a/src/lsp_ext.ts b/src/lsp_ext.ts index 2905f32e..9bff239c 100644 --- a/src/lsp_ext.ts +++ b/src/lsp_ext.ts @@ -19,6 +19,14 @@ export const serverStatus = new lc.NotificationType('experim export const reloadWorkspace = new lc.RequestType0('rust-analyzer/reloadWorkspace'); +export const hover = new lc.RequestType('textDocument/hover'); + +export interface HoverParams { + workDoneToken?: lc.ProgressToken; + textDocument: lc.TextDocumentIdentifier; + position: lc.Range | lc.Position; +} + export interface SyntaxTreeParams { textDocument: lc.TextDocumentIdentifier; range: lc.Range | null; @@ -55,7 +63,7 @@ export interface MatchingBraceParams { } export const matchingBrace = new lc.RequestType('experimental/matchingBrace'); -export const parentModule = new lc.RequestType('experimental/parentModule'); +export const parentModule = new lc.RequestType('experimental/parentModule'); export interface JoinLinesParams { textDocument: lc.TextDocumentIdentifier;