mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 05:15:04 +00:00
fmt
This commit is contained in:
parent
8af3d6367e
commit
46e022098f
8 changed files with 58 additions and 37 deletions
|
@ -4,7 +4,14 @@ import * as ra from "./lsp_ext";
|
|||
|
||||
import { Config, substituteVSCodeVariables } from "./config";
|
||||
import { createClient } from "./client";
|
||||
import { executeDiscoverProject, isRustDocument, isRustEditor, LazyOutputChannel, log, RustEditor } from "./util";
|
||||
import {
|
||||
executeDiscoverProject,
|
||||
isRustDocument,
|
||||
isRustEditor,
|
||||
LazyOutputChannel,
|
||||
log,
|
||||
RustEditor,
|
||||
} from "./util";
|
||||
import { ServerStatusParams } from "./lsp_ext";
|
||||
import { PersistentState } from "./persistent_state";
|
||||
import { bootstrap } from "./bootstrap";
|
||||
|
@ -17,12 +24,12 @@ import { ExecOptions } from "child_process";
|
|||
export type Workspace =
|
||||
| { kind: "Empty" }
|
||||
| {
|
||||
kind: "Workspace Folder";
|
||||
}
|
||||
kind: "Workspace Folder";
|
||||
}
|
||||
| {
|
||||
kind: "Detached Files";
|
||||
files: vscode.TextDocument[];
|
||||
};
|
||||
kind: "Detached Files";
|
||||
files: vscode.TextDocument[];
|
||||
};
|
||||
|
||||
export function fetchWorkspace(): Workspace {
|
||||
const folders = (vscode.workspace.workspaceFolders || []).filter(
|
||||
|
@ -36,13 +43,17 @@ export function fetchWorkspace(): Workspace {
|
|||
? rustDocuments.length === 0
|
||||
? { kind: "Empty" }
|
||||
: {
|
||||
kind: "Detached Files",
|
||||
files: rustDocuments,
|
||||
}
|
||||
kind: "Detached Files",
|
||||
files: rustDocuments,
|
||||
}
|
||||
: { kind: "Workspace Folder" };
|
||||
}
|
||||
|
||||
export async function discoverWorkspace(files: readonly vscode.TextDocument[], command: string[], options: ExecOptions): Promise<JsonProject> {
|
||||
export async function discoverWorkspace(
|
||||
files: readonly vscode.TextDocument[],
|
||||
command: string[],
|
||||
options: ExecOptions
|
||||
): Promise<JsonProject> {
|
||||
const paths = files.map((f) => f.uri.fsPath).join(" ");
|
||||
const joinedCommand = command.join(" ");
|
||||
const data = await executeDiscoverProject(`${joinedCommand} -- ${paths}`, options);
|
||||
|
@ -80,7 +91,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);
|
||||
|
@ -180,16 +191,22 @@ export class Ctx {
|
|||
|
||||
const discoverProjectCommand = this.config.discoverProjectCommand;
|
||||
if (discoverProjectCommand) {
|
||||
let workspaces: JsonProject[] = await Promise.all(vscode.workspace.workspaceFolders!.map(async (folder): Promise<JsonProject> => {
|
||||
return discoverWorkspace(vscode.workspace.textDocuments, discoverProjectCommand, { cwd: folder.uri.fsPath });
|
||||
}));
|
||||
const workspaces: JsonProject[] = await Promise.all(
|
||||
vscode.workspace.workspaceFolders!.map(async (folder): Promise<JsonProject> => {
|
||||
return discoverWorkspace(
|
||||
vscode.workspace.textDocuments,
|
||||
discoverProjectCommand,
|
||||
{ cwd: folder.uri.fsPath }
|
||||
);
|
||||
})
|
||||
);
|
||||
|
||||
this.discoveredWorkspaces = workspaces;
|
||||
}
|
||||
|
||||
let initializationOptions = substituteVSCodeVariables(rawInitializationOptions);
|
||||
const initializationOptions = substituteVSCodeVariables(rawInitializationOptions);
|
||||
// this appears to be load-bearing, for better or worse.
|
||||
await initializationOptions.update('linkedProjects', this.discoveredWorkspaces)
|
||||
await initializationOptions.update("linkedProjects", this.discoveredWorkspaces);
|
||||
|
||||
this._client = await createClient(
|
||||
this.traceOutputChannel,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue