running prettier

This commit is contained in:
Bruno Ortiz 2023-04-02 22:37:07 -03:00
parent 440889edec
commit 061940dad9
4 changed files with 86 additions and 91 deletions

View file

@ -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,
@ -13,7 +13,7 @@ import {
log,
RustEditor,
} from "./util";
import {ServerStatusParams} from "./lsp_ext";
import { ServerStatusParams } from "./lsp_ext";
import {
Dependency,
DependencyFile,
@ -27,10 +27,10 @@ import {
RustDependenciesProvider,
DependencyId,
} from "./dependencies_provider";
import {execRevealDependency} from "./commands";
import {PersistentState} from "./persistent_state";
import {bootstrap} from "./bootstrap";
import {ExecOptions} from "child_process";
import { execRevealDependency } from "./commands";
import { PersistentState } from "./persistent_state";
import { bootstrap } from "./bootstrap";
import { ExecOptions } from "child_process";
// We only support local folders, not eg. Live Share (`vlsl:` scheme), so don't activate if
// only those are in use. We use "Empty" to represent these scenarios
@ -40,11 +40,11 @@ export type Workspace =
| { kind: "Empty" }
| {
kind: "Workspace Folder";
}
}
| {
kind: "Detached Files";
files: vscode.TextDocument[];
};
};
export function fetchWorkspace(): Workspace {
const folders = (vscode.workspace.workspaceFolders || []).filter(
@ -56,12 +56,12 @@ export function fetchWorkspace(): Workspace {
return folders.length === 0
? rustDocuments.length === 0
? {kind: "Empty"}
? { kind: "Empty" }
: {
kind: "Detached Files",
files: rustDocuments,
}
: {kind: "Workspace Folder"};
: { kind: "Workspace Folder" };
}
export async function discoverWorkspace(
@ -116,7 +116,7 @@ export class Ctx {
constructor(
readonly extCtx: vscode.ExtensionContext,
commandFactories: Record<string, CommandFactory>,
workspace: Workspace,
workspace: Workspace
) {
extCtx.subscriptions.push(this);
this.statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
@ -128,8 +128,7 @@ export class Ctx {
this.state = new PersistentState(extCtx.globalState);
this.config = new Config(extCtx);
this.updateCommands("disable"
);
this.updateCommands("disable");
this.setServerStatus({
health: "stopped",
});
@ -198,7 +197,7 @@ export class Ctx {
const newEnv = Object.assign({}, process.env, this.config.serverExtraEnv);
const run: lc.Executable = {
command: this._serverPath,
options: {env: newEnv},
options: { env: newEnv },
};
const serverOptions = {
run,
@ -276,7 +275,7 @@ export class Ctx {
private prepareTreeDependenciesView(client: lc.LanguageClient) {
const ctxInit: CtxInit = {
...this,
client: client
client: client,
};
const rootPath = vscode.workspace.workspaceFolders![0].uri.fsPath;
this._dependencies = new RustDependenciesProvider(rootPath, ctxInit);

View file

@ -13,8 +13,8 @@ import * as ra from "./lsp_ext";
export class RustDependenciesProvider
implements vscode.TreeDataProvider<Dependency | DependencyFile>
{
dependenciesMap: { [id: string]: Dependency | DependencyFile };ctx: CtxInit;
dependenciesMap: { [id: string]: Dependency | DependencyFile };
ctx: CtxInit;
constructor(private readonly workspaceRoot: string,ctx: CtxInit) {
this.dependenciesMap = {};
@ -82,7 +82,10 @@ export class RustDependenciesProvider
private async getRootDependencies(): Promise<Dependency[]> {
const crates = await this.ctx.client.sendRequest(ra.fetchDependencyGraph, {});
const dependenciesResult: FetchDependencyGraphResult = await this.ctx.client.sendRequest(ra.fetchDependencyGraph, {});
const dependenciesResult: FetchDependencyGraphResult = await this.ctx.client.sendRequest(
ra.fetchDependencyGraph,
{}
);
const crates = dependenciesResult.crates;
const deps = crates.map((crate) => {
const dep = this.toDep(crate.name, crate.version, crate.path);
@ -94,13 +97,8 @@ export class RustDependenciesProvider
}
private toDep(moduleName: string, version: string, path: string): Dependency {
//const cratePath = fspath.join(basePath, `${moduleName}-${version}`);
return new Dependency(
moduleName,
version,
path,
vscode.TreeItemCollapsibleState.Collapsed
);
// const cratePath = fspath.join(basePath, `${moduleName}-${version}`);
return new Dependency(moduleName, version, path, vscode.TreeItemCollapsibleState.Collapsed);
}
}

View file

@ -2,10 +2,10 @@ import * as vscode from "vscode";
import * as lc from "vscode-languageclient/node";
import * as commands from "./commands";
import {CommandFactory, Ctx, fetchWorkspace} from "./ctx";
import { CommandFactory, Ctx, fetchWorkspace } from "./ctx";
import * as diagnostics from "./diagnostics";
import {activateTaskProvider} from "./tasks";
import {setContextValue} from "./util";
import { activateTaskProvider } from "./tasks";
import { setContextValue } from "./util";
const RUST_PROJECT_CONTEXT_NAME = "inRustProject";
@ -28,8 +28,7 @@ export async function activate(
"both plugins to not work correctly. You should disable one of them.",
"Got it"
)
.then(() => {
}, console.error);
.then(() => {}, console.error);
}
const ctx = new Ctx(context, createCommands(), fetchWorkspace());
@ -119,7 +118,7 @@ function createCommands(): Record<string, CommandFactory> {
return {
onEnter: {
enabled: commands.onEnter,
disabled: (_) => () => vscode.commands.executeCommand("default:type", {text: "\n"}),
disabled: (_) => () => vscode.commands.executeCommand("default:type", { text: "\n" }),
},
restartServer: {
enabled: (ctx) => async () => {
@ -145,53 +144,52 @@ function createCommands(): Record<string, CommandFactory> {
health: "stopped",
});
},
disabled: (_) => async () => {
},
disabled: (_) => async () => {},
},
analyzerStatus: {enabled: commands.analyzerStatus},
memoryUsage: {enabled: commands.memoryUsage},
shuffleCrateGraph: {enabled: commands.shuffleCrateGraph},
reloadWorkspace: {enabled: commands.reloadWorkspace},
rebuildProcMacros: {enabled: commands.rebuildProcMacros},
addProject: {enabled: commands.addProject},
matchingBrace: {enabled: commands.matchingBrace},
joinLines: {enabled: commands.joinLines},
parentModule: {enabled: commands.parentModule},
syntaxTree: {enabled: commands.syntaxTree},
viewHir: {enabled: commands.viewHir},
viewMir: {enabled: commands.viewMir},
analyzerStatus: { enabled: commands.analyzerStatus },
memoryUsage: { enabled: commands.memoryUsage },
shuffleCrateGraph: { enabled: commands.shuffleCrateGraph },
reloadWorkspace: { enabled: commands.reloadWorkspace },
rebuildProcMacros: { enabled: commands.rebuildProcMacros },
addProject: { enabled: commands.addProject },
matchingBrace: { enabled: commands.matchingBrace },
joinLines: { enabled: commands.joinLines },
parentModule: { enabled: commands.parentModule },
syntaxTree: { enabled: commands.syntaxTree },
viewHir: { enabled: commands.viewHir },
viewMir: { enabled: commands.viewMir },
interpretFunction: { enabled: commands.interpretFunction },
viewFileText: {enabled: commands.viewFileText},
viewItemTree: {enabled: commands.viewItemTree},
viewCrateGraph: {enabled: commands.viewCrateGraph},
viewFullCrateGraph: {enabled: commands.viewFullCrateGraph},
expandMacro: {enabled: commands.expandMacro},
run: {enabled: commands.run},
copyRunCommandLine: {enabled: commands.copyRunCommandLine},
debug: {enabled: commands.debug},
newDebugConfig: {enabled: commands.newDebugConfig},
openDocs: {enabled: commands.openDocs},
openCargoToml: {enabled: commands.openCargoToml},
peekTests: {enabled: commands.peekTests},
moveItemUp: {enabled: commands.moveItemUp},
moveItemDown: {enabled: commands.moveItemDown},
cancelFlycheck: {enabled: commands.cancelFlycheck},
clearFlycheck: {enabled: commands.clearFlycheck},
runFlycheck: {enabled: commands.runFlycheck},
ssr: {enabled: commands.ssr},
serverVersion: {enabled: commands.serverVersion},
viewFileText: { enabled: commands.viewFileText },
viewItemTree: { enabled: commands.viewItemTree },
viewCrateGraph: { enabled: commands.viewCrateGraph },
viewFullCrateGraph: { enabled: commands.viewFullCrateGraph },
expandMacro: { enabled: commands.expandMacro },
run: { enabled: commands.run },
copyRunCommandLine: { enabled: commands.copyRunCommandLine },
debug: { enabled: commands.debug },
newDebugConfig: { enabled: commands.newDebugConfig },
openDocs: { enabled: commands.openDocs },
openCargoToml: { enabled: commands.openCargoToml },
peekTests: { enabled: commands.peekTests },
moveItemUp: { enabled: commands.moveItemUp },
moveItemDown: { enabled: commands.moveItemDown },
cancelFlycheck: { enabled: commands.cancelFlycheck },
clearFlycheck: { enabled: commands.clearFlycheck },
runFlycheck: { enabled: commands.runFlycheck },
ssr: { enabled: commands.ssr },
serverVersion: { enabled: commands.serverVersion },
// Internal commands which are invoked by the server.
applyActionGroup: {enabled: commands.applyActionGroup},
applySnippetWorkspaceEdit: {enabled: commands.applySnippetWorkspaceEditCommand},
debugSingle: {enabled: commands.debugSingle},
gotoLocation: {enabled: commands.gotoLocation},
linkToCommand: {enabled: commands.linkToCommand},
resolveCodeAction: {enabled: commands.resolveCodeAction},
runSingle: {enabled: commands.runSingle},
showReferences: {enabled: commands.showReferences},
triggerParameterHints: {enabled: commands.triggerParameterHints},
openLogs: {enabled: commands.openLogs},
revealDependency: {enabled: commands.revealDependency}
applyActionGroup: { enabled: commands.applyActionGroup },
applySnippetWorkspaceEdit: { enabled: commands.applySnippetWorkspaceEditCommand },
debugSingle: { enabled: commands.debugSingle },
gotoLocation: { enabled: commands.gotoLocation },
linkToCommand: { enabled: commands.linkToCommand },
resolveCodeAction: { enabled: commands.resolveCodeAction },
runSingle: { enabled: commands.runSingle },
showReferences: { enabled: commands.showReferences },
triggerParameterHints: { enabled: commands.triggerParameterHints },
openLogs: { enabled: commands.openLogs },
revealDependency: { enabled: commands.revealDependency },
};
}

View file

@ -3,7 +3,7 @@ import * as os from "os";
import * as path from "path";
import * as readline from "readline";
import * as vscode from "vscode";
import {execute, log, memoizeAsync} from "./util";
import { execute, log, memoizeAsync } from "./util";
interface CompilationArtifact {
fileName: string;
@ -42,7 +42,7 @@ export class Cargo {
}
}
const result: ArtifactSpec = {cargoArgs: cargoArgs};
const result: ArtifactSpec = { cargoArgs: cargoArgs };
if (cargoArgs[0] === "test" || cargoArgs[0] === "bench") {
// for instance, `crates\rust-analyzer\tests\heavy_tests\main.rs` tests
// produce 2 artifacts: {"kind": "bin"} and {"kind": "test"}
@ -147,7 +147,7 @@ export class Cargo {
cargo.stderr.on("data", (chunk) => onStderrString(chunk.toString()));
const rl = readline.createInterface({input: cargo.stdout});
const rl = readline.createInterface({ input: cargo.stdout });
rl.on("line", (line) => {
const message = JSON.parse(line);
onStdoutJson(message);
@ -189,14 +189,14 @@ export async function getSysroot(dir: string): Promise<string> {
const rustcPath = await getPathForExecutable("rustc");
// do not memoize the result because the toolchain may change between runs
return await execute(`${rustcPath} --print sysroot`, {cwd: dir});
return await execute(`${rustcPath} --print sysroot`, { cwd: dir });
}
export async function getRustcId(dir: string): Promise<string> {
const rustcPath = await getPathForExecutable("rustc");
// do not memoize the result because the toolchain may change between runs
const data = await execute(`${rustcPath} -V -v`, {cwd: dir});
const data = await execute(`${rustcPath} -V -v`, { cwd: dir });
const rx = /commit-hash:\s(.*)$/m;
return rx.exec(data)![1];