mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-15 14:43:58 +00:00
Merge #2514
2514: Code: enable prettier trailing commas r=matklad a=lnicola See #2512. Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
This commit is contained in:
commit
e292573f42
31 changed files with 233 additions and 232 deletions
|
@ -27,8 +27,9 @@
|
||||||
"travis": "npm run compile && npm run test && npm run lint && npm run prettier -- --write && git diff --exit-code"
|
"travis": "npm run compile && npm run test && npm run lint && npm run prettier -- --write && git diff --exit-code"
|
||||||
},
|
},
|
||||||
"prettier": {
|
"prettier": {
|
||||||
|
"singleQuote": true,
|
||||||
"tabWidth": 4,
|
"tabWidth": 4,
|
||||||
"singleQuote": true
|
"trailingComma": "all"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"lookpath": "^1.0.3",
|
"lookpath": "^1.0.3",
|
||||||
|
|
|
@ -9,7 +9,7 @@ export class TextDocumentContentProvider
|
||||||
public syntaxTree: string = 'Not available';
|
public syntaxTree: string = 'Not available';
|
||||||
|
|
||||||
public provideTextDocumentContent(
|
public provideTextDocumentContent(
|
||||||
uri: vscode.Uri
|
uri: vscode.Uri,
|
||||||
): vscode.ProviderResult<string> {
|
): vscode.ProviderResult<string> {
|
||||||
const editor = vscode.window.activeTextEditor;
|
const editor = vscode.window.activeTextEditor;
|
||||||
if (editor == null) {
|
if (editor == null) {
|
||||||
|
@ -17,7 +17,7 @@ export class TextDocumentContentProvider
|
||||||
}
|
}
|
||||||
return Server.client.sendRequest<string>(
|
return Server.client.sendRequest<string>(
|
||||||
'rust-analyzer/analyzerStatus',
|
'rust-analyzer/analyzerStatus',
|
||||||
null
|
null,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,8 +35,8 @@ export function makeCommand(context: vscode.ExtensionContext) {
|
||||||
context.subscriptions.push(
|
context.subscriptions.push(
|
||||||
vscode.workspace.registerTextDocumentContentProvider(
|
vscode.workspace.registerTextDocumentContentProvider(
|
||||||
'rust-analyzer-status',
|
'rust-analyzer-status',
|
||||||
textDocumentContentProvider
|
textDocumentContentProvider,
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
context.subscriptions.push({
|
context.subscriptions.push({
|
||||||
|
@ -44,21 +44,21 @@ export function makeCommand(context: vscode.ExtensionContext) {
|
||||||
if (poller != null) {
|
if (poller != null) {
|
||||||
clearInterval(poller);
|
clearInterval(poller);
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return async function handle() {
|
return async function handle() {
|
||||||
if (poller == null) {
|
if (poller == null) {
|
||||||
poller = setInterval(
|
poller = setInterval(
|
||||||
() => textDocumentContentProvider.eventEmitter.fire(statusUri),
|
() => textDocumentContentProvider.eventEmitter.fire(statusUri),
|
||||||
1000
|
1000,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const document = await vscode.workspace.openTextDocument(statusUri);
|
const document = await vscode.workspace.openTextDocument(statusUri);
|
||||||
return vscode.window.showTextDocument(
|
return vscode.window.showTextDocument(
|
||||||
document,
|
document,
|
||||||
vscode.ViewColumn.Two,
|
vscode.ViewColumn.Two,
|
||||||
true
|
true,
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ export interface SourceChange {
|
||||||
|
|
||||||
export async function handle(change: SourceChange) {
|
export async function handle(change: SourceChange) {
|
||||||
const wsEdit = Server.client.protocol2CodeConverter.asWorkspaceEdit(
|
const wsEdit = Server.client.protocol2CodeConverter.asWorkspaceEdit(
|
||||||
change.workspaceEdit
|
change.workspaceEdit,
|
||||||
);
|
);
|
||||||
let created;
|
let created;
|
||||||
let moved;
|
let moved;
|
||||||
|
@ -33,10 +33,10 @@ export async function handle(change: SourceChange) {
|
||||||
await vscode.window.showTextDocument(doc);
|
await vscode.window.showTextDocument(doc);
|
||||||
} else if (toReveal) {
|
} else if (toReveal) {
|
||||||
const uri = Server.client.protocol2CodeConverter.asUri(
|
const uri = Server.client.protocol2CodeConverter.asUri(
|
||||||
toReveal.textDocument.uri
|
toReveal.textDocument.uri,
|
||||||
);
|
);
|
||||||
const position = Server.client.protocol2CodeConverter.asPosition(
|
const position = Server.client.protocol2CodeConverter.asPosition(
|
||||||
toReveal.position
|
toReveal.position,
|
||||||
);
|
);
|
||||||
const editor = vscode.window.activeTextEditor;
|
const editor = vscode.window.activeTextEditor;
|
||||||
if (!editor || editor.document.uri.toString() !== uri.toString()) {
|
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.selection = new vscode.Selection(position, position);
|
||||||
editor.revealRange(
|
editor.revealRange(
|
||||||
new vscode.Range(position, position),
|
new vscode.Range(position, position),
|
||||||
vscode.TextEditorRevealType.Default
|
vscode.TextEditorRevealType.Default,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,13 +9,13 @@ import { StatusDisplay } from './watch_status';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
mapRustDiagnosticToVsCode,
|
mapRustDiagnosticToVsCode,
|
||||||
RustDiagnostic
|
RustDiagnostic,
|
||||||
} from '../utils/diagnostics/rust';
|
} from '../utils/diagnostics/rust';
|
||||||
import SuggestedFixCollection from '../utils/diagnostics/SuggestedFixCollection';
|
import SuggestedFixCollection from '../utils/diagnostics/SuggestedFixCollection';
|
||||||
import { areDiagnosticsEqual } from '../utils/diagnostics/vscode';
|
import { areDiagnosticsEqual } from '../utils/diagnostics/vscode';
|
||||||
|
|
||||||
export async function registerCargoWatchProvider(
|
export async function registerCargoWatchProvider(
|
||||||
subscriptions: vscode.Disposable[]
|
subscriptions: vscode.Disposable[],
|
||||||
): Promise<CargoWatchProvider | undefined> {
|
): Promise<CargoWatchProvider | undefined> {
|
||||||
let cargoExists = false;
|
let cargoExists = false;
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ export async function registerCargoWatchProvider(
|
||||||
|
|
||||||
if (!cargoExists) {
|
if (!cargoExists) {
|
||||||
vscode.window.showErrorMessage(
|
vscode.window.showErrorMessage(
|
||||||
`Couldn\'t find \'Cargo.toml\' at ${cargoTomlPath}`
|
`Couldn\'t find \'Cargo.toml\' at ${cargoTomlPath}`,
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -52,13 +52,13 @@ export class CargoWatchProvider implements vscode.Disposable {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.diagnosticCollection = vscode.languages.createDiagnosticCollection(
|
this.diagnosticCollection = vscode.languages.createDiagnosticCollection(
|
||||||
'rustc'
|
'rustc',
|
||||||
);
|
);
|
||||||
this.statusDisplay = new StatusDisplay(
|
this.statusDisplay = new StatusDisplay(
|
||||||
Server.config.cargoWatchOptions.command
|
Server.config.cargoWatchOptions.command,
|
||||||
);
|
);
|
||||||
this.outputChannel = vscode.window.createOutputChannel(
|
this.outputChannel = vscode.window.createOutputChannel(
|
||||||
'Cargo Watch Trace'
|
'Cargo Watch Trace',
|
||||||
);
|
);
|
||||||
|
|
||||||
// Track `rustc`'s suggested fixes so we can convert them to code actions
|
// 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,
|
this.suggestedFixCollection,
|
||||||
{
|
{
|
||||||
providedCodeActionKinds:
|
providedCodeActionKinds:
|
||||||
SuggestedFixCollection.PROVIDED_CODE_ACTION_KINDS
|
SuggestedFixCollection.PROVIDED_CODE_ACTION_KINDS,
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public start() {
|
public start() {
|
||||||
if (this.cargoProcess) {
|
if (this.cargoProcess) {
|
||||||
vscode.window.showInformationMessage(
|
vscode.window.showInformationMessage(
|
||||||
'Cargo Watch is already running'
|
'Cargo Watch is already running',
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ export class CargoWatchProvider implements vscode.Disposable {
|
||||||
|
|
||||||
const ignoreFlags = Server.config.cargoWatchOptions.ignore.reduce(
|
const ignoreFlags = Server.config.cargoWatchOptions.ignore.reduce(
|
||||||
(flags, pattern) => [...flags, '--ignore', pattern],
|
(flags, pattern) => [...flags, '--ignore', pattern],
|
||||||
[] as string[]
|
[] as string[],
|
||||||
);
|
);
|
||||||
|
|
||||||
// Start the cargo watch with json message
|
// Start the cargo watch with json message
|
||||||
|
@ -105,8 +105,8 @@ export class CargoWatchProvider implements vscode.Disposable {
|
||||||
{
|
{
|
||||||
stdio: ['ignore', 'pipe', 'pipe'],
|
stdio: ['ignore', 'pipe', 'pipe'],
|
||||||
cwd: vscode.workspace.rootPath,
|
cwd: vscode.workspace.rootPath,
|
||||||
windowsVerbatimArguments: true
|
windowsVerbatimArguments: true,
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const stdoutData = new LineBuffer();
|
const stdoutData = new LineBuffer();
|
||||||
|
@ -130,7 +130,7 @@ export class CargoWatchProvider implements vscode.Disposable {
|
||||||
|
|
||||||
this.cargoProcess.on('error', (err: Error) => {
|
this.cargoProcess.on('error', (err: Error) => {
|
||||||
this.logError(
|
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 fileUri = location.uri;
|
||||||
|
|
||||||
const diagnostics: vscode.Diagnostic[] = [
|
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
|
// If we're building multiple targets it's possible we've already seen this diagnostic
|
||||||
const isDuplicate = diagnostics.some(d =>
|
const isDuplicate = diagnostics.some(d =>
|
||||||
areDiagnosticsEqual(d, diagnostic)
|
areDiagnosticsEqual(d, diagnostic),
|
||||||
);
|
);
|
||||||
if (isDuplicate) {
|
if (isDuplicate) {
|
||||||
return;
|
return;
|
||||||
|
@ -241,7 +241,7 @@ export class CargoWatchProvider implements vscode.Disposable {
|
||||||
for (const suggestedFix of suggestedFixes) {
|
for (const suggestedFix of suggestedFixes) {
|
||||||
this.suggestedFixCollection.addSuggestedFixForDiagnostic(
|
this.suggestedFixCollection.addSuggestedFixForDiagnostic(
|
||||||
suggestedFix,
|
suggestedFix,
|
||||||
diagnostic
|
diagnostic,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -249,7 +249,7 @@ export class CargoWatchProvider implements vscode.Disposable {
|
||||||
vscode.commands.executeCommand(
|
vscode.commands.executeCommand(
|
||||||
'vscode.executeCodeActionProvider',
|
'vscode.executeCodeActionProvider',
|
||||||
fileUri,
|
fileUri,
|
||||||
diagnostic.range
|
diagnostic.range,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { Position, TextDocumentIdentifier } from 'vscode-languageclient';
|
||||||
import { Server } from '../server';
|
import { Server } from '../server';
|
||||||
|
|
||||||
export const expandMacroUri = vscode.Uri.parse(
|
export const expandMacroUri = vscode.Uri.parse(
|
||||||
'rust-analyzer://expandMacro/[EXPANSION].rs'
|
'rust-analyzer://expandMacro/[EXPANSION].rs',
|
||||||
);
|
);
|
||||||
|
|
||||||
export class ExpandMacroContentProvider
|
export class ExpandMacroContentProvider
|
||||||
|
@ -11,7 +11,7 @@ export class ExpandMacroContentProvider
|
||||||
public eventEmitter = new vscode.EventEmitter<vscode.Uri>();
|
public eventEmitter = new vscode.EventEmitter<vscode.Uri>();
|
||||||
|
|
||||||
public provideTextDocumentContent(
|
public provideTextDocumentContent(
|
||||||
uri: vscode.Uri
|
uri: vscode.Uri,
|
||||||
): vscode.ProviderResult<string> {
|
): vscode.ProviderResult<string> {
|
||||||
async function handle() {
|
async function handle() {
|
||||||
const editor = vscode.window.activeTextEditor;
|
const editor = vscode.window.activeTextEditor;
|
||||||
|
@ -22,11 +22,11 @@ export class ExpandMacroContentProvider
|
||||||
const position = editor.selection.active;
|
const position = editor.selection.active;
|
||||||
const request: MacroExpandParams = {
|
const request: MacroExpandParams = {
|
||||||
textDocument: { uri: editor.document.uri.toString() },
|
textDocument: { uri: editor.document.uri.toString() },
|
||||||
position
|
position,
|
||||||
};
|
};
|
||||||
const expanded = await Server.client.sendRequest<ExpandedMacro>(
|
const expanded = await Server.client.sendRequest<ExpandedMacro>(
|
||||||
'rust-analyzer/expandMacro',
|
'rust-analyzer/expandMacro',
|
||||||
request
|
request,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (expanded == null) {
|
if (expanded == null) {
|
||||||
|
@ -58,7 +58,7 @@ export function createHandle(provider: ExpandMacroContentProvider) {
|
||||||
return vscode.window.showTextDocument(
|
return vscode.window.showTextDocument(
|
||||||
document,
|
document,
|
||||||
vscode.ViewColumn.Two,
|
vscode.ViewColumn.Two,
|
||||||
true
|
true,
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,5 +19,5 @@ export {
|
||||||
runnables,
|
runnables,
|
||||||
syntaxTree,
|
syntaxTree,
|
||||||
onEnter,
|
onEnter,
|
||||||
inlayHints
|
inlayHints,
|
||||||
};
|
};
|
||||||
|
|
|
@ -15,8 +15,8 @@ interface InlayHint {
|
||||||
|
|
||||||
const typeHintDecorationType = vscode.window.createTextEditorDecorationType({
|
const typeHintDecorationType = vscode.window.createTextEditorDecorationType({
|
||||||
after: {
|
after: {
|
||||||
color: new vscode.ThemeColor('ralsp.inlayHint')
|
color: new vscode.ThemeColor('ralsp.inlayHint'),
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export class HintsUpdater {
|
export class HintsUpdater {
|
||||||
|
@ -26,13 +26,13 @@ export class HintsUpdater {
|
||||||
if (this.displayHints !== displayHints) {
|
if (this.displayHints !== displayHints) {
|
||||||
this.displayHints = displayHints;
|
this.displayHints = displayHints;
|
||||||
return this.refreshVisibleEditorsHints(
|
return this.refreshVisibleEditorsHints(
|
||||||
displayHints ? undefined : []
|
displayHints ? undefined : [],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async refreshHintsForVisibleEditors(
|
public async refreshHintsForVisibleEditors(
|
||||||
cause?: TextDocumentChangeEvent
|
cause?: TextDocumentChangeEvent,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
if (!this.displayHints) {
|
if (!this.displayHints) {
|
||||||
return;
|
return;
|
||||||
|
@ -48,21 +48,21 @@ export class HintsUpdater {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async refreshVisibleEditorsHints(
|
private async refreshVisibleEditorsHints(
|
||||||
newDecorations?: vscode.DecorationOptions[]
|
newDecorations?: vscode.DecorationOptions[],
|
||||||
) {
|
) {
|
||||||
const promises: Array<Promise<void>> = [];
|
const promises: Array<Promise<void>> = [];
|
||||||
|
|
||||||
for (const rustEditor of vscode.window.visibleTextEditors.filter(
|
for (const rustEditor of vscode.window.visibleTextEditors.filter(
|
||||||
editor => this.isRustDocument(editor.document)
|
editor => this.isRustDocument(editor.document),
|
||||||
)) {
|
)) {
|
||||||
if (newDecorations !== undefined) {
|
if (newDecorations !== undefined) {
|
||||||
promises.push(
|
promises.push(
|
||||||
Promise.resolve(
|
Promise.resolve(
|
||||||
rustEditor.setDecorations(
|
rustEditor.setDecorations(
|
||||||
typeHintDecorationType,
|
typeHintDecorationType,
|
||||||
newDecorations
|
newDecorations,
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
promises.push(this.updateDecorationsFromServer(rustEditor));
|
promises.push(this.updateDecorationsFromServer(rustEditor));
|
||||||
|
@ -79,7 +79,7 @@ export class HintsUpdater {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async updateDecorationsFromServer(
|
private async updateDecorationsFromServer(
|
||||||
editor: TextEditor
|
editor: TextEditor,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const newHints = await this.queryHints(editor.document.uri.toString());
|
const newHints = await this.queryHints(editor.document.uri.toString());
|
||||||
if (newHints !== null) {
|
if (newHints !== null) {
|
||||||
|
@ -87,20 +87,20 @@ export class HintsUpdater {
|
||||||
range: hint.range,
|
range: hint.range,
|
||||||
renderOptions: {
|
renderOptions: {
|
||||||
after: {
|
after: {
|
||||||
contentText: `: ${hint.label}`
|
contentText: `: ${hint.label}`,
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
}));
|
}));
|
||||||
return editor.setDecorations(
|
return editor.setDecorations(
|
||||||
typeHintDecorationType,
|
typeHintDecorationType,
|
||||||
newDecorations
|
newDecorations,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async queryHints(documentUri: string): Promise<InlayHint[] | null> {
|
private async queryHints(documentUri: string): Promise<InlayHint[] | null> {
|
||||||
const request: InlayHintsParams = {
|
const request: InlayHintsParams = {
|
||||||
textDocument: { uri: documentUri }
|
textDocument: { uri: documentUri },
|
||||||
};
|
};
|
||||||
const client = Server.client;
|
const client = Server.client;
|
||||||
return client
|
return client
|
||||||
|
@ -108,8 +108,8 @@ export class HintsUpdater {
|
||||||
.then(() =>
|
.then(() =>
|
||||||
client.sendRequest<InlayHint[] | null>(
|
client.sendRequest<InlayHint[] | null>(
|
||||||
'rust-analyzer/inlayHints',
|
'rust-analyzer/inlayHints',
|
||||||
request
|
request,
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { Range, TextDocumentIdentifier } from 'vscode-languageclient';
|
||||||
import { Server } from '../server';
|
import { Server } from '../server';
|
||||||
import {
|
import {
|
||||||
handle as applySourceChange,
|
handle as applySourceChange,
|
||||||
SourceChange
|
SourceChange,
|
||||||
} from './apply_source_change';
|
} from './apply_source_change';
|
||||||
|
|
||||||
interface JoinLinesParams {
|
interface JoinLinesParams {
|
||||||
|
@ -19,11 +19,11 @@ export async function handle() {
|
||||||
}
|
}
|
||||||
const request: JoinLinesParams = {
|
const request: JoinLinesParams = {
|
||||||
range: Server.client.code2ProtocolConverter.asRange(editor.selection),
|
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<SourceChange>(
|
const change = await Server.client.sendRequest<SourceChange>(
|
||||||
'rust-analyzer/joinLines',
|
'rust-analyzer/joinLines',
|
||||||
request
|
request,
|
||||||
);
|
);
|
||||||
await applySourceChange(change);
|
await applySourceChange(change);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,15 +17,15 @@ export async function handle() {
|
||||||
textDocument: { uri: editor.document.uri.toString() },
|
textDocument: { uri: editor.document.uri.toString() },
|
||||||
offsets: editor.selections.map(s => {
|
offsets: editor.selections.map(s => {
|
||||||
return Server.client.code2ProtocolConverter.asPosition(s.active);
|
return Server.client.code2ProtocolConverter.asPosition(s.active);
|
||||||
})
|
}),
|
||||||
};
|
};
|
||||||
const response = await Server.client.sendRequest<Position[]>(
|
const response = await Server.client.sendRequest<Position[]>(
|
||||||
'rust-analyzer/findMatchingBrace',
|
'rust-analyzer/findMatchingBrace',
|
||||||
request
|
request,
|
||||||
);
|
);
|
||||||
editor.selections = editor.selections.map((sel, idx) => {
|
editor.selections = editor.selections.map((sel, idx) => {
|
||||||
const active = Server.client.protocol2CodeConverter.asPosition(
|
const active = Server.client.protocol2CodeConverter.asPosition(
|
||||||
response[idx]
|
response[idx],
|
||||||
);
|
);
|
||||||
const anchor = sel.isEmpty ? active : sel.anchor;
|
const anchor = sel.isEmpty ? active : sel.anchor;
|
||||||
return new vscode.Selection(anchor, active);
|
return new vscode.Selection(anchor, active);
|
||||||
|
|
|
@ -3,7 +3,7 @@ import * as lc from 'vscode-languageclient';
|
||||||
import { Server } from '../server';
|
import { Server } from '../server';
|
||||||
import {
|
import {
|
||||||
handle as applySourceChange,
|
handle as applySourceChange,
|
||||||
SourceChange
|
SourceChange,
|
||||||
} from './apply_source_change';
|
} from './apply_source_change';
|
||||||
|
|
||||||
export async function handle(event: { text: string }): Promise<boolean> {
|
export async function handle(event: { text: string }): Promise<boolean> {
|
||||||
|
@ -18,12 +18,12 @@ export async function handle(event: { text: string }): Promise<boolean> {
|
||||||
const request: lc.TextDocumentPositionParams = {
|
const request: lc.TextDocumentPositionParams = {
|
||||||
textDocument: { uri: editor.document.uri.toString() },
|
textDocument: { uri: editor.document.uri.toString() },
|
||||||
position: Server.client.code2ProtocolConverter.asPosition(
|
position: Server.client.code2ProtocolConverter.asPosition(
|
||||||
editor.selection.active
|
editor.selection.active,
|
||||||
)
|
),
|
||||||
};
|
};
|
||||||
const change = await Server.client.sendRequest<undefined | SourceChange>(
|
const change = await Server.client.sendRequest<undefined | SourceChange>(
|
||||||
'rust-analyzer/onEnter',
|
'rust-analyzer/onEnter',
|
||||||
request
|
request,
|
||||||
);
|
);
|
||||||
if (!change) {
|
if (!change) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -11,12 +11,12 @@ export async function handle() {
|
||||||
const request: lc.TextDocumentPositionParams = {
|
const request: lc.TextDocumentPositionParams = {
|
||||||
textDocument: { uri: editor.document.uri.toString() },
|
textDocument: { uri: editor.document.uri.toString() },
|
||||||
position: Server.client.code2ProtocolConverter.asPosition(
|
position: Server.client.code2ProtocolConverter.asPosition(
|
||||||
editor.selection.active
|
editor.selection.active,
|
||||||
)
|
),
|
||||||
};
|
};
|
||||||
const response = await Server.client.sendRequest<lc.Location[]>(
|
const response = await Server.client.sendRequest<lc.Location[]>(
|
||||||
'rust-analyzer/parentModule',
|
'rust-analyzer/parentModule',
|
||||||
request
|
request,
|
||||||
);
|
);
|
||||||
const loc = response[0];
|
const loc = response[0];
|
||||||
if (loc == null) {
|
if (loc == null) {
|
||||||
|
|
|
@ -46,17 +46,17 @@ function createTask(spec: Runnable): vscode.Task {
|
||||||
label: spec.label,
|
label: spec.label,
|
||||||
command: spec.bin,
|
command: spec.bin,
|
||||||
args: spec.args,
|
args: spec.args,
|
||||||
env: spec.env
|
env: spec.env,
|
||||||
};
|
};
|
||||||
|
|
||||||
const execOption: vscode.ShellExecutionOptions = {
|
const execOption: vscode.ShellExecutionOptions = {
|
||||||
cwd: spec.cwd || '.',
|
cwd: spec.cwd || '.',
|
||||||
env: definition.env
|
env: definition.env,
|
||||||
};
|
};
|
||||||
const exec = new vscode.ShellExecution(
|
const exec = new vscode.ShellExecution(
|
||||||
definition.command,
|
definition.command,
|
||||||
definition.args,
|
definition.args,
|
||||||
execOption
|
execOption,
|
||||||
);
|
);
|
||||||
|
|
||||||
const f = vscode.workspace.workspaceFolders![0];
|
const f = vscode.workspace.workspaceFolders![0];
|
||||||
|
@ -66,7 +66,7 @@ function createTask(spec: Runnable): vscode.Task {
|
||||||
definition.label,
|
definition.label,
|
||||||
TASK_SOURCE,
|
TASK_SOURCE,
|
||||||
exec,
|
exec,
|
||||||
['$rustc']
|
['$rustc'],
|
||||||
);
|
);
|
||||||
t.presentationOptions.clear = true;
|
t.presentationOptions.clear = true;
|
||||||
return t;
|
return t;
|
||||||
|
@ -79,17 +79,17 @@ export async function handle() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const textDocument: lc.TextDocumentIdentifier = {
|
const textDocument: lc.TextDocumentIdentifier = {
|
||||||
uri: editor.document.uri.toString()
|
uri: editor.document.uri.toString(),
|
||||||
};
|
};
|
||||||
const params: RunnablesParams = {
|
const params: RunnablesParams = {
|
||||||
textDocument,
|
textDocument,
|
||||||
position: Server.client.code2ProtocolConverter.asPosition(
|
position: Server.client.code2ProtocolConverter.asPosition(
|
||||||
editor.selection.active
|
editor.selection.active,
|
||||||
)
|
),
|
||||||
};
|
};
|
||||||
const runnables = await Server.client.sendRequest<Runnable[]>(
|
const runnables = await Server.client.sendRequest<Runnable[]>(
|
||||||
'rust-analyzer/runnables',
|
'rust-analyzer/runnables',
|
||||||
params
|
params,
|
||||||
);
|
);
|
||||||
const items: RunnableQuickPick[] = [];
|
const items: RunnableQuickPick[] = [];
|
||||||
if (prevRunnable) {
|
if (prevRunnable) {
|
||||||
|
@ -124,7 +124,7 @@ export async function handleSingle(runnable: Runnable) {
|
||||||
task.presentationOptions = {
|
task.presentationOptions = {
|
||||||
reveal: vscode.TaskRevealKind.Always,
|
reveal: vscode.TaskRevealKind.Always,
|
||||||
panel: vscode.TaskPanelKind.Dedicated,
|
panel: vscode.TaskPanelKind.Dedicated,
|
||||||
clear: true
|
clear: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
return vscode.tasks.executeTask(task);
|
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.
|
* that, when accepted, allow us to `cargo install cargo-watch` and then run it.
|
||||||
*/
|
*/
|
||||||
export async function interactivelyStartCargoWatch(
|
export async function interactivelyStartCargoWatch(
|
||||||
context: vscode.ExtensionContext
|
context: vscode.ExtensionContext,
|
||||||
): Promise<CargoWatchProvider | undefined> {
|
): Promise<CargoWatchProvider | undefined> {
|
||||||
if (Server.config.cargoWatchOptions.enableOnStartup === 'disabled') {
|
if (Server.config.cargoWatchOptions.enableOnStartup === 'disabled') {
|
||||||
return;
|
return;
|
||||||
|
@ -146,7 +146,7 @@ export async function interactivelyStartCargoWatch(
|
||||||
const watch = await vscode.window.showInformationMessage(
|
const watch = await vscode.window.showInformationMessage(
|
||||||
'Start watching changes with cargo? (Executes `cargo watch`, provides inline diagnostics)',
|
'Start watching changes with cargo? (Executes `cargo watch`, provides inline diagnostics)',
|
||||||
'yes',
|
'yes',
|
||||||
'no'
|
'no',
|
||||||
);
|
);
|
||||||
if (watch !== 'yes') {
|
if (watch !== 'yes') {
|
||||||
return;
|
return;
|
||||||
|
@ -157,12 +157,12 @@ export async function interactivelyStartCargoWatch(
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function startCargoWatch(
|
export async function startCargoWatch(
|
||||||
context: vscode.ExtensionContext
|
context: vscode.ExtensionContext,
|
||||||
): Promise<CargoWatchProvider | undefined> {
|
): Promise<CargoWatchProvider | undefined> {
|
||||||
const execPromise = util.promisify(child_process.exec);
|
const execPromise = util.promisify(child_process.exec);
|
||||||
|
|
||||||
const { stderr, code = 0 } = await execPromise(
|
const { stderr, code = 0 } = await execPromise(
|
||||||
'cargo watch --version'
|
'cargo watch --version',
|
||||||
).catch(e => e);
|
).catch(e => e);
|
||||||
|
|
||||||
if (stderr.includes('no such subcommand: `watch`')) {
|
if (stderr.includes('no such subcommand: `watch`')) {
|
||||||
|
@ -171,7 +171,7 @@ export async function startCargoWatch(
|
||||||
const install = await vscode.window.showInformationMessage(
|
const install = await vscode.window.showInformationMessage(
|
||||||
msg,
|
msg,
|
||||||
'yes',
|
'yes',
|
||||||
'no'
|
'no',
|
||||||
);
|
);
|
||||||
if (install !== 'yes') {
|
if (install !== 'yes') {
|
||||||
return;
|
return;
|
||||||
|
@ -192,20 +192,20 @@ export async function startCargoWatch(
|
||||||
label,
|
label,
|
||||||
bin: 'cargo',
|
bin: 'cargo',
|
||||||
args: ['install', 'cargo-watch'],
|
args: ['install', 'cargo-watch'],
|
||||||
env: {}
|
env: {},
|
||||||
})
|
}),
|
||||||
);
|
);
|
||||||
await taskFinished;
|
await taskFinished;
|
||||||
const output = await execPromise('cargo watch --version').catch(e => e);
|
const output = await execPromise('cargo watch --version').catch(e => e);
|
||||||
if (output.stderr !== '') {
|
if (output.stderr !== '') {
|
||||||
vscode.window.showErrorMessage(
|
vscode.window.showErrorMessage(
|
||||||
`Couldn't install \`cargo-\`watch: ${output.stderr}`
|
`Couldn't install \`cargo-\`watch: ${output.stderr}`,
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (code !== 0) {
|
} else if (code !== 0) {
|
||||||
vscode.window.showErrorMessage(
|
vscode.window.showErrorMessage(
|
||||||
`\`cargo watch\` failed with ${code}: ${stderr}`
|
`\`cargo watch\` failed with ${code}: ${stderr}`,
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ export class SyntaxTreeContentProvider
|
||||||
public syntaxTree: string = 'Not available';
|
public syntaxTree: string = 'Not available';
|
||||||
|
|
||||||
public provideTextDocumentContent(
|
public provideTextDocumentContent(
|
||||||
uri: vscode.Uri
|
uri: vscode.Uri,
|
||||||
): vscode.ProviderResult<string> {
|
): vscode.ProviderResult<string> {
|
||||||
const editor = vscode.window.activeTextEditor;
|
const editor = vscode.window.activeTextEditor;
|
||||||
if (editor == null) {
|
if (editor == null) {
|
||||||
|
@ -25,17 +25,17 @@ export class SyntaxTreeContentProvider
|
||||||
range = editor.selection.isEmpty
|
range = editor.selection.isEmpty
|
||||||
? undefined
|
? undefined
|
||||||
: Server.client.code2ProtocolConverter.asRange(
|
: Server.client.code2ProtocolConverter.asRange(
|
||||||
editor.selection
|
editor.selection,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const request: SyntaxTreeParams = {
|
const request: SyntaxTreeParams = {
|
||||||
textDocument: { uri: editor.document.uri.toString() },
|
textDocument: { uri: editor.document.uri.toString() },
|
||||||
range
|
range,
|
||||||
};
|
};
|
||||||
return Server.client.sendRequest<SyntaxTreeResult>(
|
return Server.client.sendRequest<SyntaxTreeResult>(
|
||||||
'rust-analyzer/syntaxTree',
|
'rust-analyzer/syntaxTree',
|
||||||
request
|
request,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ export function createHandle(provider: SyntaxTreeContentProvider) {
|
||||||
return vscode.window.showTextDocument(
|
return vscode.window.showTextDocument(
|
||||||
document,
|
document,
|
||||||
vscode.ViewColumn.Two,
|
vscode.ViewColumn.Two,
|
||||||
true
|
true,
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ export class StatusDisplay implements vscode.Disposable {
|
||||||
constructor(command: string) {
|
constructor(command: string) {
|
||||||
this.statusBarItem = vscode.window.createStatusBarItem(
|
this.statusBarItem = vscode.window.createStatusBarItem(
|
||||||
vscode.StatusBarAlignment.Left,
|
vscode.StatusBarAlignment.Left,
|
||||||
10
|
10,
|
||||||
);
|
);
|
||||||
this.command = command;
|
this.command = command;
|
||||||
this.statusBarItem.hide();
|
this.statusBarItem.hide();
|
||||||
|
|
|
@ -33,14 +33,14 @@ export class Config {
|
||||||
trace: 'off',
|
trace: 'off',
|
||||||
arguments: '',
|
arguments: '',
|
||||||
command: '',
|
command: '',
|
||||||
ignore: []
|
ignore: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
private prevEnhancedTyping: null | boolean = null;
|
private prevEnhancedTyping: null | boolean = null;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
vscode.workspace.onDidChangeConfiguration(_ =>
|
vscode.workspace.onDidChangeConfiguration(_ =>
|
||||||
this.userConfigChanged()
|
this.userConfigChanged(),
|
||||||
);
|
);
|
||||||
this.userConfigChanged();
|
this.userConfigChanged();
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ export class Config {
|
||||||
|
|
||||||
if (config.has('rainbowHighlightingOn')) {
|
if (config.has('rainbowHighlightingOn')) {
|
||||||
this.rainbowHighlightingOn = config.get(
|
this.rainbowHighlightingOn = config.get(
|
||||||
'rainbowHighlightingOn'
|
'rainbowHighlightingOn',
|
||||||
) as boolean;
|
) as boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ export class Config {
|
||||||
|
|
||||||
if (config.has('enableEnhancedTyping')) {
|
if (config.has('enableEnhancedTyping')) {
|
||||||
this.enableEnhancedTyping = config.get(
|
this.enableEnhancedTyping = config.get(
|
||||||
'enableEnhancedTyping'
|
'enableEnhancedTyping',
|
||||||
) as boolean;
|
) as boolean;
|
||||||
|
|
||||||
if (this.prevEnhancedTyping === null) {
|
if (this.prevEnhancedTyping === null) {
|
||||||
|
@ -78,12 +78,12 @@ export class Config {
|
||||||
vscode.window
|
vscode.window
|
||||||
.showInformationMessage(
|
.showInformationMessage(
|
||||||
'Changing enhanced typing setting requires a reload',
|
'Changing enhanced typing setting requires a reload',
|
||||||
reloadAction
|
reloadAction,
|
||||||
)
|
)
|
||||||
.then(selectedAction => {
|
.then(selectedAction => {
|
||||||
if (selectedAction === reloadAction) {
|
if (selectedAction === reloadAction) {
|
||||||
vscode.commands.executeCommand(
|
vscode.commands.executeCommand(
|
||||||
'workbench.action.reloadWindow'
|
'workbench.action.reloadWindow',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -104,28 +104,28 @@ export class Config {
|
||||||
if (config.has('trace.cargo-watch')) {
|
if (config.has('trace.cargo-watch')) {
|
||||||
this.cargoWatchOptions.trace = config.get<CargoWatchTraceOptions>(
|
this.cargoWatchOptions.trace = config.get<CargoWatchTraceOptions>(
|
||||||
'trace.cargo-watch',
|
'trace.cargo-watch',
|
||||||
'off'
|
'off',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.has('cargo-watch.arguments')) {
|
if (config.has('cargo-watch.arguments')) {
|
||||||
this.cargoWatchOptions.arguments = config.get<string>(
|
this.cargoWatchOptions.arguments = config.get<string>(
|
||||||
'cargo-watch.arguments',
|
'cargo-watch.arguments',
|
||||||
''
|
'',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.has('cargo-watch.command')) {
|
if (config.has('cargo-watch.command')) {
|
||||||
this.cargoWatchOptions.command = config.get<string>(
|
this.cargoWatchOptions.command = config.get<string>(
|
||||||
'cargo-watch.command',
|
'cargo-watch.command',
|
||||||
''
|
'',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.has('cargo-watch.ignore')) {
|
if (config.has('cargo-watch.ignore')) {
|
||||||
this.cargoWatchOptions.ignore = config.get<string[]>(
|
this.cargoWatchOptions.ignore = config.get<string[]>(
|
||||||
'cargo-watch.ignore',
|
'cargo-watch.ignore',
|
||||||
[]
|
[],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ export class Config {
|
||||||
}
|
}
|
||||||
if (config.has('maxInlayHintLength')) {
|
if (config.has('maxInlayHintLength')) {
|
||||||
this.maxInlayHintLength = config.get(
|
this.maxInlayHintLength = config.get(
|
||||||
'maxInlayHintLength'
|
'maxInlayHintLength',
|
||||||
) as number;
|
) as number;
|
||||||
}
|
}
|
||||||
if (config.has('excludeGlobs')) {
|
if (config.has('excludeGlobs')) {
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { TextDocumentIdentifier } from 'vscode-languageclient';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
SyntaxTreeContentProvider,
|
SyntaxTreeContentProvider,
|
||||||
syntaxTreeUri
|
syntaxTreeUri,
|
||||||
} from '../commands/syntaxTree';
|
} from '../commands/syntaxTree';
|
||||||
import { Decoration } from '../highlighting';
|
import { Decoration } from '../highlighting';
|
||||||
import { Server } from '../server';
|
import { Server } from '../server';
|
||||||
|
@ -21,11 +21,11 @@ export function makeHandler(syntaxTreeProvider: SyntaxTreeContentProvider) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const params: TextDocumentIdentifier = {
|
const params: TextDocumentIdentifier = {
|
||||||
uri: editor.document.uri.toString()
|
uri: editor.document.uri.toString(),
|
||||||
};
|
};
|
||||||
const decorations = await Server.client.sendRequest<Decoration[]>(
|
const decorations = await Server.client.sendRequest<Decoration[]>(
|
||||||
'rust-analyzer/decorationsRequest',
|
'rust-analyzer/decorationsRequest',
|
||||||
params
|
params,
|
||||||
);
|
);
|
||||||
Server.highlighter.setHighlights(editor, decorations);
|
Server.highlighter.setHighlights(editor, decorations);
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,7 +2,7 @@ import * as vscode from 'vscode';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
SyntaxTreeContentProvider,
|
SyntaxTreeContentProvider,
|
||||||
syntaxTreeUri
|
syntaxTreeUri,
|
||||||
} from '../commands/syntaxTree';
|
} from '../commands/syntaxTree';
|
||||||
|
|
||||||
export function createHandler(syntaxTreeProvider: SyntaxTreeContentProvider) {
|
export function createHandler(syntaxTreeProvider: SyntaxTreeContentProvider) {
|
||||||
|
|
|
@ -7,7 +7,7 @@ import { ExpandMacroContentProvider } from './commands/expand_macro';
|
||||||
import { HintsUpdater } from './commands/inlay_hints';
|
import { HintsUpdater } from './commands/inlay_hints';
|
||||||
import {
|
import {
|
||||||
interactivelyStartCargoWatch,
|
interactivelyStartCargoWatch,
|
||||||
startCargoWatch
|
startCargoWatch,
|
||||||
} from './commands/runnables';
|
} from './commands/runnables';
|
||||||
import { SyntaxTreeContentProvider } from './commands/syntaxTree';
|
import { SyntaxTreeContentProvider } from './commands/syntaxTree';
|
||||||
import * as events from './events';
|
import * as events from './events';
|
||||||
|
@ -24,7 +24,7 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||||
}
|
}
|
||||||
function overrideCommand(
|
function overrideCommand(
|
||||||
name: string,
|
name: string,
|
||||||
f: (...args: any[]) => Promise<boolean>
|
f: (...args: any[]) => Promise<boolean>,
|
||||||
) {
|
) {
|
||||||
const defaultCmd = `default:${name}`;
|
const defaultCmd = `default:${name}`;
|
||||||
const original = (...args: any[]) =>
|
const original = (...args: any[]) =>
|
||||||
|
@ -46,7 +46,7 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||||
});
|
});
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
vscode.window.showWarningMessage(
|
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
|
// Commands are requests from vscode to the language server
|
||||||
registerCommand(
|
registerCommand(
|
||||||
'rust-analyzer.analyzerStatus',
|
'rust-analyzer.analyzerStatus',
|
||||||
commands.analyzerStatus.makeCommand(context)
|
commands.analyzerStatus.makeCommand(context),
|
||||||
);
|
);
|
||||||
registerCommand('rust-analyzer.collectGarbage', () =>
|
registerCommand('rust-analyzer.collectGarbage', () =>
|
||||||
Server.client.sendRequest<null>('rust-analyzer/collectGarbage', null)
|
Server.client.sendRequest<null>('rust-analyzer/collectGarbage', null),
|
||||||
);
|
);
|
||||||
registerCommand(
|
registerCommand(
|
||||||
'rust-analyzer.matchingBrace',
|
'rust-analyzer.matchingBrace',
|
||||||
commands.matchingBrace.handle
|
commands.matchingBrace.handle,
|
||||||
);
|
);
|
||||||
registerCommand('rust-analyzer.joinLines', commands.joinLines.handle);
|
registerCommand('rust-analyzer.joinLines', commands.joinLines.handle);
|
||||||
registerCommand('rust-analyzer.parentModule', commands.parentModule.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.runSingle', commands.runnables.handleSingle);
|
||||||
registerCommand(
|
registerCommand(
|
||||||
'rust-analyzer.applySourceChange',
|
'rust-analyzer.applySourceChange',
|
||||||
commands.applySourceChange.handle
|
commands.applySourceChange.handle,
|
||||||
);
|
);
|
||||||
registerCommand(
|
registerCommand(
|
||||||
'rust-analyzer.showReferences',
|
'rust-analyzer.showReferences',
|
||||||
|
@ -79,9 +79,9 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||||
'editor.action.showReferences',
|
'editor.action.showReferences',
|
||||||
vscode.Uri.parse(uri),
|
vscode.Uri.parse(uri),
|
||||||
Server.client.protocol2CodeConverter.asPosition(position),
|
Server.client.protocol2CodeConverter.asPosition(position),
|
||||||
locations.map(Server.client.protocol2CodeConverter.asLocation)
|
locations.map(Server.client.protocol2CodeConverter.asLocation),
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
if (Server.config.enableEnhancedTyping) {
|
if (Server.config.enableEnhancedTyping) {
|
||||||
|
@ -91,47 +91,47 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||||
// Notifications are events triggered by the language server
|
// Notifications are events triggered by the language server
|
||||||
const allNotifications: Iterable<[
|
const allNotifications: Iterable<[
|
||||||
string,
|
string,
|
||||||
lc.GenericNotificationHandler
|
lc.GenericNotificationHandler,
|
||||||
]> = [
|
]> = [
|
||||||
[
|
[
|
||||||
'rust-analyzer/publishDecorations',
|
'rust-analyzer/publishDecorations',
|
||||||
notifications.publishDecorations.handle
|
notifications.publishDecorations.handle,
|
||||||
]
|
],
|
||||||
];
|
];
|
||||||
const syntaxTreeContentProvider = new SyntaxTreeContentProvider();
|
const syntaxTreeContentProvider = new SyntaxTreeContentProvider();
|
||||||
const expandMacroContentProvider = new ExpandMacroContentProvider();
|
const expandMacroContentProvider = new ExpandMacroContentProvider();
|
||||||
|
|
||||||
// The events below are plain old javascript events, triggered and handled by vscode
|
// The events below are plain old javascript events, triggered and handled by vscode
|
||||||
vscode.window.onDidChangeActiveTextEditor(
|
vscode.window.onDidChangeActiveTextEditor(
|
||||||
events.changeActiveTextEditor.makeHandler(syntaxTreeContentProvider)
|
events.changeActiveTextEditor.makeHandler(syntaxTreeContentProvider),
|
||||||
);
|
);
|
||||||
|
|
||||||
disposeOnDeactivation(
|
disposeOnDeactivation(
|
||||||
vscode.workspace.registerTextDocumentContentProvider(
|
vscode.workspace.registerTextDocumentContentProvider(
|
||||||
'rust-analyzer',
|
'rust-analyzer',
|
||||||
syntaxTreeContentProvider
|
syntaxTreeContentProvider,
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
disposeOnDeactivation(
|
disposeOnDeactivation(
|
||||||
vscode.workspace.registerTextDocumentContentProvider(
|
vscode.workspace.registerTextDocumentContentProvider(
|
||||||
'rust-analyzer',
|
'rust-analyzer',
|
||||||
expandMacroContentProvider
|
expandMacroContentProvider,
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
registerCommand(
|
registerCommand(
|
||||||
'rust-analyzer.syntaxTree',
|
'rust-analyzer.syntaxTree',
|
||||||
commands.syntaxTree.createHandle(syntaxTreeContentProvider)
|
commands.syntaxTree.createHandle(syntaxTreeContentProvider),
|
||||||
);
|
);
|
||||||
registerCommand(
|
registerCommand(
|
||||||
'rust-analyzer.expandMacro',
|
'rust-analyzer.expandMacro',
|
||||||
commands.expandMacro.createHandle(expandMacroContentProvider)
|
commands.expandMacro.createHandle(expandMacroContentProvider),
|
||||||
);
|
);
|
||||||
|
|
||||||
vscode.workspace.onDidChangeTextDocument(
|
vscode.workspace.onDidChangeTextDocument(
|
||||||
events.changeTextDocument.createHandler(syntaxTreeContentProvider),
|
events.changeTextDocument.createHandler(syntaxTreeContentProvider),
|
||||||
null,
|
null,
|
||||||
context.subscriptions
|
context.subscriptions,
|
||||||
);
|
);
|
||||||
|
|
||||||
const startServer = () => Server.start(allNotifications);
|
const startServer = () => Server.start(allNotifications);
|
||||||
|
@ -178,25 +178,25 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||||
editorChangeDisposable.dispose();
|
editorChangeDisposable.dispose();
|
||||||
}
|
}
|
||||||
return hintsUpdater.refreshHintsForVisibleEditors();
|
return hintsUpdater.refreshHintsForVisibleEditors();
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
disposeOnDeactivation(
|
disposeOnDeactivation(
|
||||||
vscode.window.onDidChangeVisibleTextEditors(_ =>
|
vscode.window.onDidChangeVisibleTextEditors(_ =>
|
||||||
hintsUpdater.refreshHintsForVisibleEditors()
|
hintsUpdater.refreshHintsForVisibleEditors(),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
disposeOnDeactivation(
|
disposeOnDeactivation(
|
||||||
vscode.workspace.onDidChangeTextDocument(e =>
|
vscode.workspace.onDidChangeTextDocument(e =>
|
||||||
hintsUpdater.refreshHintsForVisibleEditors(e)
|
hintsUpdater.refreshHintsForVisibleEditors(e),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
disposeOnDeactivation(
|
disposeOnDeactivation(
|
||||||
vscode.workspace.onDidChangeConfiguration(_ =>
|
vscode.workspace.onDidChangeConfiguration(_ =>
|
||||||
hintsUpdater.toggleHintsDisplay(
|
hintsUpdater.toggleHintsDisplay(
|
||||||
Server.config.displayInlayHints
|
Server.config.displayInlayHints,
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,19 +30,19 @@ export class Highlighter {
|
||||||
> {
|
> {
|
||||||
const decoration = (
|
const decoration = (
|
||||||
tag: string,
|
tag: string,
|
||||||
textDecoration?: string
|
textDecoration?: string,
|
||||||
): [string, vscode.TextEditorDecorationType] => {
|
): [string, vscode.TextEditorDecorationType] => {
|
||||||
const color = new vscode.ThemeColor('ralsp.' + tag);
|
const color = new vscode.ThemeColor('ralsp.' + tag);
|
||||||
const decor = vscode.window.createTextEditorDecorationType({
|
const decor = vscode.window.createTextEditorDecorationType({
|
||||||
color,
|
color,
|
||||||
textDecoration
|
textDecoration,
|
||||||
});
|
});
|
||||||
return [tag, decor];
|
return [tag, decor];
|
||||||
};
|
};
|
||||||
|
|
||||||
const decorations: Iterable<[
|
const decorations: Iterable<[
|
||||||
string,
|
string,
|
||||||
vscode.TextEditorDecorationType
|
vscode.TextEditorDecorationType,
|
||||||
]> = [
|
]> = [
|
||||||
decoration('comment'),
|
decoration('comment'),
|
||||||
decoration('string'),
|
decoration('string'),
|
||||||
|
@ -61,7 +61,7 @@ export class Highlighter {
|
||||||
decoration('variable'),
|
decoration('variable'),
|
||||||
decoration('variable.mut', 'underline'),
|
decoration('variable.mut', 'underline'),
|
||||||
decoration('field'),
|
decoration('field'),
|
||||||
decoration('module')
|
decoration('module'),
|
||||||
];
|
];
|
||||||
|
|
||||||
return new Map<string, vscode.TextEditorDecorationType>(decorations);
|
return new Map<string, vscode.TextEditorDecorationType>(decorations);
|
||||||
|
@ -118,20 +118,20 @@ export class Highlighter {
|
||||||
colorfulIdents
|
colorfulIdents
|
||||||
.get(d.bindingHash)![0]
|
.get(d.bindingHash)![0]
|
||||||
.push(
|
.push(
|
||||||
Server.client.protocol2CodeConverter.asRange(d.range)
|
Server.client.protocol2CodeConverter.asRange(d.range),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
byTag
|
byTag
|
||||||
.get(d.tag)!
|
.get(d.tag)!
|
||||||
.push(
|
.push(
|
||||||
Server.client.protocol2CodeConverter.asRange(d.range)
|
Server.client.protocol2CodeConverter.asRange(d.range),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const tag of byTag.keys()) {
|
for (const tag of byTag.keys()) {
|
||||||
const dec = this.decorations.get(
|
const dec = this.decorations.get(
|
||||||
tag
|
tag,
|
||||||
) as vscode.TextEditorDecorationType;
|
) as vscode.TextEditorDecorationType;
|
||||||
const ranges = byTag.get(tag)!;
|
const ranges = byTag.get(tag)!;
|
||||||
editor.setDecorations(dec, ranges);
|
editor.setDecorations(dec, ranges);
|
||||||
|
@ -141,7 +141,7 @@ export class Highlighter {
|
||||||
const textDecoration = mut ? 'underline' : undefined;
|
const textDecoration = mut ? 'underline' : undefined;
|
||||||
const dec = vscode.window.createTextEditorDecorationType({
|
const dec = vscode.window.createTextEditorDecorationType({
|
||||||
light: { color: fancify(hash, 'light'), textDecoration },
|
light: { color: fancify(hash, 'light'), textDecoration },
|
||||||
dark: { color: fancify(hash, 'dark'), textDecoration }
|
dark: { color: fancify(hash, 'dark'), textDecoration },
|
||||||
});
|
});
|
||||||
editor.setDecorations(dec, ranges);
|
editor.setDecorations(dec, ranges);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ export interface PublishDecorationsParams {
|
||||||
|
|
||||||
export function handle(params: PublishDecorationsParams) {
|
export function handle(params: PublishDecorationsParams) {
|
||||||
const targetEditor = vscode.window.visibleTextEditors.find(
|
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) {
|
if (!Server.config.highlightingOn || !targetEditor) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -19,7 +19,7 @@ export class Server {
|
||||||
public static client: lc.LanguageClient;
|
public static client: lc.LanguageClient;
|
||||||
|
|
||||||
public static async start(
|
public static async start(
|
||||||
notificationHandlers: Iterable<[string, lc.GenericNotificationHandler]>
|
notificationHandlers: Iterable<[string, lc.GenericNotificationHandler]>,
|
||||||
) {
|
) {
|
||||||
// '.' Is the fallback if no folder is open
|
// '.' 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.
|
// 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 (platform() !== 'win32') {
|
||||||
if (!(await lookpath(command))) {
|
if (!(await lookpath(command))) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Cannot find rust-analyzer server \`${command}\` in PATH.`
|
`Cannot find rust-analyzer server \`${command}\` in PATH.`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const run: lc.Executable = {
|
const run: lc.Executable = {
|
||||||
command,
|
command,
|
||||||
options: { cwd: folder }
|
options: { cwd: folder },
|
||||||
};
|
};
|
||||||
const serverOptions: lc.ServerOptions = {
|
const serverOptions: lc.ServerOptions = {
|
||||||
run,
|
run,
|
||||||
debug: run
|
debug: run,
|
||||||
};
|
};
|
||||||
const traceOutputChannel = window.createOutputChannel(
|
const traceOutputChannel = window.createOutputChannel(
|
||||||
'Rust Analyzer Language Server Trace'
|
'Rust Analyzer Language Server Trace',
|
||||||
);
|
);
|
||||||
const clientOptions: lc.LanguageClientOptions = {
|
const clientOptions: lc.LanguageClientOptions = {
|
||||||
documentSelector: [{ scheme: 'file', language: 'rust' }],
|
documentSelector: [{ scheme: 'file', language: 'rust' }],
|
||||||
|
@ -58,16 +58,16 @@ export class Server {
|
||||||
excludeGlobs: Server.config.excludeGlobs,
|
excludeGlobs: Server.config.excludeGlobs,
|
||||||
useClientWatching: Server.config.useClientWatching,
|
useClientWatching: Server.config.useClientWatching,
|
||||||
featureFlags: Server.config.featureFlags,
|
featureFlags: Server.config.featureFlags,
|
||||||
withSysroot: Server.config.withSysroot
|
withSysroot: Server.config.withSysroot,
|
||||||
},
|
},
|
||||||
traceOutputChannel
|
traceOutputChannel,
|
||||||
};
|
};
|
||||||
|
|
||||||
Server.client = new lc.LanguageClient(
|
Server.client = new lc.LanguageClient(
|
||||||
'rust-analyzer',
|
'rust-analyzer',
|
||||||
'Rust Analyzer Language Server',
|
'Rust Analyzer Language Server',
|
||||||
serverOptions,
|
serverOptions,
|
||||||
clientOptions
|
clientOptions,
|
||||||
);
|
);
|
||||||
// HACK: This is an awful way of filtering out the decorations notifications
|
// HACK: This is an awful way of filtering out the decorations notifications
|
||||||
// However, pending proper support, this is the most effecitve approach
|
// However, pending proper support, this is the most effecitve approach
|
||||||
|
@ -80,10 +80,10 @@ export class Server {
|
||||||
if (typeof messageOrDataObject === 'string') {
|
if (typeof messageOrDataObject === 'string') {
|
||||||
if (
|
if (
|
||||||
messageOrDataObject.includes(
|
messageOrDataObject.includes(
|
||||||
'rust-analyzer/publishDecorations'
|
'rust-analyzer/publishDecorations',
|
||||||
) ||
|
) ||
|
||||||
messageOrDataObject.includes(
|
messageOrDataObject.includes(
|
||||||
'rust-analyzer/decorationsRequest'
|
'rust-analyzer/decorationsRequest',
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
// Don't log publish decorations requests
|
// Don't log publish decorations requests
|
||||||
|
@ -95,7 +95,7 @@ export class Server {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
Server.client.logObjectTrace(messageOrDataObject);
|
Server.client.logObjectTrace(messageOrDataObject);
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
Server.client.registerProposedFeatures();
|
Server.client.registerProposedFeatures();
|
||||||
Server.client.onReady().then(() => {
|
Server.client.onReady().then(() => {
|
||||||
|
|
|
@ -6,12 +6,12 @@ import SuggestedFix from '../../../utils/diagnostics/SuggestedFix';
|
||||||
|
|
||||||
const location1 = new vscode.Location(
|
const location1 = new vscode.Location(
|
||||||
vscode.Uri.file('/file/1'),
|
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(
|
const location2 = new vscode.Location(
|
||||||
vscode.Uri.file('/file/2'),
|
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', () => {
|
describe('SuggestedFix', () => {
|
||||||
|
@ -20,13 +20,13 @@ describe('SuggestedFix', () => {
|
||||||
const suggestion1 = new SuggestedFix(
|
const suggestion1 = new SuggestedFix(
|
||||||
'Replace me!',
|
'Replace me!',
|
||||||
location1,
|
location1,
|
||||||
'With this!'
|
'With this!',
|
||||||
);
|
);
|
||||||
|
|
||||||
const suggestion2 = new SuggestedFix(
|
const suggestion2 = new SuggestedFix(
|
||||||
'Replace me!',
|
'Replace me!',
|
||||||
location1,
|
location1,
|
||||||
'With this!'
|
'With this!',
|
||||||
);
|
);
|
||||||
|
|
||||||
assert(suggestion1.isEqual(suggestion2));
|
assert(suggestion1.isEqual(suggestion2));
|
||||||
|
@ -36,13 +36,13 @@ describe('SuggestedFix', () => {
|
||||||
const suggestion1 = new SuggestedFix(
|
const suggestion1 = new SuggestedFix(
|
||||||
'Replace me!',
|
'Replace me!',
|
||||||
location1,
|
location1,
|
||||||
'With this!'
|
'With this!',
|
||||||
);
|
);
|
||||||
|
|
||||||
const suggestion2 = new SuggestedFix(
|
const suggestion2 = new SuggestedFix(
|
||||||
'Not the same title!',
|
'Not the same title!',
|
||||||
location1,
|
location1,
|
||||||
'With this!'
|
'With this!',
|
||||||
);
|
);
|
||||||
|
|
||||||
assert(!suggestion1.isEqual(suggestion2));
|
assert(!suggestion1.isEqual(suggestion2));
|
||||||
|
@ -52,13 +52,13 @@ describe('SuggestedFix', () => {
|
||||||
const suggestion1 = new SuggestedFix(
|
const suggestion1 = new SuggestedFix(
|
||||||
'Replace me!',
|
'Replace me!',
|
||||||
location1,
|
location1,
|
||||||
'With this!'
|
'With this!',
|
||||||
);
|
);
|
||||||
|
|
||||||
const suggestion2 = new SuggestedFix(
|
const suggestion2 = new SuggestedFix(
|
||||||
'Replace me!',
|
'Replace me!',
|
||||||
location1,
|
location1,
|
||||||
'With something else!'
|
'With something else!',
|
||||||
);
|
);
|
||||||
|
|
||||||
assert(!suggestion1.isEqual(suggestion2));
|
assert(!suggestion1.isEqual(suggestion2));
|
||||||
|
@ -68,13 +68,13 @@ describe('SuggestedFix', () => {
|
||||||
const suggestion1 = new SuggestedFix(
|
const suggestion1 = new SuggestedFix(
|
||||||
'Replace me!',
|
'Replace me!',
|
||||||
location1,
|
location1,
|
||||||
'With this!'
|
'With this!',
|
||||||
);
|
);
|
||||||
|
|
||||||
const suggestion2 = new SuggestedFix(
|
const suggestion2 = new SuggestedFix(
|
||||||
'Replace me!',
|
'Replace me!',
|
||||||
location2,
|
location2,
|
||||||
'With this!'
|
'With this!',
|
||||||
);
|
);
|
||||||
|
|
||||||
assert(!suggestion1.isEqual(suggestion2));
|
assert(!suggestion1.isEqual(suggestion2));
|
||||||
|
@ -85,14 +85,14 @@ describe('SuggestedFix', () => {
|
||||||
'Replace me!',
|
'Replace me!',
|
||||||
location1,
|
location1,
|
||||||
'With this!',
|
'With this!',
|
||||||
SuggestionApplicability.MachineApplicable
|
SuggestionApplicability.MachineApplicable,
|
||||||
);
|
);
|
||||||
|
|
||||||
const suggestion2 = new SuggestedFix(
|
const suggestion2 = new SuggestedFix(
|
||||||
'Replace me!',
|
'Replace me!',
|
||||||
location2,
|
location2,
|
||||||
'With this!',
|
'With this!',
|
||||||
SuggestionApplicability.HasPlaceholders
|
SuggestionApplicability.HasPlaceholders,
|
||||||
);
|
);
|
||||||
|
|
||||||
assert(!suggestion1.isEqual(suggestion2));
|
assert(!suggestion1.isEqual(suggestion2));
|
||||||
|
@ -104,7 +104,7 @@ describe('SuggestedFix', () => {
|
||||||
const suggestion = new SuggestedFix(
|
const suggestion = new SuggestedFix(
|
||||||
'Replace me!',
|
'Replace me!',
|
||||||
location1,
|
location1,
|
||||||
'With this!'
|
'With this!',
|
||||||
);
|
);
|
||||||
|
|
||||||
const codeAction = suggestion.toCodeAction();
|
const codeAction = suggestion.toCodeAction();
|
||||||
|
|
|
@ -8,20 +8,20 @@ const uri1 = vscode.Uri.file('/file/1');
|
||||||
const uri2 = vscode.Uri.file('/file/2');
|
const uri2 = vscode.Uri.file('/file/2');
|
||||||
|
|
||||||
const mockDocument1 = ({
|
const mockDocument1 = ({
|
||||||
uri: uri1
|
uri: uri1,
|
||||||
} as unknown) as vscode.TextDocument;
|
} as unknown) as vscode.TextDocument;
|
||||||
|
|
||||||
const mockDocument2 = ({
|
const mockDocument2 = ({
|
||||||
uri: uri2
|
uri: uri2,
|
||||||
} as unknown) as vscode.TextDocument;
|
} as unknown) as vscode.TextDocument;
|
||||||
|
|
||||||
const range1 = new vscode.Range(
|
const range1 = new vscode.Range(
|
||||||
new vscode.Position(1, 2),
|
new vscode.Position(1, 2),
|
||||||
new vscode.Position(3, 4)
|
new vscode.Position(3, 4),
|
||||||
);
|
);
|
||||||
const range2 = new vscode.Range(
|
const range2 = new vscode.Range(
|
||||||
new vscode.Position(5, 6),
|
new vscode.Position(5, 6),
|
||||||
new vscode.Position(7, 8)
|
new vscode.Position(7, 8),
|
||||||
);
|
);
|
||||||
|
|
||||||
const diagnostic1 = new vscode.Diagnostic(range1, 'First diagnostic');
|
const diagnostic1 = new vscode.Diagnostic(range1, 'First diagnostic');
|
||||||
|
@ -32,7 +32,7 @@ function suggestion1(): SuggestedFix {
|
||||||
return new SuggestedFix(
|
return new SuggestedFix(
|
||||||
'Replace me!',
|
'Replace me!',
|
||||||
new vscode.Location(uri1, range1),
|
new vscode.Location(uri1, range1),
|
||||||
'With this!'
|
'With this!',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ describe('SuggestedFixCollection', () => {
|
||||||
// Specify the document and range that exactly matches
|
// Specify the document and range that exactly matches
|
||||||
const codeActions = suggestedFixes.provideCodeActions(
|
const codeActions = suggestedFixes.provideCodeActions(
|
||||||
mockDocument1,
|
mockDocument1,
|
||||||
range1
|
range1,
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.strictEqual(codeActions.length, 1);
|
assert.strictEqual(codeActions.length, 1);
|
||||||
|
@ -66,7 +66,7 @@ describe('SuggestedFixCollection', () => {
|
||||||
|
|
||||||
const codeActions = suggestedFixes.provideCodeActions(
|
const codeActions = suggestedFixes.provideCodeActions(
|
||||||
mockDocument1,
|
mockDocument1,
|
||||||
range2
|
range2,
|
||||||
);
|
);
|
||||||
|
|
||||||
assert(!codeActions || codeActions.length === 0);
|
assert(!codeActions || codeActions.length === 0);
|
||||||
|
@ -78,7 +78,7 @@ describe('SuggestedFixCollection', () => {
|
||||||
|
|
||||||
const codeActions = suggestedFixes.provideCodeActions(
|
const codeActions = suggestedFixes.provideCodeActions(
|
||||||
mockDocument2,
|
mockDocument2,
|
||||||
range1
|
range1,
|
||||||
);
|
);
|
||||||
|
|
||||||
assert(!codeActions || codeActions.length === 0);
|
assert(!codeActions || codeActions.length === 0);
|
||||||
|
@ -91,7 +91,7 @@ describe('SuggestedFixCollection', () => {
|
||||||
|
|
||||||
const codeActions = suggestedFixes.provideCodeActions(
|
const codeActions = suggestedFixes.provideCodeActions(
|
||||||
mockDocument1,
|
mockDocument1,
|
||||||
range1
|
range1,
|
||||||
);
|
);
|
||||||
|
|
||||||
assert(!codeActions || codeActions.length === 0);
|
assert(!codeActions || codeActions.length === 0);
|
||||||
|
@ -106,7 +106,7 @@ describe('SuggestedFixCollection', () => {
|
||||||
|
|
||||||
const codeActions = suggestedFixes.provideCodeActions(
|
const codeActions = suggestedFixes.provideCodeActions(
|
||||||
mockDocument1,
|
mockDocument1,
|
||||||
range1
|
range1,
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.strictEqual(codeActions.length, 1);
|
assert.strictEqual(codeActions.length, 1);
|
||||||
|
|
|
@ -6,14 +6,14 @@ import {
|
||||||
MappedRustDiagnostic,
|
MappedRustDiagnostic,
|
||||||
mapRustDiagnosticToVsCode,
|
mapRustDiagnosticToVsCode,
|
||||||
RustDiagnostic,
|
RustDiagnostic,
|
||||||
SuggestionApplicability
|
SuggestionApplicability,
|
||||||
} from '../../../utils/diagnostics/rust';
|
} from '../../../utils/diagnostics/rust';
|
||||||
|
|
||||||
function loadDiagnosticFixture(name: string): RustDiagnostic {
|
function loadDiagnosticFixture(name: string): RustDiagnostic {
|
||||||
const jsonText = fs
|
const jsonText = fs
|
||||||
.readFileSync(
|
.readFileSync(
|
||||||
// We're actually in our JavaScript output directory, climb out
|
// 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();
|
.toString();
|
||||||
|
|
||||||
|
@ -33,12 +33,12 @@ function mapFixtureToVsCode(name: string): MappedRustDiagnostic {
|
||||||
describe('mapRustDiagnosticToVsCode', () => {
|
describe('mapRustDiagnosticToVsCode', () => {
|
||||||
it('should map an incompatible type for trait error', () => {
|
it('should map an incompatible type for trait error', () => {
|
||||||
const { diagnostic, suggestedFixes } = mapFixtureToVsCode(
|
const { diagnostic, suggestedFixes } = mapFixtureToVsCode(
|
||||||
'error/E0053'
|
'error/E0053',
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
diagnostic.severity,
|
diagnostic.severity,
|
||||||
vscode.DiagnosticSeverity.Error
|
vscode.DiagnosticSeverity.Error,
|
||||||
);
|
);
|
||||||
assert.strictEqual(diagnostic.source, 'rustc');
|
assert.strictEqual(diagnostic.source, 'rustc');
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
|
@ -46,8 +46,8 @@ describe('mapRustDiagnosticToVsCode', () => {
|
||||||
[
|
[
|
||||||
`method \`next\` has an incompatible type for trait`,
|
`method \`next\` has an incompatible type for trait`,
|
||||||
`expected type \`fn(&mut ty::list_iter::ListIterator<'list, M>) -> std::option::Option<&ty::Ref<M>>\``,
|
`expected type \`fn(&mut ty::list_iter::ListIterator<'list, M>) -> std::option::Option<&ty::Ref<M>>\``,
|
||||||
` found type \`fn(&ty::list_iter::ListIterator<'list, M>) -> std::option::Option<&'list ty::Ref<M>>\``
|
` found type \`fn(&ty::list_iter::ListIterator<'list, M>) -> std::option::Option<&'list ty::Ref<M>>\``,
|
||||||
].join('\n')
|
].join('\n'),
|
||||||
);
|
);
|
||||||
assert.strictEqual(diagnostic.code, 'E0053');
|
assert.strictEqual(diagnostic.code, 'E0053');
|
||||||
assert.deepStrictEqual(diagnostic.tags, []);
|
assert.deepStrictEqual(diagnostic.tags, []);
|
||||||
|
@ -61,24 +61,24 @@ describe('mapRustDiagnosticToVsCode', () => {
|
||||||
|
|
||||||
it('should map an unused variable warning', () => {
|
it('should map an unused variable warning', () => {
|
||||||
const { diagnostic, suggestedFixes } = mapFixtureToVsCode(
|
const { diagnostic, suggestedFixes } = mapFixtureToVsCode(
|
||||||
'warning/unused_variables'
|
'warning/unused_variables',
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
diagnostic.severity,
|
diagnostic.severity,
|
||||||
vscode.DiagnosticSeverity.Warning
|
vscode.DiagnosticSeverity.Warning,
|
||||||
);
|
);
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
diagnostic.message,
|
diagnostic.message,
|
||||||
[
|
[
|
||||||
'unused variable: `foo`',
|
'unused variable: `foo`',
|
||||||
'#[warn(unused_variables)] on by default'
|
'#[warn(unused_variables)] on by default',
|
||||||
].join('\n')
|
].join('\n'),
|
||||||
);
|
);
|
||||||
assert.strictEqual(diagnostic.code, 'unused_variables');
|
assert.strictEqual(diagnostic.code, 'unused_variables');
|
||||||
assert.strictEqual(diagnostic.source, 'rustc');
|
assert.strictEqual(diagnostic.source, 'rustc');
|
||||||
assert.deepStrictEqual(diagnostic.tags, [
|
assert.deepStrictEqual(diagnostic.tags, [
|
||||||
vscode.DiagnosticTag.Unnecessary
|
vscode.DiagnosticTag.Unnecessary,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// No related information
|
// No related information
|
||||||
|
@ -89,29 +89,29 @@ describe('mapRustDiagnosticToVsCode', () => {
|
||||||
const [suggestedFix] = suggestedFixes;
|
const [suggestedFix] = suggestedFixes;
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
suggestedFix.title,
|
suggestedFix.title,
|
||||||
'consider prefixing with an underscore: `_foo`'
|
'consider prefixing with an underscore: `_foo`',
|
||||||
);
|
);
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
suggestedFix.applicability,
|
suggestedFix.applicability,
|
||||||
SuggestionApplicability.MachineApplicable
|
SuggestionApplicability.MachineApplicable,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should map a wrong number of parameters error', () => {
|
it('should map a wrong number of parameters error', () => {
|
||||||
const { diagnostic, suggestedFixes } = mapFixtureToVsCode(
|
const { diagnostic, suggestedFixes } = mapFixtureToVsCode(
|
||||||
'error/E0061'
|
'error/E0061',
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
diagnostic.severity,
|
diagnostic.severity,
|
||||||
vscode.DiagnosticSeverity.Error
|
vscode.DiagnosticSeverity.Error,
|
||||||
);
|
);
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
diagnostic.message,
|
diagnostic.message,
|
||||||
[
|
[
|
||||||
'this function takes 2 parameters but 3 parameters were supplied',
|
'this function takes 2 parameters but 3 parameters were supplied',
|
||||||
'expected 2 parameters'
|
'expected 2 parameters',
|
||||||
].join('\n')
|
].join('\n'),
|
||||||
);
|
);
|
||||||
assert.strictEqual(diagnostic.code, 'E0061');
|
assert.strictEqual(diagnostic.code, 'E0061');
|
||||||
assert.strictEqual(diagnostic.source, 'rustc');
|
assert.strictEqual(diagnostic.source, 'rustc');
|
||||||
|
@ -132,12 +132,12 @@ describe('mapRustDiagnosticToVsCode', () => {
|
||||||
|
|
||||||
it('should map a Clippy copy pass by ref warning', () => {
|
it('should map a Clippy copy pass by ref warning', () => {
|
||||||
const { diagnostic, suggestedFixes } = mapFixtureToVsCode(
|
const { diagnostic, suggestedFixes } = mapFixtureToVsCode(
|
||||||
'clippy/trivially_copy_pass_by_ref'
|
'clippy/trivially_copy_pass_by_ref',
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
diagnostic.severity,
|
diagnostic.severity,
|
||||||
vscode.DiagnosticSeverity.Warning
|
vscode.DiagnosticSeverity.Warning,
|
||||||
);
|
);
|
||||||
assert.strictEqual(diagnostic.source, 'clippy');
|
assert.strictEqual(diagnostic.source, 'clippy');
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
|
@ -145,8 +145,8 @@ describe('mapRustDiagnosticToVsCode', () => {
|
||||||
[
|
[
|
||||||
'this argument is passed by reference, but would be more efficient if passed by value',
|
'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)]',
|
'#[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'
|
'for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#trivially_copy_pass_by_ref',
|
||||||
].join('\n')
|
].join('\n'),
|
||||||
);
|
);
|
||||||
assert.strictEqual(diagnostic.code, 'trivially_copy_pass_by_ref');
|
assert.strictEqual(diagnostic.code, 'trivially_copy_pass_by_ref');
|
||||||
assert.deepStrictEqual(diagnostic.tags, []);
|
assert.deepStrictEqual(diagnostic.tags, []);
|
||||||
|
@ -165,27 +165,27 @@ describe('mapRustDiagnosticToVsCode', () => {
|
||||||
const [suggestedFix] = suggestedFixes;
|
const [suggestedFix] = suggestedFixes;
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
suggestedFix.title,
|
suggestedFix.title,
|
||||||
'consider passing by value instead: `self`'
|
'consider passing by value instead: `self`',
|
||||||
);
|
);
|
||||||
// Clippy does not mark this with any applicability
|
// Clippy does not mark this with any applicability
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
suggestedFix.applicability,
|
suggestedFix.applicability,
|
||||||
SuggestionApplicability.Unspecified
|
SuggestionApplicability.Unspecified,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should map a mismatched type error', () => {
|
it('should map a mismatched type error', () => {
|
||||||
const { diagnostic, suggestedFixes } = mapFixtureToVsCode(
|
const { diagnostic, suggestedFixes } = mapFixtureToVsCode(
|
||||||
'error/E0308'
|
'error/E0308',
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
diagnostic.severity,
|
diagnostic.severity,
|
||||||
vscode.DiagnosticSeverity.Error
|
vscode.DiagnosticSeverity.Error,
|
||||||
);
|
);
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
diagnostic.message,
|
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.code, 'E0308');
|
||||||
assert.strictEqual(diagnostic.source, 'rustc');
|
assert.strictEqual(diagnostic.source, 'rustc');
|
||||||
|
|
|
@ -5,12 +5,12 @@ import { areDiagnosticsEqual } from '../../../utils/diagnostics/vscode';
|
||||||
|
|
||||||
const range1 = new vscode.Range(
|
const range1 = new vscode.Range(
|
||||||
new vscode.Position(1, 2),
|
new vscode.Position(1, 2),
|
||||||
new vscode.Position(3, 4)
|
new vscode.Position(3, 4),
|
||||||
);
|
);
|
||||||
|
|
||||||
const range2 = new vscode.Range(
|
const range2 = new vscode.Range(
|
||||||
new vscode.Position(5, 6),
|
new vscode.Position(5, 6),
|
||||||
new vscode.Position(7, 8)
|
new vscode.Position(7, 8),
|
||||||
);
|
);
|
||||||
|
|
||||||
describe('areDiagnosticsEqual', () => {
|
describe('areDiagnosticsEqual', () => {
|
||||||
|
@ -18,13 +18,13 @@ describe('areDiagnosticsEqual', () => {
|
||||||
const diagnostic1 = new vscode.Diagnostic(
|
const diagnostic1 = new vscode.Diagnostic(
|
||||||
range1,
|
range1,
|
||||||
'Hello, world!',
|
'Hello, world!',
|
||||||
vscode.DiagnosticSeverity.Error
|
vscode.DiagnosticSeverity.Error,
|
||||||
);
|
);
|
||||||
|
|
||||||
const diagnostic2 = new vscode.Diagnostic(
|
const diagnostic2 = new vscode.Diagnostic(
|
||||||
range1,
|
range1,
|
||||||
'Hello, world!',
|
'Hello, world!',
|
||||||
vscode.DiagnosticSeverity.Error
|
vscode.DiagnosticSeverity.Error,
|
||||||
);
|
);
|
||||||
|
|
||||||
assert(areDiagnosticsEqual(diagnostic1, diagnostic2));
|
assert(areDiagnosticsEqual(diagnostic1, diagnostic2));
|
||||||
|
@ -34,14 +34,14 @@ describe('areDiagnosticsEqual', () => {
|
||||||
const diagnostic1 = new vscode.Diagnostic(
|
const diagnostic1 = new vscode.Diagnostic(
|
||||||
range1,
|
range1,
|
||||||
'Hello, world!',
|
'Hello, world!',
|
||||||
vscode.DiagnosticSeverity.Error
|
vscode.DiagnosticSeverity.Error,
|
||||||
);
|
);
|
||||||
diagnostic1.source = 'rustc';
|
diagnostic1.source = 'rustc';
|
||||||
|
|
||||||
const diagnostic2 = new vscode.Diagnostic(
|
const diagnostic2 = new vscode.Diagnostic(
|
||||||
range1,
|
range1,
|
||||||
'Hello, world!',
|
'Hello, world!',
|
||||||
vscode.DiagnosticSeverity.Error
|
vscode.DiagnosticSeverity.Error,
|
||||||
);
|
);
|
||||||
diagnostic2.source = 'clippy';
|
diagnostic2.source = 'clippy';
|
||||||
|
|
||||||
|
@ -52,13 +52,13 @@ describe('areDiagnosticsEqual', () => {
|
||||||
const diagnostic1 = new vscode.Diagnostic(
|
const diagnostic1 = new vscode.Diagnostic(
|
||||||
range1,
|
range1,
|
||||||
'Hello, world!',
|
'Hello, world!',
|
||||||
vscode.DiagnosticSeverity.Error
|
vscode.DiagnosticSeverity.Error,
|
||||||
);
|
);
|
||||||
|
|
||||||
const diagnostic2 = new vscode.Diagnostic(
|
const diagnostic2 = new vscode.Diagnostic(
|
||||||
range2,
|
range2,
|
||||||
'Hello, world!',
|
'Hello, world!',
|
||||||
vscode.DiagnosticSeverity.Error
|
vscode.DiagnosticSeverity.Error,
|
||||||
);
|
);
|
||||||
|
|
||||||
assert(!areDiagnosticsEqual(diagnostic1, diagnostic2));
|
assert(!areDiagnosticsEqual(diagnostic1, diagnostic2));
|
||||||
|
@ -68,13 +68,13 @@ describe('areDiagnosticsEqual', () => {
|
||||||
const diagnostic1 = new vscode.Diagnostic(
|
const diagnostic1 = new vscode.Diagnostic(
|
||||||
range1,
|
range1,
|
||||||
'Hello, world!',
|
'Hello, world!',
|
||||||
vscode.DiagnosticSeverity.Error
|
vscode.DiagnosticSeverity.Error,
|
||||||
);
|
);
|
||||||
|
|
||||||
const diagnostic2 = new vscode.Diagnostic(
|
const diagnostic2 = new vscode.Diagnostic(
|
||||||
range1,
|
range1,
|
||||||
'Goodbye!, world!',
|
'Goodbye!, world!',
|
||||||
vscode.DiagnosticSeverity.Error
|
vscode.DiagnosticSeverity.Error,
|
||||||
);
|
);
|
||||||
|
|
||||||
assert(!areDiagnosticsEqual(diagnostic1, diagnostic2));
|
assert(!areDiagnosticsEqual(diagnostic1, diagnostic2));
|
||||||
|
@ -84,13 +84,13 @@ describe('areDiagnosticsEqual', () => {
|
||||||
const diagnostic1 = new vscode.Diagnostic(
|
const diagnostic1 = new vscode.Diagnostic(
|
||||||
range1,
|
range1,
|
||||||
'Hello, world!',
|
'Hello, world!',
|
||||||
vscode.DiagnosticSeverity.Warning
|
vscode.DiagnosticSeverity.Warning,
|
||||||
);
|
);
|
||||||
|
|
||||||
const diagnostic2 = new vscode.Diagnostic(
|
const diagnostic2 = new vscode.Diagnostic(
|
||||||
range1,
|
range1,
|
||||||
'Hello, world!',
|
'Hello, world!',
|
||||||
vscode.DiagnosticSeverity.Error
|
vscode.DiagnosticSeverity.Error,
|
||||||
);
|
);
|
||||||
|
|
||||||
assert(!areDiagnosticsEqual(diagnostic1, diagnostic2));
|
assert(!areDiagnosticsEqual(diagnostic1, diagnostic2));
|
||||||
|
|
|
@ -17,7 +17,7 @@ import * as path from 'path';
|
||||||
export function run(): Promise<void> {
|
export function run(): Promise<void> {
|
||||||
// Create the mocha test
|
// Create the mocha test
|
||||||
const mocha = new Mocha({
|
const mocha = new Mocha({
|
||||||
ui: 'bdd'
|
ui: 'bdd',
|
||||||
});
|
});
|
||||||
mocha.useColors(true);
|
mocha.useColors(true);
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ export default class SuggestedFix {
|
||||||
title: string,
|
title: string,
|
||||||
location: vscode.Location,
|
location: vscode.Location,
|
||||||
replacement: string,
|
replacement: string,
|
||||||
applicability: SuggestionApplicability = SuggestionApplicability.Unspecified
|
applicability: SuggestionApplicability = SuggestionApplicability.Unspecified,
|
||||||
) {
|
) {
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.location = location;
|
this.location = location;
|
||||||
|
@ -51,7 +51,7 @@ export default class SuggestedFix {
|
||||||
public toCodeAction(): vscode.CodeAction {
|
public toCodeAction(): vscode.CodeAction {
|
||||||
const codeAction = new vscode.CodeAction(
|
const codeAction = new vscode.CodeAction(
|
||||||
this.title,
|
this.title,
|
||||||
vscode.CodeActionKind.QuickFix
|
vscode.CodeActionKind.QuickFix,
|
||||||
);
|
);
|
||||||
|
|
||||||
const edit = new vscode.WorkspaceEdit();
|
const edit = new vscode.WorkspaceEdit();
|
||||||
|
|
|
@ -38,13 +38,13 @@ export default class SuggestedFixCollection
|
||||||
*/
|
*/
|
||||||
public addSuggestedFixForDiagnostic(
|
public addSuggestedFixForDiagnostic(
|
||||||
suggestedFix: SuggestedFix,
|
suggestedFix: SuggestedFix,
|
||||||
diagnostic: vscode.Diagnostic
|
diagnostic: vscode.Diagnostic,
|
||||||
): void {
|
): void {
|
||||||
const fileUriString = suggestedFix.location.uri.toString();
|
const fileUriString = suggestedFix.location.uri.toString();
|
||||||
const fileSuggestions = this.suggestedFixes.get(fileUriString) || [];
|
const fileSuggestions = this.suggestedFixes.get(fileUriString) || [];
|
||||||
|
|
||||||
const existingSuggestion = fileSuggestions.find(s =>
|
const existingSuggestion = fileSuggestions.find(s =>
|
||||||
s.isEqual(suggestedFix)
|
s.isEqual(suggestedFix),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (existingSuggestion) {
|
if (existingSuggestion) {
|
||||||
|
@ -65,7 +65,7 @@ export default class SuggestedFixCollection
|
||||||
*/
|
*/
|
||||||
public provideCodeActions(
|
public provideCodeActions(
|
||||||
document: vscode.TextDocument,
|
document: vscode.TextDocument,
|
||||||
range: vscode.Range
|
range: vscode.Range,
|
||||||
): vscode.CodeAction[] {
|
): vscode.CodeAction[] {
|
||||||
const documentUriString = document.uri.toString();
|
const documentUriString = document.uri.toString();
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ export enum SuggestionApplicability {
|
||||||
MachineApplicable = 'MachineApplicable',
|
MachineApplicable = 'MachineApplicable',
|
||||||
HasPlaceholders = 'HasPlaceholders',
|
HasPlaceholders = 'HasPlaceholders',
|
||||||
MaybeIncorrect = 'MaybeIncorrect',
|
MaybeIncorrect = 'MaybeIncorrect',
|
||||||
Unspecified = 'Unspecified'
|
Unspecified = 'Unspecified',
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reference:
|
// Reference:
|
||||||
|
@ -69,7 +69,7 @@ function mapSpanToLocation(span: RustDiagnosticSpan): vscode.Location {
|
||||||
|
|
||||||
const range = new vscode.Range(
|
const range = new vscode.Range(
|
||||||
new vscode.Position(span.line_start - 1, span.column_start - 1),
|
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);
|
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`.
|
* If the span is unlabelled this will return `undefined`.
|
||||||
*/
|
*/
|
||||||
function mapSecondarySpanToRelated(
|
function mapSecondarySpanToRelated(
|
||||||
span: RustDiagnosticSpan
|
span: RustDiagnosticSpan,
|
||||||
): vscode.DiagnosticRelatedInformation | undefined {
|
): vscode.DiagnosticRelatedInformation | undefined {
|
||||||
if (!span.label) {
|
if (!span.label) {
|
||||||
// Nothing to label this with
|
// Nothing to label this with
|
||||||
|
@ -107,7 +107,7 @@ function isUnusedOrUnnecessary(rd: RustDiagnostic): boolean {
|
||||||
'unused_attributes',
|
'unused_attributes',
|
||||||
'unused_imports',
|
'unused_imports',
|
||||||
'unused_macros',
|
'unused_macros',
|
||||||
'unused_variables'
|
'unused_variables',
|
||||||
].includes(rd.code.code);
|
].includes(rd.code.code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,13 +157,13 @@ function mapRustChildDiagnostic(rd: RustDiagnostic): MappedRustChildDiagnostic {
|
||||||
title,
|
title,
|
||||||
location,
|
location,
|
||||||
span.suggested_replacement,
|
span.suggested_replacement,
|
||||||
span.suggestion_applicability
|
span.suggestion_applicability,
|
||||||
)
|
),
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
const related = new vscode.DiagnosticRelatedInformation(
|
const related = new vscode.DiagnosticRelatedInformation(
|
||||||
location,
|
location,
|
||||||
rd.message
|
rd.message,
|
||||||
);
|
);
|
||||||
|
|
||||||
return { related };
|
return { related };
|
||||||
|
@ -183,7 +183,7 @@ function mapRustChildDiagnostic(rd: RustDiagnostic): MappedRustChildDiagnostic {
|
||||||
* If the diagnostic has no primary span this will return `undefined`
|
* If the diagnostic has no primary span this will return `undefined`
|
||||||
*/
|
*/
|
||||||
export function mapRustDiagnosticToVsCode(
|
export function mapRustDiagnosticToVsCode(
|
||||||
rd: RustDiagnostic
|
rd: RustDiagnostic,
|
||||||
): MappedRustDiagnostic | undefined {
|
): MappedRustDiagnostic | undefined {
|
||||||
const primarySpan = rd.spans.find(s => s.is_primary);
|
const primarySpan = rd.spans.find(s => s.is_primary);
|
||||||
if (!primarySpan) {
|
if (!primarySpan) {
|
||||||
|
@ -223,7 +223,7 @@ export function mapRustDiagnosticToVsCode(
|
||||||
const suggestedFixes = [];
|
const suggestedFixes = [];
|
||||||
for (const child of rd.children) {
|
for (const child of rd.children) {
|
||||||
const { related, suggestedFix, messageLine } = mapRustChildDiagnostic(
|
const { related, suggestedFix, messageLine } = mapRustChildDiagnostic(
|
||||||
child
|
child,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (related) {
|
if (related) {
|
||||||
|
@ -256,6 +256,6 @@ export function mapRustDiagnosticToVsCode(
|
||||||
return {
|
return {
|
||||||
location,
|
location,
|
||||||
diagnostic: vd,
|
diagnostic: vd,
|
||||||
suggestedFixes
|
suggestedFixes,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ import * as vscode from 'vscode';
|
||||||
/** Compares two `vscode.Diagnostic`s for equality */
|
/** Compares two `vscode.Diagnostic`s for equality */
|
||||||
export function areDiagnosticsEqual(
|
export function areDiagnosticsEqual(
|
||||||
left: vscode.Diagnostic,
|
left: vscode.Diagnostic,
|
||||||
right: vscode.Diagnostic
|
right: vscode.Diagnostic,
|
||||||
): boolean {
|
): boolean {
|
||||||
return (
|
return (
|
||||||
left.source === right.source &&
|
left.source === right.source &&
|
||||||
|
|
|
@ -22,7 +22,7 @@ export function terminate(process: ChildProcess, cwd?: string): boolean {
|
||||||
// Ignore stderr since this is otherwise piped to parent.stderr
|
// Ignore stderr since this is otherwise piped to parent.stderr
|
||||||
// which might be already closed.
|
// which might be already closed.
|
||||||
const options: any = {
|
const options: any = {
|
||||||
stdio: ['pipe', 'pipe', 'ignore']
|
stdio: ['pipe', 'pipe', 'ignore'],
|
||||||
};
|
};
|
||||||
if (cwd) {
|
if (cwd) {
|
||||||
options.cwd = cwd;
|
options.cwd = cwd;
|
||||||
|
@ -30,7 +30,7 @@ export function terminate(process: ChildProcess, cwd?: string): boolean {
|
||||||
cp.execFileSync(
|
cp.execFileSync(
|
||||||
'taskkill',
|
'taskkill',
|
||||||
['/T', '/F', '/PID', process.pid.toString()],
|
['/T', '/F', '/PID', process.pid.toString()],
|
||||||
options
|
options,
|
||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
Loading…
Reference in a new issue