Skip to content

Navigation Menu

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 9bab179

Browse filesBrowse files
authored
Handle missing RLS when the RLS mode is chosen (#255)
1 parent cc78970 commit 9bab179
Copy full SHA for 9bab179

25 files changed

+431
-688
lines changed

‎src/components/cargo/cargo_manager.ts

Copy file name to clipboardExpand all lines: src/components/cargo/cargo_manager.ts
+3-11
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
11
import * as vscode from 'vscode';
22
import * as tmp from 'tmp';
3-
43
import { ExtensionContext } from 'vscode';
5-
64
import { Configuration } from '../configuration/Configuration';
7-
8-
import CurrentWorkingDirectoryManager from '../configuration/current_working_directory_manager';
9-
10-
import ChildLogger from '../logging/child_logger';
11-
12-
import CustomConfigurationChooser from './custom_configuration_chooser';
13-
5+
import { CurrentWorkingDirectoryManager } from '../configuration/current_working_directory_manager';
6+
import { ChildLogger } from '../logging/child_logger';
7+
import { CustomConfigurationChooser } from './custom_configuration_chooser';
148
import { CommandStartHandleResult, Helper } from './helper';
15-
169
import { OutputChannelTaskManager } from './output_channel_task_manager';
17-
1810
import { TerminalTaskManager } from './terminal_task_manager';
1911

2012
/**

‎src/components/cargo/custom_configuration_chooser.ts

Copy file name to clipboardExpand all lines: src/components/cargo/custom_configuration_chooser.ts
+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class CustomConfigurationQuickPickItem implements QuickPickItem {
2424
}
2525
}
2626

27-
export default class CustomConfigurationChooser {
27+
export class CustomConfigurationChooser {
2828
private configuration: Configuration;
2929

3030
public constructor(configuration: Configuration) {

‎src/components/cargo/output_channel_task_manager.ts

Copy file name to clipboardExpand all lines: src/components/cargo/output_channel_task_manager.ts
+1-42
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,20 @@
11
import { join } from 'path';
2-
32
import { DiagnosticCollection, languages, window } from 'vscode';
4-
53
import { Configuration } from '../configuration/Configuration';
6-
7-
import ChildLogger from '../logging/child_logger';
8-
4+
import { ChildLogger } from '../logging/child_logger';
95
import { DiagnosticParser } from './diagnostic_parser';
10-
116
import { normalizeDiagnosticPath, addUniqueDiagnostic } from './diagnostic_utils';
12-
137
import { OutputChannelWrapper } from './output_channel_wrapper';
14-
158
import { OutputChannelTaskStatusBarItem } from './output_channel_task_status_bar_item';
16-
179
import { ExitCode, Task } from './task';
1810

1911
export class OutputChannelTaskManager {
2012
private channel: OutputChannelWrapper;
21-
2213
private configuration: Configuration;
23-
2414
private logger: ChildLogger;
25-
2615
private runningTask: Task | undefined;
27-
2816
private diagnostics: DiagnosticCollection;
29-
3017
private diagnosticParser: DiagnosticParser;
31-
3218
private statusBarItem: OutputChannelTaskStatusBarItem;
3319

3420
public constructor(
@@ -37,15 +23,10 @@ export class OutputChannelTaskManager {
3723
stopCommandName: string
3824
) {
3925
this.channel = new OutputChannelWrapper(window.createOutputChannel('Cargo'));
40-
4126
this.configuration = configuration;
42-
4327
this.logger = logger;
44-
4528
this.diagnostics = languages.createDiagnosticCollection('rust');
46-
4729
this.diagnosticParser = new DiagnosticParser();
48-
4930
this.statusBarItem = new OutputChannelTaskStatusBarItem(stopCommandName);
5031
}
5132

@@ -57,7 +38,6 @@ export class OutputChannelTaskManager {
5738
shouldShowOutputChannnel: boolean
5839
): Promise<void> {
5940
const cargoCwd = this.configuration.getCargoCwd();
60-
6141
/**
6242
* Prepends the manifest path to arguments
6343
* if the command should be executed in a directory
@@ -72,7 +52,6 @@ export class OutputChannelTaskManager {
7252

7353
args = ['--manifest-path', manifestPath].concat(args);
7454
}
75-
7655
function prependArgsWithMessageFormatIfRequired(): void {
7756
if (!parseOutput) {
7857
return;
@@ -89,38 +68,29 @@ export class OutputChannelTaskManager {
8968
break;
9069
}
9170
}
92-
9371
prependArgsWithMessageFormatIfRequired();
94-
9572
prependArgsWithManifestPathIfRequired();
96-
9773
// Prepend arguments with a command.
9874
args = [command].concat(args);
99-
10075
// Change cwd if the user specified custom cwd.
10176
if (cargoCwd !== undefined) {
10277
cwd = cargoCwd;
10378
}
104-
10579
this.runningTask = new Task(
10680
this.configuration,
10781
this.logger.createChildLogger('Task: '),
10882
args,
10983
cwd
11084
);
111-
11285
this.runningTask.setStarted(() => {
11386
this.channel.clear();
11487
this.channel.append(`Working directory: ${cwd}\n`);
11588
this.channel.append(`Started cargo ${args.join(' ')}\n\n`);
116-
11789
this.diagnostics.clear();
11890
});
119-
12091
this.runningTask.setLineReceivedInStdout(line => {
12192
if (parseOutput && line.startsWith('{')) {
12293
const fileDiagnostics = this.diagnosticParser.parseLine(line);
123-
12494
for (const fileDiagnostic of fileDiagnostics) {
12595
fileDiagnostic.filePath = normalizeDiagnosticPath(fileDiagnostic.filePath, cwd);
12696
addUniqueDiagnostic(fileDiagnostic, this.diagnostics);
@@ -129,39 +99,28 @@ export class OutputChannelTaskManager {
12999
this.channel.append(`${line}\n`);
130100
}
131101
});
132-
133102
this.runningTask.setLineReceivedInStderr(line => {
134103
this.channel.append(`${line}\n`);
135104
});
136-
137105
if (shouldShowOutputChannnel) {
138106
this.channel.show();
139107
}
140-
141108
this.statusBarItem.show();
142-
143109
let exitCode: ExitCode;
144-
145110
try {
146111
exitCode = await this.runningTask.execute();
147112
} catch (error) {
148113
this.statusBarItem.hide();
149-
150114
this.runningTask = undefined;
151-
152115
// No error means the task has been interrupted
153116
if (error && error.message === 'ENOENT') {
154117
const message = 'The "cargo" command is not available. Make sure it is installed.';
155118
window.showInformationMessage(message);
156119
}
157-
158120
return;
159121
}
160-
161122
this.statusBarItem.hide();
162-
163123
this.runningTask = undefined;
164-
165124
this.channel.append(`\nCompleted with code ${exitCode}\n`);
166125
}
167126

‎src/components/cargo/task.ts

Copy file name to clipboardExpand all lines: src/components/cargo/task.ts
+1-41
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,20 @@
11
import { ChildProcess, spawn as spawn_process } from 'child_process';
2-
32
import kill = require('tree-kill');
4-
53
import * as readline from 'readline';
6-
74
import { Configuration } from '../configuration/Configuration';
8-
9-
import ChildLogger from '../logging/child_logger';
5+
import { ChildLogger } from '../logging/child_logger';
106

117
export type ExitCode = number;
128

139
export class Task {
1410
private configuration: Configuration;
15-
1611
private logger: ChildLogger;
17-
1812
private args: string[];
19-
2013
private cwd: string;
21-
2214
private onStarted?: () => void;
23-
2415
private onLineReceivedInStderr?: (line: string) => void;
25-
2616
private onLineReceivedInStdout?: (line: string) => void;
27-
2817
private process: ChildProcess | undefined;
29-
3018
private interrupted: boolean;
3119

3220
public constructor(
@@ -36,21 +24,13 @@ export class Task {
3624
cwd: string
3725
) {
3826
this.configuration = configuration;
39-
4027
this.logger = logger;
41-
4228
this.args = args;
43-
4429
this.cwd = cwd;
45-
4630
this.onStarted = undefined;
47-
4831
this.onLineReceivedInStderr = undefined;
49-
5032
this.onLineReceivedInStdout = undefined;
51-
5233
this.process = undefined;
53-
5434
this.interrupted = false;
5535
}
5636

@@ -69,64 +49,45 @@ export class Task {
6949
public execute(): Thenable<ExitCode> {
7050
return new Promise<ExitCode>((resolve, reject) => {
7151
const cargoPath = this.configuration.getCargoPath();
72-
7352
let env = Object.assign({}, process.env);
74-
7553
const cargoEnv = this.configuration.getCargoEnv();
76-
7754
if (cargoEnv) {
7855
env = Object.assign(env, cargoEnv);
7956
}
80-
8157
this.logger.debug(`execute: cargoPath = "${cargoPath}"`);
8258
this.logger.debug(`execute: this.args = ${JSON.stringify(this.args)}`);
8359
this.logger.debug(`execute: cargoEnv = ${JSON.stringify(cargoEnv)}`);
84-
8560
if (this.onStarted) {
8661
this.onStarted();
8762
}
88-
8963
const spawnedProcess: ChildProcess = spawn_process(cargoPath, this.args, { cwd: this.cwd, env });
90-
9164
this.process = spawnedProcess;
92-
9365
if (this.onLineReceivedInStdout !== undefined) {
9466
const onLineReceivedInStdout = this.onLineReceivedInStdout;
95-
9667
const stdout = readline.createInterface({ input: spawnedProcess.stdout });
97-
9868
stdout.on('line', line => {
9969
onLineReceivedInStdout(line);
10070
});
10171
}
102-
10372
if (this.onLineReceivedInStderr !== undefined) {
10473
const onLineReceivedInStderr = this.onLineReceivedInStderr;
105-
10674
const stderr = readline.createInterface({ input: spawnedProcess.stderr });
107-
10875
stderr.on('line', line => {
10976
onLineReceivedInStderr(line);
11077
});
11178
}
112-
11379
spawnedProcess.on('error', error => {
11480
reject(error);
11581
});
116-
11782
spawnedProcess.on('exit', code => {
11883
process.removeAllListeners();
119-
12084
if (this.process === spawnedProcess) {
12185
this.process = undefined;
12286
}
123-
12487
if (this.interrupted) {
12588
reject();
126-
12789
return;
12890
}
129-
13091
resolve(code);
13192
});
13293
});
@@ -136,7 +97,6 @@ export class Task {
13697
return new Promise(resolve => {
13798
if (!this.interrupted && this.process) {
13899
kill(this.process.pid, 'SIGTERM', resolve);
139-
140100
this.interrupted = true;
141101
}
142102
});

‎src/components/completion/completion_manager.ts

Copy file name to clipboardExpand all lines: src/components/completion/completion_manager.ts
+14-7
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@ import { CompletionItem, CompletionItemKind, Definition, Disposable, ExtensionCo
99
import { fileSync } from 'tmp';
1010
import { surround_by_double_quotes } from '../../Utils';
1111
import { Configuration } from '../configuration/Configuration';
12+
import { RustSource } from '../configuration/RustSource';
1213
import { Rustup } from '../configuration/Rustup';
13-
import getDocumentFilter from '../configuration/mod';
14-
import ChildLogger from '../logging/child_logger';
15-
import RacerStatusBarItem from './racer_status_bar_item';
14+
import { getDocumentFilter } from '../configuration/mod';
15+
import { ChildLogger } from '../logging/child_logger';
16+
import { RacerStatusBarItem } from './racer_status_bar_item';
1617

17-
export default class CompletionManager {
18+
export class CompletionManager {
1819
private configuration: Configuration;
20+
private _rustSource: RustSource;
21+
private _rustup: Rustup | undefined;
1922
private logger: ChildLogger;
2023
private racerDaemon: ChildProcess | undefined;
2124
private commandCallbacks: ((lines: string[]) => void)[];
@@ -51,9 +54,13 @@ export default class CompletionManager {
5154
public constructor(
5255
context: ExtensionContext,
5356
configuration: Configuration,
57+
rustSource: RustSource,
58+
rustup: Rustup | undefined,
5459
logger: ChildLogger
5560
) {
5661
this.configuration = configuration;
62+
this._rustSource = rustSource;
63+
this._rustup = rustup;
5764
this.logger = logger;
5865
this.listeners = [];
5966
const showErrorCommandName = 'rust.racer.show_error';
@@ -117,10 +124,10 @@ export default class CompletionManager {
117124
* @returns flag indicating whether the source code if available or not
118125
*/
119126
private ensureSourceCodeIsAvailable(): boolean {
120-
if (this.configuration.getRustSourcePath()) {
127+
if (this._rustSource.getPath()) {
121128
return true;
122129
}
123-
if (this.configuration.getRustInstallation() instanceof Rustup) {
130+
if (this._rustup) {
124131
// tslint:disable-next-line
125132
const message = 'You are using rustup, but don\'t have installed source code. Do you want to install it?';
126133
window.showErrorMessage(message, 'Yes').then(chosenItem => {
@@ -156,7 +163,7 @@ export default class CompletionManager {
156163
shell: true,
157164
env: Object.assign({}, process.env)
158165
};
159-
const rustSourcePath = this.configuration.getRustSourcePath();
166+
const rustSourcePath = this._rustSource.getPath();
160167
if (rustSourcePath) {
161168
racerSpawnOptions.env.RUST_SRC_PATH = rustSourcePath;
162169
}

‎src/components/completion/racer_status_bar_item.ts

Copy file name to clipboardExpand all lines: src/components/completion/racer_status_bar_item.ts
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { StatusBarAlignment, StatusBarItem, window } from 'vscode';
22

3-
export default class RacerStatusBarItem {
3+
export class RacerStatusBarItem {
44
private showErrorCommandName: string;
55

66
private statusBarItem: StatusBarItem;

0 commit comments

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