Skip to content

Commit

Permalink
feat: range hover (#839)
Browse files Browse the repository at this point in the history
* feat: range hover

close #836
FYI #256

* fix: range hover
  • Loading branch information
fannheyward authored Aug 12, 2021
1 parent f2da688 commit 6574b52
Showing 2 changed files with 26 additions and 2 deletions.
18 changes: 17 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
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 { existsSync } from 'fs';
import { join } from 'path';
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 {
@@ -62,6 +63,21 @@ export function createClient(bin: string, extra: Env): LanguageClient {
documentSelector: [{ language: 'rust' }],
initializationOptions,
middleware: {
async provideHover(document, position, token) {
let positionOrRange: Range | Position | null = null;
const mode = (await workspace.nvim.call('mode')) as string;
if (mode === 'v' || mode === 'V') {
const doc = workspace.getDocument(document.uri);
await workspace.nvim.call('eval', 'feedkeys("\\<esc>", "in")');
positionOrRange = await workspace.getSelectedRange(mode, doc);
}
if (!positionOrRange) positionOrRange = position;
const param: ra.HoverParams = {
position: positionOrRange || position,
textDocument: { uri: document.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
10 changes: 9 additions & 1 deletion src/lsp_ext.ts
Original file line number Diff line number Diff line change
@@ -19,6 +19,14 @@ export const serverStatus = new lc.NotificationType<ServerStatusParams>('experim

export const reloadWorkspace = new lc.RequestType0<null, void>('rust-analyzer/reloadWorkspace');

export const hover = new lc.RequestType<HoverParams, lc.Hover | null, void>('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<MatchingBraceParams, lc.Position[], void>('experimental/matchingBrace');

export const parentModule = new lc.RequestType<lc.TextDocumentPositionParams, lc.Location[] | lc.LocationLink[], void>('experimental/parentModule');
export const parentModule = new lc.RequestType<lc.TextDocumentPositionParams, lc.LocationLink[], void>('experimental/parentModule');

export interface JoinLinesParams {
textDocument: lc.TextDocumentIdentifier;

0 comments on commit 6574b52

Please sign in to comment.