refactor: Make handle_hover handle ranges too
This commit is contained in:
@@ -57,45 +57,11 @@ export function createClient(serverPath: string, workspace: Workspace, extraEnv:
|
||||
middleware: {
|
||||
async provideHover(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken, _next: lc.ProvideHoverSignature) {
|
||||
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(
|
||||
const positionOrRange = editor?.selection?.contains(position) ? client.code2ProtocolConverter.asRange(editor.selection) : client.code2ProtocolConverter.asPosition(position);
|
||||
return client.sendRequest(ra.hover, {
|
||||
textDocument: client.code2ProtocolConverter.asTextDocumentIdentifier(document),
|
||||
position: positionOrRange
|
||||
}, token).then(
|
||||
(result) => {
|
||||
const hover =
|
||||
client.protocol2CodeConverter.asHover(result);
|
||||
|
||||
@@ -19,11 +19,11 @@ 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 const hover = new lc.RequestType<HoverParams, lc.Hover | null, void>("textDocument/hover");
|
||||
|
||||
export interface HoverRangeParams {
|
||||
export interface HoverParams extends lc.WorkDoneProgressParams{
|
||||
textDocument: lc.TextDocumentIdentifier;
|
||||
range: lc.Range;
|
||||
position: lc.Range | lc.Position;
|
||||
}
|
||||
|
||||
export interface SyntaxTreeParams {
|
||||
|
||||
Reference in New Issue
Block a user