mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 21:43:37 +00:00
final rabasing fixes
This commit is contained in:
parent
66fe84d936
commit
bd2160f014
3 changed files with 23 additions and 104 deletions
|
@ -22,13 +22,6 @@ import {
|
||||||
DependencyId,
|
DependencyId,
|
||||||
} from "./dependencies_provider";
|
} from "./dependencies_provider";
|
||||||
import { execRevealDependency } from "./commands";
|
import { execRevealDependency } from "./commands";
|
||||||
import {
|
|
||||||
Dependency,
|
|
||||||
DependencyFile,
|
|
||||||
RustDependenciesProvider,
|
|
||||||
DependencyId,
|
|
||||||
} from "./dependencies_provider";
|
|
||||||
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";
|
||||||
|
@ -40,12 +33,12 @@ import { ExecOptions } from "child_process";
|
||||||
export type Workspace =
|
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(
|
||||||
|
@ -59,9 +52,9 @@ export function fetchWorkspace(): Workspace {
|
||||||
? 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" };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -483,4 +476,4 @@ export interface Disposable {
|
||||||
dispose(): void;
|
dispose(): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Cmd = (...args: any[]) => unknown;
|
export type Cmd = (...args: any[]) => unknown;
|
|
@ -1,17 +1,12 @@
|
||||||
import * as vscode from "vscode";
|
import * as vscode from "vscode";
|
||||||
import * as fspath from "path";
|
import * as fspath from "path";
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { CtxInit } from "./ctx";
|
import {CtxInit} from "./ctx";
|
||||||
import * as ra from "./lsp_ext";
|
import * as ra from "./lsp_ext";
|
||||||
import { FetchDependencyListResult } from "./lsp_ext";
|
import {FetchDependencyListResult} from "./lsp_ext";
|
||||||
import { Ctx } from "./ctx";
|
|
||||||
import { setFlagsFromString } from "v8";
|
|
||||||
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;
|
||||||
|
|
||||||
|
@ -61,7 +56,6 @@ export class RustDependenciesProvider
|
||||||
void vscode.window.showInformationMessage("No dependency in empty workspace");
|
void vscode.window.showInformationMessage("No dependency in empty workspace");
|
||||||
return Promise.resolve([]);
|
return Promise.resolve([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (element) {
|
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 filePath = fspath.join(element.dependencyPath, fileName);
|
||||||
|
@ -80,20 +74,17 @@ export class RustDependenciesProvider
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getRootDependencies(): Promise<Dependency[]> {
|
private async getRootDependencies(): Promise<Dependency[]> {
|
||||||
const crates = await this.ctx.client.sendRequest(ra.fetchDependencyGraph, {});
|
|
||||||
|
|
||||||
const dependenciesResult: FetchDependencyListResult = await this.ctx.client.sendRequest(
|
const dependenciesResult: FetchDependencyListResult = await this.ctx.client.sendRequest(
|
||||||
ra.fetchDependencyList,
|
ra.fetchDependencyList,
|
||||||
{}
|
{}
|
||||||
);
|
);
|
||||||
const crates = dependenciesResult.crates;
|
const crates = dependenciesResult.crates;
|
||||||
const deps = crates.map((crate) => {
|
|
||||||
const dep = this.toDep(crate.name || "unknown", crate.version || "", crate.path);
|
return crates.map((crate) => {
|
||||||
|
const dep = this.toDep(crate.name || "unknown", crate.version || "", crate.path);
|
||||||
this.dependenciesMap[dep.dependencyPath.toLowerCase()] = dep;
|
this.dependenciesMap[dep.dependencyPath.toLowerCase()] = dep;
|
||||||
this.dependenciesMap[stdlib.dependencyPath.toLowerCase()] = stdlib;
|
return dep;
|
||||||
return dep;
|
|
||||||
});
|
});
|
||||||
return deps;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private toDep(moduleName: string, version: string, path: string): Dependency {
|
private toDep(moduleName: string, version: string, path: string): Dependency {
|
||||||
|
@ -131,11 +122,13 @@ export class DependencyFile extends vscode.TreeItem {
|
||||||
this.id = this.dependencyPath.toLowerCase();
|
this.id = this.dependencyPath.toLowerCase();
|
||||||
const isDir = fs.lstatSync(this.dependencyPath).isDirectory();
|
const isDir = fs.lstatSync(this.dependencyPath).isDirectory();
|
||||||
if (!isDir) {
|
if (!isDir) {
|
||||||
this.command = { command: "vscode.open",
|
this.command = {
|
||||||
|
command: "vscode.open",
|
||||||
title: "Open File",
|
title: "Open File",
|
||||||
arguments: [vscode.Uri.file(this.dependencyPath)],
|
arguments: [vscode.Uri.file(this.dependencyPath)],
|
||||||
};
|
};
|
||||||
}}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export type DependencyId = { id: string };
|
export type DependencyId = { id: string };
|
|
@ -96,40 +96,6 @@ export class Cargo {
|
||||||
return artifacts[0].fileName;
|
return artifacts[0].fileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
async crates(): Promise<Crate[]> {
|
|
||||||
const pathToCargo = await cargoPath();
|
|
||||||
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 rl = readline.createInterface({ input: cargo.stdout });
|
|
||||||
rl.on("line", (line) => {
|
|
||||||
const match = line.match(TREE_LINE_PATTERN);
|
|
||||||
if (match) {
|
|
||||||
const name = match[1];
|
|
||||||
const version = match[2];
|
|
||||||
const extraInfo = match[3];
|
|
||||||
// ignore duplicates '(*)' and path dependencies
|
|
||||||
if (this.shouldIgnore(extraInfo)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
crates.push({ name, version });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
private async runCargo(
|
private async runCargo(
|
||||||
cargoArgs: string[],
|
cargoArgs: string[],
|
||||||
onStdoutJson: (obj: any) => void,
|
onStdoutJson: (obj: any) => void,
|
||||||
|
@ -161,29 +127,6 @@ 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 rl = readline.createInterface({ input: execution.stdout });
|
|
||||||
|
|
||||||
let currToolchain: string | undefined = undefined;
|
|
||||||
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}.`));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Mirrors `project_model::sysroot::discover_sysroot_dir()` implementation*/
|
/** Mirrors `project_model::sysroot::discover_sysroot_dir()` implementation*/
|
||||||
export async function getSysroot(dir: string): Promise<string> {
|
export async function getSysroot(dir: string): Promise<string> {
|
||||||
const rustcPath = await getPathForExecutable("rustc");
|
const rustcPath = await getPathForExecutable("rustc");
|
||||||
|
@ -202,16 +145,6 @@ export async function getRustcId(dir: string): Promise<string> {
|
||||||
return rx.exec(data)![1];
|
return rx.exec(data)![1];
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getRustcVersion(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`, { cwd: dir });
|
|
||||||
const rx = /(\d\.\d+\.\d+)/;
|
|
||||||
|
|
||||||
return rx.exec(data)![1];
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Mirrors `toolchain::cargo()` implementation */
|
/** Mirrors `toolchain::cargo()` implementation */
|
||||||
export function cargoPath(): Promise<string> {
|
export function cargoPath(): Promise<string> {
|
||||||
return getPathForExecutable("cargo");
|
return getPathForExecutable("cargo");
|
||||||
|
@ -278,4 +211,4 @@ async function isFileAtUri(uri: vscode.Uri): Promise<boolean> {
|
||||||
} catch {
|
} catch {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue