Code: enable prettier trailing commas

This commit is contained in:
Laurențiu Nicola 2019-12-09 20:57:55 +02:00
parent 897b550049
commit 273299693b
31 changed files with 233 additions and 232 deletions

View file

@ -9,7 +9,7 @@ export class TextDocumentContentProvider
public syntaxTree: string = 'Not available';
public provideTextDocumentContent(
uri: vscode.Uri
uri: vscode.Uri,
): vscode.ProviderResult<string> {
const editor = vscode.window.activeTextEditor;
if (editor == null) {
@ -17,7 +17,7 @@ export class TextDocumentContentProvider
}
return Server.client.sendRequest<string>(
'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,
);
};
}

View file

@ -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,
);
}
}

View file

@ -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<CargoWatchProvider | undefined> {
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,
);
}
}

View file

@ -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<vscode.Uri>();
public provideTextDocumentContent(
uri: vscode.Uri
uri: vscode.Uri,
): vscode.ProviderResult<string> {
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<ExpandedMacro>(
'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,
);
};
}

View file

@ -19,5 +19,5 @@ export {
runnables,
syntaxTree,
onEnter,
inlayHints
inlayHints,
};

View file

@ -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<void> {
if (!this.displayHints) {
return;
@ -48,21 +48,21 @@ export class HintsUpdater {
}
private async refreshVisibleEditorsHints(
newDecorations?: vscode.DecorationOptions[]
newDecorations?: vscode.DecorationOptions[],
) {
const promises: Array<Promise<void>> = [];
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<void> {
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<InlayHint[] | null> {
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<InlayHint[] | null>(
'rust-analyzer/inlayHints',
request
)
request,
),
);
}
}

View file

@ -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<SourceChange>(
'rust-analyzer/joinLines',
request
request,
);
await applySourceChange(change);
}

View file

@ -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<Position[]>(
'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);

View file

@ -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<boolean> {
@ -18,12 +18,12 @@ export async function handle(event: { text: string }): Promise<boolean> {
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<undefined | SourceChange>(
'rust-analyzer/onEnter',
request
request,
);
if (!change) {
return false;

View file

@ -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<lc.Location[]>(
'rust-analyzer/parentModule',
request
request,
);
const loc = response[0];
if (loc == null) {

View file

@ -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<Runnable[]>(
'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<CargoWatchProvider | undefined> {
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<CargoWatchProvider | undefined> {
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;
}

View file

@ -11,7 +11,7 @@ export class SyntaxTreeContentProvider
public syntaxTree: string = 'Not available';
public provideTextDocumentContent(
uri: vscode.Uri
uri: vscode.Uri,
): vscode.ProviderResult<string> {
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<SyntaxTreeResult>(
'rust-analyzer/syntaxTree',
request
request,
);
}
@ -70,7 +70,7 @@ export function createHandle(provider: SyntaxTreeContentProvider) {
return vscode.window.showTextDocument(
document,
vscode.ViewColumn.Two,
true
true,
);
};
}

View file

@ -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();