mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 13:51:31 +00:00
Refactor vscode extension
This commit is contained in:
parent
e4fdfd1501
commit
69de7e2fd7
14 changed files with 518 additions and 415 deletions
27
editors/code/src/commands/matching_brace.ts
Normal file
27
editors/code/src/commands/matching_brace.ts
Normal file
|
@ -0,0 +1,27 @@
|
|||
import * as vscode from 'vscode';
|
||||
|
||||
import { TextDocumentIdentifier, Position } from "vscode-languageclient";
|
||||
import { Server } from '../server';
|
||||
|
||||
interface FindMatchingBraceParams {
|
||||
textDocument: TextDocumentIdentifier;
|
||||
offsets: Position[];
|
||||
}
|
||||
|
||||
export async function handle() {
|
||||
let editor = vscode.window.activeTextEditor
|
||||
if (editor == null || editor.document.languageId != "rust") return
|
||||
let request: FindMatchingBraceParams = {
|
||||
textDocument: { uri: editor.document.uri.toString() },
|
||||
offsets: editor.selections.map((s) => {
|
||||
return Server.client.code2ProtocolConverter.asPosition(s.active)
|
||||
})
|
||||
}
|
||||
let response = await Server.client.sendRequest<Position[]>("m/findMatchingBrace", request)
|
||||
editor.selections = editor.selections.map((sel, idx) => {
|
||||
let active = Server.client.protocol2CodeConverter.asPosition(response[idx])
|
||||
let anchor = sel.isEmpty ? active : sel.anchor
|
||||
return new vscode.Selection(anchor, active)
|
||||
})
|
||||
editor.revealRange(editor.selection)
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue