mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 05:15:04 +00:00
Move parentModule to the new Ctx
This commit is contained in:
parent
5aebf1081d
commit
9bfeac708d
3 changed files with 37 additions and 37 deletions
|
@ -4,9 +4,9 @@ import { analyzerStatus } from './analyzer_status';
|
|||
import { matchingBrace } from './matching_brace';
|
||||
import { joinLines } from './join_lines';
|
||||
import { onEnter } from './on_enter';
|
||||
import { parentModule } from './parent_module';
|
||||
import * as expandMacro from './expand_macro';
|
||||
import * as inlayHints from './inlay_hints';
|
||||
import * as parentModule from './parent_module';
|
||||
import * as runnables from './runnables';
|
||||
import * as syntaxTree from './syntaxTree';
|
||||
|
||||
|
|
|
@ -1,32 +1,32 @@
|
|||
import * as vscode from 'vscode';
|
||||
|
||||
import * as lc from 'vscode-languageclient';
|
||||
import { Server } from '../server';
|
||||
import { Ctx, Cmd } from '../ctx';
|
||||
|
||||
export async function handle() {
|
||||
const editor = vscode.window.activeTextEditor;
|
||||
if (editor == null || editor.document.languageId !== 'rust') {
|
||||
return;
|
||||
}
|
||||
const request: lc.TextDocumentPositionParams = {
|
||||
textDocument: { uri: editor.document.uri.toString() },
|
||||
position: Server.client.code2ProtocolConverter.asPosition(
|
||||
editor.selection.active,
|
||||
),
|
||||
};
|
||||
const response = await Server.client.sendRequest<lc.Location[]>(
|
||||
'rust-analyzer/parentModule',
|
||||
request,
|
||||
);
|
||||
const loc = response[0];
|
||||
if (loc == null) {
|
||||
return;
|
||||
}
|
||||
const uri = Server.client.protocol2CodeConverter.asUri(loc.uri);
|
||||
const range = Server.client.protocol2CodeConverter.asRange(loc.range);
|
||||
export function parentModule(ctx: Ctx): Cmd {
|
||||
return async () => {
|
||||
const editor = ctx.activeRustEditor;
|
||||
if (!editor) return;
|
||||
|
||||
const doc = await vscode.workspace.openTextDocument(uri);
|
||||
const e = await vscode.window.showTextDocument(doc);
|
||||
e.selection = new vscode.Selection(range.start, range.start);
|
||||
e.revealRange(range, vscode.TextEditorRevealType.InCenter);
|
||||
const request: lc.TextDocumentPositionParams = {
|
||||
textDocument: { uri: editor.document.uri.toString() },
|
||||
position: ctx.client.code2ProtocolConverter.asPosition(
|
||||
editor.selection.active,
|
||||
),
|
||||
};
|
||||
const response = await ctx.client.sendRequest<lc.Location[]>(
|
||||
'rust-analyzer/parentModule',
|
||||
request,
|
||||
);
|
||||
const loc = response[0];
|
||||
if (loc == null) return;
|
||||
|
||||
const uri = ctx.client.protocol2CodeConverter.asUri(loc.uri);
|
||||
const range = ctx.client.protocol2CodeConverter.asRange(loc.range);
|
||||
|
||||
const doc = await vscode.workspace.openTextDocument(uri);
|
||||
const e = await vscode.window.showTextDocument(doc);
|
||||
e.selection = new vscode.Selection(range.start, range.start);
|
||||
e.revealRange(range, vscode.TextEditorRevealType.InCenter);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue