mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 13:48:50 +00:00
Add config for cargo-watch trace
This commit is contained in:
parent
b84d0fc1a3
commit
ee05eafe6c
5 changed files with 67 additions and 15 deletions
|
@ -60,6 +60,7 @@ for details.
|
||||||
* `rust-analyzer.enableCargoWatchOnStartup`: prompt to install & enable `cargo
|
* `rust-analyzer.enableCargoWatchOnStartup`: prompt to install & enable `cargo
|
||||||
watch` for live error highlighting (note, this **does not** use rust-analyzer)
|
watch` for live error highlighting (note, this **does not** use rust-analyzer)
|
||||||
* `rust-analyzer.trace.server`: enables internal logging
|
* `rust-analyzer.trace.server`: enables internal logging
|
||||||
|
* `rust-analyzer.trace.cargo-watch`: enables cargo-watch logging
|
||||||
|
|
||||||
|
|
||||||
## Emacs
|
## Emacs
|
||||||
|
|
|
@ -194,6 +194,17 @@
|
||||||
],
|
],
|
||||||
"default": "off",
|
"default": "off",
|
||||||
"description": "Trace requests to the ra_lsp_server"
|
"description": "Trace requests to the ra_lsp_server"
|
||||||
|
},
|
||||||
|
"rust-analyzer.trace.cargo-watch": {
|
||||||
|
"type": "string",
|
||||||
|
"scope": "window",
|
||||||
|
"enum": [
|
||||||
|
"off",
|
||||||
|
"error",
|
||||||
|
"verbose"
|
||||||
|
],
|
||||||
|
"default": "off",
|
||||||
|
"description": "Trace output of cargo-watch"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import * as child_process from 'child_process';
|
import * as child_process from 'child_process';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
|
import { Server } from '../server';
|
||||||
import { terminate } from '../utils/processes';
|
import { terminate } from '../utils/processes';
|
||||||
import { StatusDisplay } from './watch_status';
|
import { StatusDisplay } from './watch_status';
|
||||||
|
|
||||||
|
@ -10,6 +11,7 @@ export class CargoWatchProvider {
|
||||||
private cargoProcess?: child_process.ChildProcess;
|
private cargoProcess?: child_process.ChildProcess;
|
||||||
private outBuffer: string = '';
|
private outBuffer: string = '';
|
||||||
private statusDisplay?: StatusDisplay;
|
private statusDisplay?: StatusDisplay;
|
||||||
|
private outputChannel?: vscode.OutputChannel;
|
||||||
|
|
||||||
public activate(subscriptions: vscode.Disposable[]) {
|
public activate(subscriptions: vscode.Disposable[]) {
|
||||||
subscriptions.push(this);
|
subscriptions.push(this);
|
||||||
|
@ -18,7 +20,10 @@ export class CargoWatchProvider {
|
||||||
);
|
);
|
||||||
|
|
||||||
this.statusDisplay = new StatusDisplay(subscriptions);
|
this.statusDisplay = new StatusDisplay(subscriptions);
|
||||||
|
this.outputChannel = vscode.window.createOutputChannel(
|
||||||
|
'Cargo Watch Trace'
|
||||||
|
);
|
||||||
|
|
||||||
// Start the cargo watch with json message
|
// Start the cargo watch with json message
|
||||||
this.cargoProcess = child_process.spawn(
|
this.cargoProcess = child_process.spawn(
|
||||||
'cargo',
|
'cargo',
|
||||||
|
@ -31,17 +36,23 @@ export class CargoWatchProvider {
|
||||||
);
|
);
|
||||||
|
|
||||||
this.cargoProcess.stdout.on('data', (s: string) => {
|
this.cargoProcess.stdout.on('data', (s: string) => {
|
||||||
this.processOutput(s);
|
this.processOutput(s, (line) => {
|
||||||
console.log(s);
|
this.logInfo(line);
|
||||||
|
this.parseLine(line);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
this.cargoProcess.stderr.on('data', (s: string) => {
|
this.cargoProcess.stderr.on('data', (s: string) => {
|
||||||
console.error('Error on cargo watch : ' + s);
|
this.processOutput(s, (line) => {
|
||||||
|
this.logError('Error on cargo-watch : {\n' + line + '}\n' );
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
this.cargoProcess.on('error', (err: Error) => {
|
this.cargoProcess.on('error', (err: Error) => {
|
||||||
console.error('Error on spawn cargo process : ' + err);
|
this.logError('Error on cargo-watch process : {\n' + err.message + '}\n');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.logInfo('cargo-watch started.');
|
||||||
}
|
}
|
||||||
|
|
||||||
public dispose(): void {
|
public dispose(): void {
|
||||||
|
@ -54,6 +65,22 @@ export class CargoWatchProvider {
|
||||||
this.cargoProcess.kill();
|
this.cargoProcess.kill();
|
||||||
terminate(this.cargoProcess);
|
terminate(this.cargoProcess);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(this.outputChannel) {
|
||||||
|
this.outputChannel.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private logInfo(line: string) {
|
||||||
|
if (Server.config.cargoWatchOptions.trace === 'verbose') {
|
||||||
|
this.outputChannel!.append(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private logError(line: string) {
|
||||||
|
if (Server.config.cargoWatchOptions.trace === 'error' || Server.config.cargoWatchOptions.trace === 'verbose' ) {
|
||||||
|
this.outputChannel!.append(line);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private parseLine(line: string) {
|
private parseLine(line: string) {
|
||||||
|
@ -124,14 +151,14 @@ export class CargoWatchProvider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private processOutput(chunk: string) {
|
private processOutput(chunk: string, cb: (line: string) => void ) {
|
||||||
// The stdout is not line based, convert it to line based for proceess.
|
// The stdout is not line based, convert it to line based for proceess.
|
||||||
this.outBuffer += chunk;
|
this.outBuffer += chunk;
|
||||||
let eolIndex = this.outBuffer.indexOf('\n');
|
let eolIndex = this.outBuffer.indexOf('\n');
|
||||||
while (eolIndex >= 0) {
|
while (eolIndex >= 0) {
|
||||||
// line includes the EOL
|
// line includes the EOL
|
||||||
const line = this.outBuffer.slice(0, eolIndex + 1);
|
const line = this.outBuffer.slice(0, eolIndex + 1);
|
||||||
this.parseLine(line);
|
cb(line);
|
||||||
this.outBuffer = this.outBuffer.slice(eolIndex + 1);
|
this.outBuffer = this.outBuffer.slice(eolIndex + 1);
|
||||||
|
|
||||||
eolIndex = this.outBuffer.indexOf('\n');
|
eolIndex = this.outBuffer.indexOf('\n');
|
||||||
|
|
|
@ -137,11 +137,11 @@ export async function handleSingle(runnable: Runnable) {
|
||||||
export async function interactivelyStartCargoWatch(
|
export async function interactivelyStartCargoWatch(
|
||||||
context: vscode.ExtensionContext
|
context: vscode.ExtensionContext
|
||||||
) {
|
) {
|
||||||
if (Server.config.enableCargoWatchOnStartup === 'disabled') {
|
if (Server.config.cargoWatchOptions.enableOnStartup === 'disabled') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Server.config.enableCargoWatchOnStartup === 'ask') {
|
if (Server.config.cargoWatchOptions.enableOnStartup === 'ask') {
|
||||||
const watch = await vscode.window.showInformationMessage(
|
const watch = await vscode.window.showInformationMessage(
|
||||||
'Start watching changes with cargo? (Executes `cargo watch`, provides inline diagnostics)',
|
'Start watching changes with cargo? (Executes `cargo watch`, provides inline diagnostics)',
|
||||||
'yes',
|
'yes',
|
||||||
|
|
|
@ -4,14 +4,20 @@ import { Server } from './server';
|
||||||
|
|
||||||
const RA_LSP_DEBUG = process.env.__RA_LSP_SERVER_DEBUG;
|
const RA_LSP_DEBUG = process.env.__RA_LSP_SERVER_DEBUG;
|
||||||
|
|
||||||
export type CargoWatchOptions = 'ask' | 'enabled' | 'disabled';
|
export type CargoWatchStartupOptions = 'ask' | 'enabled' | 'disabled';
|
||||||
|
export type CargoWatchTraceOptions = 'off' | 'error' | 'verbose';
|
||||||
|
|
||||||
|
export interface CargoWatchOptions {
|
||||||
|
enableOnStartup: CargoWatchStartupOptions,
|
||||||
|
trace: CargoWatchTraceOptions,
|
||||||
|
};
|
||||||
|
|
||||||
export class Config {
|
export class Config {
|
||||||
public highlightingOn = true;
|
public highlightingOn = true;
|
||||||
public enableEnhancedTyping = true;
|
public enableEnhancedTyping = true;
|
||||||
public raLspServerPath = RA_LSP_DEBUG || 'ra_lsp_server';
|
public raLspServerPath = RA_LSP_DEBUG || 'ra_lsp_server';
|
||||||
public showWorkspaceLoadedNotification = true;
|
public showWorkspaceLoadedNotification = true;
|
||||||
public enableCargoWatchOnStartup: CargoWatchOptions = 'ask';
|
public cargoWatchOptions: CargoWatchOptions = { enableOnStartup: 'ask', trace: 'off' };
|
||||||
|
|
||||||
private prevEnhancedTyping: null | boolean = null;
|
private prevEnhancedTyping: null | boolean = null;
|
||||||
|
|
||||||
|
@ -73,10 +79,17 @@ export class Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.has('enableCargoWatchOnStartup')) {
|
if (config.has('enableCargoWatchOnStartup')) {
|
||||||
this.enableCargoWatchOnStartup = config.get<CargoWatchOptions>(
|
this.cargoWatchOptions.enableOnStartup =
|
||||||
'enableCargoWatchOnStartup',
|
config.get<CargoWatchStartupOptions>(
|
||||||
'ask'
|
'enableCargoWatchOnStartup',
|
||||||
);
|
'ask'
|
||||||
|
);
|
||||||
|
this.cargoWatchOptions.trace =
|
||||||
|
config.get<CargoWatchTraceOptions>(
|
||||||
|
'trace.cargo-watch',
|
||||||
|
'off'
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue