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

View file

@ -13,8 +13,8 @@ import * as ra from "./lsp_ext";
export class RustDependenciesProvider export class RustDependenciesProvider
implements vscode.TreeDataProvider<Dependency | DependencyFile> implements vscode.TreeDataProvider<Dependency | DependencyFile>
{ {
dependenciesMap: { [id: string]: Dependency | DependencyFile };
dependenciesMap: { [id: string]: Dependency | DependencyFile };ctx: CtxInit; ctx: CtxInit;
constructor(private readonly workspaceRoot: string,ctx: CtxInit) { constructor(private readonly workspaceRoot: string,ctx: CtxInit) {
this.dependenciesMap = {}; this.dependenciesMap = {};
@ -82,7 +82,10 @@ export class RustDependenciesProvider
private async getRootDependencies(): Promise<Dependency[]> { private async getRootDependencies(): Promise<Dependency[]> {
const crates = await this.ctx.client.sendRequest(ra.fetchDependencyGraph, {}); 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 crates = dependenciesResult.crates;
const deps = crates.map((crate) => { const deps = crates.map((crate) => {
const dep = this.toDep(crate.name, crate.version, crate.path); 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 { private toDep(moduleName: string, version: string, path: string): Dependency {
//const cratePath = fspath.join(basePath, `${moduleName}-${version}`); // const cratePath = fspath.join(basePath, `${moduleName}-${version}`);
return new Dependency( return new Dependency(moduleName, version, path, vscode.TreeItemCollapsibleState.Collapsed);
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 lc from "vscode-languageclient/node";
import * as commands from "./commands"; import * as commands from "./commands";
import {CommandFactory, Ctx, fetchWorkspace} from "./ctx"; import { CommandFactory, Ctx, fetchWorkspace } from "./ctx";
import * as diagnostics from "./diagnostics"; import * as diagnostics from "./diagnostics";
import {activateTaskProvider} from "./tasks"; import { activateTaskProvider } from "./tasks";
import {setContextValue} from "./util"; import { setContextValue } from "./util";
const RUST_PROJECT_CONTEXT_NAME = "inRustProject"; 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.", "both plugins to not work correctly. You should disable one of them.",
"Got it" "Got it"
) )
.then(() => { .then(() => {}, console.error);
}, console.error);
} }
const ctx = new Ctx(context, createCommands(), fetchWorkspace()); const ctx = new Ctx(context, createCommands(), fetchWorkspace());
@ -119,7 +118,7 @@ function createCommands(): Record<string, CommandFactory> {
return { return {
onEnter: { onEnter: {
enabled: commands.onEnter, enabled: commands.onEnter,
disabled: (_) => () => vscode.commands.executeCommand("default:type", {text: "\n"}), disabled: (_) => () => vscode.commands.executeCommand("default:type", { text: "\n" }),
}, },
restartServer: { restartServer: {
enabled: (ctx) => async () => { enabled: (ctx) => async () => {
@ -145,53 +144,52 @@ function createCommands(): Record<string, CommandFactory> {
health: "stopped", health: "stopped",
}); });
}, },
disabled: (_) => async () => { disabled: (_) => async () => {},
},
}, },
analyzerStatus: {enabled: commands.analyzerStatus}, analyzerStatus: { enabled: commands.analyzerStatus },
memoryUsage: {enabled: commands.memoryUsage}, memoryUsage: { enabled: commands.memoryUsage },
shuffleCrateGraph: {enabled: commands.shuffleCrateGraph}, shuffleCrateGraph: { enabled: commands.shuffleCrateGraph },
reloadWorkspace: {enabled: commands.reloadWorkspace}, reloadWorkspace: { enabled: commands.reloadWorkspace },
rebuildProcMacros: {enabled: commands.rebuildProcMacros}, rebuildProcMacros: { enabled: commands.rebuildProcMacros },
addProject: {enabled: commands.addProject}, addProject: { enabled: commands.addProject },
matchingBrace: {enabled: commands.matchingBrace}, matchingBrace: { enabled: commands.matchingBrace },
joinLines: {enabled: commands.joinLines}, joinLines: { enabled: commands.joinLines },
parentModule: {enabled: commands.parentModule}, parentModule: { enabled: commands.parentModule },
syntaxTree: {enabled: commands.syntaxTree}, syntaxTree: { enabled: commands.syntaxTree },
viewHir: {enabled: commands.viewHir}, viewHir: { enabled: commands.viewHir },
viewMir: {enabled: commands.viewMir}, viewMir: { enabled: commands.viewMir },
interpretFunction: { enabled: commands.interpretFunction }, interpretFunction: { enabled: commands.interpretFunction },
viewFileText: {enabled: commands.viewFileText}, viewFileText: { enabled: commands.viewFileText },
viewItemTree: {enabled: commands.viewItemTree}, viewItemTree: { enabled: commands.viewItemTree },
viewCrateGraph: {enabled: commands.viewCrateGraph}, viewCrateGraph: { enabled: commands.viewCrateGraph },
viewFullCrateGraph: {enabled: commands.viewFullCrateGraph}, viewFullCrateGraph: { enabled: commands.viewFullCrateGraph },
expandMacro: {enabled: commands.expandMacro}, expandMacro: { enabled: commands.expandMacro },
run: {enabled: commands.run}, run: { enabled: commands.run },
copyRunCommandLine: {enabled: commands.copyRunCommandLine}, copyRunCommandLine: { enabled: commands.copyRunCommandLine },
debug: {enabled: commands.debug}, debug: { enabled: commands.debug },
newDebugConfig: {enabled: commands.newDebugConfig}, newDebugConfig: { enabled: commands.newDebugConfig },
openDocs: {enabled: commands.openDocs}, openDocs: { enabled: commands.openDocs },
openCargoToml: {enabled: commands.openCargoToml}, openCargoToml: { enabled: commands.openCargoToml },
peekTests: {enabled: commands.peekTests}, peekTests: { enabled: commands.peekTests },
moveItemUp: {enabled: commands.moveItemUp}, moveItemUp: { enabled: commands.moveItemUp },
moveItemDown: {enabled: commands.moveItemDown}, moveItemDown: { enabled: commands.moveItemDown },
cancelFlycheck: {enabled: commands.cancelFlycheck}, cancelFlycheck: { enabled: commands.cancelFlycheck },
clearFlycheck: {enabled: commands.clearFlycheck}, clearFlycheck: { enabled: commands.clearFlycheck },
runFlycheck: {enabled: commands.runFlycheck}, runFlycheck: { enabled: commands.runFlycheck },
ssr: {enabled: commands.ssr}, ssr: { enabled: commands.ssr },
serverVersion: {enabled: commands.serverVersion}, serverVersion: { enabled: commands.serverVersion },
// Internal commands which are invoked by the server. // Internal commands which are invoked by the server.
applyActionGroup: {enabled: commands.applyActionGroup}, applyActionGroup: { enabled: commands.applyActionGroup },
applySnippetWorkspaceEdit: {enabled: commands.applySnippetWorkspaceEditCommand}, applySnippetWorkspaceEdit: { enabled: commands.applySnippetWorkspaceEditCommand },
debugSingle: {enabled: commands.debugSingle}, debugSingle: { enabled: commands.debugSingle },
gotoLocation: {enabled: commands.gotoLocation}, gotoLocation: { enabled: commands.gotoLocation },
linkToCommand: {enabled: commands.linkToCommand}, linkToCommand: { enabled: commands.linkToCommand },
resolveCodeAction: {enabled: commands.resolveCodeAction}, resolveCodeAction: { enabled: commands.resolveCodeAction },
runSingle: {enabled: commands.runSingle}, runSingle: { enabled: commands.runSingle },
showReferences: {enabled: commands.showReferences}, showReferences: { enabled: commands.showReferences },
triggerParameterHints: {enabled: commands.triggerParameterHints}, triggerParameterHints: { enabled: commands.triggerParameterHints },
openLogs: {enabled: commands.openLogs}, openLogs: { enabled: commands.openLogs },
revealDependency: {enabled: commands.revealDependency} revealDependency: { enabled: commands.revealDependency },
}; };
} }

View file

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