Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: range hover #839

Merged
merged 2 commits into from
Aug 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Expand Down Expand Up @@ -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);
fannheyward marked this conversation as resolved.
Show resolved Hide resolved
}
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
Expand Down
10 changes: 9 additions & 1 deletion src/lsp_ext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down