mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
vscode: migrate runnables to rust-analyzer-api.ts
This commit is contained in:
parent
d6a96a90f4
commit
8a8a4d08ef
1 changed files with 7 additions and 22 deletions
|
@ -1,5 +1,6 @@
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
import * as lc from 'vscode-languageclient';
|
import * as lc from 'vscode-languageclient';
|
||||||
|
import * as ra from '../rust-analyzer-api';
|
||||||
|
|
||||||
import { Ctx, Cmd } from '../ctx';
|
import { Ctx, Cmd } from '../ctx';
|
||||||
|
|
||||||
|
@ -14,16 +15,13 @@ export function run(ctx: Ctx): Cmd {
|
||||||
const textDocument: lc.TextDocumentIdentifier = {
|
const textDocument: lc.TextDocumentIdentifier = {
|
||||||
uri: editor.document.uri.toString(),
|
uri: editor.document.uri.toString(),
|
||||||
};
|
};
|
||||||
const params: RunnablesParams = {
|
|
||||||
|
const runnables = await client.sendRequest(ra.runnables, {
|
||||||
textDocument,
|
textDocument,
|
||||||
position: client.code2ProtocolConverter.asPosition(
|
position: client.code2ProtocolConverter.asPosition(
|
||||||
editor.selection.active,
|
editor.selection.active,
|
||||||
),
|
),
|
||||||
};
|
});
|
||||||
const runnables = await client.sendRequest<Runnable[]>(
|
|
||||||
'rust-analyzer/runnables',
|
|
||||||
params,
|
|
||||||
);
|
|
||||||
const items: RunnableQuickPick[] = [];
|
const items: RunnableQuickPick[] = [];
|
||||||
if (prevRunnable) {
|
if (prevRunnable) {
|
||||||
items.push(prevRunnable);
|
items.push(prevRunnable);
|
||||||
|
@ -48,7 +46,7 @@ export function run(ctx: Ctx): Cmd {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function runSingle(ctx: Ctx): Cmd {
|
export function runSingle(ctx: Ctx): Cmd {
|
||||||
return async (runnable: Runnable) => {
|
return async (runnable: ra.Runnable) => {
|
||||||
const editor = ctx.activeRustEditor;
|
const editor = ctx.activeRustEditor;
|
||||||
if (!editor) return;
|
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 {
|
class RunnableQuickPick implements vscode.QuickPickItem {
|
||||||
public label: string;
|
public label: string;
|
||||||
public description?: string | undefined;
|
public description?: string | undefined;
|
||||||
public detail?: string | undefined;
|
public detail?: string | undefined;
|
||||||
public picked?: boolean | undefined;
|
public picked?: boolean | undefined;
|
||||||
|
|
||||||
constructor(public runnable: Runnable) {
|
constructor(public runnable: ra.Runnable) {
|
||||||
this.label = runnable.label;
|
this.label = runnable.label;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,7 +81,7 @@ interface CargoTaskDefinition extends vscode.TaskDefinition {
|
||||||
env?: { [key: string]: string };
|
env?: { [key: string]: string };
|
||||||
}
|
}
|
||||||
|
|
||||||
function createTask(spec: Runnable): vscode.Task {
|
function createTask(spec: ra.Runnable): vscode.Task {
|
||||||
const TASK_SOURCE = 'Rust';
|
const TASK_SOURCE = 'Rust';
|
||||||
const definition: CargoTaskDefinition = {
|
const definition: CargoTaskDefinition = {
|
||||||
type: 'cargo',
|
type: 'cargo',
|
||||||
|
|
Loading…
Reference in a new issue