mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-01 12:24:29 +00:00
feat: Completed the client side implementation of rust-analyzer/hoverRange
This commit is contained in:
parent
8ca3bb8fcd
commit
18644720eb
7 changed files with 129 additions and 30 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -116,6 +116,30 @@ export function matchingBrace(ctx: Ctx): Cmd {
|
|||
};
|
||||
}
|
||||
|
||||
export function hoverRange(ctx: Ctx): Cmd {
|
||||
return async () => {
|
||||
const editor = ctx.activeRustEditor;
|
||||
const client = ctx.client;
|
||||
if (!editor || !client) return;
|
||||
|
||||
client
|
||||
.sendRequest(ra.hoverRange, {
|
||||
textDocument: client.code2ProtocolConverter.asTextDocumentIdentifier(
|
||||
editor.document
|
||||
),
|
||||
range: client.code2ProtocolConverter.asRange(editor.selection),
|
||||
})
|
||||
.then(
|
||||
(result) => client.protocol2CodeConverter.asHover(result),
|
||||
(error) => {
|
||||
client.handleFailedRequest(lc.HoverRequest.type, undefined, error, null);
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
export function joinLines(ctx: Ctx): Cmd {
|
||||
return async () => {
|
||||
const editor = ctx.activeRustEditor;
|
||||
|
|
|
|||
|
|
@ -19,6 +19,13 @@ export const serverStatus = new lc.NotificationType<ServerStatusParams>("experim
|
|||
|
||||
export const reloadWorkspace = new lc.RequestType0<null, void>("rust-analyzer/reloadWorkspace");
|
||||
|
||||
export const hoverRange = new lc.RequestType<HoverRangeParams, lc.Hover | null, void>("rust-analyzer/hoverRange");
|
||||
|
||||
export interface HoverRangeParams {
|
||||
textDocument: lc.TextDocumentIdentifier;
|
||||
range: lc.Range;
|
||||
}
|
||||
|
||||
export interface SyntaxTreeParams {
|
||||
textDocument: lc.TextDocumentIdentifier;
|
||||
range: lc.Range | null;
|
||||
|
|
|
|||
|
|
@ -118,6 +118,7 @@ async function initCommonContext(context: vscode.ExtensionContext, ctx: Ctx) {
|
|||
ctx.registerCommand('reloadWorkspace', commands.reloadWorkspace);
|
||||
ctx.registerCommand('matchingBrace', commands.matchingBrace);
|
||||
ctx.registerCommand('joinLines', commands.joinLines);
|
||||
ctx.registerCommand('hoverRange', commands.hoverRange);
|
||||
ctx.registerCommand('parentModule', commands.parentModule);
|
||||
ctx.registerCommand('syntaxTree', commands.syntaxTree);
|
||||
ctx.registerCommand('viewHir', commands.viewHir);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue