Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Dec 8, 2020. It is now read-only.

Commit 8e6422d

Browse filesBrowse files
authored
Fix installing missing tools (#293)
1 parent b042e8b commit 8e6422d
Copy full SHA for 8e6422d

File tree

7 files changed

+57
-37
lines changed
Filter options

7 files changed

+57
-37
lines changed

‎src/CargoInvocationManager.ts

Copy file name to clipboardExpand all lines: src/CargoInvocationManager.ts
+2-4Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ import { Rustup } from './components/configuration/Rustup';
55
* The class defines functions which can be used to get data required to invoke Cargo
66
*/
77
export class CargoInvocationManager {
8-
private _configuration: Configuration;
98
private _rustup: Rustup | undefined;
109

11-
public constructor(configuration: Configuration, rustup: Rustup | undefined) {
12-
this._configuration = configuration;
10+
public constructor(rustup: Rustup | undefined) {
1311
this._rustup = rustup;
1412
}
1513

@@ -20,7 +18,7 @@ export class CargoInvocationManager {
2018
* understand that Cargo is requested. An example is running Cargo using rustup.
2119
*/
2220
public getExecutableAndArgs(): { executable: string, args: string[] } {
23-
const userCargoPath = this._configuration.getCargoPath();
21+
const userCargoPath = Configuration.getPathConfigParameter('cargoPath');
2422
if (userCargoPath) {
2523
return { executable: userCargoPath, args: [] };
2624
}

‎src/CommandLine.ts

Copy file name to clipboardExpand all lines: src/CommandLine.ts
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ export function escapeSpaces(s: string, shell: Shell): string {
7676
}
7777
}
7878

79+
/**
80+
* Prepares the specified arguments to be passed to the specified shell and constructs the command
81+
* from the arguments
82+
* @param shell The shell in which the command will be executed
83+
* @param args The arguments to prepare and construct the command from
84+
* @return The command which is constructed from the specified arguments
85+
*/
86+
export function getCommandForArgs(shell: Shell, args: string[]): string {
87+
args = args.map(a => escapeSpaces(a, shell));
88+
return args.join(' ');
89+
}
90+
7991
/**
8092
* Creates a command to execute several statements one by one if the previous one is succeed
8193
* @param shell The shell which the command is going to be passed to

‎src/components/cargo/terminal_task_manager.ts

Copy file name to clipboardExpand all lines: src/components/cargo/terminal_task_manager.ts
+4-6Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ExtensionContext, Terminal, window, workspace } from 'vscode';
2-
import { escapeSpaces, getCommandToSetEnvVar, parseShell } from '../../CommandLine';
2+
import { getCommandForArgs, getCommandToSetEnvVar, parseShell }
3+
from '../../CommandLine';
34
import { Configuration } from '../configuration/Configuration';
45

56
export class TerminalTaskManager {
@@ -53,13 +54,10 @@ export class TerminalTaskManager {
5354
}
5455
};
5556
setEnvironmentVariables();
56-
cwd = escapeSpaces(cwd, shell);
5757
// Change the current directory to a specified directory
58-
this._runningTerminal.sendText(`cd ${cwd}`);
59-
executable = escapeSpaces(executable, shell);
60-
args = args.map((arg) => escapeSpaces(arg, shell));
58+
this._runningTerminal.sendText(getCommandForArgs(shell, ['cd', cwd]));
6159
// Start a requested command
62-
this._runningTerminal.sendText(`${executable} ${args.join(' ')}`);
60+
this._runningTerminal.sendText(getCommandForArgs(shell, [executable, ...args]));
6361
this._runningTerminal.show(true);
6462
}
6563
}

‎src/components/configuration/Configuration.ts

Copy file name to clipboardExpand all lines: src/components/configuration/Configuration.ts
-4Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,6 @@ export class Configuration {
206206
return Configuration.getPathConfigParameter('cargoCwd');
207207
}
208208

209-
public getCargoPath(): string | undefined {
210-
return Configuration.getPathConfigParameter('cargoPath');
211-
}
212-
213209
public getCargoHomePath(): string | undefined {
214210
const configPath = Configuration.getPathConfigParameter('cargoHomePath');
215211
const envPath = Configuration.getPathEnvParameter('CARGO_HOME');

‎src/components/tools_installation/installator.ts

Copy file name to clipboardExpand all lines: src/components/tools_installation/installator.ts
+30-22Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,49 @@
11
import { existsSync } from 'fs';
22
import * as path from 'path';
33
import { ExtensionContext, commands, window, workspace } from 'vscode';
4-
import { getCommandToExecuteStatementsOneByOneIfPreviousIsSucceed, parseShell }
4+
import { CargoInvocationManager } from '../../CargoInvocationManager';
5+
import { getCommandForArgs, getCommandToExecuteStatementsOneByOneIfPreviousIsSucceed, parseShell }
56
from '../../CommandLine';
67
import { Configuration } from '../configuration/Configuration';
78
import { ChildLogger } from '../logging/child_logger';
89
import { MissingToolsStatusBarItem } from './missing_tools_status_bar_item';
910

1011
export class Installator {
11-
private configuration: Configuration;
12-
private logger: ChildLogger;
13-
private missingToolsStatusBarItem: MissingToolsStatusBarItem;
14-
private missingTools: string[];
12+
private _configuration: Configuration;
13+
private _cargoInvocationManager: CargoInvocationManager;
14+
private _logger: ChildLogger;
15+
private _missingToolsStatusBarItem: MissingToolsStatusBarItem;
16+
private _missingTools: string[];
1517

1618
public constructor(
1719
context: ExtensionContext,
1820
configuration: Configuration,
21+
cargoInvocationManager: CargoInvocationManager,
1922
logger: ChildLogger
2023
) {
21-
this.configuration = configuration;
22-
this.logger = logger;
24+
this._configuration = configuration;
25+
this._cargoInvocationManager = cargoInvocationManager;
26+
this._logger = logger;
2327
const installToolsCommandName = 'rust.install_missing_tools';
24-
this.missingToolsStatusBarItem = new MissingToolsStatusBarItem(context, installToolsCommandName);
25-
this.missingTools = [];
28+
this._missingToolsStatusBarItem = new MissingToolsStatusBarItem(context, installToolsCommandName);
29+
this._missingTools = [];
2630
commands.registerCommand(installToolsCommandName, () => {
2731
this.offerToInstallMissingTools();
2832
});
2933
}
3034

3135
public addStatusBarItemIfSomeToolsAreMissing(): void {
3236
this.getMissingTools();
33-
if (this.missingTools.length === 0) {
37+
if (this._missingTools.length === 0) {
3438
return;
3539
}
36-
this.missingToolsStatusBarItem.show();
40+
this._missingToolsStatusBarItem.show();
3741
}
3842

3943
private offerToInstallMissingTools(): void {
4044
// Plurality is important. :')
41-
const group = this.missingTools.length > 1 ? 'them' : 'it';
42-
const message = `You are missing ${this.missingTools.join(', ')}. Would you like to install ${group}?`;
45+
const group = this._missingTools.length > 1 ? 'them' : 'it';
46+
const message = `You are missing ${this._missingTools.join(', ')}. Would you like to install ${group}?`;
4347
const option = { title: 'Install' };
4448
window.showInformationMessage(message, option).then(selection => {
4549
if (selection !== option) {
@@ -52,23 +56,27 @@ export class Installator {
5256
private installMissingTools(): void {
5357
const terminal = window.createTerminal('Rust tools installation');
5458
// cargo install tool && cargo install another_tool
55-
const cargoBinPath = this.configuration.getCargoPath();
59+
const { executable: cargoExecutable, args: cargoArgs } = this._cargoInvocationManager.getExecutableAndArgs();
5660
const shell = parseShell(workspace.getConfiguration('terminal')['integrated']['shell']['windows']);
57-
const statements = this.missingTools.map(tool => `${cargoBinPath} install ${tool}`);
61+
62+
const statements = this._missingTools.map(tool => {
63+
const args = [cargoExecutable, ...cargoArgs, 'install', tool];
64+
return getCommandForArgs(shell, args);
65+
});
5866
const command = getCommandToExecuteStatementsOneByOneIfPreviousIsSucceed(shell, statements);
5967
terminal.sendText(command);
6068
terminal.show();
61-
this.missingToolsStatusBarItem.hide();
69+
this._missingToolsStatusBarItem.hide();
6270
}
6371

6472
private getMissingTools(): void {
65-
const logger = this.logger.createChildLogger('getMissingTools(): ');
73+
const logger = this._logger.createChildLogger('getMissingTools(): ');
6674
const pathDirectories: string[] = (process.env.PATH || '').split(path.delimiter);
6775
logger.debug(`pathDirectories=${JSON.stringify(pathDirectories)}`);
6876
const tools: { [tool: string]: string | undefined } = {
69-
'racer': this.configuration.getPathToRacer(),
70-
'rustfmt': this.configuration.getRustfmtPath(),
71-
'rustsym': this.configuration.getRustsymPath()
77+
'racer': this._configuration.getPathToRacer(),
78+
'rustfmt': this._configuration.getRustfmtPath(),
79+
'rustsym': this._configuration.getRustsymPath()
7280
};
7381
logger.debug(`tools=${JSON.stringify(tools)}`);
7482
const keys = Object.keys(tools);
@@ -99,7 +107,7 @@ export class Installator {
99107
// The tool wasn't found, we should install it
100108
return tool;
101109
}).filter(tool => tool !== undefined);
102-
this.missingTools = <string[]>missingTools;
103-
logger.debug(`this.missingTools = ${JSON.stringify(this.missingTools)}`);
110+
this._missingTools = <string[]>missingTools;
111+
logger.debug(`this.missingTools = ${JSON.stringify(this._missingTools)}`);
104112
}
105113
}

‎src/extension.ts

Copy file name to clipboardExpand all lines: src/extension.ts
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ export async function activate(ctx: ExtensionContext): Promise<void> {
408408
}
409409
const rustSource = await RustSource.create(rustup);
410410
const configuration = new Configuration(logger.createChildLogger('Configuration: '));
411-
const cargoInvocationManager = new CargoInvocationManager(configuration, rustup);
411+
const cargoInvocationManager = new CargoInvocationManager(rustup);
412412
const rlsConfiguration = await RlsConfiguration.create(rustup, rustSource);
413413
if (configuration.mode() === undefined) {
414414
// The current configuration does not contain any specified mode and hence we should try to
@@ -455,6 +455,7 @@ export async function activate(ctx: ExtensionContext): Promise<void> {
455455
await runInLegacyMode(
456456
ctx,
457457
configuration,
458+
cargoInvocationManager,
458459
rustSource,
459460
rustup,
460461
currentWorkingDirectoryManager,
@@ -469,6 +470,7 @@ export async function activate(ctx: ExtensionContext): Promise<void> {
469470
async function runInLegacyMode(
470471
context: ExtensionContext,
471472
configuration: Configuration,
473+
cargoInvocationManager: CargoInvocationManager,
472474
rustSource: RustSource,
473475
rustup: Rustup | undefined,
474476
currentWorkingDirectoryManager: CurrentWorkingDirectoryManager,
@@ -477,6 +479,7 @@ async function runInLegacyMode(
477479
const legacyModeManager = await LegacyModeManager.create(
478480
context,
479481
configuration,
482+
cargoInvocationManager,
480483
rustSource,
481484
rustup,
482485
currentWorkingDirectoryManager,

‎src/legacy_mode_manager.ts

Copy file name to clipboardExpand all lines: src/legacy_mode_manager.ts
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { WorkspaceSymbolProvisionManager }
1313
from './components/symbol_provision/workspace_symbol_provision_manager';
1414
import { Installator as MissingToolsInstallator }
1515
from './components/tools_installation/installator';
16+
import { CargoInvocationManager } from './CargoInvocationManager';
1617

1718
export class LegacyModeManager {
1819
private context: ExtensionContext;
@@ -26,6 +27,7 @@ export class LegacyModeManager {
2627
public static async create(
2728
context: ExtensionContext,
2829
configuration: Configuration,
30+
cargoInvocationManager: CargoInvocationManager,
2931
rustSource: RustSource,
3032
rustup: Rustup | undefined,
3133
currentWorkingDirectoryManager: CurrentWorkingDirectoryManager,
@@ -35,6 +37,7 @@ export class LegacyModeManager {
3537
return new LegacyModeManager(
3638
context,
3739
configuration,
40+
cargoInvocationManager,
3841
rustSource,
3942
rustup,
4043
currentWorkingDirectoryManager,
@@ -53,6 +56,7 @@ export class LegacyModeManager {
5356
private constructor(
5457
context: ExtensionContext,
5558
configuration: Configuration,
59+
cargoInvocationManager: CargoInvocationManager,
5660
rustSource: RustSource,
5761
rustup: Rustup | undefined,
5862
currentWorkingDirectoryManager: CurrentWorkingDirectoryManager,
@@ -78,6 +82,7 @@ export class LegacyModeManager {
7882
this.missingToolsInstallator = new MissingToolsInstallator(
7983
context,
8084
configuration,
85+
cargoInvocationManager,
8186
logger.createChildLogger('MissingToolsInstallator: ')
8287
);
8388
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.