mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
matching brace
This commit is contained in:
parent
aa0d344581
commit
c631b585a7
9 changed files with 135 additions and 14 deletions
|
@ -35,6 +35,22 @@ export function activate(context: vscode.ExtensionContext) {
|
|||
return new vscode.Selection(r.start, r.end)
|
||||
})
|
||||
})
|
||||
registerCommand('libsyntax-rust.matchingBrace', async () => {
|
||||
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 client.code2ProtocolConverter.asPosition(s.active)
|
||||
})
|
||||
}
|
||||
let response = await client.sendRequest<lc.Position[]>("m/findMatchingBrace", request)
|
||||
editor.selections = editor.selections.map((sel, idx) => {
|
||||
let active = client.protocol2CodeConverter.asPosition(response[idx])
|
||||
let anchor = sel.isEmpty ? active : sel.anchor
|
||||
return new vscode.Selection(anchor, active)
|
||||
})
|
||||
})
|
||||
|
||||
dispose(vscode.workspace.registerTextDocumentContentProvider(
|
||||
'libsyntax-rust',
|
||||
|
@ -184,6 +200,11 @@ interface ExtendSelectionResult {
|
|||
selections: lc.Range[];
|
||||
}
|
||||
|
||||
interface FindMatchingBraceParams {
|
||||
textDocument: lc.TextDocumentIdentifier;
|
||||
offsets: lc.Position[];
|
||||
}
|
||||
|
||||
interface PublishDecorationsParams {
|
||||
uri: string,
|
||||
decorations: Decoration[],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue