From 603bc71a57ce386d78f1b1c842714ff0dbeeaf9c Mon Sep 17 00:00:00 2001 From: Veetaha Date: Tue, 25 Feb 2020 00:50:14 +0200 Subject: vscode: migrate analyzer_status to rust-analyzer-api.ts --- editors/code/src/commands/analyzer_status.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'editors/code/src/commands') diff --git a/editors/code/src/commands/analyzer_status.ts b/editors/code/src/commands/analyzer_status.ts index 6631e8db7..1c6ea399b 100644 --- a/editors/code/src/commands/analyzer_status.ts +++ b/editors/code/src/commands/analyzer_status.ts @@ -1,5 +1,6 @@ import * as vscode from 'vscode'; +import * as ra from '../rust-analyzer-api'; import { Ctx, Cmd } from '../ctx'; // Shows status of rust-analyzer (for debugging) @@ -50,10 +51,7 @@ class TextDocumentContentProvider const client = this.ctx.client; if (!editor || !client) return ''; - return client.sendRequest( - 'rust-analyzer/analyzerStatus', - null, - ); + return client.sendRequest(ra.analyzerStatus, null); } get onDidChange(): vscode.Event { -- cgit v1.2.3 From 31d9932d18151bffe94e4137ac3b5d10df37641f Mon Sep 17 00:00:00 2001 From: Veetaha Date: Tue, 25 Feb 2020 00:50:36 +0200 Subject: vscode: migrate expand_macro to rust-analyzer-api.ts --- editors/code/src/commands/expand_macro.ts | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to 'editors/code/src/commands') diff --git a/editors/code/src/commands/expand_macro.ts b/editors/code/src/commands/expand_macro.ts index edec9bbc1..23f2ef1d5 100644 --- a/editors/code/src/commands/expand_macro.ts +++ b/editors/code/src/commands/expand_macro.ts @@ -1,5 +1,5 @@ import * as vscode from 'vscode'; -import * as lc from 'vscode-languageclient'; +import * as ra from '../rust-analyzer-api'; import { Ctx, Cmd } from '../ctx'; @@ -26,12 +26,7 @@ export function expandMacro(ctx: Ctx): Cmd { }; } -interface ExpandedMacro { - name: string; - expansion: string; -} - -function codeFormat(expanded: ExpandedMacro): string { +function codeFormat(expanded: ra.ExpandedMacro): string { let result = `// Recursive expansion of ${expanded.name}! macro\n`; result += '// ' + '='.repeat(result.length - 3); result += '\n\n'; @@ -54,14 +49,11 @@ class TextDocumentContentProvider if (!editor || !client) return ''; const position = editor.selection.active; - const request: lc.TextDocumentPositionParams = { + + const expanded = await client.sendRequest(ra.expandMacro, { textDocument: { uri: editor.document.uri.toString() }, position, - }; - const expanded = await client.sendRequest( - 'rust-analyzer/expandMacro', - request, - ); + }); if (expanded == null) return 'Not available'; -- cgit v1.2.3 From c9a2fa1835a9b91d7e9332f7eceb8c899c727d32 Mon Sep 17 00:00:00 2001 From: Veetaha Date: Tue, 25 Feb 2020 00:50:57 +0200 Subject: vscode: migrate collectGarbage to rust-analyzer-api.ts --- editors/code/src/commands/index.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'editors/code/src/commands') diff --git a/editors/code/src/commands/index.ts b/editors/code/src/commands/index.ts index 839245f48..bdb7fc3b0 100644 --- a/editors/code/src/commands/index.ts +++ b/editors/code/src/commands/index.ts @@ -1,5 +1,6 @@ import * as vscode from 'vscode'; import * as lc from 'vscode-languageclient'; +import * as ra from '../rust-analyzer-api'; import { Ctx, Cmd } from '../ctx'; import * as sourceChange from '../source_change'; @@ -16,9 +17,7 @@ export * from './ssr'; export * from './server_version'; export function collectGarbage(ctx: Ctx): Cmd { - return async () => { - await ctx.client?.sendRequest('rust-analyzer/collectGarbage', null); - }; + return async () => ctx.client.sendRequest(ra.collectGarbage, null); } export function showReferences(ctx: Ctx): Cmd { @@ -36,13 +35,13 @@ export function showReferences(ctx: Ctx): Cmd { } export function applySourceChange(ctx: Ctx): Cmd { - return async (change: sourceChange.SourceChange) => { + return async (change: ra.SourceChange) => { await sourceChange.applySourceChange(ctx, change); }; } export function selectAndApplySourceChange(ctx: Ctx): Cmd { - return async (changes: sourceChange.SourceChange[]) => { + return async (changes: ra.SourceChange[]) => { if (changes.length === 1) { await sourceChange.applySourceChange(ctx, changes[0]); } else if (changes.length > 0) { -- cgit v1.2.3 From 38d7945ec7d3522e09a105a92156d1aaf8651f46 Mon Sep 17 00:00:00 2001 From: Veetaha Date: Tue, 25 Feb 2020 00:54:50 +0200 Subject: vscode: migrate join_lines to rust-analyzer-api.ts --- editors/code/src/commands/join_lines.ts | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) (limited to 'editors/code/src/commands') diff --git a/editors/code/src/commands/join_lines.ts b/editors/code/src/commands/join_lines.ts index 7b08c3255..de0614653 100644 --- a/editors/code/src/commands/join_lines.ts +++ b/editors/code/src/commands/join_lines.ts @@ -1,7 +1,7 @@ -import * as lc from 'vscode-languageclient'; +import * as ra from '../rust-analyzer-api'; import { Ctx, Cmd } from '../ctx'; -import { applySourceChange, SourceChange } from '../source_change'; +import { applySourceChange } from '../source_change'; export function joinLines(ctx: Ctx): Cmd { return async () => { @@ -9,19 +9,10 @@ export function joinLines(ctx: Ctx): Cmd { const client = ctx.client; if (!editor || !client) return; - const request: JoinLinesParams = { + const change = await client.sendRequest(ra.joinLines, { range: client.code2ProtocolConverter.asRange(editor.selection), textDocument: { uri: editor.document.uri.toString() }, - }; - const change = await client.sendRequest( - 'rust-analyzer/joinLines', - request, - ); + }); await applySourceChange(ctx, change); }; } - -interface JoinLinesParams { - textDocument: lc.TextDocumentIdentifier; - range: lc.Range; -} -- cgit v1.2.3 From 56d1ff65324d59623e8483c7cbf03672611cbcdf Mon Sep 17 00:00:00 2001 From: Veetaha Date: Tue, 25 Feb 2020 00:55:13 +0200 Subject: vscode: migrate matching_brace to rust-analyzer-api.ts --- editors/code/src/commands/matching_brace.ts | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) (limited to 'editors/code/src/commands') diff --git a/editors/code/src/commands/matching_brace.ts b/editors/code/src/commands/matching_brace.ts index 7c58bb7e7..a60776e2d 100644 --- a/editors/code/src/commands/matching_brace.ts +++ b/editors/code/src/commands/matching_brace.ts @@ -1,5 +1,5 @@ import * as vscode from 'vscode'; -import * as lc from 'vscode-languageclient'; +import * as ra from '../rust-analyzer-api'; import { Ctx, Cmd } from '../ctx'; @@ -9,16 +9,12 @@ export function matchingBrace(ctx: Ctx): Cmd { const client = ctx.client; if (!editor || !client) return; - const request: FindMatchingBraceParams = { + const response = await client.sendRequest(ra.findMatchingBrace, { textDocument: { uri: editor.document.uri.toString() }, offsets: editor.selections.map(s => client.code2ProtocolConverter.asPosition(s.active), ), - }; - const response = await client.sendRequest( - 'rust-analyzer/findMatchingBrace', - request, - ); + }); editor.selections = editor.selections.map((sel, idx) => { const active = client.protocol2CodeConverter.asPosition( response[idx], @@ -29,8 +25,3 @@ export function matchingBrace(ctx: Ctx): Cmd { editor.revealRange(editor.selection); }; } - -interface FindMatchingBraceParams { - textDocument: lc.TextDocumentIdentifier; - offsets: lc.Position[]; -} -- cgit v1.2.3 From 8c6581dcc3db0e79a075d22ab930cb58a31dfe3c Mon Sep 17 00:00:00 2001 From: Veetaha Date: Tue, 25 Feb 2020 00:55:48 +0200 Subject: vscode: migrate on_enter to rust-analyzer-api.ts --- editors/code/src/commands/on_enter.ts | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'editors/code/src/commands') diff --git a/editors/code/src/commands/on_enter.ts b/editors/code/src/commands/on_enter.ts index 27ae8ec23..285849db7 100644 --- a/editors/code/src/commands/on_enter.ts +++ b/editors/code/src/commands/on_enter.ts @@ -1,7 +1,7 @@ import * as vscode from 'vscode'; -import * as lc from 'vscode-languageclient'; +import * as ra from '../rust-analyzer-api'; -import { applySourceChange, SourceChange } from '../source_change'; +import { applySourceChange } from '../source_change'; import { Cmd, Ctx } from '../ctx'; async function handleKeypress(ctx: Ctx) { @@ -10,22 +10,15 @@ async function handleKeypress(ctx: Ctx) { if (!editor || !client) return false; - const request: lc.TextDocumentPositionParams = { + const change = await client.sendRequest(ra.onEnter, { textDocument: { uri: editor.document.uri.toString() }, position: client.code2ProtocolConverter.asPosition( editor.selection.active, ), - }; - const change = await client.sendRequest( - 'rust-analyzer/onEnter', - request, - ).catch( - (_error: any) => { - // FIXME: switch to the more modern (?) typed request infrastructure - // client.logFailedRequest(OnEnterRequest.type, error); - return Promise.resolve(null); - } - ); + }).catch(_error => { + // client.logFailedRequest(OnEnterRequest.type, error); + return null; + }); if (!change) return false; await applySourceChange(ctx, change); -- cgit v1.2.3 From d6a96a90f417d48e6391d2233abf752988c04f1a Mon Sep 17 00:00:00 2001 From: Veetaha Date: Tue, 25 Feb 2020 00:56:19 +0200 Subject: vscode: migrate parent_module to rust-analyzer-api.ts --- editors/code/src/commands/parent_module.ts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'editors/code/src/commands') diff --git a/editors/code/src/commands/parent_module.ts b/editors/code/src/commands/parent_module.ts index bf40b4021..8f78ddd71 100644 --- a/editors/code/src/commands/parent_module.ts +++ b/editors/code/src/commands/parent_module.ts @@ -1,5 +1,5 @@ import * as vscode from 'vscode'; -import * as lc from 'vscode-languageclient'; +import * as ra from '../rust-analyzer-api'; import { Ctx, Cmd } from '../ctx'; @@ -9,16 +9,12 @@ export function parentModule(ctx: Ctx): Cmd { const client = ctx.client; if (!editor || !client) return; - const request: lc.TextDocumentPositionParams = { + const response = await client.sendRequest(ra.parentModule, { textDocument: { uri: editor.document.uri.toString() }, position: client.code2ProtocolConverter.asPosition( editor.selection.active, ), - }; - const response = await client.sendRequest( - 'rust-analyzer/parentModule', - request, - ); + }); const loc = response[0]; if (loc == null) return; -- cgit v1.2.3 From 8a8a4d08ef6c695cce04f5e306fad83cc9abddcd Mon Sep 17 00:00:00 2001 From: Veetaha Date: Tue, 25 Feb 2020 00:56:38 +0200 Subject: vscode: migrate runnables to rust-analyzer-api.ts --- editors/code/src/commands/runnables.ts | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) (limited to 'editors/code/src/commands') diff --git a/editors/code/src/commands/runnables.ts b/editors/code/src/commands/runnables.ts index 7919997ce..06b513466 100644 --- a/editors/code/src/commands/runnables.ts +++ b/editors/code/src/commands/runnables.ts @@ -1,5 +1,6 @@ import * as vscode from 'vscode'; import * as lc from 'vscode-languageclient'; +import * as ra from '../rust-analyzer-api'; import { Ctx, Cmd } from '../ctx'; @@ -14,16 +15,13 @@ export function run(ctx: Ctx): Cmd { const textDocument: lc.TextDocumentIdentifier = { uri: editor.document.uri.toString(), }; - const params: RunnablesParams = { + + const runnables = await client.sendRequest(ra.runnables, { textDocument, position: client.code2ProtocolConverter.asPosition( editor.selection.active, ), - }; - const runnables = await client.sendRequest( - 'rust-analyzer/runnables', - params, - ); + }); const items: RunnableQuickPick[] = []; if (prevRunnable) { items.push(prevRunnable); @@ -48,7 +46,7 @@ export function run(ctx: Ctx): Cmd { } export function runSingle(ctx: Ctx): Cmd { - return async (runnable: Runnable) => { + return async (runnable: ra.Runnable) => { const editor = ctx.activeRustEditor; if (!editor) return; @@ -64,26 +62,13 @@ export function runSingle(ctx: Ctx): Cmd { }; } -interface RunnablesParams { - textDocument: lc.TextDocumentIdentifier; - position?: lc.Position; -} - -interface Runnable { - label: string; - bin: string; - args: string[]; - env: { [index: string]: string }; - cwd?: string; -} - class RunnableQuickPick implements vscode.QuickPickItem { public label: string; public description?: string | undefined; public detail?: string | undefined; public picked?: boolean | undefined; - constructor(public runnable: Runnable) { + constructor(public runnable: ra.Runnable) { this.label = runnable.label; } } @@ -96,7 +81,7 @@ interface CargoTaskDefinition extends vscode.TaskDefinition { env?: { [key: string]: string }; } -function createTask(spec: Runnable): vscode.Task { +function createTask(spec: ra.Runnable): vscode.Task { const TASK_SOURCE = 'Rust'; const definition: CargoTaskDefinition = { type: 'cargo', -- cgit v1.2.3 From 9ea63d5a86b8217c25f0db49a535105b345ceae1 Mon Sep 17 00:00:00 2001 From: Veetaha Date: Tue, 25 Feb 2020 00:56:57 +0200 Subject: vscode: migrate ssr to rust-analyzer-api.ts --- editors/code/src/commands/ssr.ts | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'editors/code/src/commands') diff --git a/editors/code/src/commands/ssr.ts b/editors/code/src/commands/ssr.ts index 9b814612a..63c36ce80 100644 --- a/editors/code/src/commands/ssr.ts +++ b/editors/code/src/commands/ssr.ts @@ -1,6 +1,8 @@ -import { Ctx, Cmd } from '../ctx'; -import { applySourceChange, SourceChange } from '../source_change'; import * as vscode from 'vscode'; +import * as ra from "../rust-analyzer-api"; + +import { Ctx, Cmd } from '../ctx'; +import { applySourceChange } from '../source_change'; export function ssr(ctx: Ctx): Cmd { return async () => { @@ -21,16 +23,8 @@ export function ssr(ctx: Ctx): Cmd { if (!request) return; - const ssrRequest: SsrRequest = { arg: request }; - const change = await client.sendRequest( - 'rust-analyzer/ssr', - ssrRequest, - ); + const change = await client.sendRequest(ra.ssr, { arg: request },); await applySourceChange(ctx, change); }; } - -interface SsrRequest { - arg: string; -} -- cgit v1.2.3 From 8aea0ec511d141b5c53d419960c688b13bb6c061 Mon Sep 17 00:00:00 2001 From: Veetaha Date: Tue, 25 Feb 2020 00:57:14 +0200 Subject: vscode: migrate syntax_tree to rust-analyzer-api.ts --- editors/code/src/commands/syntax_tree.ts | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) (limited to 'editors/code/src/commands') diff --git a/editors/code/src/commands/syntax_tree.ts b/editors/code/src/commands/syntax_tree.ts index 2887c96c8..7218bfb90 100644 --- a/editors/code/src/commands/syntax_tree.ts +++ b/editors/code/src/commands/syntax_tree.ts @@ -1,5 +1,5 @@ import * as vscode from 'vscode'; -import * as lc from 'vscode-languageclient'; +import * as ra from '../rust-analyzer-api'; import { Ctx, Cmd } from '../ctx'; @@ -61,13 +61,8 @@ function afterLs(f: () => void) { setTimeout(f, 10); } -interface SyntaxTreeParams { - textDocument: lc.TextDocumentIdentifier; - range?: lc.Range; -} -class TextDocumentContentProvider - implements vscode.TextDocumentContentProvider { +class TextDocumentContentProvider implements vscode.TextDocumentContentProvider { uri = vscode.Uri.parse('rust-analyzer://syntaxtree'); eventEmitter = new vscode.EventEmitter(); @@ -79,23 +74,15 @@ class TextDocumentContentProvider const client = this.ctx.client; if (!editor || !client) return ''; - let range: lc.Range | undefined; - // When the range based query is enabled we take the range of the selection - if (uri.query === 'range=true') { - range = editor.selection.isEmpty - ? undefined - : client.code2ProtocolConverter.asRange(editor.selection); - } + const range = uri.query === 'range=true' && !editor.selection.isEmpty + ? client.code2ProtocolConverter.asRange(editor.selection) + : null; - const request: SyntaxTreeParams = { + return client.sendRequest(ra.syntaxTree, { textDocument: { uri: editor.document.uri.toString() }, range, - }; - return client.sendRequest( - 'rust-analyzer/syntaxTree', - request, - ); + }); } get onDidChange(): vscode.Event { -- cgit v1.2.3 From 72e81dae71b8d2efbc418cba206b1988727766b7 Mon Sep 17 00:00:00 2001 From: Veetaha Date: Tue, 25 Feb 2020 01:00:00 +0200 Subject: vscode: run fmt --- editors/code/src/commands/ssr.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'editors/code/src/commands') diff --git a/editors/code/src/commands/ssr.ts b/editors/code/src/commands/ssr.ts index 63c36ce80..eee48c693 100644 --- a/editors/code/src/commands/ssr.ts +++ b/editors/code/src/commands/ssr.ts @@ -23,7 +23,7 @@ export function ssr(ctx: Ctx): Cmd { if (!request) return; - const change = await client.sendRequest(ra.ssr, { arg: request },); + const change = await client.sendRequest(ra.ssr, { arg: request }); await applySourceChange(ctx, change); }; -- cgit v1.2.3