Skip to content

Commit 76432d3

Browse files
Veykrilbruno-ortiz
authored andcommitted
Reformat VSCode client code
1 parent 364308d commit 76432d3

File tree

4 files changed

+82
-72
lines changed

4 files changed

+82
-72
lines changed

editors/code/src/commands.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import { applySnippetWorkspaceEdit, applySnippetTextEdits } from "./snippets";
88
import { spawnSync } from "child_process";
99
import { RunnableQuickPick, selectRunnable, createTask, createArgs } from "./run";
1010
import { AstInspector } from "./ast_inspector";
11-
import { isRustDocument, isCargoTomlDocument, sleep, isRustEditor, RustEditor } from './util';
11+
import { isRustDocument, isCargoTomlDocument, sleep, isRustEditor, RustEditor } from "./util";
1212
import { startDebugSession, makeDebugConfig } from "./debug";
1313
import { LanguageClient } from "vscode-languageclient/node";
1414
import { LINKED_COMMANDS } from "./client";
15-
import { DependencyId } from './dependencies_provider';
15+
import { DependencyId } from "./dependencies_provider";
1616

1717
export * from "./ast_inspector";
1818
export * from "./run";
@@ -291,8 +291,7 @@ export function revealDependency(ctx: CtxInit): Cmd {
291291
do {
292292
documentPath = path.dirname(documentPath);
293293
parentChain.push({ id: documentPath.toLowerCase() });
294-
}
295-
while (!ctx.dependencies.contains(documentPath));
294+
} while (!ctx.dependencies.contains(documentPath));
296295
parentChain.reverse();
297296
for (const idx in parentChain) {
298297
await ctx.treeView.reveal(parentChain[idx], { select: true, expand: true });
@@ -302,7 +301,7 @@ export function revealDependency(ctx: CtxInit): Cmd {
302301
}
303302

304303
export async function execRevealDependency(e: RustEditor): Promise<void> {
305-
await vscode.commands.executeCommand('rust-analyzer.revealDependency', e);
304+
await vscode.commands.executeCommand("rust-analyzer.revealDependency", e);
306305
}
307306

308307
export function ssr(ctx: CtxInit): Cmd {

editors/code/src/ctx.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,24 @@ import * as lc from "vscode-languageclient/node";
33
import * as ra from "./lsp_ext";
44
import * as path from "path";
55

6-
import {Config, prepareVSCodeConfig} from './config';
7-
import {createClient} from './client';
6+
import {Config, prepareVSCodeConfig} from "./config";
7+
import {createClient} from "./client";
88
import {
99
executeDiscoverProject,
1010
isRustDocument,
1111
isRustEditor,
1212
LazyOutputChannel,
1313
log,
1414
RustEditor,
15-
} from './util';
16-
import {ServerStatusParams} from './lsp_ext';
17-
import {Dependency, DependencyFile, RustDependenciesProvider, DependencyId} from './dependencies_provider';
18-
import {execRevealDependency} from './commands';
15+
} from "./util";
16+
import {ServerStatusParams} from "./lsp_ext";
17+
import {
18+
Dependency,
19+
DependencyFile,
20+
RustDependenciesProvider,
21+
DependencyId,
22+
} from "./dependencies_provider";
23+
import {execRevealDependency} from "./commands";
1924
import {PersistentState} from "./persistent_state";
2025
import {bootstrap} from "./bootstrap";
2126
import {ExecOptions} from "child_process";
@@ -113,13 +118,14 @@ export class Ctx {
113118
this.state = new PersistentState(extCtx.globalState);
114119
this.config = new Config(extCtx);
115120

116-
this.updateCommands("disable");
121+
this.updateCommands("disable"
122+
);
117123
this.setServerStatus({
118124
health: "stopped",
119125
});
120-
vscode.window.onDidChangeActiveTextEditor(e => {
126+
vscode.window.onDidChangeActiveTextEditor((e) => {
121127
if (e && isRustEditor(e)) {
122-
execRevealDependency(e).catch(reason => {
128+
execRevealDependency(e).catch((reason) => {
123129
void vscode.window.showErrorMessage(`Dependency error: ${reason}`);
124130
});
125131
}

editors/code/src/dependencies_provider.ts

Lines changed: 48 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
1-
import * as vscode from 'vscode';
2-
import * as fspath from 'path';
3-
import * as fs from 'fs';
4-
import * as os from 'os';
5-
import { activeToolchain, Cargo, Crate, getRustcVersion } from './toolchain';
1+
import * as vscode from "vscode";
2+
import * as fspath from "path";
3+
import * as fs from "fs";
4+
import * as os from "os";
5+
import { activeToolchain, Cargo, Crate, getRustcVersion } from "./toolchain";
66

77
const debugOutput = vscode.window.createOutputChannel("Debug");
88

9-
export class RustDependenciesProvider implements vscode.TreeDataProvider<Dependency | DependencyFile>{
9+
export class RustDependenciesProvider
10+
implements vscode.TreeDataProvider<Dependency | DependencyFile>
11+
{
1012
cargo: Cargo;
1113
dependenciesMap: { [id: string]: Dependency | DependencyFile };
1214

13-
constructor(
14-
private readonly workspaceRoot: string,
15-
) {
16-
this.cargo = new Cargo(this.workspaceRoot || '.', debugOutput);
15+
constructor(private readonly workspaceRoot: string) {
16+
this.cargo = new Cargo(this.workspaceRoot || ".", debugOutput);
1717
this.dependenciesMap = {};
1818
}
1919

20-
private _onDidChangeTreeData: vscode.EventEmitter<Dependency | DependencyFile | undefined | null | void> = new vscode.EventEmitter<Dependency | undefined | null | void>();
21-
22-
readonly onDidChangeTreeData: vscode.Event<Dependency | DependencyFile | undefined | null | void> = this._onDidChangeTreeData.event;
20+
private _onDidChangeTreeData: vscode.EventEmitter<
21+
Dependency | DependencyFile | undefined | null | void
22+
> = new vscode.EventEmitter<Dependency | undefined | null | void>();
2323

24+
readonly onDidChangeTreeData: vscode.Event<
25+
Dependency | DependencyFile | undefined | null | void
26+
> = this._onDidChangeTreeData.event;
2427

2528
getDependency(filePath: string): Dependency | DependencyFile | undefined {
2629
return this.dependenciesMap[filePath.toLowerCase()];
@@ -34,7 +37,9 @@ export class RustDependenciesProvider implements vscode.TreeDataProvider<Depende
3437
this._onDidChangeTreeData.fire();
3538
}
3639

37-
getParent?(element: Dependency | DependencyFile): vscode.ProviderResult<Dependency | DependencyFile> {
40+
getParent?(
41+
element: Dependency | DependencyFile
42+
): vscode.ProviderResult<Dependency | DependencyFile> {
3843
if (element instanceof Dependency) return undefined;
3944
return element.parent;
4045
}
@@ -44,39 +49,34 @@ export class RustDependenciesProvider implements vscode.TreeDataProvider<Depende
4449
return element;
4550
}
4651

47-
getChildren(element?: Dependency | DependencyFile): vscode.ProviderResult<Dependency[] | DependencyFile[]> {
52+
getChildren(
53+
element?: Dependency | DependencyFile
54+
): vscode.ProviderResult<Dependency[] | DependencyFile[]> {
4855
return new Promise((resolve, _reject) => {
4956
if (!this.workspaceRoot) {
50-
void vscode.window.showInformationMessage('No dependency in empty workspace');
57+
void vscode.window.showInformationMessage("No dependency in empty workspace");
5158
return Promise.resolve([]);
5259
}
5360

5461
if (element) {
55-
const files = fs.readdirSync(element.dependencyPath).map(fileName => {
62+
const files = fs.readdirSync(element.dependencyPath).map((fileName) => {
5663
const filePath = fspath.join(element.dependencyPath, fileName);
57-
const collapsibleState = fs.lstatSync(filePath).isDirectory() ?
58-
vscode.TreeItemCollapsibleState.Collapsed :
59-
vscode.TreeItemCollapsibleState.None;
60-
const dep = new DependencyFile(
61-
fileName,
62-
filePath,
63-
element,
64-
collapsibleState
65-
);
64+
const collapsibleState = fs.lstatSync(filePath).isDirectory()
65+
? vscode.TreeItemCollapsibleState.Collapsed
66+
: vscode.TreeItemCollapsibleState.None;
67+
const dep = new DependencyFile(fileName, filePath, element, collapsibleState);
6668
this.dependenciesMap[dep.dependencyPath.toLowerCase()] = dep;
6769
return dep;
6870
});
69-
return resolve(
70-
files
71-
);
71+
return resolve(files);
7272
} else {
7373
return resolve(this.getRootDependencies());
7474
}
7575
});
7676
}
7777

7878
private async getRootDependencies(): Promise<Dependency[]> {
79-
const registryDir = fspath.join(os.homedir(), '.cargo', 'registry', 'src');
79+
const registryDir = fspath.join(os.homedir(), ".cargo", "registry", "src");
8080
const basePath = fspath.join(registryDir, fs.readdirSync(registryDir)[0]);
8181
const deps = await this.getDepsInCartoTree(basePath);
8282
const stdlib = await this.getStdLib();
@@ -87,7 +87,17 @@ export class RustDependenciesProvider implements vscode.TreeDataProvider<Depende
8787
private async getStdLib(): Promise<Dependency> {
8888
const toolchain = await activeToolchain();
8989
const rustVersion = await getRustcVersion(os.homedir());
90-
const stdlibPath = fspath.join(os.homedir(), '.rustup', 'toolchains', toolchain, 'lib', 'rustlib', 'src', 'rust', 'library');
90+
const stdlibPath = fspath.join(
91+
os.homedir(),
92+
".rustup",
93+
"toolchains",
94+
toolchain,
95+
"lib",
96+
"rustlib",
97+
"src",
98+
"rust",
99+
"library"
100+
);
91101
const stdlib = new Dependency(
92102
"stdlib",
93103
rustVersion,
@@ -110,7 +120,7 @@ export class RustDependenciesProvider implements vscode.TreeDataProvider<Depende
110120
);
111121
};
112122

113-
const deps = crates.map(crate => {
123+
const deps = crates.map((crate) => {
114124
const dep = toDep(crate.name, crate.version);
115125
this.dependenciesMap[dep.dependencyPath.toLowerCase()] = dep;
116126
return dep;
@@ -119,7 +129,6 @@ export class RustDependenciesProvider implements vscode.TreeDataProvider<Depende
119129
}
120130
}
121131

122-
123132
export class Dependency extends vscode.TreeItem {
124133
constructor(
125134
public readonly label: string,
@@ -135,7 +144,6 @@ export class Dependency extends vscode.TreeItem {
135144
}
136145

137146
export class DependencyFile extends vscode.TreeItem {
138-
139147
constructor(
140148
readonly label: string,
141149
readonly dependencyPath: string,
@@ -146,9 +154,13 @@ export class DependencyFile extends vscode.TreeItem {
146154
const isDir = fs.lstatSync(this.dependencyPath).isDirectory();
147155
this.id = this.dependencyPath.toLowerCase();
148156
if (!isDir) {
149-
this.command = { command: 'rust-analyzer.openFile', title: "Open File", arguments: [vscode.Uri.file(this.dependencyPath)], };
157+
this.command = {
158+
command: "rust-analyzer.openFile",
159+
title: "Open File",
160+
arguments: [vscode.Uri.file(this.dependencyPath)],
161+
};
150162
}
151163
}
152164
}
153165

154-
export type DependencyId = { id: string };
166+
export type DependencyId = { id: string };

editors/code/src/toolchain.ts

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import * as readline from "readline";
55
import * as vscode from "vscode";
66
import { execute, log, memoizeAsync } from "./util";
77

8-
98
const TREE_LINE_PATTERN = new RegExp(/(.+)\sv(\d+\.\d+\.\d+)(?:\s\((.+)\))?/);
109
const TOOLCHAIN_PATTERN = new RegExp(/(.*)\s\(.*\)/);
1110

@@ -110,12 +109,12 @@ export class Cargo {
110109
return await new Promise((resolve, reject) => {
111110
const crates: Crate[] = [];
112111

113-
const cargo = cp.spawn(pathToCargo, ['tree', '--prefix', 'none'], {
114-
stdio: ['ignore', 'pipe', 'pipe'],
115-
cwd: this.rootFolder
112+
const cargo = cp.spawn(pathToCargo, ["tree", "--prefix", "none"], {
113+
stdio: ["ignore", "pipe", "pipe"],
114+
cwd: this.rootFolder,
116115
});
117116
const rl = readline.createInterface({ input: cargo.stdout });
118-
rl.on('line', line => {
117+
rl.on("line", (line) => {
119118
const match = line.match(TREE_LINE_PATTERN);
120119
if (match) {
121120
const name = match[1];
@@ -128,18 +127,15 @@ export class Cargo {
128127
crates.push({ name, version });
129128
}
130129
});
131-
cargo.on('exit', (exitCode, _) => {
132-
if (exitCode === 0)
133-
resolve(crates);
134-
else
135-
reject(new Error(`exit code: ${exitCode}.`));
130+
cargo.on("exit", (exitCode, _) => {
131+
if (exitCode === 0) resolve(crates);
132+
else reject(new Error(`exit code: ${exitCode}.`));
136133
});
137-
138134
});
139135
}
140136

141137
private shouldIgnore(extraInfo: string): boolean {
142-
return extraInfo !== undefined && (extraInfo === '*' || path.isAbsolute(extraInfo));
138+
return extraInfo !== undefined && (extraInfo === "*" || path.isAbsolute(extraInfo));
143139
}
144140

145141
private async runCargo(
@@ -176,26 +172,23 @@ export class Cargo {
176172
export async function activeToolchain(): Promise<string> {
177173
const pathToRustup = await rustupPath();
178174
return await new Promise((resolve, reject) => {
179-
const execution = cp.spawn(pathToRustup, ['show', 'active-toolchain'], {
180-
stdio: ['ignore', 'pipe', 'pipe'],
181-
cwd: os.homedir()
175+
const execution = cp.spawn(pathToRustup, ["show", "active-toolchain"], {
176+
stdio: ["ignore", "pipe", "pipe"],
177+
cwd: os.homedir(),
182178
});
183179
const rl = readline.createInterface({ input: execution.stdout });
184180

185181
let currToolchain: string | undefined = undefined;
186-
rl.on('line', line => {
182+
rl.on("line", (line) => {
187183
const match = line.match(TOOLCHAIN_PATTERN);
188184
if (match) {
189185
currToolchain = match[1];
190186
}
191187
});
192-
execution.on('exit', (exitCode, _) => {
193-
if (exitCode === 0 && currToolchain)
194-
resolve(currToolchain);
195-
else
196-
reject(new Error(`exit code: ${exitCode}.`));
188+
execution.on("exit", (exitCode, _) => {
189+
if (exitCode === 0 && currToolchain) resolve(currToolchain);
190+
else reject(new Error(`exit code: ${exitCode}.`));
197191
});
198-
199192
});
200193
}
201194

0 commit comments

Comments
 (0)