mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
Reformat VSCode client code
This commit is contained in:
parent
d1721b11e9
commit
af999f152b
4 changed files with 36 additions and 41 deletions
|
@ -8,7 +8,7 @@ import { applySnippetWorkspaceEdit, applySnippetTextEdits } from "./snippets";
|
|||
import { spawnSync } from "child_process";
|
||||
import { RunnableQuickPick, selectRunnable, createTask, createArgs } from "./run";
|
||||
import { AstInspector } from "./ast_inspector";
|
||||
import { isRustDocument, isCargoTomlDocument, sleep, isRustEditor, RustEditor } from './util';
|
||||
import { isRustDocument, isCargoTomlDocument, sleep, isRustEditor, RustEditor } from "./util";
|
||||
import { startDebugSession, makeDebugConfig } from "./debug";
|
||||
import { LanguageClient } from "vscode-languageclient/node";
|
||||
import { LINKED_COMMANDS } from "./client";
|
||||
|
|
|
@ -3,8 +3,8 @@ import * as lc from "vscode-languageclient/node";
|
|||
import * as ra from "./lsp_ext";
|
||||
import * as path from "path";
|
||||
|
||||
import {Config, prepareVSCodeConfig} from './config';
|
||||
import {createClient} from './client';
|
||||
import {Config, prepareVSCodeConfig} from "./config";
|
||||
import {createClient} from "./client";
|
||||
import {
|
||||
executeDiscoverProject,
|
||||
isRustDocument,
|
||||
|
@ -12,10 +12,15 @@ import {
|
|||
LazyOutputChannel,
|
||||
log,
|
||||
RustEditor,
|
||||
} from './util';
|
||||
import {ServerStatusParams} from './lsp_ext';
|
||||
import { Dependency, DependencyFile, RustDependenciesProvider, DependencyId } from './dependencies_provider';
|
||||
import { execRevealDependency } from './commands';
|
||||
} from "./util";
|
||||
import {ServerStatusParams} from "./lsp_ext";
|
||||
import {
|
||||
Dependency,
|
||||
DependencyFile,
|
||||
RustDependenciesProvider,
|
||||
DependencyId,
|
||||
} from "./dependencies_provider";
|
||||
import { execRevealDependency } from "./commands";
|
||||
import {
|
||||
Dependency,
|
||||
DependencyFile,
|
||||
|
|
|
@ -7,7 +7,9 @@ import { FetchDependencyGraphResult } from "./lsp_ext";
|
|||
|
||||
|
||||
|
||||
export class RustDependenciesProvider implements vscode.TreeDataProvider<Dependency | DependencyFile>{
|
||||
export class RustDependenciesProvider
|
||||
implements vscode.TreeDataProvider<Dependency | DependencyFile>
|
||||
{
|
||||
|
||||
dependenciesMap: { [id: string]: Dependency | DependencyFile };ctx: CtxInit;
|
||||
|
||||
|
@ -49,7 +51,9 @@ export class RustDependenciesProvider implements vscode.TreeDataProvider<Depende
|
|||
return element;
|
||||
}
|
||||
|
||||
getChildren(element?: Dependency | DependencyFile): vscode.ProviderResult<Dependency[] | DependencyFile[]> {
|
||||
getChildren(
|
||||
element?: Dependency | DependencyFile
|
||||
): vscode.ProviderResult<Dependency[] | DependencyFile[]> {
|
||||
return new Promise((resolve, _reject) => {
|
||||
if (!this.workspaceRoot) {
|
||||
void vscode.window.showInformationMessage("No dependency in empty workspace");
|
||||
|
@ -61,19 +65,12 @@ export class RustDependenciesProvider implements vscode.TreeDataProvider<Depende
|
|||
const filePath = fspath.join(element.dependencyPath, fileName);
|
||||
const collapsibleState = fs.lstatSync(filePath).isDirectory()
|
||||
? vscode.TreeItemCollapsibleState.Collapsed
|
||||
:vscode.TreeItemCollapsibleState.None;
|
||||
const dep = new DependencyFile(
|
||||
fileName,
|
||||
filePath,
|
||||
element,
|
||||
collapsibleState);
|
||||
|
||||
: vscode.TreeItemCollapsibleState.None;
|
||||
const dep = new DependencyFile(fileName, filePath, element, collapsibleState);
|
||||
this.dependenciesMap[dep.dependencyPath.toLowerCase()] = dep;
|
||||
return dep;
|
||||
});
|
||||
return resolve(
|
||||
files
|
||||
);
|
||||
return resolve(files);
|
||||
} else {
|
||||
return resolve(this.getRootDependencies());
|
||||
}
|
||||
|
@ -118,7 +115,6 @@ export class Dependency extends vscode.TreeItem {
|
|||
}
|
||||
|
||||
export class DependencyFile extends vscode.TreeItem {
|
||||
|
||||
constructor(
|
||||
readonly label: string,
|
||||
readonly dependencyPath: string,
|
||||
|
|
|
@ -103,12 +103,12 @@ export class Cargo {
|
|||
return await new Promise((resolve, reject) => {
|
||||
const crates: Crate[] = [];
|
||||
|
||||
const cargo = cp.spawn(pathToCargo, ['tree', '--prefix', 'none'], {
|
||||
stdio: ['ignore', 'pipe', 'pipe'],
|
||||
cwd: this.rootFolder
|
||||
const cargo = cp.spawn(pathToCargo, ["tree", "--prefix", "none"], {
|
||||
stdio: ["ignore", "pipe", "pipe"],
|
||||
cwd: this.rootFolder,
|
||||
});
|
||||
const rl = readline.createInterface({ input: cargo.stdout });
|
||||
rl.on('line', line => {
|
||||
rl.on("line", (line) => {
|
||||
const match = line.match(TREE_LINE_PATTERN);
|
||||
if (match) {
|
||||
const name = match[1];
|
||||
|
@ -121,18 +121,15 @@ export class Cargo {
|
|||
crates.push({ name, version });
|
||||
}
|
||||
});
|
||||
cargo.on('exit', (exitCode, _) => {
|
||||
if (exitCode === 0)
|
||||
resolve(crates);
|
||||
else
|
||||
reject(new Error(`exit code: ${exitCode}.`));
|
||||
cargo.on("exit", (exitCode, _) => {
|
||||
if (exitCode === 0) resolve(crates);
|
||||
else reject(new Error(`exit code: ${exitCode}.`));
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private shouldIgnore(extraInfo: string): boolean {
|
||||
return extraInfo !== undefined && (extraInfo === '*' || path.isAbsolute(extraInfo));
|
||||
return extraInfo !== undefined && (extraInfo === "*" || path.isAbsolute(extraInfo));
|
||||
}
|
||||
|
||||
private async runCargo(
|
||||
|
@ -169,26 +166,23 @@ export class Cargo {
|
|||
export async function activeToolchain(): Promise<string> {
|
||||
const pathToRustup = await rustupPath();
|
||||
return await new Promise((resolve, reject) => {
|
||||
const execution = cp.spawn(pathToRustup, ['show', 'active-toolchain'], {
|
||||
stdio: ['ignore', 'pipe', 'pipe'],
|
||||
cwd: os.homedir()
|
||||
const execution = cp.spawn(pathToRustup, ["show", "active-toolchain"], {
|
||||
stdio: ["ignore", "pipe", "pipe"],
|
||||
cwd: os.homedir(),
|
||||
});
|
||||
const rl = readline.createInterface({ input: execution.stdout });
|
||||
|
||||
let currToolchain: string | undefined = undefined;
|
||||
rl.on('line', line => {
|
||||
rl.on("line", (line) => {
|
||||
const match = line.match(TOOLCHAIN_PATTERN);
|
||||
if (match) {
|
||||
currToolchain = match[1];
|
||||
}
|
||||
});
|
||||
execution.on('exit', (exitCode, _) => {
|
||||
if (exitCode === 0 && currToolchain)
|
||||
resolve(currToolchain);
|
||||
else
|
||||
reject(new Error(`exit code: ${exitCode}.`));
|
||||
execution.on("exit", (exitCode, _) => {
|
||||
if (exitCode === 0 && currToolchain) resolve(currToolchain);
|
||||
else reject(new Error(`exit code: ${exitCode}.`));
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue