Skip to content

Commit bd2160f

Browse files
committed
final rabasing fixes
1 parent 66fe84d commit bd2160f

File tree

3 files changed

+23
-104
lines changed

3 files changed

+23
-104
lines changed

editors/code/src/ctx.ts

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@ import {
2222
DependencyId,
2323
} from "./dependencies_provider";
2424
import { execRevealDependency } from "./commands";
25-
import {
26-
Dependency,
27-
DependencyFile,
28-
RustDependenciesProvider,
29-
DependencyId,
30-
} from "./dependencies_provider";
31-
import { execRevealDependency } from "./commands";
3225
import { PersistentState } from "./persistent_state";
3326
import { bootstrap } from "./bootstrap";
3427
import { ExecOptions } from "child_process";
@@ -40,12 +33,12 @@ import { ExecOptions } from "child_process";
4033
export type Workspace =
4134
| { kind: "Empty" }
4235
| {
43-
kind: "Workspace Folder";
44-
}
36+
kind: "Workspace Folder";
37+
}
4538
| {
46-
kind: "Detached Files";
47-
files: vscode.TextDocument[];
48-
};
39+
kind: "Detached Files";
40+
files: vscode.TextDocument[];
41+
};
4942

5043
export function fetchWorkspace(): Workspace {
5144
const folders = (vscode.workspace.workspaceFolders || []).filter(
@@ -59,9 +52,9 @@ export function fetchWorkspace(): Workspace {
5952
? rustDocuments.length === 0
6053
? { kind: "Empty" }
6154
: {
62-
kind: "Detached Files",
63-
files: rustDocuments,
64-
}
55+
kind: "Detached Files",
56+
files: rustDocuments,
57+
}
6558
: { kind: "Workspace Folder" };
6659
}
6760

@@ -483,4 +476,4 @@ export interface Disposable {
483476
dispose(): void;
484477
}
485478

486-
export type Cmd = (...args: any[]) => unknown;
479+
export type Cmd = (...args: any[]) => unknown;

editors/code/src/dependencies_provider.ts

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
import * as vscode from "vscode";
22
import * as fspath from "path";
33
import * as fs from "fs";
4-
import { CtxInit } from "./ctx";
4+
import {CtxInit} from "./ctx";
55
import * as ra from "./lsp_ext";
6-
import { FetchDependencyListResult } from "./lsp_ext";
7-
import { Ctx } from "./ctx";
8-
import { setFlagsFromString } from "v8";
9-
import * as ra from "./lsp_ext";
10-
6+
import {FetchDependencyListResult} from "./lsp_ext";
117

128
export class RustDependenciesProvider
13-
implements vscode.TreeDataProvider<Dependency | DependencyFile>
14-
{
9+
implements vscode.TreeDataProvider<Dependency | DependencyFile> {
1510
dependenciesMap: { [id: string]: Dependency | DependencyFile };
1611
ctx: CtxInit;
1712

@@ -61,7 +56,6 @@ export class RustDependenciesProvider
6156
void vscode.window.showInformationMessage("No dependency in empty workspace");
6257
return Promise.resolve([]);
6358
}
64-
6559
if (element) {
6660
const files = fs.readdirSync(element.dependencyPath).map((fileName) => {
6761
const filePath = fspath.join(element.dependencyPath, fileName);
@@ -80,20 +74,17 @@ export class RustDependenciesProvider
8074
}
8175

8276
private async getRootDependencies(): Promise<Dependency[]> {
83-
const crates = await this.ctx.client.sendRequest(ra.fetchDependencyGraph, {});
84-
8577
const dependenciesResult: FetchDependencyListResult = await this.ctx.client.sendRequest(
8678
ra.fetchDependencyList,
8779
{}
8880
);
8981
const crates = dependenciesResult.crates;
90-
const deps = crates.map((crate) => {
91-
const dep = this.toDep(crate.name || "unknown", crate.version || "", crate.path);
82+
83+
return crates.map((crate) => {
84+
const dep = this.toDep(crate.name || "unknown", crate.version || "", crate.path);
9285
this.dependenciesMap[dep.dependencyPath.toLowerCase()] = dep;
93-
this.dependenciesMap[stdlib.dependencyPath.toLowerCase()] = stdlib;
94-
return dep;
86+
return dep;
9587
});
96-
return deps;
9788
}
9889

9990
private toDep(moduleName: string, version: string, path: string): Dependency {
@@ -131,11 +122,13 @@ export class DependencyFile extends vscode.TreeItem {
131122
this.id = this.dependencyPath.toLowerCase();
132123
const isDir = fs.lstatSync(this.dependencyPath).isDirectory();
133124
if (!isDir) {
134-
this.command = { command: "vscode.open",
125+
this.command = {
126+
command: "vscode.open",
135127
title: "Open File",
136128
arguments: [vscode.Uri.file(this.dependencyPath)],
137-
};
138-
}}
129+
};
130+
}
131+
}
139132
}
140133

141-
export type DependencyId = { id: string };
134+
export type DependencyId = { id: string };

editors/code/src/toolchain.ts

Lines changed: 1 addition & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -96,40 +96,6 @@ export class Cargo {
9696
return artifacts[0].fileName;
9797
}
9898

99-
async crates(): Promise<Crate[]> {
100-
const pathToCargo = await cargoPath();
101-
return await new Promise((resolve, reject) => {
102-
const crates: Crate[] = [];
103-
104-
const cargo = cp.spawn(pathToCargo, ["tree", "--prefix", "none"], {
105-
stdio: ["ignore", "pipe", "pipe"],
106-
cwd: this.rootFolder,
107-
});
108-
const rl = readline.createInterface({ input: cargo.stdout });
109-
rl.on("line", (line) => {
110-
const match = line.match(TREE_LINE_PATTERN);
111-
if (match) {
112-
const name = match[1];
113-
const version = match[2];
114-
const extraInfo = match[3];
115-
// ignore duplicates '(*)' and path dependencies
116-
if (this.shouldIgnore(extraInfo)) {
117-
return;
118-
}
119-
crates.push({ name, version });
120-
}
121-
});
122-
cargo.on("exit", (exitCode, _) => {
123-
if (exitCode === 0) resolve(crates);
124-
else reject(new Error(`exit code: ${exitCode}.`));
125-
});
126-
});
127-
}
128-
129-
private shouldIgnore(extraInfo: string): boolean {
130-
return extraInfo !== undefined && (extraInfo === "*" || path.isAbsolute(extraInfo));
131-
}
132-
13399
private async runCargo(
134100
cargoArgs: string[],
135101
onStdoutJson: (obj: any) => void,
@@ -161,29 +127,6 @@ export class Cargo {
161127
}
162128
}
163129

164-
export async function activeToolchain(): Promise<string> {
165-
const pathToRustup = await rustupPath();
166-
return await new Promise((resolve, reject) => {
167-
const execution = cp.spawn(pathToRustup, ["show", "active-toolchain"], {
168-
stdio: ["ignore", "pipe", "pipe"],
169-
cwd: os.homedir(),
170-
});
171-
const rl = readline.createInterface({ input: execution.stdout });
172-
173-
let currToolchain: string | undefined = undefined;
174-
rl.on("line", (line) => {
175-
const match = line.match(TOOLCHAIN_PATTERN);
176-
if (match) {
177-
currToolchain = match[1];
178-
}
179-
});
180-
execution.on("exit", (exitCode, _) => {
181-
if (exitCode === 0 && currToolchain) resolve(currToolchain);
182-
else reject(new Error(`exit code: ${exitCode}.`));
183-
});
184-
});
185-
}
186-
187130
/** Mirrors `project_model::sysroot::discover_sysroot_dir()` implementation*/
188131
export async function getSysroot(dir: string): Promise<string> {
189132
const rustcPath = await getPathForExecutable("rustc");
@@ -202,16 +145,6 @@ export async function getRustcId(dir: string): Promise<string> {
202145
return rx.exec(data)![1];
203146
}
204147

205-
export async function getRustcVersion(dir: string): Promise<string> {
206-
const rustcPath = await getPathForExecutable("rustc");
207-
208-
// do not memoize the result because the toolchain may change between runs
209-
const data = await execute(`${rustcPath} -V`, { cwd: dir });
210-
const rx = /(\d\.\d+\.\d+)/;
211-
212-
return rx.exec(data)![1];
213-
}
214-
215148
/** Mirrors `toolchain::cargo()` implementation */
216149
export function cargoPath(): Promise<string> {
217150
return getPathForExecutable("cargo");
@@ -278,4 +211,4 @@ async function isFileAtUri(uri: vscode.Uri): Promise<boolean> {
278211
} catch {
279212
return false;
280213
}
281-
}
214+
}

0 commit comments

Comments
 (0)