From 78e8934976fa3135c151d2b6b395ce57e832f90e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Sun, 8 Dec 2019 14:41:44 +0200 Subject: Code: check whether the LSP binary is in PATH --- editors/code/src/extension.ts | 12 ++++++++---- editors/code/src/server.ts | 11 +++++++++-- 2 files changed, 17 insertions(+), 6 deletions(-) (limited to 'editors/code/src') diff --git a/editors/code/src/extension.ts b/editors/code/src/extension.ts index 683497dfd..6637c3bf0 100644 --- a/editors/code/src/extension.ts +++ b/editors/code/src/extension.ts @@ -14,7 +14,7 @@ import * as events from './events'; import * as notifications from './notifications'; import { Server } from './server'; -export function activate(context: vscode.ExtensionContext) { +export async function activate(context: vscode.ExtensionContext) { function disposeOnDeactivation(disposable: vscode.Disposable) { context.subscriptions.push(disposable); } @@ -159,7 +159,11 @@ export function activate(context: vscode.ExtensionContext) { }); // Start the language server, finally! - startServer(); + try { + await startServer(); + } catch (e) { + vscode.window.showErrorMessage(e.message); + } if (Server.config.displayInlayHints) { const hintsUpdater = new HintsUpdater(); @@ -204,10 +208,10 @@ export function deactivate(): Thenable { return Server.client.stop(); } -async function reloadServer(startServer: () => void) { +async function reloadServer(startServer: () => Promise) { if (Server.client != null) { vscode.window.showInformationMessage('Reloading rust-analyzer...'); await Server.client.stop(); - startServer(); + await startServer(); } } diff --git a/editors/code/src/server.ts b/editors/code/src/server.ts index 7907b70bc..e717ab294 100644 --- a/editors/code/src/server.ts +++ b/editors/code/src/server.ts @@ -1,3 +1,4 @@ +import { lookpath } from 'lookpath'; import { homedir } from 'os'; import * as lc from 'vscode-languageclient'; @@ -17,7 +18,7 @@ export class Server { public static config = new Config(); public static client: lc.LanguageClient; - public static start( + public static async start( notificationHandlers: Iterable<[string, lc.GenericNotificationHandler]> ) { // '.' Is the fallback if no folder is open @@ -27,8 +28,14 @@ export class Server { folder = workspace.workspaceFolders[0].uri.fsPath.toString(); } + const command = expandPathResolving(this.config.raLspServerPath); + if (!(await lookpath(command))) { + throw new Error( + `Cannot find rust-analyzer server \`${command}\` in PATH.` + ); + } const run: lc.Executable = { - command: expandPathResolving(this.config.raLspServerPath), + command, options: { cwd: folder } }; const serverOptions: lc.ServerOptions = { -- cgit v1.2.3 From c7dc067104c602e18264be0fab2eb197366ac827 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Sun, 8 Dec 2019 20:27:50 +0200 Subject: Code: bump deps --- editors/code/src/extension.ts | 7 ++++--- editors/code/src/highlighting.ts | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'editors/code/src') diff --git a/editors/code/src/extension.ts b/editors/code/src/extension.ts index 6637c3bf0..a78aa3b42 100644 --- a/editors/code/src/extension.ts +++ b/editors/code/src/extension.ts @@ -89,9 +89,10 @@ export async function activate(context: vscode.ExtensionContext) { } // Notifications are events triggered by the language server - const allNotifications: Iterable< - [string, lc.GenericNotificationHandler] - > = [ + const allNotifications: Iterable<[ + string, + lc.GenericNotificationHandler + ]> = [ [ 'rust-analyzer/publishDecorations', notifications.publishDecorations.handle diff --git a/editors/code/src/highlighting.ts b/editors/code/src/highlighting.ts index d21d8a06a..48f2a2547 100644 --- a/editors/code/src/highlighting.ts +++ b/editors/code/src/highlighting.ts @@ -40,9 +40,10 @@ export class Highlighter { return [tag, decor]; }; - const decorations: Iterable< - [string, vscode.TextEditorDecorationType] - > = [ + const decorations: Iterable<[ + string, + vscode.TextEditorDecorationType + ]> = [ decoration('comment'), decoration('string'), decoration('keyword'), -- cgit v1.2.3 From ee2bc73d2a8bb5479019609b495c65d1d6132d9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Sun, 8 Dec 2019 21:08:46 +0200 Subject: Code: don't check for ra_lsp_server on Windows --- editors/code/src/server.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'editors/code/src') diff --git a/editors/code/src/server.ts b/editors/code/src/server.ts index e717ab294..b346c0828 100644 --- a/editors/code/src/server.ts +++ b/editors/code/src/server.ts @@ -1,5 +1,5 @@ import { lookpath } from 'lookpath'; -import { homedir } from 'os'; +import { homedir, platform } from 'os'; import * as lc from 'vscode-languageclient'; import { window, workspace } from 'vscode'; @@ -29,10 +29,14 @@ export class Server { } const command = expandPathResolving(this.config.raLspServerPath); - if (!(await lookpath(command))) { - throw new Error( - `Cannot find rust-analyzer server \`${command}\` in PATH.` - ); + // FIXME: remove check when the following issue is fixed: + // https://github.com/otiai10/lookpath/issues/4 + if (platform() !== 'win32') { + if (!(await lookpath(command))) { + throw new Error( + `Cannot find rust-analyzer server \`${command}\` in PATH.` + ); + } } const run: lc.Executable = { command, -- cgit v1.2.3 From 7ac4ea7fec018f76eed5b5c10fc96ba3d9b969be Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 9 Dec 2019 18:05:49 +0100 Subject: Allow disabling sysroot Might be helpful for debugging --- editors/code/src/config.ts | 5 +++++ editors/code/src/server.ts | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'editors/code/src') diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index 95c3f42e5..fb9e55dd6 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts @@ -26,6 +26,8 @@ export class Config { public excludeGlobs = []; public useClientWatching = false; public featureFlags = {}; + // for internal use + public withSysroot: null | boolean = null; public cargoWatchOptions: CargoWatchOptions = { enableOnStartup: 'ask', trace: 'off', @@ -148,5 +150,8 @@ export class Config { if (config.has('featureFlags')) { this.featureFlags = config.get('featureFlags') || {}; } + if (config.has('withSysroot')) { + this.withSysroot = config.get('withSysroot') || false; + } } } diff --git a/editors/code/src/server.ts b/editors/code/src/server.ts index b346c0828..e767b6f1b 100644 --- a/editors/code/src/server.ts +++ b/editors/code/src/server.ts @@ -57,7 +57,8 @@ export class Server { maxInlayHintLength: Server.config.maxInlayHintLength, excludeGlobs: Server.config.excludeGlobs, useClientWatching: Server.config.useClientWatching, - featureFlags: Server.config.featureFlags + featureFlags: Server.config.featureFlags, + withSysroot: Server.config.withSysroot }, traceOutputChannel }; -- cgit v1.2.3 From 273299693b85996878907ad256ed55f072ec3f1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Mon, 9 Dec 2019 20:57:55 +0200 Subject: Code: enable prettier trailing commas --- editors/code/src/commands/analyzer_status.ts | 14 +++--- editors/code/src/commands/apply_source_change.ts | 8 ++-- editors/code/src/commands/cargo_watch.ts | 34 ++++++------- editors/code/src/commands/expand_macro.ts | 10 ++-- editors/code/src/commands/index.ts | 2 +- editors/code/src/commands/inlay_hints.ts | 34 ++++++------- editors/code/src/commands/join_lines.ts | 6 +-- editors/code/src/commands/matching_brace.ts | 6 +-- editors/code/src/commands/on_enter.ts | 8 ++-- editors/code/src/commands/parent_module.ts | 6 +-- editors/code/src/commands/runnables.ts | 36 +++++++------- editors/code/src/commands/syntaxTree.ts | 10 ++-- editors/code/src/commands/watch_status.ts | 2 +- editors/code/src/config.ts | 22 ++++----- .../code/src/events/change_active_text_editor.ts | 6 +-- editors/code/src/events/change_text_document.ts | 2 +- editors/code/src/extension.ts | 56 +++++++++++----------- editors/code/src/highlighting.ts | 16 +++---- .../code/src/notifications/publish_decorations.ts | 2 +- editors/code/src/server.ts | 22 ++++----- .../src/test/utils/diagnotics/SuggestedFix.test.ts | 26 +++++----- .../diagnotics/SuggestedFixCollection.test.ts | 20 ++++---- .../code/src/test/utils/diagnotics/rust.test.ts | 52 ++++++++++---------- .../code/src/test/utils/diagnotics/vscode.test.ts | 24 +++++----- editors/code/src/test/utils/index.ts | 2 +- editors/code/src/utils/diagnostics/SuggestedFix.ts | 4 +- .../utils/diagnostics/SuggestedFixCollection.ts | 6 +-- editors/code/src/utils/diagnostics/rust.ts | 20 ++++---- editors/code/src/utils/diagnostics/vscode.ts | 2 +- editors/code/src/utils/processes.ts | 4 +- 30 files changed, 231 insertions(+), 231 deletions(-) (limited to 'editors/code/src') diff --git a/editors/code/src/commands/analyzer_status.ts b/editors/code/src/commands/analyzer_status.ts index 63f82c92d..9e4ce0eb3 100644 --- a/editors/code/src/commands/analyzer_status.ts +++ b/editors/code/src/commands/analyzer_status.ts @@ -9,7 +9,7 @@ export class TextDocumentContentProvider public syntaxTree: string = 'Not available'; public provideTextDocumentContent( - uri: vscode.Uri + uri: vscode.Uri, ): vscode.ProviderResult { const editor = vscode.window.activeTextEditor; if (editor == null) { @@ -17,7 +17,7 @@ export class TextDocumentContentProvider } return Server.client.sendRequest( 'rust-analyzer/analyzerStatus', - null + null, ); } @@ -35,8 +35,8 @@ export function makeCommand(context: vscode.ExtensionContext) { context.subscriptions.push( vscode.workspace.registerTextDocumentContentProvider( 'rust-analyzer-status', - textDocumentContentProvider - ) + textDocumentContentProvider, + ), ); context.subscriptions.push({ @@ -44,21 +44,21 @@ export function makeCommand(context: vscode.ExtensionContext) { if (poller != null) { clearInterval(poller); } - } + }, }); return async function handle() { if (poller == null) { poller = setInterval( () => textDocumentContentProvider.eventEmitter.fire(statusUri), - 1000 + 1000, ); } const document = await vscode.workspace.openTextDocument(statusUri); return vscode.window.showTextDocument( document, vscode.ViewColumn.Two, - true + true, ); }; } diff --git a/editors/code/src/commands/apply_source_change.ts b/editors/code/src/commands/apply_source_change.ts index dcd074b8b..8167398b1 100644 --- a/editors/code/src/commands/apply_source_change.ts +++ b/editors/code/src/commands/apply_source_change.ts @@ -11,7 +11,7 @@ export interface SourceChange { export async function handle(change: SourceChange) { const wsEdit = Server.client.protocol2CodeConverter.asWorkspaceEdit( - change.workspaceEdit + change.workspaceEdit, ); let created; let moved; @@ -33,10 +33,10 @@ export async function handle(change: SourceChange) { await vscode.window.showTextDocument(doc); } else if (toReveal) { const uri = Server.client.protocol2CodeConverter.asUri( - toReveal.textDocument.uri + toReveal.textDocument.uri, ); const position = Server.client.protocol2CodeConverter.asPosition( - toReveal.position + toReveal.position, ); const editor = vscode.window.activeTextEditor; if (!editor || editor.document.uri.toString() !== uri.toString()) { @@ -48,7 +48,7 @@ export async function handle(change: SourceChange) { editor.selection = new vscode.Selection(position, position); editor.revealRange( new vscode.Range(position, position), - vscode.TextEditorRevealType.Default + vscode.TextEditorRevealType.Default, ); } } diff --git a/editors/code/src/commands/cargo_watch.ts b/editors/code/src/commands/cargo_watch.ts index 59d4ba97a..512362eb1 100644 --- a/editors/code/src/commands/cargo_watch.ts +++ b/editors/code/src/commands/cargo_watch.ts @@ -9,13 +9,13 @@ import { StatusDisplay } from './watch_status'; import { mapRustDiagnosticToVsCode, - RustDiagnostic + RustDiagnostic, } from '../utils/diagnostics/rust'; import SuggestedFixCollection from '../utils/diagnostics/SuggestedFixCollection'; import { areDiagnosticsEqual } from '../utils/diagnostics/vscode'; export async function registerCargoWatchProvider( - subscriptions: vscode.Disposable[] + subscriptions: vscode.Disposable[], ): Promise { let cargoExists = false; @@ -30,7 +30,7 @@ export async function registerCargoWatchProvider( if (!cargoExists) { vscode.window.showErrorMessage( - `Couldn\'t find \'Cargo.toml\' at ${cargoTomlPath}` + `Couldn\'t find \'Cargo.toml\' at ${cargoTomlPath}`, ); return; } @@ -52,13 +52,13 @@ export class CargoWatchProvider implements vscode.Disposable { constructor() { this.diagnosticCollection = vscode.languages.createDiagnosticCollection( - 'rustc' + 'rustc', ); this.statusDisplay = new StatusDisplay( - Server.config.cargoWatchOptions.command + Server.config.cargoWatchOptions.command, ); this.outputChannel = vscode.window.createOutputChannel( - 'Cargo Watch Trace' + 'Cargo Watch Trace', ); // Track `rustc`'s suggested fixes so we can convert them to code actions @@ -68,15 +68,15 @@ export class CargoWatchProvider implements vscode.Disposable { this.suggestedFixCollection, { providedCodeActionKinds: - SuggestedFixCollection.PROVIDED_CODE_ACTION_KINDS - } + SuggestedFixCollection.PROVIDED_CODE_ACTION_KINDS, + }, ); } public start() { if (this.cargoProcess) { vscode.window.showInformationMessage( - 'Cargo Watch is already running' + 'Cargo Watch is already running', ); return; } @@ -95,7 +95,7 @@ export class CargoWatchProvider implements vscode.Disposable { const ignoreFlags = Server.config.cargoWatchOptions.ignore.reduce( (flags, pattern) => [...flags, '--ignore', pattern], - [] as string[] + [] as string[], ); // Start the cargo watch with json message @@ -105,8 +105,8 @@ export class CargoWatchProvider implements vscode.Disposable { { stdio: ['ignore', 'pipe', 'pipe'], cwd: vscode.workspace.rootPath, - windowsVerbatimArguments: true - } + windowsVerbatimArguments: true, + }, ); const stdoutData = new LineBuffer(); @@ -130,7 +130,7 @@ export class CargoWatchProvider implements vscode.Disposable { this.cargoProcess.on('error', (err: Error) => { this.logError( - 'Error on cargo-watch process : {\n' + err.message + '}\n' + 'Error on cargo-watch process : {\n' + err.message + '}\n', ); }); @@ -223,12 +223,12 @@ export class CargoWatchProvider implements vscode.Disposable { const fileUri = location.uri; const diagnostics: vscode.Diagnostic[] = [ - ...(this.diagnosticCollection!.get(fileUri) || []) + ...(this.diagnosticCollection!.get(fileUri) || []), ]; // If we're building multiple targets it's possible we've already seen this diagnostic const isDuplicate = diagnostics.some(d => - areDiagnosticsEqual(d, diagnostic) + areDiagnosticsEqual(d, diagnostic), ); if (isDuplicate) { return; @@ -241,7 +241,7 @@ export class CargoWatchProvider implements vscode.Disposable { for (const suggestedFix of suggestedFixes) { this.suggestedFixCollection.addSuggestedFixForDiagnostic( suggestedFix, - diagnostic + diagnostic, ); } @@ -249,7 +249,7 @@ export class CargoWatchProvider implements vscode.Disposable { vscode.commands.executeCommand( 'vscode.executeCodeActionProvider', fileUri, - diagnostic.range + diagnostic.range, ); } } diff --git a/editors/code/src/commands/expand_macro.ts b/editors/code/src/commands/expand_macro.ts index 34e0c8fb3..842898020 100644 --- a/editors/code/src/commands/expand_macro.ts +++ b/editors/code/src/commands/expand_macro.ts @@ -3,7 +3,7 @@ import { Position, TextDocumentIdentifier } from 'vscode-languageclient'; import { Server } from '../server'; export const expandMacroUri = vscode.Uri.parse( - 'rust-analyzer://expandMacro/[EXPANSION].rs' + 'rust-analyzer://expandMacro/[EXPANSION].rs', ); export class ExpandMacroContentProvider @@ -11,7 +11,7 @@ export class ExpandMacroContentProvider public eventEmitter = new vscode.EventEmitter(); public provideTextDocumentContent( - uri: vscode.Uri + uri: vscode.Uri, ): vscode.ProviderResult { async function handle() { const editor = vscode.window.activeTextEditor; @@ -22,11 +22,11 @@ export class ExpandMacroContentProvider const position = editor.selection.active; const request: MacroExpandParams = { textDocument: { uri: editor.document.uri.toString() }, - position + position, }; const expanded = await Server.client.sendRequest( 'rust-analyzer/expandMacro', - request + request, ); if (expanded == null) { @@ -58,7 +58,7 @@ export function createHandle(provider: ExpandMacroContentProvider) { return vscode.window.showTextDocument( document, vscode.ViewColumn.Two, - true + true, ); }; } diff --git a/editors/code/src/commands/index.ts b/editors/code/src/commands/index.ts index 2ade6d331..13a696758 100644 --- a/editors/code/src/commands/index.ts +++ b/editors/code/src/commands/index.ts @@ -19,5 +19,5 @@ export { runnables, syntaxTree, onEnter, - inlayHints + inlayHints, }; diff --git a/editors/code/src/commands/inlay_hints.ts b/editors/code/src/commands/inlay_hints.ts index 0dbdd94fb..ac7dcce60 100644 --- a/editors/code/src/commands/inlay_hints.ts +++ b/editors/code/src/commands/inlay_hints.ts @@ -15,8 +15,8 @@ interface InlayHint { const typeHintDecorationType = vscode.window.createTextEditorDecorationType({ after: { - color: new vscode.ThemeColor('ralsp.inlayHint') - } + color: new vscode.ThemeColor('ralsp.inlayHint'), + }, }); export class HintsUpdater { @@ -26,13 +26,13 @@ export class HintsUpdater { if (this.displayHints !== displayHints) { this.displayHints = displayHints; return this.refreshVisibleEditorsHints( - displayHints ? undefined : [] + displayHints ? undefined : [], ); } } public async refreshHintsForVisibleEditors( - cause?: TextDocumentChangeEvent + cause?: TextDocumentChangeEvent, ): Promise { if (!this.displayHints) { return; @@ -48,21 +48,21 @@ export class HintsUpdater { } private async refreshVisibleEditorsHints( - newDecorations?: vscode.DecorationOptions[] + newDecorations?: vscode.DecorationOptions[], ) { const promises: Array> = []; for (const rustEditor of vscode.window.visibleTextEditors.filter( - editor => this.isRustDocument(editor.document) + editor => this.isRustDocument(editor.document), )) { if (newDecorations !== undefined) { promises.push( Promise.resolve( rustEditor.setDecorations( typeHintDecorationType, - newDecorations - ) - ) + newDecorations, + ), + ), ); } else { promises.push(this.updateDecorationsFromServer(rustEditor)); @@ -79,7 +79,7 @@ export class HintsUpdater { } private async updateDecorationsFromServer( - editor: TextEditor + editor: TextEditor, ): Promise { const newHints = await this.queryHints(editor.document.uri.toString()); if (newHints !== null) { @@ -87,20 +87,20 @@ export class HintsUpdater { range: hint.range, renderOptions: { after: { - contentText: `: ${hint.label}` - } - } + contentText: `: ${hint.label}`, + }, + }, })); return editor.setDecorations( typeHintDecorationType, - newDecorations + newDecorations, ); } } private async queryHints(documentUri: string): Promise { const request: InlayHintsParams = { - textDocument: { uri: documentUri } + textDocument: { uri: documentUri }, }; const client = Server.client; return client @@ -108,8 +108,8 @@ export class HintsUpdater { .then(() => client.sendRequest( 'rust-analyzer/inlayHints', - request - ) + request, + ), ); } } diff --git a/editors/code/src/commands/join_lines.ts b/editors/code/src/commands/join_lines.ts index 0d4b12f4d..134ddc801 100644 --- a/editors/code/src/commands/join_lines.ts +++ b/editors/code/src/commands/join_lines.ts @@ -4,7 +4,7 @@ import { Range, TextDocumentIdentifier } from 'vscode-languageclient'; import { Server } from '../server'; import { handle as applySourceChange, - SourceChange + SourceChange, } from './apply_source_change'; interface JoinLinesParams { @@ -19,11 +19,11 @@ export async function handle() { } const request: JoinLinesParams = { range: Server.client.code2ProtocolConverter.asRange(editor.selection), - textDocument: { uri: editor.document.uri.toString() } + textDocument: { uri: editor.document.uri.toString() }, }; const change = await Server.client.sendRequest( 'rust-analyzer/joinLines', - request + request, ); await applySourceChange(change); } diff --git a/editors/code/src/commands/matching_brace.ts b/editors/code/src/commands/matching_brace.ts index d86faf405..364208cc7 100644 --- a/editors/code/src/commands/matching_brace.ts +++ b/editors/code/src/commands/matching_brace.ts @@ -17,15 +17,15 @@ export async function handle() { textDocument: { uri: editor.document.uri.toString() }, offsets: editor.selections.map(s => { return Server.client.code2ProtocolConverter.asPosition(s.active); - }) + }), }; const response = await Server.client.sendRequest( 'rust-analyzer/findMatchingBrace', - request + request, ); editor.selections = editor.selections.map((sel, idx) => { const active = Server.client.protocol2CodeConverter.asPosition( - response[idx] + response[idx], ); const anchor = sel.isEmpty ? active : sel.anchor; return new vscode.Selection(anchor, active); diff --git a/editors/code/src/commands/on_enter.ts b/editors/code/src/commands/on_enter.ts index 16dcb70c8..772c64b3c 100644 --- a/editors/code/src/commands/on_enter.ts +++ b/editors/code/src/commands/on_enter.ts @@ -3,7 +3,7 @@ import * as lc from 'vscode-languageclient'; import { Server } from '../server'; import { handle as applySourceChange, - SourceChange + SourceChange, } from './apply_source_change'; export async function handle(event: { text: string }): Promise { @@ -18,12 +18,12 @@ export async function handle(event: { text: string }): Promise { const request: lc.TextDocumentPositionParams = { textDocument: { uri: editor.document.uri.toString() }, position: Server.client.code2ProtocolConverter.asPosition( - editor.selection.active - ) + editor.selection.active, + ), }; const change = await Server.client.sendRequest( 'rust-analyzer/onEnter', - request + request, ); if (!change) { return false; diff --git a/editors/code/src/commands/parent_module.ts b/editors/code/src/commands/parent_module.ts index 9d30b7b59..ad49e1bdb 100644 --- a/editors/code/src/commands/parent_module.ts +++ b/editors/code/src/commands/parent_module.ts @@ -11,12 +11,12 @@ export async function handle() { const request: lc.TextDocumentPositionParams = { textDocument: { uri: editor.document.uri.toString() }, position: Server.client.code2ProtocolConverter.asPosition( - editor.selection.active - ) + editor.selection.active, + ), }; const response = await Server.client.sendRequest( 'rust-analyzer/parentModule', - request + request, ); const loc = response[0]; if (loc == null) { diff --git a/editors/code/src/commands/runnables.ts b/editors/code/src/commands/runnables.ts index ac59bf60d..9b1c6643d 100644 --- a/editors/code/src/commands/runnables.ts +++ b/editors/code/src/commands/runnables.ts @@ -46,17 +46,17 @@ function createTask(spec: Runnable): vscode.Task { label: spec.label, command: spec.bin, args: spec.args, - env: spec.env + env: spec.env, }; const execOption: vscode.ShellExecutionOptions = { cwd: spec.cwd || '.', - env: definition.env + env: definition.env, }; const exec = new vscode.ShellExecution( definition.command, definition.args, - execOption + execOption, ); const f = vscode.workspace.workspaceFolders![0]; @@ -66,7 +66,7 @@ function createTask(spec: Runnable): vscode.Task { definition.label, TASK_SOURCE, exec, - ['$rustc'] + ['$rustc'], ); t.presentationOptions.clear = true; return t; @@ -79,17 +79,17 @@ export async function handle() { return; } const textDocument: lc.TextDocumentIdentifier = { - uri: editor.document.uri.toString() + uri: editor.document.uri.toString(), }; const params: RunnablesParams = { textDocument, position: Server.client.code2ProtocolConverter.asPosition( - editor.selection.active - ) + editor.selection.active, + ), }; const runnables = await Server.client.sendRequest( 'rust-analyzer/runnables', - params + params, ); const items: RunnableQuickPick[] = []; if (prevRunnable) { @@ -124,7 +124,7 @@ export async function handleSingle(runnable: Runnable) { task.presentationOptions = { reveal: vscode.TaskRevealKind.Always, panel: vscode.TaskPanelKind.Dedicated, - clear: true + clear: true, }; return vscode.tasks.executeTask(task); @@ -136,7 +136,7 @@ export async function handleSingle(runnable: Runnable) { * that, when accepted, allow us to `cargo install cargo-watch` and then run it. */ export async function interactivelyStartCargoWatch( - context: vscode.ExtensionContext + context: vscode.ExtensionContext, ): Promise { if (Server.config.cargoWatchOptions.enableOnStartup === 'disabled') { return; @@ -146,7 +146,7 @@ export async function interactivelyStartCargoWatch( const watch = await vscode.window.showInformationMessage( 'Start watching changes with cargo? (Executes `cargo watch`, provides inline diagnostics)', 'yes', - 'no' + 'no', ); if (watch !== 'yes') { return; @@ -157,12 +157,12 @@ export async function interactivelyStartCargoWatch( } export async function startCargoWatch( - context: vscode.ExtensionContext + context: vscode.ExtensionContext, ): Promise { const execPromise = util.promisify(child_process.exec); const { stderr, code = 0 } = await execPromise( - 'cargo watch --version' + 'cargo watch --version', ).catch(e => e); if (stderr.includes('no such subcommand: `watch`')) { @@ -171,7 +171,7 @@ export async function startCargoWatch( const install = await vscode.window.showInformationMessage( msg, 'yes', - 'no' + 'no', ); if (install !== 'yes') { return; @@ -192,20 +192,20 @@ export async function startCargoWatch( label, bin: 'cargo', args: ['install', 'cargo-watch'], - env: {} - }) + env: {}, + }), ); await taskFinished; const output = await execPromise('cargo watch --version').catch(e => e); if (output.stderr !== '') { vscode.window.showErrorMessage( - `Couldn't install \`cargo-\`watch: ${output.stderr}` + `Couldn't install \`cargo-\`watch: ${output.stderr}`, ); return; } } else if (code !== 0) { vscode.window.showErrorMessage( - `\`cargo watch\` failed with ${code}: ${stderr}` + `\`cargo watch\` failed with ${code}: ${stderr}`, ); return; } diff --git a/editors/code/src/commands/syntaxTree.ts b/editors/code/src/commands/syntaxTree.ts index 2f50fe14b..89a80550c 100644 --- a/editors/code/src/commands/syntaxTree.ts +++ b/editors/code/src/commands/syntaxTree.ts @@ -11,7 +11,7 @@ export class SyntaxTreeContentProvider public syntaxTree: string = 'Not available'; public provideTextDocumentContent( - uri: vscode.Uri + uri: vscode.Uri, ): vscode.ProviderResult { const editor = vscode.window.activeTextEditor; if (editor == null) { @@ -25,17 +25,17 @@ export class SyntaxTreeContentProvider range = editor.selection.isEmpty ? undefined : Server.client.code2ProtocolConverter.asRange( - editor.selection + editor.selection, ); } const request: SyntaxTreeParams = { textDocument: { uri: editor.document.uri.toString() }, - range + range, }; return Server.client.sendRequest( 'rust-analyzer/syntaxTree', - request + request, ); } @@ -70,7 +70,7 @@ export function createHandle(provider: SyntaxTreeContentProvider) { return vscode.window.showTextDocument( document, vscode.ViewColumn.Two, - true + true, ); }; } diff --git a/editors/code/src/commands/watch_status.ts b/editors/code/src/commands/watch_status.ts index 6c1f9041b..8d64394c7 100644 --- a/editors/code/src/commands/watch_status.ts +++ b/editors/code/src/commands/watch_status.ts @@ -13,7 +13,7 @@ export class StatusDisplay implements vscode.Disposable { constructor(command: string) { this.statusBarItem = vscode.window.createStatusBarItem( vscode.StatusBarAlignment.Left, - 10 + 10, ); this.command = command; this.statusBarItem.hide(); diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index fb9e55dd6..2d3b6a54e 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts @@ -33,14 +33,14 @@ export class Config { trace: 'off', arguments: '', command: '', - ignore: [] + ignore: [], }; private prevEnhancedTyping: null | boolean = null; constructor() { vscode.workspace.onDidChangeConfiguration(_ => - this.userConfigChanged() + this.userConfigChanged(), ); this.userConfigChanged(); } @@ -53,7 +53,7 @@ export class Config { if (config.has('rainbowHighlightingOn')) { this.rainbowHighlightingOn = config.get( - 'rainbowHighlightingOn' + 'rainbowHighlightingOn', ) as boolean; } @@ -63,7 +63,7 @@ export class Config { if (config.has('enableEnhancedTyping')) { this.enableEnhancedTyping = config.get( - 'enableEnhancedTyping' + 'enableEnhancedTyping', ) as boolean; if (this.prevEnhancedTyping === null) { @@ -78,12 +78,12 @@ export class Config { vscode.window .showInformationMessage( 'Changing enhanced typing setting requires a reload', - reloadAction + reloadAction, ) .then(selectedAction => { if (selectedAction === reloadAction) { vscode.commands.executeCommand( - 'workbench.action.reloadWindow' + 'workbench.action.reloadWindow', ); } }); @@ -104,28 +104,28 @@ export class Config { if (config.has('trace.cargo-watch')) { this.cargoWatchOptions.trace = config.get( 'trace.cargo-watch', - 'off' + 'off', ); } if (config.has('cargo-watch.arguments')) { this.cargoWatchOptions.arguments = config.get( 'cargo-watch.arguments', - '' + '', ); } if (config.has('cargo-watch.command')) { this.cargoWatchOptions.command = config.get( 'cargo-watch.command', - '' + '', ); } if (config.has('cargo-watch.ignore')) { this.cargoWatchOptions.ignore = config.get( 'cargo-watch.ignore', - [] + [], ); } @@ -138,7 +138,7 @@ export class Config { } if (config.has('maxInlayHintLength')) { this.maxInlayHintLength = config.get( - 'maxInlayHintLength' + 'maxInlayHintLength', ) as number; } if (config.has('excludeGlobs')) { diff --git a/editors/code/src/events/change_active_text_editor.ts b/editors/code/src/events/change_active_text_editor.ts index 64be56225..74b91bd48 100644 --- a/editors/code/src/events/change_active_text_editor.ts +++ b/editors/code/src/events/change_active_text_editor.ts @@ -3,7 +3,7 @@ import { TextDocumentIdentifier } from 'vscode-languageclient'; import { SyntaxTreeContentProvider, - syntaxTreeUri + syntaxTreeUri, } from '../commands/syntaxTree'; import { Decoration } from '../highlighting'; import { Server } from '../server'; @@ -21,11 +21,11 @@ export function makeHandler(syntaxTreeProvider: SyntaxTreeContentProvider) { } const params: TextDocumentIdentifier = { - uri: editor.document.uri.toString() + uri: editor.document.uri.toString(), }; const decorations = await Server.client.sendRequest( 'rust-analyzer/decorationsRequest', - params + params, ); Server.highlighter.setHighlights(editor, decorations); }; diff --git a/editors/code/src/events/change_text_document.ts b/editors/code/src/events/change_text_document.ts index 89488bc61..2e998e889 100644 --- a/editors/code/src/events/change_text_document.ts +++ b/editors/code/src/events/change_text_document.ts @@ -2,7 +2,7 @@ import * as vscode from 'vscode'; import { SyntaxTreeContentProvider, - syntaxTreeUri + syntaxTreeUri, } from '../commands/syntaxTree'; export function createHandler(syntaxTreeProvider: SyntaxTreeContentProvider) { diff --git a/editors/code/src/extension.ts b/editors/code/src/extension.ts index a78aa3b42..815f3692c 100644 --- a/editors/code/src/extension.ts +++ b/editors/code/src/extension.ts @@ -7,7 +7,7 @@ import { ExpandMacroContentProvider } from './commands/expand_macro'; import { HintsUpdater } from './commands/inlay_hints'; import { interactivelyStartCargoWatch, - startCargoWatch + startCargoWatch, } from './commands/runnables'; import { SyntaxTreeContentProvider } from './commands/syntaxTree'; import * as events from './events'; @@ -24,7 +24,7 @@ export async function activate(context: vscode.ExtensionContext) { } function overrideCommand( name: string, - f: (...args: any[]) => Promise + f: (...args: any[]) => Promise, ) { const defaultCmd = `default:${name}`; const original = (...args: any[]) => @@ -46,7 +46,7 @@ export async function activate(context: vscode.ExtensionContext) { }); } catch (_) { vscode.window.showWarningMessage( - 'Enhanced typing feature is disabled because of incompatibility with VIM extension, consider turning off rust-analyzer.enableEnhancedTyping: https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/user/README.md#settings' + 'Enhanced typing feature is disabled because of incompatibility with VIM extension, consider turning off rust-analyzer.enableEnhancedTyping: https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/user/README.md#settings', ); } } @@ -54,14 +54,14 @@ export async function activate(context: vscode.ExtensionContext) { // Commands are requests from vscode to the language server registerCommand( 'rust-analyzer.analyzerStatus', - commands.analyzerStatus.makeCommand(context) + commands.analyzerStatus.makeCommand(context), ); registerCommand('rust-analyzer.collectGarbage', () => - Server.client.sendRequest('rust-analyzer/collectGarbage', null) + Server.client.sendRequest('rust-analyzer/collectGarbage', null), ); registerCommand( 'rust-analyzer.matchingBrace', - commands.matchingBrace.handle + commands.matchingBrace.handle, ); registerCommand('rust-analyzer.joinLines', commands.joinLines.handle); registerCommand('rust-analyzer.parentModule', commands.parentModule.handle); @@ -70,7 +70,7 @@ export async function activate(context: vscode.ExtensionContext) { registerCommand('rust-analyzer.runSingle', commands.runnables.handleSingle); registerCommand( 'rust-analyzer.applySourceChange', - commands.applySourceChange.handle + commands.applySourceChange.handle, ); registerCommand( 'rust-analyzer.showReferences', @@ -79,9 +79,9 @@ export async function activate(context: vscode.ExtensionContext) { 'editor.action.showReferences', vscode.Uri.parse(uri), Server.client.protocol2CodeConverter.asPosition(position), - locations.map(Server.client.protocol2CodeConverter.asLocation) + locations.map(Server.client.protocol2CodeConverter.asLocation), ); - } + }, ); if (Server.config.enableEnhancedTyping) { @@ -91,47 +91,47 @@ export async function activate(context: vscode.ExtensionContext) { // Notifications are events triggered by the language server const allNotifications: Iterable<[ string, - lc.GenericNotificationHandler + lc.GenericNotificationHandler, ]> = [ [ 'rust-analyzer/publishDecorations', - notifications.publishDecorations.handle - ] + notifications.publishDecorations.handle, + ], ]; const syntaxTreeContentProvider = new SyntaxTreeContentProvider(); const expandMacroContentProvider = new ExpandMacroContentProvider(); // The events below are plain old javascript events, triggered and handled by vscode vscode.window.onDidChangeActiveTextEditor( - events.changeActiveTextEditor.makeHandler(syntaxTreeContentProvider) + events.changeActiveTextEditor.makeHandler(syntaxTreeContentProvider), ); disposeOnDeactivation( vscode.workspace.registerTextDocumentContentProvider( 'rust-analyzer', - syntaxTreeContentProvider - ) + syntaxTreeContentProvider, + ), ); disposeOnDeactivation( vscode.workspace.registerTextDocumentContentProvider( 'rust-analyzer', - expandMacroContentProvider - ) + expandMacroContentProvider, + ), ); registerCommand( 'rust-analyzer.syntaxTree', - commands.syntaxTree.createHandle(syntaxTreeContentProvider) + commands.syntaxTree.createHandle(syntaxTreeContentProvider), ); registerCommand( 'rust-analyzer.expandMacro', - commands.expandMacro.createHandle(expandMacroContentProvider) + commands.expandMacro.createHandle(expandMacroContentProvider), ); vscode.workspace.onDidChangeTextDocument( events.changeTextDocument.createHandler(syntaxTreeContentProvider), null, - context.subscriptions + context.subscriptions, ); const startServer = () => Server.start(allNotifications); @@ -178,25 +178,25 @@ export async function activate(context: vscode.ExtensionContext) { editorChangeDisposable.dispose(); } return hintsUpdater.refreshHintsForVisibleEditors(); - } + }, ); disposeOnDeactivation( vscode.window.onDidChangeVisibleTextEditors(_ => - hintsUpdater.refreshHintsForVisibleEditors() - ) + hintsUpdater.refreshHintsForVisibleEditors(), + ), ); disposeOnDeactivation( vscode.workspace.onDidChangeTextDocument(e => - hintsUpdater.refreshHintsForVisibleEditors(e) - ) + hintsUpdater.refreshHintsForVisibleEditors(e), + ), ); disposeOnDeactivation( vscode.workspace.onDidChangeConfiguration(_ => hintsUpdater.toggleHintsDisplay( - Server.config.displayInlayHints - ) - ) + Server.config.displayInlayHints, + ), + ), ); }); } diff --git a/editors/code/src/highlighting.ts b/editors/code/src/highlighting.ts index 48f2a2547..6d50a2f2d 100644 --- a/editors/code/src/highlighting.ts +++ b/editors/code/src/highlighting.ts @@ -30,19 +30,19 @@ export class Highlighter { > { const decoration = ( tag: string, - textDecoration?: string + textDecoration?: string, ): [string, vscode.TextEditorDecorationType] => { const color = new vscode.ThemeColor('ralsp.' + tag); const decor = vscode.window.createTextEditorDecorationType({ color, - textDecoration + textDecoration, }); return [tag, decor]; }; const decorations: Iterable<[ string, - vscode.TextEditorDecorationType + vscode.TextEditorDecorationType, ]> = [ decoration('comment'), decoration('string'), @@ -61,7 +61,7 @@ export class Highlighter { decoration('variable'), decoration('variable.mut', 'underline'), decoration('field'), - decoration('module') + decoration('module'), ]; return new Map(decorations); @@ -118,20 +118,20 @@ export class Highlighter { colorfulIdents .get(d.bindingHash)![0] .push( - Server.client.protocol2CodeConverter.asRange(d.range) + Server.client.protocol2CodeConverter.asRange(d.range), ); } else { byTag .get(d.tag)! .push( - Server.client.protocol2CodeConverter.asRange(d.range) + Server.client.protocol2CodeConverter.asRange(d.range), ); } } for (const tag of byTag.keys()) { const dec = this.decorations.get( - tag + tag, ) as vscode.TextEditorDecorationType; const ranges = byTag.get(tag)!; editor.setDecorations(dec, ranges); @@ -141,7 +141,7 @@ export class Highlighter { const textDecoration = mut ? 'underline' : undefined; const dec = vscode.window.createTextEditorDecorationType({ light: { color: fancify(hash, 'light'), textDecoration }, - dark: { color: fancify(hash, 'dark'), textDecoration } + dark: { color: fancify(hash, 'dark'), textDecoration }, }); editor.setDecorations(dec, ranges); } diff --git a/editors/code/src/notifications/publish_decorations.ts b/editors/code/src/notifications/publish_decorations.ts index 3180019b7..00ffb7776 100644 --- a/editors/code/src/notifications/publish_decorations.ts +++ b/editors/code/src/notifications/publish_decorations.ts @@ -10,7 +10,7 @@ export interface PublishDecorationsParams { export function handle(params: PublishDecorationsParams) { const targetEditor = vscode.window.visibleTextEditors.find( - editor => editor.document.uri.toString() === params.uri + editor => editor.document.uri.toString() === params.uri, ); if (!Server.config.highlightingOn || !targetEditor) { return; diff --git a/editors/code/src/server.ts b/editors/code/src/server.ts index e767b6f1b..2fe45f1ed 100644 --- a/editors/code/src/server.ts +++ b/editors/code/src/server.ts @@ -19,7 +19,7 @@ export class Server { public static client: lc.LanguageClient; public static async start( - notificationHandlers: Iterable<[string, lc.GenericNotificationHandler]> + notificationHandlers: Iterable<[string, lc.GenericNotificationHandler]>, ) { // '.' Is the fallback if no folder is open // TODO?: Workspace folders support Uri's (eg: file://test.txt). It might be a good idea to test if the uri points to a file. @@ -34,20 +34,20 @@ export class Server { if (platform() !== 'win32') { if (!(await lookpath(command))) { throw new Error( - `Cannot find rust-analyzer server \`${command}\` in PATH.` + `Cannot find rust-analyzer server \`${command}\` in PATH.`, ); } } const run: lc.Executable = { command, - options: { cwd: folder } + options: { cwd: folder }, }; const serverOptions: lc.ServerOptions = { run, - debug: run + debug: run, }; const traceOutputChannel = window.createOutputChannel( - 'Rust Analyzer Language Server Trace' + 'Rust Analyzer Language Server Trace', ); const clientOptions: lc.LanguageClientOptions = { documentSelector: [{ scheme: 'file', language: 'rust' }], @@ -58,16 +58,16 @@ export class Server { excludeGlobs: Server.config.excludeGlobs, useClientWatching: Server.config.useClientWatching, featureFlags: Server.config.featureFlags, - withSysroot: Server.config.withSysroot + withSysroot: Server.config.withSysroot, }, - traceOutputChannel + traceOutputChannel, }; Server.client = new lc.LanguageClient( 'rust-analyzer', 'Rust Analyzer Language Server', serverOptions, - clientOptions + clientOptions, ); // HACK: This is an awful way of filtering out the decorations notifications // However, pending proper support, this is the most effecitve approach @@ -80,10 +80,10 @@ export class Server { if (typeof messageOrDataObject === 'string') { if ( messageOrDataObject.includes( - 'rust-analyzer/publishDecorations' + 'rust-analyzer/publishDecorations', ) || messageOrDataObject.includes( - 'rust-analyzer/decorationsRequest' + 'rust-analyzer/decorationsRequest', ) ) { // Don't log publish decorations requests @@ -95,7 +95,7 @@ export class Server { // @ts-ignore Server.client.logObjectTrace(messageOrDataObject); } - } + }, }; Server.client.registerProposedFeatures(); Server.client.onReady().then(() => { diff --git a/editors/code/src/test/utils/diagnotics/SuggestedFix.test.ts b/editors/code/src/test/utils/diagnotics/SuggestedFix.test.ts index 6c7f436f3..96ec8c614 100644 --- a/editors/code/src/test/utils/diagnotics/SuggestedFix.test.ts +++ b/editors/code/src/test/utils/diagnotics/SuggestedFix.test.ts @@ -6,12 +6,12 @@ import SuggestedFix from '../../../utils/diagnostics/SuggestedFix'; const location1 = new vscode.Location( vscode.Uri.file('/file/1'), - new vscode.Range(new vscode.Position(1, 2), new vscode.Position(3, 4)) + new vscode.Range(new vscode.Position(1, 2), new vscode.Position(3, 4)), ); const location2 = new vscode.Location( vscode.Uri.file('/file/2'), - new vscode.Range(new vscode.Position(5, 6), new vscode.Position(7, 8)) + new vscode.Range(new vscode.Position(5, 6), new vscode.Position(7, 8)), ); describe('SuggestedFix', () => { @@ -20,13 +20,13 @@ describe('SuggestedFix', () => { const suggestion1 = new SuggestedFix( 'Replace me!', location1, - 'With this!' + 'With this!', ); const suggestion2 = new SuggestedFix( 'Replace me!', location1, - 'With this!' + 'With this!', ); assert(suggestion1.isEqual(suggestion2)); @@ -36,13 +36,13 @@ describe('SuggestedFix', () => { const suggestion1 = new SuggestedFix( 'Replace me!', location1, - 'With this!' + 'With this!', ); const suggestion2 = new SuggestedFix( 'Not the same title!', location1, - 'With this!' + 'With this!', ); assert(!suggestion1.isEqual(suggestion2)); @@ -52,13 +52,13 @@ describe('SuggestedFix', () => { const suggestion1 = new SuggestedFix( 'Replace me!', location1, - 'With this!' + 'With this!', ); const suggestion2 = new SuggestedFix( 'Replace me!', location1, - 'With something else!' + 'With something else!', ); assert(!suggestion1.isEqual(suggestion2)); @@ -68,13 +68,13 @@ describe('SuggestedFix', () => { const suggestion1 = new SuggestedFix( 'Replace me!', location1, - 'With this!' + 'With this!', ); const suggestion2 = new SuggestedFix( 'Replace me!', location2, - 'With this!' + 'With this!', ); assert(!suggestion1.isEqual(suggestion2)); @@ -85,14 +85,14 @@ describe('SuggestedFix', () => { 'Replace me!', location1, 'With this!', - SuggestionApplicability.MachineApplicable + SuggestionApplicability.MachineApplicable, ); const suggestion2 = new SuggestedFix( 'Replace me!', location2, 'With this!', - SuggestionApplicability.HasPlaceholders + SuggestionApplicability.HasPlaceholders, ); assert(!suggestion1.isEqual(suggestion2)); @@ -104,7 +104,7 @@ describe('SuggestedFix', () => { const suggestion = new SuggestedFix( 'Replace me!', location1, - 'With this!' + 'With this!', ); const codeAction = suggestion.toCodeAction(); diff --git a/editors/code/src/test/utils/diagnotics/SuggestedFixCollection.test.ts b/editors/code/src/test/utils/diagnotics/SuggestedFixCollection.test.ts index f0328893e..4c1467b57 100644 --- a/editors/code/src/test/utils/diagnotics/SuggestedFixCollection.test.ts +++ b/editors/code/src/test/utils/diagnotics/SuggestedFixCollection.test.ts @@ -8,20 +8,20 @@ const uri1 = vscode.Uri.file('/file/1'); const uri2 = vscode.Uri.file('/file/2'); const mockDocument1 = ({ - uri: uri1 + uri: uri1, } as unknown) as vscode.TextDocument; const mockDocument2 = ({ - uri: uri2 + uri: uri2, } as unknown) as vscode.TextDocument; const range1 = new vscode.Range( new vscode.Position(1, 2), - new vscode.Position(3, 4) + new vscode.Position(3, 4), ); const range2 = new vscode.Range( new vscode.Position(5, 6), - new vscode.Position(7, 8) + new vscode.Position(7, 8), ); const diagnostic1 = new vscode.Diagnostic(range1, 'First diagnostic'); @@ -32,7 +32,7 @@ function suggestion1(): SuggestedFix { return new SuggestedFix( 'Replace me!', new vscode.Location(uri1, range1), - 'With this!' + 'With this!', ); } @@ -44,7 +44,7 @@ describe('SuggestedFixCollection', () => { // Specify the document and range that exactly matches const codeActions = suggestedFixes.provideCodeActions( mockDocument1, - range1 + range1, ); assert.strictEqual(codeActions.length, 1); @@ -66,7 +66,7 @@ describe('SuggestedFixCollection', () => { const codeActions = suggestedFixes.provideCodeActions( mockDocument1, - range2 + range2, ); assert(!codeActions || codeActions.length === 0); @@ -78,7 +78,7 @@ describe('SuggestedFixCollection', () => { const codeActions = suggestedFixes.provideCodeActions( mockDocument2, - range1 + range1, ); assert(!codeActions || codeActions.length === 0); @@ -91,7 +91,7 @@ describe('SuggestedFixCollection', () => { const codeActions = suggestedFixes.provideCodeActions( mockDocument1, - range1 + range1, ); assert(!codeActions || codeActions.length === 0); @@ -106,7 +106,7 @@ describe('SuggestedFixCollection', () => { const codeActions = suggestedFixes.provideCodeActions( mockDocument1, - range1 + range1, ); assert.strictEqual(codeActions.length, 1); diff --git a/editors/code/src/test/utils/diagnotics/rust.test.ts b/editors/code/src/test/utils/diagnotics/rust.test.ts index 327d15046..cee59061f 100644 --- a/editors/code/src/test/utils/diagnotics/rust.test.ts +++ b/editors/code/src/test/utils/diagnotics/rust.test.ts @@ -6,14 +6,14 @@ import { MappedRustDiagnostic, mapRustDiagnosticToVsCode, RustDiagnostic, - SuggestionApplicability + SuggestionApplicability, } from '../../../utils/diagnostics/rust'; function loadDiagnosticFixture(name: string): RustDiagnostic { const jsonText = fs .readFileSync( // We're actually in our JavaScript output directory, climb out - `${__dirname}/../../../../src/test/fixtures/rust-diagnostics/${name}.json` + `${__dirname}/../../../../src/test/fixtures/rust-diagnostics/${name}.json`, ) .toString(); @@ -33,12 +33,12 @@ function mapFixtureToVsCode(name: string): MappedRustDiagnostic { describe('mapRustDiagnosticToVsCode', () => { it('should map an incompatible type for trait error', () => { const { diagnostic, suggestedFixes } = mapFixtureToVsCode( - 'error/E0053' + 'error/E0053', ); assert.strictEqual( diagnostic.severity, - vscode.DiagnosticSeverity.Error + vscode.DiagnosticSeverity.Error, ); assert.strictEqual(diagnostic.source, 'rustc'); assert.strictEqual( @@ -46,8 +46,8 @@ describe('mapRustDiagnosticToVsCode', () => { [ `method \`next\` has an incompatible type for trait`, `expected type \`fn(&mut ty::list_iter::ListIterator<'list, M>) -> std::option::Option<&ty::Ref>\``, - ` found type \`fn(&ty::list_iter::ListIterator<'list, M>) -> std::option::Option<&'list ty::Ref>\`` - ].join('\n') + ` found type \`fn(&ty::list_iter::ListIterator<'list, M>) -> std::option::Option<&'list ty::Ref>\``, + ].join('\n'), ); assert.strictEqual(diagnostic.code, 'E0053'); assert.deepStrictEqual(diagnostic.tags, []); @@ -61,24 +61,24 @@ describe('mapRustDiagnosticToVsCode', () => { it('should map an unused variable warning', () => { const { diagnostic, suggestedFixes } = mapFixtureToVsCode( - 'warning/unused_variables' + 'warning/unused_variables', ); assert.strictEqual( diagnostic.severity, - vscode.DiagnosticSeverity.Warning + vscode.DiagnosticSeverity.Warning, ); assert.strictEqual( diagnostic.message, [ 'unused variable: `foo`', - '#[warn(unused_variables)] on by default' - ].join('\n') + '#[warn(unused_variables)] on by default', + ].join('\n'), ); assert.strictEqual(diagnostic.code, 'unused_variables'); assert.strictEqual(diagnostic.source, 'rustc'); assert.deepStrictEqual(diagnostic.tags, [ - vscode.DiagnosticTag.Unnecessary + vscode.DiagnosticTag.Unnecessary, ]); // No related information @@ -89,29 +89,29 @@ describe('mapRustDiagnosticToVsCode', () => { const [suggestedFix] = suggestedFixes; assert.strictEqual( suggestedFix.title, - 'consider prefixing with an underscore: `_foo`' + 'consider prefixing with an underscore: `_foo`', ); assert.strictEqual( suggestedFix.applicability, - SuggestionApplicability.MachineApplicable + SuggestionApplicability.MachineApplicable, ); }); it('should map a wrong number of parameters error', () => { const { diagnostic, suggestedFixes } = mapFixtureToVsCode( - 'error/E0061' + 'error/E0061', ); assert.strictEqual( diagnostic.severity, - vscode.DiagnosticSeverity.Error + vscode.DiagnosticSeverity.Error, ); assert.strictEqual( diagnostic.message, [ 'this function takes 2 parameters but 3 parameters were supplied', - 'expected 2 parameters' - ].join('\n') + 'expected 2 parameters', + ].join('\n'), ); assert.strictEqual(diagnostic.code, 'E0061'); assert.strictEqual(diagnostic.source, 'rustc'); @@ -132,12 +132,12 @@ describe('mapRustDiagnosticToVsCode', () => { it('should map a Clippy copy pass by ref warning', () => { const { diagnostic, suggestedFixes } = mapFixtureToVsCode( - 'clippy/trivially_copy_pass_by_ref' + 'clippy/trivially_copy_pass_by_ref', ); assert.strictEqual( diagnostic.severity, - vscode.DiagnosticSeverity.Warning + vscode.DiagnosticSeverity.Warning, ); assert.strictEqual(diagnostic.source, 'clippy'); assert.strictEqual( @@ -145,8 +145,8 @@ describe('mapRustDiagnosticToVsCode', () => { [ 'this argument is passed by reference, but would be more efficient if passed by value', '#[warn(clippy::trivially_copy_pass_by_ref)] implied by #[warn(clippy::all)]', - 'for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#trivially_copy_pass_by_ref' - ].join('\n') + 'for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#trivially_copy_pass_by_ref', + ].join('\n'), ); assert.strictEqual(diagnostic.code, 'trivially_copy_pass_by_ref'); assert.deepStrictEqual(diagnostic.tags, []); @@ -165,27 +165,27 @@ describe('mapRustDiagnosticToVsCode', () => { const [suggestedFix] = suggestedFixes; assert.strictEqual( suggestedFix.title, - 'consider passing by value instead: `self`' + 'consider passing by value instead: `self`', ); // Clippy does not mark this with any applicability assert.strictEqual( suggestedFix.applicability, - SuggestionApplicability.Unspecified + SuggestionApplicability.Unspecified, ); }); it('should map a mismatched type error', () => { const { diagnostic, suggestedFixes } = mapFixtureToVsCode( - 'error/E0308' + 'error/E0308', ); assert.strictEqual( diagnostic.severity, - vscode.DiagnosticSeverity.Error + vscode.DiagnosticSeverity.Error, ); assert.strictEqual( diagnostic.message, - ['mismatched types', 'expected usize, found u32'].join('\n') + ['mismatched types', 'expected usize, found u32'].join('\n'), ); assert.strictEqual(diagnostic.code, 'E0308'); assert.strictEqual(diagnostic.source, 'rustc'); diff --git a/editors/code/src/test/utils/diagnotics/vscode.test.ts b/editors/code/src/test/utils/diagnotics/vscode.test.ts index 542dec1f5..4944dd032 100644 --- a/editors/code/src/test/utils/diagnotics/vscode.test.ts +++ b/editors/code/src/test/utils/diagnotics/vscode.test.ts @@ -5,12 +5,12 @@ import { areDiagnosticsEqual } from '../../../utils/diagnostics/vscode'; const range1 = new vscode.Range( new vscode.Position(1, 2), - new vscode.Position(3, 4) + new vscode.Position(3, 4), ); const range2 = new vscode.Range( new vscode.Position(5, 6), - new vscode.Position(7, 8) + new vscode.Position(7, 8), ); describe('areDiagnosticsEqual', () => { @@ -18,13 +18,13 @@ describe('areDiagnosticsEqual', () => { const diagnostic1 = new vscode.Diagnostic( range1, 'Hello, world!', - vscode.DiagnosticSeverity.Error + vscode.DiagnosticSeverity.Error, ); const diagnostic2 = new vscode.Diagnostic( range1, 'Hello, world!', - vscode.DiagnosticSeverity.Error + vscode.DiagnosticSeverity.Error, ); assert(areDiagnosticsEqual(diagnostic1, diagnostic2)); @@ -34,14 +34,14 @@ describe('areDiagnosticsEqual', () => { const diagnostic1 = new vscode.Diagnostic( range1, 'Hello, world!', - vscode.DiagnosticSeverity.Error + vscode.DiagnosticSeverity.Error, ); diagnostic1.source = 'rustc'; const diagnostic2 = new vscode.Diagnostic( range1, 'Hello, world!', - vscode.DiagnosticSeverity.Error + vscode.DiagnosticSeverity.Error, ); diagnostic2.source = 'clippy'; @@ -52,13 +52,13 @@ describe('areDiagnosticsEqual', () => { const diagnostic1 = new vscode.Diagnostic( range1, 'Hello, world!', - vscode.DiagnosticSeverity.Error + vscode.DiagnosticSeverity.Error, ); const diagnostic2 = new vscode.Diagnostic( range2, 'Hello, world!', - vscode.DiagnosticSeverity.Error + vscode.DiagnosticSeverity.Error, ); assert(!areDiagnosticsEqual(diagnostic1, diagnostic2)); @@ -68,13 +68,13 @@ describe('areDiagnosticsEqual', () => { const diagnostic1 = new vscode.Diagnostic( range1, 'Hello, world!', - vscode.DiagnosticSeverity.Error + vscode.DiagnosticSeverity.Error, ); const diagnostic2 = new vscode.Diagnostic( range1, 'Goodbye!, world!', - vscode.DiagnosticSeverity.Error + vscode.DiagnosticSeverity.Error, ); assert(!areDiagnosticsEqual(diagnostic1, diagnostic2)); @@ -84,13 +84,13 @@ describe('areDiagnosticsEqual', () => { const diagnostic1 = new vscode.Diagnostic( range1, 'Hello, world!', - vscode.DiagnosticSeverity.Warning + vscode.DiagnosticSeverity.Warning, ); const diagnostic2 = new vscode.Diagnostic( range1, 'Hello, world!', - vscode.DiagnosticSeverity.Error + vscode.DiagnosticSeverity.Error, ); assert(!areDiagnosticsEqual(diagnostic1, diagnostic2)); diff --git a/editors/code/src/test/utils/index.ts b/editors/code/src/test/utils/index.ts index 16715a286..9927daaf6 100644 --- a/editors/code/src/test/utils/index.ts +++ b/editors/code/src/test/utils/index.ts @@ -17,7 +17,7 @@ import * as path from 'path'; export function run(): Promise { // Create the mocha test const mocha = new Mocha({ - ui: 'bdd' + ui: 'bdd', }); mocha.useColors(true); diff --git a/editors/code/src/utils/diagnostics/SuggestedFix.ts b/editors/code/src/utils/diagnostics/SuggestedFix.ts index b1be2a225..6e660bb61 100644 --- a/editors/code/src/utils/diagnostics/SuggestedFix.ts +++ b/editors/code/src/utils/diagnostics/SuggestedFix.ts @@ -24,7 +24,7 @@ export default class SuggestedFix { title: string, location: vscode.Location, replacement: string, - applicability: SuggestionApplicability = SuggestionApplicability.Unspecified + applicability: SuggestionApplicability = SuggestionApplicability.Unspecified, ) { this.title = title; this.location = location; @@ -51,7 +51,7 @@ export default class SuggestedFix { public toCodeAction(): vscode.CodeAction { const codeAction = new vscode.CodeAction( this.title, - vscode.CodeActionKind.QuickFix + vscode.CodeActionKind.QuickFix, ); const edit = new vscode.WorkspaceEdit(); diff --git a/editors/code/src/utils/diagnostics/SuggestedFixCollection.ts b/editors/code/src/utils/diagnostics/SuggestedFixCollection.ts index 132ce12f8..57c9856cf 100644 --- a/editors/code/src/utils/diagnostics/SuggestedFixCollection.ts +++ b/editors/code/src/utils/diagnostics/SuggestedFixCollection.ts @@ -38,13 +38,13 @@ export default class SuggestedFixCollection */ public addSuggestedFixForDiagnostic( suggestedFix: SuggestedFix, - diagnostic: vscode.Diagnostic + diagnostic: vscode.Diagnostic, ): void { const fileUriString = suggestedFix.location.uri.toString(); const fileSuggestions = this.suggestedFixes.get(fileUriString) || []; const existingSuggestion = fileSuggestions.find(s => - s.isEqual(suggestedFix) + s.isEqual(suggestedFix), ); if (existingSuggestion) { @@ -65,7 +65,7 @@ export default class SuggestedFixCollection */ public provideCodeActions( document: vscode.TextDocument, - range: vscode.Range + range: vscode.Range, ): vscode.CodeAction[] { const documentUriString = document.uri.toString(); diff --git a/editors/code/src/utils/diagnostics/rust.ts b/editors/code/src/utils/diagnostics/rust.ts index 0550d0372..b6efc0f56 100644 --- a/editors/code/src/utils/diagnostics/rust.ts +++ b/editors/code/src/utils/diagnostics/rust.ts @@ -7,7 +7,7 @@ export enum SuggestionApplicability { MachineApplicable = 'MachineApplicable', HasPlaceholders = 'HasPlaceholders', MaybeIncorrect = 'MaybeIncorrect', - Unspecified = 'Unspecified' + Unspecified = 'Unspecified', } // Reference: @@ -69,7 +69,7 @@ function mapSpanToLocation(span: RustDiagnosticSpan): vscode.Location { const range = new vscode.Range( new vscode.Position(span.line_start - 1, span.column_start - 1), - new vscode.Position(span.line_end - 1, span.column_end - 1) + new vscode.Position(span.line_end - 1, span.column_end - 1), ); return new vscode.Location(fileUri, range); @@ -81,7 +81,7 @@ function mapSpanToLocation(span: RustDiagnosticSpan): vscode.Location { * If the span is unlabelled this will return `undefined`. */ function mapSecondarySpanToRelated( - span: RustDiagnosticSpan + span: RustDiagnosticSpan, ): vscode.DiagnosticRelatedInformation | undefined { if (!span.label) { // Nothing to label this with @@ -107,7 +107,7 @@ function isUnusedOrUnnecessary(rd: RustDiagnostic): boolean { 'unused_attributes', 'unused_imports', 'unused_macros', - 'unused_variables' + 'unused_variables', ].includes(rd.code.code); } @@ -157,13 +157,13 @@ function mapRustChildDiagnostic(rd: RustDiagnostic): MappedRustChildDiagnostic { title, location, span.suggested_replacement, - span.suggestion_applicability - ) + span.suggestion_applicability, + ), }; } else { const related = new vscode.DiagnosticRelatedInformation( location, - rd.message + rd.message, ); return { related }; @@ -183,7 +183,7 @@ function mapRustChildDiagnostic(rd: RustDiagnostic): MappedRustChildDiagnostic { * If the diagnostic has no primary span this will return `undefined` */ export function mapRustDiagnosticToVsCode( - rd: RustDiagnostic + rd: RustDiagnostic, ): MappedRustDiagnostic | undefined { const primarySpan = rd.spans.find(s => s.is_primary); if (!primarySpan) { @@ -223,7 +223,7 @@ export function mapRustDiagnosticToVsCode( const suggestedFixes = []; for (const child of rd.children) { const { related, suggestedFix, messageLine } = mapRustChildDiagnostic( - child + child, ); if (related) { @@ -256,6 +256,6 @@ export function mapRustDiagnosticToVsCode( return { location, diagnostic: vd, - suggestedFixes + suggestedFixes, }; } diff --git a/editors/code/src/utils/diagnostics/vscode.ts b/editors/code/src/utils/diagnostics/vscode.ts index d8b85b720..f4a5450e2 100644 --- a/editors/code/src/utils/diagnostics/vscode.ts +++ b/editors/code/src/utils/diagnostics/vscode.ts @@ -3,7 +3,7 @@ import * as vscode from 'vscode'; /** Compares two `vscode.Diagnostic`s for equality */ export function areDiagnosticsEqual( left: vscode.Diagnostic, - right: vscode.Diagnostic + right: vscode.Diagnostic, ): boolean { return ( left.source === right.source && diff --git a/editors/code/src/utils/processes.ts b/editors/code/src/utils/processes.ts index da8be9eb1..a1d6b7eaf 100644 --- a/editors/code/src/utils/processes.ts +++ b/editors/code/src/utils/processes.ts @@ -22,7 +22,7 @@ export function terminate(process: ChildProcess, cwd?: string): boolean { // Ignore stderr since this is otherwise piped to parent.stderr // which might be already closed. const options: any = { - stdio: ['pipe', 'pipe', 'ignore'] + stdio: ['pipe', 'pipe', 'ignore'], }; if (cwd) { options.cwd = cwd; @@ -30,7 +30,7 @@ export function terminate(process: ChildProcess, cwd?: string): boolean { cp.execFileSync( 'taskkill', ['/T', '/F', '/PID', process.pid.toString()], - options + options, ); return true; } catch (err) { -- cgit v1.2.3 From b21bb44c8dcd43e9e42ef7e3d752dd550e6505ad Mon Sep 17 00:00:00 2001 From: Tetsuharu OHZEKI Date: Thu, 12 Dec 2019 00:41:16 +0900 Subject: Enable noUnusedParameters option for vscode extension --- editors/code/src/commands/analyzer_status.ts | 2 +- editors/code/src/commands/expand_macro.ts | 2 +- editors/code/src/commands/runnables.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'editors/code/src') diff --git a/editors/code/src/commands/analyzer_status.ts b/editors/code/src/commands/analyzer_status.ts index 9e4ce0eb3..2777ced24 100644 --- a/editors/code/src/commands/analyzer_status.ts +++ b/editors/code/src/commands/analyzer_status.ts @@ -9,7 +9,7 @@ export class TextDocumentContentProvider public syntaxTree: string = 'Not available'; public provideTextDocumentContent( - uri: vscode.Uri, + _uri: vscode.Uri, ): vscode.ProviderResult { const editor = vscode.window.activeTextEditor; if (editor == null) { diff --git a/editors/code/src/commands/expand_macro.ts b/editors/code/src/commands/expand_macro.ts index 842898020..17c78280a 100644 --- a/editors/code/src/commands/expand_macro.ts +++ b/editors/code/src/commands/expand_macro.ts @@ -11,7 +11,7 @@ export class ExpandMacroContentProvider public eventEmitter = new vscode.EventEmitter(); public provideTextDocumentContent( - uri: vscode.Uri, + _uri: vscode.Uri, ): vscode.ProviderResult { async function handle() { const editor = vscode.window.activeTextEditor; diff --git a/editors/code/src/commands/runnables.ts b/editors/code/src/commands/runnables.ts index 9b1c6643d..c81d7ce0f 100644 --- a/editors/code/src/commands/runnables.ts +++ b/editors/code/src/commands/runnables.ts @@ -178,7 +178,7 @@ export async function startCargoWatch( } const label = 'install-cargo-watch'; - const taskFinished = new Promise((resolve, reject) => { + const taskFinished = new Promise((resolve, _reject) => { const disposable = vscode.tasks.onDidEndTask(({ execution }) => { if (execution.task.name === label) { disposable.dispose(); -- cgit v1.2.3 From 0e9cabab3fb4c15fb1b88e62a35ccf1ea52ef853 Mon Sep 17 00:00:00 2001 From: Tetsuharu OHZEKI Date: Thu, 12 Dec 2019 00:49:54 +0900 Subject: Enable noImplicitReturns option for vscode extension --- editors/code/src/commands/runnables.ts | 14 ++++++++------ .../code/src/test/utils/diagnotics/SuggestedFix.test.ts | 3 ++- .../test/utils/diagnotics/SuggestedFixCollection.test.ts | 6 ++++-- editors/code/src/test/utils/diagnotics/rust.test.ts | 6 ++++-- 4 files changed, 18 insertions(+), 11 deletions(-) (limited to 'editors/code/src') diff --git a/editors/code/src/commands/runnables.ts b/editors/code/src/commands/runnables.ts index c81d7ce0f..cf980e257 100644 --- a/editors/code/src/commands/runnables.ts +++ b/editors/code/src/commands/runnables.ts @@ -73,7 +73,7 @@ function createTask(spec: Runnable): vscode.Task { } let prevRunnable: RunnableQuickPick | undefined; -export async function handle() { +export async function handle(): Promise { const editor = vscode.window.activeTextEditor; if (editor == null || editor.document.languageId !== 'rust') { return; @@ -105,12 +105,14 @@ export async function handle() { items.push(new RunnableQuickPick(r)); } const item = await vscode.window.showQuickPick(items); - if (item) { - item.detail = 'rerun'; - prevRunnable = item; - const task = createTask(item.runnable); - return await vscode.tasks.executeTask(task); + if (!item) { + return; } + + item.detail = 'rerun'; + prevRunnable = item; + const task = createTask(item.runnable); + return await vscode.tasks.executeTask(task); } export async function handleSingle(runnable: Runnable) { diff --git a/editors/code/src/test/utils/diagnotics/SuggestedFix.test.ts b/editors/code/src/test/utils/diagnotics/SuggestedFix.test.ts index 96ec8c614..2b25eb705 100644 --- a/editors/code/src/test/utils/diagnotics/SuggestedFix.test.ts +++ b/editors/code/src/test/utils/diagnotics/SuggestedFix.test.ts @@ -114,7 +114,8 @@ describe('SuggestedFix', () => { const edit = codeAction.edit; if (!edit) { - return assert.fail('Code Action edit unexpectedly missing'); + assert.fail('Code Action edit unexpectedly missing'); + return; } const editEntries = edit.entries(); diff --git a/editors/code/src/test/utils/diagnotics/SuggestedFixCollection.test.ts b/editors/code/src/test/utils/diagnotics/SuggestedFixCollection.test.ts index 4c1467b57..ef09013f4 100644 --- a/editors/code/src/test/utils/diagnotics/SuggestedFixCollection.test.ts +++ b/editors/code/src/test/utils/diagnotics/SuggestedFixCollection.test.ts @@ -53,7 +53,8 @@ describe('SuggestedFixCollection', () => { const { diagnostics } = codeAction; if (!diagnostics) { - return assert.fail('Diagnostics unexpectedly missing'); + assert.fail('Diagnostics unexpectedly missing'); + return; } assert.strictEqual(diagnostics.length, 1); @@ -114,7 +115,8 @@ describe('SuggestedFixCollection', () => { const { diagnostics } = codeAction; if (!diagnostics) { - return assert.fail('Diagnostics unexpectedly missing'); + assert.fail('Diagnostics unexpectedly missing'); + return; } // We should be associated with both diagnostics diff --git a/editors/code/src/test/utils/diagnotics/rust.test.ts b/editors/code/src/test/utils/diagnotics/rust.test.ts index cee59061f..0222dbbaa 100644 --- a/editors/code/src/test/utils/diagnotics/rust.test.ts +++ b/editors/code/src/test/utils/diagnotics/rust.test.ts @@ -120,7 +120,8 @@ describe('mapRustDiagnosticToVsCode', () => { // One related information for the original definition const relatedInformation = diagnostic.relatedInformation; if (!relatedInformation) { - return assert.fail('Related information unexpectedly undefined'); + assert.fail('Related information unexpectedly undefined'); + return; } assert.strictEqual(relatedInformation.length, 1); const [related] = relatedInformation; @@ -154,7 +155,8 @@ describe('mapRustDiagnosticToVsCode', () => { // One related information for the lint definition const relatedInformation = diagnostic.relatedInformation; if (!relatedInformation) { - return assert.fail('Related information unexpectedly undefined'); + assert.fail('Related information unexpectedly undefined'); + return; } assert.strictEqual(relatedInformation.length, 1); const [related] = relatedInformation; -- cgit v1.2.3 From af4eb266457eb784010da28d80535f9fd38d4d1e Mon Sep 17 00:00:00 2001 From: oxalica Date: Fri, 13 Dec 2019 18:16:34 +0800 Subject: Support setting cargo features --- editors/code/src/config.ts | 70 +++++++++++++++++++++++++++++++++++++--------- editors/code/src/server.ts | 1 + 2 files changed, 58 insertions(+), 13 deletions(-) (limited to 'editors/code/src') diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index 2d3b6a54e..6d709f7a8 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts @@ -15,6 +15,12 @@ export interface CargoWatchOptions { ignore: string[]; } +export interface CargoFeatures { + noDefaultFeatures: boolean; + allFeatures: boolean; + features: string[]; +} + export class Config { public highlightingOn = true; public rainbowHighlightingOn = false; @@ -35,8 +41,14 @@ export class Config { command: '', ignore: [], }; + public cargoFeatures: CargoFeatures = { + noDefaultFeatures: false, + allFeatures: false, + features: [], + }; private prevEnhancedTyping: null | boolean = null; + private prevCargoFeatures: null | CargoFeatures = null; constructor() { vscode.workspace.onDidChangeConfiguration(_ => @@ -47,6 +59,8 @@ export class Config { public userConfigChanged() { const config = vscode.workspace.getConfiguration('rust-analyzer'); + let requireReloadMessage = null; + if (config.has('highlightingOn')) { this.highlightingOn = config.get('highlightingOn') as boolean; } @@ -74,19 +88,7 @@ export class Config { } if (this.prevEnhancedTyping !== this.enableEnhancedTyping) { - const reloadAction = 'Reload now'; - vscode.window - .showInformationMessage( - 'Changing enhanced typing setting requires a reload', - reloadAction, - ) - .then(selectedAction => { - if (selectedAction === reloadAction) { - vscode.commands.executeCommand( - 'workbench.action.reloadWindow', - ); - } - }); + requireReloadMessage = 'Changing enhanced typing setting requires a reload'; this.prevEnhancedTyping = this.enableEnhancedTyping; } @@ -153,5 +155,47 @@ export class Config { if (config.has('withSysroot')) { this.withSysroot = config.get('withSysroot') || false; } + + if (config.has('cargoFeatures.noDefaultFeatures')) { + this.cargoFeatures.noDefaultFeatures = config.get( + 'cargoFeatures.noDefaultFeatures', + false, + ); + } + if (config.has('cargoFeatures.allFeatures')) { + this.cargoFeatures.allFeatures = config.get( + 'cargoFeatures.allFeatures', + false, + ); + } + if (config.has('cargoFeatures.features')) { + this.cargoFeatures.features = config.get( + 'cargoFeatures.features', + [], + ); + } + + if (this.prevCargoFeatures !== null && ( + this.cargoFeatures.allFeatures !== this.prevCargoFeatures.allFeatures || + this.cargoFeatures.noDefaultFeatures !== this.prevCargoFeatures.noDefaultFeatures || + this.cargoFeatures.features.length !== this.prevCargoFeatures.features.length || + this.cargoFeatures.features.some((v, i) => v !== this.prevCargoFeatures!.features[i]) + )) { + requireReloadMessage = 'Changing cargo features requires a reload'; + } + this.prevCargoFeatures = { ...this.cargoFeatures }; + + if (requireReloadMessage !== null) { + const reloadAction = 'Reload now'; + vscode.window + .showInformationMessage(requireReloadMessage, reloadAction) + .then(selectedAction => { + if (selectedAction === reloadAction) { + vscode.commands.executeCommand( + 'workbench.action.reloadWindow', + ); + } + }); + } } } diff --git a/editors/code/src/server.ts b/editors/code/src/server.ts index 2fe45f1ed..5ace1d0fa 100644 --- a/editors/code/src/server.ts +++ b/editors/code/src/server.ts @@ -59,6 +59,7 @@ export class Server { useClientWatching: Server.config.useClientWatching, featureFlags: Server.config.featureFlags, withSysroot: Server.config.withSysroot, + cargoFeatures: Server.config.cargoFeatures, }, traceOutputChannel, }; -- cgit v1.2.3 From f56a2a079069edafd74ef92b7e545f18be88b243 Mon Sep 17 00:00:00 2001 From: oxalica Date: Sat, 14 Dec 2019 00:48:47 +0800 Subject: Enable `allFeatures` by default and fix lints --- editors/code/src/config.ts | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'editors/code/src') diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index 6d709f7a8..defdfeb9c 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts @@ -43,7 +43,7 @@ export class Config { }; public cargoFeatures: CargoFeatures = { noDefaultFeatures: false, - allFeatures: false, + allFeatures: true, features: [], }; @@ -88,7 +88,8 @@ export class Config { } if (this.prevEnhancedTyping !== this.enableEnhancedTyping) { - requireReloadMessage = 'Changing enhanced typing setting requires a reload'; + requireReloadMessage = + 'Changing enhanced typing setting requires a reload'; this.prevEnhancedTyping = this.enableEnhancedTyping; } @@ -165,7 +166,7 @@ export class Config { if (config.has('cargoFeatures.allFeatures')) { this.cargoFeatures.allFeatures = config.get( 'cargoFeatures.allFeatures', - false, + true, ); } if (config.has('cargoFeatures.features')) { @@ -175,12 +176,18 @@ export class Config { ); } - if (this.prevCargoFeatures !== null && ( - this.cargoFeatures.allFeatures !== this.prevCargoFeatures.allFeatures || - this.cargoFeatures.noDefaultFeatures !== this.prevCargoFeatures.noDefaultFeatures || - this.cargoFeatures.features.length !== this.prevCargoFeatures.features.length || - this.cargoFeatures.features.some((v, i) => v !== this.prevCargoFeatures!.features[i]) - )) { + if ( + this.prevCargoFeatures !== null && + (this.cargoFeatures.allFeatures !== + this.prevCargoFeatures.allFeatures || + this.cargoFeatures.noDefaultFeatures !== + this.prevCargoFeatures.noDefaultFeatures || + this.cargoFeatures.features.length !== + this.prevCargoFeatures.features.length || + this.cargoFeatures.features.some( + (v, i) => v !== this.prevCargoFeatures!.features[i], + )) + ) { requireReloadMessage = 'Changing cargo features requires a reload'; } this.prevCargoFeatures = { ...this.cargoFeatures }; -- cgit v1.2.3 From 67641d3f5fd1cfd49673c4eea9e3d646ed97e108 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Sat, 14 Dec 2019 13:24:07 +0200 Subject: added decorations --- editors/code/src/highlighting.ts | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'editors/code/src') diff --git a/editors/code/src/highlighting.ts b/editors/code/src/highlighting.ts index 6d50a2f2d..2c8a98aa6 100644 --- a/editors/code/src/highlighting.ts +++ b/editors/code/src/highlighting.ts @@ -53,10 +53,16 @@ export class Highlighter { decoration('parameter'), decoration('constant'), decoration('type'), + decoration('type.self'), + decoration('type.generic'), + decoration('type.param'), decoration('builtin'), decoration('text'), decoration('attribute'), decoration('literal'), + decoration('literal.numeric'), + decoration('literal.char'), + decoration('literal.byte'), decoration('macro'), decoration('variable'), decoration('variable.mut', 'underline'), -- cgit v1.2.3 From 083010f6339e558184f06ce76a18e1ad0b0ee936 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Sat, 14 Dec 2019 13:29:42 +0200 Subject: removed `type.alias` --- editors/code/src/highlighting.ts | 1 + 1 file changed, 1 insertion(+) (limited to 'editors/code/src') diff --git a/editors/code/src/highlighting.ts b/editors/code/src/highlighting.ts index 2c8a98aa6..d7c0ae131 100644 --- a/editors/code/src/highlighting.ts +++ b/editors/code/src/highlighting.ts @@ -56,6 +56,7 @@ export class Highlighter { decoration('type.self'), decoration('type.generic'), decoration('type.param'), + decoration('type.lifetime'), decoration('builtin'), decoration('text'), decoration('attribute'), -- cgit v1.2.3 From 1d9b585c62dc92889380c9ae130d15ce7f9b08d4 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Sun, 15 Dec 2019 15:07:33 +0200 Subject: make drive comparison case-insensitive. --- editors/code/src/notifications/publish_decorations.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'editors/code/src') diff --git a/editors/code/src/notifications/publish_decorations.ts b/editors/code/src/notifications/publish_decorations.ts index 00ffb7776..120eabbc6 100644 --- a/editors/code/src/notifications/publish_decorations.ts +++ b/editors/code/src/notifications/publish_decorations.ts @@ -10,10 +10,19 @@ export interface PublishDecorationsParams { export function handle(params: PublishDecorationsParams) { const targetEditor = vscode.window.visibleTextEditors.find( - editor => editor.document.uri.toString() === params.uri, + editor => { + const unescapedUri = unescape(editor.document.uri.toString()); + // Unescaped URI should be something like: + // file:///c:/Workspace/ra-test/src/main.rs + // RA server might send it with the drive letter uppercased, so we force only the drive letter to lowercase. + const uriWithLowercasedDrive = params.uri.substr(0, 8) + params.uri[8].toLowerCase() + params.uri.substr(9); + return unescapedUri === uriWithLowercasedDrive + } ); + if (!Server.config.highlightingOn || !targetEditor) { return; } + Server.highlighter.setHighlights(targetEditor, params.decorations); } -- cgit v1.2.3 From 324cbe839f3110bd4d51726d5a7afe29808ade02 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Sun, 15 Dec 2019 16:51:57 +0200 Subject: Lowercase drive letters on windows before sending to extension. --- editors/code/src/notifications/publish_decorations.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'editors/code/src') diff --git a/editors/code/src/notifications/publish_decorations.ts b/editors/code/src/notifications/publish_decorations.ts index 120eabbc6..4441e2b28 100644 --- a/editors/code/src/notifications/publish_decorations.ts +++ b/editors/code/src/notifications/publish_decorations.ts @@ -15,8 +15,7 @@ export function handle(params: PublishDecorationsParams) { // Unescaped URI should be something like: // file:///c:/Workspace/ra-test/src/main.rs // RA server might send it with the drive letter uppercased, so we force only the drive letter to lowercase. - const uriWithLowercasedDrive = params.uri.substr(0, 8) + params.uri[8].toLowerCase() + params.uri.substr(9); - return unescapedUri === uriWithLowercasedDrive + return unescapedUri === params.uri } ); -- cgit v1.2.3 From 498a7912e923ad8ce349f6874568373f430e9602 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Sun, 15 Dec 2019 16:55:39 +0200 Subject: fixed comment --- editors/code/src/notifications/publish_decorations.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'editors/code/src') diff --git a/editors/code/src/notifications/publish_decorations.ts b/editors/code/src/notifications/publish_decorations.ts index 4441e2b28..2ccd2d585 100644 --- a/editors/code/src/notifications/publish_decorations.ts +++ b/editors/code/src/notifications/publish_decorations.ts @@ -12,9 +12,8 @@ export function handle(params: PublishDecorationsParams) { const targetEditor = vscode.window.visibleTextEditors.find( editor => { const unescapedUri = unescape(editor.document.uri.toString()); - // Unescaped URI should be something like: + // Unescaped URI looks like: // file:///c:/Workspace/ra-test/src/main.rs - // RA server might send it with the drive letter uppercased, so we force only the drive letter to lowercase. return unescapedUri === params.uri } ); -- cgit v1.2.3 From 75353753cdcb993c277ce1d8bb366c708eabe2c6 Mon Sep 17 00:00:00 2001 From: Omer Ben-Amram Date: Sun, 15 Dec 2019 17:10:39 +0200 Subject: `npm run fix` --- editors/code/src/notifications/publish_decorations.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'editors/code/src') diff --git a/editors/code/src/notifications/publish_decorations.ts b/editors/code/src/notifications/publish_decorations.ts index 2ccd2d585..f23e286ad 100644 --- a/editors/code/src/notifications/publish_decorations.ts +++ b/editors/code/src/notifications/publish_decorations.ts @@ -9,14 +9,12 @@ export interface PublishDecorationsParams { } export function handle(params: PublishDecorationsParams) { - const targetEditor = vscode.window.visibleTextEditors.find( - editor => { - const unescapedUri = unescape(editor.document.uri.toString()); - // Unescaped URI looks like: - // file:///c:/Workspace/ra-test/src/main.rs - return unescapedUri === params.uri - } - ); + const targetEditor = vscode.window.visibleTextEditors.find(editor => { + const unescapedUri = unescape(editor.document.uri.toString()); + // Unescaped URI looks like: + // file:///c:/Workspace/ra-test/src/main.rs + return unescapedUri === params.uri; + }); if (!Server.config.highlightingOn || !targetEditor) { return; -- cgit v1.2.3 From a85cd6455a66ca75ba9991d91acf36f55cb74e8c Mon Sep 17 00:00:00 2001 From: Vadzim Dambrouski Date: Sun, 15 Dec 2019 23:02:13 +0530 Subject: Add option to disable all-targets. Can be useful in embedded. --- editors/code/src/commands/cargo_watch.ts | 5 ++++- editors/code/src/config.ts | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) (limited to 'editors/code/src') diff --git a/editors/code/src/commands/cargo_watch.ts b/editors/code/src/commands/cargo_watch.ts index 512362eb1..45f1dd49f 100644 --- a/editors/code/src/commands/cargo_watch.ts +++ b/editors/code/src/commands/cargo_watch.ts @@ -83,7 +83,10 @@ export class CargoWatchProvider implements vscode.Disposable { let args = Server.config.cargoWatchOptions.command + - ' --all-targets --message-format json'; + ' --message-format json'; + if (Server.config.cargoWatchOptions.allTargets) { + args += ' --all-targets'; + } if (Server.config.cargoWatchOptions.command.length > 0) { // Excape the double quote string: args += ' ' + Server.config.cargoWatchOptions.arguments; diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index defdfeb9c..a6e0f6454 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts @@ -13,6 +13,7 @@ export interface CargoWatchOptions { command: string; trace: CargoWatchTraceOptions; ignore: string[]; + allTargets: boolean; } export interface CargoFeatures { @@ -40,6 +41,7 @@ export class Config { arguments: '', command: '', ignore: [], + allTargets: true, }; public cargoFeatures: CargoFeatures = { noDefaultFeatures: false, @@ -132,6 +134,13 @@ export class Config { ); } + if (config.has('cargo-watch.allTargets')) { + this.cargoWatchOptions.allTargets = config.get( + 'cargo-watch.allTargets', + true, + ); + } + if (config.has('lruCapacity')) { this.lruCapacity = config.get('lruCapacity') as number; } -- cgit v1.2.3 From 22ae4cb90699d64b8bb455635bad7abb406bb39e Mon Sep 17 00:00:00 2001 From: Vadzim Dambrouski Date: Mon, 16 Dec 2019 09:01:38 +0530 Subject: Fix formatting --- editors/code/src/commands/cargo_watch.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'editors/code/src') diff --git a/editors/code/src/commands/cargo_watch.ts b/editors/code/src/commands/cargo_watch.ts index 45f1dd49f..748be535c 100644 --- a/editors/code/src/commands/cargo_watch.ts +++ b/editors/code/src/commands/cargo_watch.ts @@ -82,8 +82,7 @@ export class CargoWatchProvider implements vscode.Disposable { } let args = - Server.config.cargoWatchOptions.command + - ' --message-format json'; + Server.config.cargoWatchOptions.command + ' --message-format json'; if (Server.config.cargoWatchOptions.allTargets) { args += ' --all-targets'; } -- cgit v1.2.3 From 2432f278cb97701e1ca3750bc691ca9bd757892f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 17 Dec 2019 12:41:44 +0100 Subject: Default to client watching on VS Code --- editors/code/src/config.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'editors/code/src') diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index defdfeb9c..df15c8172 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts @@ -30,7 +30,7 @@ export class Config { public displayInlayHints = true; public maxInlayHintLength: null | number = null; public excludeGlobs = []; - public useClientWatching = false; + public useClientWatching = true; public featureFlags = {}; // for internal use public withSysroot: null | boolean = null; @@ -148,7 +148,7 @@ export class Config { this.excludeGlobs = config.get('excludeGlobs') || []; } if (config.has('useClientWatching')) { - this.useClientWatching = config.get('useClientWatching') || false; + this.useClientWatching = config.get('useClientWatching') || true; } if (config.has('featureFlags')) { this.featureFlags = config.get('featureFlags') || {}; -- cgit v1.2.3 From 1c8467e20aa8d481a4583a1c2cf40fad3d2ff53c Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 17 Dec 2019 14:43:37 +0100 Subject: Fix highlighting token names --- editors/code/src/highlighting.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'editors/code/src') diff --git a/editors/code/src/highlighting.ts b/editors/code/src/highlighting.ts index d7c0ae131..e1b0d13e7 100644 --- a/editors/code/src/highlighting.ts +++ b/editors/code/src/highlighting.ts @@ -52,12 +52,12 @@ export class Highlighter { decoration('function'), decoration('parameter'), decoration('constant'), - decoration('type'), - decoration('type.self'), + decoration('type.builtin'), decoration('type.generic'), - decoration('type.param'), decoration('type.lifetime'), - decoration('builtin'), + decoration('type.param'), + decoration('type.self'), + decoration('type'), decoration('text'), decoration('attribute'), decoration('literal'), -- cgit v1.2.3 From d2c1f8ee2606e10e196485d6bdbd87146d2545de Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Tue, 17 Dec 2019 13:50:00 +0800 Subject: Add macro span handling --- editors/code/src/utils/diagnostics/rust.ts | 38 ++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'editors/code/src') diff --git a/editors/code/src/utils/diagnostics/rust.ts b/editors/code/src/utils/diagnostics/rust.ts index b6efc0f56..1f0c0d3e4 100644 --- a/editors/code/src/utils/diagnostics/rust.ts +++ b/editors/code/src/utils/diagnostics/rust.ts @@ -10,6 +10,12 @@ export enum SuggestionApplicability { Unspecified = 'Unspecified', } +export interface RustDiagnosticSpanMacroExpansion { + span: RustDiagnosticSpan; + macro_decl_name: string; + def_site_span?: RustDiagnosticSpan; +} + // Reference: // https://github.com/rust-lang/rust/blob/master/src/libsyntax/json.rs export interface RustDiagnosticSpan { @@ -20,6 +26,7 @@ export interface RustDiagnosticSpan { is_primary: boolean; file_name: string; label?: string; + expansion?: RustDiagnosticSpanMacroExpansion; suggested_replacement?: string; suggestion_applicability?: SuggestionApplicability; } @@ -60,10 +67,41 @@ function mapLevelToSeverity(s: string): vscode.DiagnosticSeverity { return vscode.DiagnosticSeverity.Information; } +/** + * Check whether a file name is from macro invocation + */ +function isFromMacro(fileName: string): boolean { + return fileName.startsWith('<') && fileName.endsWith('>'); +} + +/** + * Converts a Rust macro span to a VsCode location recursively + */ +function mapMacroSpanToLocation( + spanMacro: RustDiagnosticSpanMacroExpansion, +): vscode.Location | undefined { + if (!isFromMacro(spanMacro.span.file_name)) { + return mapSpanToLocation(spanMacro.span); + } + + if (spanMacro.span.expansion) { + return mapMacroSpanToLocation(spanMacro.span.expansion); + } + + return; +} + /** * Converts a Rust span to a VsCode location */ function mapSpanToLocation(span: RustDiagnosticSpan): vscode.Location { + if (isFromMacro(span.file_name) && span.expansion) { + const macroLoc = mapMacroSpanToLocation(span.expansion); + if (macroLoc) { + return macroLoc; + } + } + const fileName = path.join(vscode.workspace.rootPath || '', span.file_name); const fileUri = vscode.Uri.file(fileName); -- cgit v1.2.3 From 63c59308e6ece788084374c4fc393576684992a7 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Tue, 17 Dec 2019 13:50:08 +0800 Subject: Add tests --- .../fixtures/rust-diagnostics/error/E0277.json | 261 +++++++++++++++++++++ .../code/src/test/utils/diagnotics/rust.test.ts | 34 +++ 2 files changed, 295 insertions(+) create mode 100644 editors/code/src/test/fixtures/rust-diagnostics/error/E0277.json (limited to 'editors/code/src') diff --git a/editors/code/src/test/fixtures/rust-diagnostics/error/E0277.json b/editors/code/src/test/fixtures/rust-diagnostics/error/E0277.json new file mode 100644 index 000000000..bfef33c7d --- /dev/null +++ b/editors/code/src/test/fixtures/rust-diagnostics/error/E0277.json @@ -0,0 +1,261 @@ +{ + "rendered": "error[E0277]: can't compare `{integer}` with `&str`\n --> src/main.rs:2:5\n |\n2 | assert_eq!(1, \"love\");\n | ^^^^^^^^^^^^^^^^^^^^^^ no implementation for `{integer} == &str`\n |\n = help: the trait `std::cmp::PartialEq<&str>` is not implemented for `{integer}`\n = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)\n\n", + "children": [ + { + "children": [], + "code": null, + "level": "help", + "message": "the trait `std::cmp::PartialEq<&str>` is not implemented for `{integer}`", + "rendered": null, + "spans": [] + } + ], + "code": { + "code": "E0277", + "explanation": "\nYou tried to use a type which doesn't implement some trait in a place which\nexpected that trait. Erroneous code example:\n\n```compile_fail,E0277\n// here we declare the Foo trait with a bar method\ntrait Foo {\n fn bar(&self);\n}\n\n// we now declare a function which takes an object implementing the Foo trait\nfn some_func(foo: T) {\n foo.bar();\n}\n\nfn main() {\n // we now call the method with the i32 type, which doesn't implement\n // the Foo trait\n some_func(5i32); // error: the trait bound `i32 : Foo` is not satisfied\n}\n```\n\nIn order to fix this error, verify that the type you're using does implement\nthe trait. Example:\n\n```\ntrait Foo {\n fn bar(&self);\n}\n\nfn some_func(foo: T) {\n foo.bar(); // we can now use this method since i32 implements the\n // Foo trait\n}\n\n// we implement the trait on the i32 type\nimpl Foo for i32 {\n fn bar(&self) {}\n}\n\nfn main() {\n some_func(5i32); // ok!\n}\n```\n\nOr in a generic context, an erroneous code example would look like:\n\n```compile_fail,E0277\nfn some_func(foo: T) {\n println!(\"{:?}\", foo); // error: the trait `core::fmt::Debug` is not\n // implemented for the type `T`\n}\n\nfn main() {\n // We now call the method with the i32 type,\n // which *does* implement the Debug trait.\n some_func(5i32);\n}\n```\n\nNote that the error here is in the definition of the generic function: Although\nwe only call it with a parameter that does implement `Debug`, the compiler\nstill rejects the function: It must work with all possible input types. In\norder to make this example compile, we need to restrict the generic type we're\naccepting:\n\n```\nuse std::fmt;\n\n// Restrict the input type to types that implement Debug.\nfn some_func(foo: T) {\n println!(\"{:?}\", foo);\n}\n\nfn main() {\n // Calling the method is still fine, as i32 implements Debug.\n some_func(5i32);\n\n // This would fail to compile now:\n // struct WithoutDebug;\n // some_func(WithoutDebug);\n}\n```\n\nRust only looks at the signature of the called function, as such it must\nalready specify all requirements that will be used for every type parameter.\n" + }, + "level": "error", + "message": "can't compare `{integer}` with `&str`", + "spans": [ + { + "byte_end": 155, + "byte_start": 153, + "column_end": 33, + "column_start": 31, + "expansion": { + "def_site_span": { + "byte_end": 940, + "byte_start": 0, + "column_end": 6, + "column_start": 1, + "expansion": null, + "file_name": "<::core::macros::assert_eq macros>", + "is_primary": false, + "label": null, + "line_end": 36, + "line_start": 1, + "suggested_replacement": null, + "suggestion_applicability": null, + "text": [ + { + "highlight_end": 35, + "highlight_start": 1, + "text": "($ left : expr, $ right : expr) =>" + }, + { + "highlight_end": 3, + "highlight_start": 1, + "text": "({" + }, + { + "highlight_end": 33, + "highlight_start": 1, + "text": " match (& $ left, & $ right)" + }, + { + "highlight_end": 7, + "highlight_start": 1, + "text": " {" + }, + { + "highlight_end": 34, + "highlight_start": 1, + "text": " (left_val, right_val) =>" + }, + { + "highlight_end": 11, + "highlight_start": 1, + "text": " {" + }, + { + "highlight_end": 46, + "highlight_start": 1, + "text": " if ! (* left_val == * right_val)" + }, + { + "highlight_end": 15, + "highlight_start": 1, + "text": " {" + }, + { + "highlight_end": 25, + "highlight_start": 1, + "text": " panic !" + }, + { + "highlight_end": 57, + "highlight_start": 1, + "text": " (r#\"assertion failed: `(left == right)`" + }, + { + "highlight_end": 16, + "highlight_start": 1, + "text": " left: `{:?}`," + }, + { + "highlight_end": 18, + "highlight_start": 1, + "text": " right: `{:?}`\"#," + }, + { + "highlight_end": 47, + "highlight_start": 1, + "text": " & * left_val, & * right_val)" + }, + { + "highlight_end": 15, + "highlight_start": 1, + "text": " }" + }, + { + "highlight_end": 11, + "highlight_start": 1, + "text": " }" + }, + { + "highlight_end": 7, + "highlight_start": 1, + "text": " }" + }, + { + "highlight_end": 42, + "highlight_start": 1, + "text": " }) ; ($ left : expr, $ right : expr,) =>" + }, + { + "highlight_end": 49, + "highlight_start": 1, + "text": "({ $ crate :: assert_eq ! ($ left, $ right) }) ;" + }, + { + "highlight_end": 53, + "highlight_start": 1, + "text": "($ left : expr, $ right : expr, $ ($ arg : tt) +) =>" + }, + { + "highlight_end": 3, + "highlight_start": 1, + "text": "({" + }, + { + "highlight_end": 37, + "highlight_start": 1, + "text": " match (& ($ left), & ($ right))" + }, + { + "highlight_end": 7, + "highlight_start": 1, + "text": " {" + }, + { + "highlight_end": 34, + "highlight_start": 1, + "text": " (left_val, right_val) =>" + }, + { + "highlight_end": 11, + "highlight_start": 1, + "text": " {" + }, + { + "highlight_end": 46, + "highlight_start": 1, + "text": " if ! (* left_val == * right_val)" + }, + { + "highlight_end": 15, + "highlight_start": 1, + "text": " {" + }, + { + "highlight_end": 25, + "highlight_start": 1, + "text": " panic !" + }, + { + "highlight_end": 57, + "highlight_start": 1, + "text": " (r#\"assertion failed: `(left == right)`" + }, + { + "highlight_end": 16, + "highlight_start": 1, + "text": " left: `{:?}`," + }, + { + "highlight_end": 22, + "highlight_start": 1, + "text": " right: `{:?}`: {}\"#," + }, + { + "highlight_end": 72, + "highlight_start": 1, + "text": " & * left_val, & * right_val, $ crate :: format_args !" + }, + { + "highlight_end": 33, + "highlight_start": 1, + "text": " ($ ($ arg) +))" + }, + { + "highlight_end": 15, + "highlight_start": 1, + "text": " }" + }, + { + "highlight_end": 11, + "highlight_start": 1, + "text": " }" + }, + { + "highlight_end": 7, + "highlight_start": 1, + "text": " }" + }, + { + "highlight_end": 6, + "highlight_start": 1, + "text": " }) ;" + } + ] + }, + "macro_decl_name": "assert_eq!", + "span": { + "byte_end": 38, + "byte_start": 16, + "column_end": 27, + "column_start": 5, + "expansion": null, + "file_name": "src/main.rs", + "is_primary": false, + "label": null, + "line_end": 2, + "line_start": 2, + "suggested_replacement": null, + "suggestion_applicability": null, + "text": [ + { + "highlight_end": 27, + "highlight_start": 5, + "text": " assert_eq!(1, \"love\");" + } + ] + } + }, + "file_name": "<::core::macros::assert_eq macros>", + "is_primary": true, + "label": "no implementation for `{integer} == &str`", + "line_end": 7, + "line_start": 7, + "suggested_replacement": null, + "suggestion_applicability": null, + "text": [ + { + "highlight_end": 33, + "highlight_start": 31, + "text": " if ! (* left_val == * right_val)" + } + ] + } + ] +} diff --git a/editors/code/src/test/utils/diagnotics/rust.test.ts b/editors/code/src/test/utils/diagnotics/rust.test.ts index 0222dbbaa..9acd319b3 100644 --- a/editors/code/src/test/utils/diagnotics/rust.test.ts +++ b/editors/code/src/test/utils/diagnotics/rust.test.ts @@ -199,4 +199,38 @@ describe('mapRustDiagnosticToVsCode', () => { // There are no suggested fixes assert.strictEqual(suggestedFixes.length, 0); }); + + it('should map a macro invocation location to normal file path', () => { + const { location, diagnostic, suggestedFixes } = mapFixtureToVsCode( + 'error/E0277', + ); + + assert.strictEqual( + diagnostic.severity, + vscode.DiagnosticSeverity.Error, + ); + assert.strictEqual( + diagnostic.message, + [ + 'can\'t compare `{integer}` with `&str`', + 'the trait `std::cmp::PartialEq<&str>` is not implemented for `{integer}`', + ].join('\n'), + ); + assert.strictEqual(diagnostic.code, 'E0277'); + assert.strictEqual(diagnostic.source, 'rustc'); + assert.deepStrictEqual(diagnostic.tags, []); + + // No related information + assert.deepStrictEqual(diagnostic.relatedInformation, []); + + // There are no suggested fixes + assert.strictEqual(suggestedFixes.length, 0); + + // The file url should be normal file + // Ignore the first part because it depends on vs workspace location + assert.strictEqual( + true, + location.uri.toString().endsWith('src/main.rs'), + ); + }); }); -- cgit v1.2.3 From bb9c60d90863b21a0e981f00e354d02b0e9fb584 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Tue, 17 Dec 2019 21:43:19 +0800 Subject: Use substr instead of endswith --- editors/code/src/test/utils/diagnotics/rust.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'editors/code/src') diff --git a/editors/code/src/test/utils/diagnotics/rust.test.ts b/editors/code/src/test/utils/diagnotics/rust.test.ts index 9acd319b3..358325cc8 100644 --- a/editors/code/src/test/utils/diagnotics/rust.test.ts +++ b/editors/code/src/test/utils/diagnotics/rust.test.ts @@ -212,7 +212,7 @@ describe('mapRustDiagnosticToVsCode', () => { assert.strictEqual( diagnostic.message, [ - 'can\'t compare `{integer}` with `&str`', + "can't compare `{integer}` with `&str`", 'the trait `std::cmp::PartialEq<&str>` is not implemented for `{integer}`', ].join('\n'), ); @@ -229,8 +229,8 @@ describe('mapRustDiagnosticToVsCode', () => { // The file url should be normal file // Ignore the first part because it depends on vs workspace location assert.strictEqual( - true, - location.uri.toString().endsWith('src/main.rs'), + location.uri.path.substr(-'src/main.rs'.length), + 'src/main.rs', ); }); }); -- cgit v1.2.3 From 6049f60a052b4097ab45a631480f8207ac5f6009 Mon Sep 17 00:00:00 2001 From: kjeremy Date: Fri, 20 Dec 2019 13:52:34 -0500 Subject: Protect against null as revealed by `npm test` --- editors/code/src/commands/cargo_watch.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'editors/code/src') diff --git a/editors/code/src/commands/cargo_watch.ts b/editors/code/src/commands/cargo_watch.ts index 748be535c..ac62bdd48 100644 --- a/editors/code/src/commands/cargo_watch.ts +++ b/editors/code/src/commands/cargo_watch.ts @@ -111,8 +111,13 @@ export class CargoWatchProvider implements vscode.Disposable { }, ); + if (!this.cargoProcess) { + vscode.window.showErrorMessage('Cargo Watch failed to start'); + return; + } + const stdoutData = new LineBuffer(); - this.cargoProcess.stdout.on('data', (s: string) => { + this.cargoProcess.stdout?.on('data', (s: string) => { stdoutData.processOutput(s, line => { this.logInfo(line); try { @@ -124,7 +129,7 @@ export class CargoWatchProvider implements vscode.Disposable { }); const stderrData = new LineBuffer(); - this.cargoProcess.stderr.on('data', (s: string) => { + this.cargoProcess.stderr?.on('data', (s: string) => { stderrData.processOutput(s, line => { this.logError('Error on cargo-watch : {\n' + line + '}\n'); }); -- cgit v1.2.3