about summary refs log tree commit diff
path: root/editors/code/src
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2022-07-17 17:38:56 +0200
committerBruno Ortiz <brunortiz11@gmail.com>2023-05-02 10:48:38 -0300
commit76432d39cb01423ca3c3add391218269d95c46a4 (patch)
treeebba31b3760ab261b75b48fdcccc45af3aa2291d /editors/code/src
parent364308d1dc653199dd786486f4eed0d456a95330 (diff)
downloadrust-76432d39cb01423ca3c3add391218269d95c46a4.tar.gz
rust-76432d39cb01423ca3c3add391218269d95c46a4.zip
Reformat VSCode client code
Diffstat (limited to 'editors/code/src')
-rw-r--r--editors/code/src/commands.ts9
-rw-r--r--editors/code/src/ctx.ts24
-rw-r--r--editors/code/src/dependencies_provider.ts84
-rw-r--r--editors/code/src/toolchain.ts37
4 files changed, 82 insertions, 72 deletions
diff --git a/editors/code/src/commands.ts b/editors/code/src/commands.ts
index e5aa06025b2..c8b54970a5f 100644
--- a/editors/code/src/commands.ts
+++ b/editors/code/src/commands.ts
@@ -8,11 +8,11 @@ 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";
-import { DependencyId } from './dependencies_provider';
+import { DependencyId } from "./dependencies_provider";
 
 export * from "./ast_inspector";
 export * from "./run";
@@ -291,8 +291,7 @@ export function revealDependency(ctx: CtxInit): Cmd {
             do {
                 documentPath = path.dirname(documentPath);
                 parentChain.push({ id: documentPath.toLowerCase() });
-            }
-            while (!ctx.dependencies.contains(documentPath));
+            } while (!ctx.dependencies.contains(documentPath));
             parentChain.reverse();
             for (const idx in parentChain) {
                 await ctx.treeView.reveal(parentChain[idx], { select: true, expand: true });
@@ -302,7 +301,7 @@ export function revealDependency(ctx: CtxInit): Cmd {
 }
 
 export async function execRevealDependency(e: RustEditor): Promise<void> {
-    await vscode.commands.executeCommand('rust-analyzer.revealDependency', e);
+    await vscode.commands.executeCommand("rust-analyzer.revealDependency", e);
 }
 
 export function ssr(ctx: CtxInit): Cmd {
diff --git a/editors/code/src/ctx.ts b/editors/code/src/ctx.ts
index e6829ac4b9e..feb39198c22 100644
--- a/editors/code/src/ctx.ts
+++ b/editors/code/src/ctx.ts
@@ -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 {PersistentState} from "./persistent_state";
 import {bootstrap} from "./bootstrap";
 import {ExecOptions} from "child_process";
@@ -113,13 +118,14 @@ export class Ctx {
         this.state = new PersistentState(extCtx.globalState);
         this.config = new Config(extCtx);
 
-        this.updateCommands("disable");
+        this.updateCommands("disable"
+        );
         this.setServerStatus({
             health: "stopped",
         });
-        vscode.window.onDidChangeActiveTextEditor(e => {
+        vscode.window.onDidChangeActiveTextEditor((e) => {
             if (e && isRustEditor(e)) {
-                execRevealDependency(e).catch(reason => {
+                execRevealDependency(e).catch((reason) => {
                     void vscode.window.showErrorMessage(`Dependency error: ${reason}`);
                 });
             }
diff --git a/editors/code/src/dependencies_provider.ts b/editors/code/src/dependencies_provider.ts
index 2df5ef61111..b8b33a9be6a 100644
--- a/editors/code/src/dependencies_provider.ts
+++ b/editors/code/src/dependencies_provider.ts
@@ -1,26 +1,29 @@
-import * as vscode from 'vscode';
-import * as fspath from 'path';
-import * as fs from 'fs';
-import * as os from 'os';
-import { activeToolchain, Cargo, Crate, getRustcVersion } from './toolchain';
+import * as vscode from "vscode";
+import * as fspath from "path";
+import * as fs from "fs";
+import * as os from "os";
+import { activeToolchain, Cargo, Crate, getRustcVersion } from "./toolchain";
 
 const debugOutput = vscode.window.createOutputChannel("Debug");
 
-export class RustDependenciesProvider implements vscode.TreeDataProvider<Dependency | DependencyFile>{
+export class RustDependenciesProvider
+    implements vscode.TreeDataProvider<Dependency | DependencyFile>
+{
     cargo: Cargo;
     dependenciesMap: { [id: string]: Dependency | DependencyFile };
 
-    constructor(
-        private readonly workspaceRoot: string,
-    ) {
-        this.cargo = new Cargo(this.workspaceRoot || '.', debugOutput);
+    constructor(private readonly workspaceRoot: string) {
+        this.cargo = new Cargo(this.workspaceRoot || ".", debugOutput);
         this.dependenciesMap = {};
     }
 
-    private _onDidChangeTreeData: vscode.EventEmitter<Dependency | DependencyFile | undefined | null | void> = new vscode.EventEmitter<Dependency | undefined | null | void>();
-
-    readonly onDidChangeTreeData: vscode.Event<Dependency | DependencyFile | undefined | null | void> = this._onDidChangeTreeData.event;
+    private _onDidChangeTreeData: vscode.EventEmitter<
+        Dependency | DependencyFile | undefined | null | void
+    > = new vscode.EventEmitter<Dependency | undefined | null | void>();
 
+    readonly onDidChangeTreeData: vscode.Event<
+        Dependency | DependencyFile | undefined | null | void
+    > = this._onDidChangeTreeData.event;
 
     getDependency(filePath: string): Dependency | DependencyFile | undefined {
         return this.dependenciesMap[filePath.toLowerCase()];
@@ -34,7 +37,9 @@ export class RustDependenciesProvider implements vscode.TreeDataProvider<Depende
         this._onDidChangeTreeData.fire();
     }
 
-    getParent?(element: Dependency | DependencyFile): vscode.ProviderResult<Dependency | DependencyFile> {
+    getParent?(
+        element: Dependency | DependencyFile
+    ): vscode.ProviderResult<Dependency | DependencyFile> {
         if (element instanceof Dependency) return undefined;
         return element.parent;
     }
@@ -44,31 +49,26 @@ 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');
+                void vscode.window.showInformationMessage("No dependency in empty workspace");
                 return Promise.resolve([]);
             }
 
             if (element) {
-                const files = fs.readdirSync(element.dependencyPath).map(fileName => {
+                const files = fs.readdirSync(element.dependencyPath).map((fileName) => {
                     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
-                    );
+                    const collapsibleState = fs.lstatSync(filePath).isDirectory()
+                        ? vscode.TreeItemCollapsibleState.Collapsed
+                        : 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());
             }
@@ -76,7 +76,7 @@ export class RustDependenciesProvider implements vscode.TreeDataProvider<Depende
     }
 
     private async getRootDependencies(): Promise<Dependency[]> {
-        const registryDir = fspath.join(os.homedir(), '.cargo', 'registry', 'src');
+        const registryDir = fspath.join(os.homedir(), ".cargo", "registry", "src");
         const basePath = fspath.join(registryDir, fs.readdirSync(registryDir)[0]);
         const deps = await this.getDepsInCartoTree(basePath);
         const stdlib = await this.getStdLib();
@@ -87,7 +87,17 @@ export class RustDependenciesProvider implements vscode.TreeDataProvider<Depende
     private async getStdLib(): Promise<Dependency> {
         const toolchain = await activeToolchain();
         const rustVersion = await getRustcVersion(os.homedir());
-        const stdlibPath = fspath.join(os.homedir(), '.rustup', 'toolchains', toolchain, 'lib', 'rustlib', 'src', 'rust', 'library');
+        const stdlibPath = fspath.join(
+            os.homedir(),
+            ".rustup",
+            "toolchains",
+            toolchain,
+            "lib",
+            "rustlib",
+            "src",
+            "rust",
+            "library"
+        );
         const stdlib = new Dependency(
             "stdlib",
             rustVersion,
@@ -110,7 +120,7 @@ export class RustDependenciesProvider implements vscode.TreeDataProvider<Depende
             );
         };
 
-        const deps = crates.map(crate => {
+        const deps = crates.map((crate) => {
             const dep = toDep(crate.name, crate.version);
             this.dependenciesMap[dep.dependencyPath.toLowerCase()] = dep;
             return dep;
@@ -119,7 +129,6 @@ export class RustDependenciesProvider implements vscode.TreeDataProvider<Depende
     }
 }
 
-
 export class Dependency extends vscode.TreeItem {
     constructor(
         public readonly label: string,
@@ -135,7 +144,6 @@ export class Dependency extends vscode.TreeItem {
 }
 
 export class DependencyFile extends vscode.TreeItem {
-
     constructor(
         readonly label: string,
         readonly dependencyPath: string,
@@ -146,9 +154,13 @@ export class DependencyFile extends vscode.TreeItem {
         const isDir = fs.lstatSync(this.dependencyPath).isDirectory();
         this.id = this.dependencyPath.toLowerCase();
         if (!isDir) {
-            this.command = { command: 'rust-analyzer.openFile', title: "Open File", arguments: [vscode.Uri.file(this.dependencyPath)], };
+            this.command = {
+                command: "rust-analyzer.openFile",
+                title: "Open File",
+                arguments: [vscode.Uri.file(this.dependencyPath)],
+            };
         }
     }
 }
 
-export type DependencyId = { id: string };
\ No newline at end of file
+export type DependencyId = { id: string };
diff --git a/editors/code/src/toolchain.ts b/editors/code/src/toolchain.ts
index 75e0ed1d125..c068cfc3118 100644
--- a/editors/code/src/toolchain.ts
+++ b/editors/code/src/toolchain.ts
@@ -5,7 +5,6 @@ import * as readline from "readline";
 import * as vscode from "vscode";
 import { execute, log, memoizeAsync } from "./util";
 
-
 const TREE_LINE_PATTERN = new RegExp(/(.+)\sv(\d+\.\d+\.\d+)(?:\s\((.+)\))?/);
 const TOOLCHAIN_PATTERN = new RegExp(/(.*)\s\(.*\)/);
 
@@ -110,12 +109,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];
@@ -128,18 +127,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(
@@ -176,26 +172,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}.`));
         });
-
     });
 }