Run prettier on all files

This commit is contained in:
Daniel McNab 2018-10-08 22:38:33 +01:00
parent 3a405b65d6
commit e26071d96e
23 changed files with 220 additions and 129 deletions

View file

@ -20,8 +20,12 @@ export interface SourceChange {
export async function handle(change: SourceChange) {
const wsEdit = new vscode.WorkspaceEdit();
for (const sourceEdit of change.sourceFileEdits) {
const uri = Server.client.protocol2CodeConverter.asUri(sourceEdit.textDocument.uri);
const edits = Server.client.protocol2CodeConverter.asTextEdits(sourceEdit.edits);
const uri = Server.client.protocol2CodeConverter.asUri(
sourceEdit.textDocument.uri
);
const edits = Server.client.protocol2CodeConverter.asTextEdits(
sourceEdit.edits
);
wsEdit.set(uri, edits);
}
let created;
@ -48,11 +52,19 @@ export async function handle(change: SourceChange) {
const doc = await vscode.workspace.openTextDocument(toOpen);
await vscode.window.showTextDocument(doc);
} else if (toReveal) {
const uri = Server.client.protocol2CodeConverter.asUri(toReveal.textDocument.uri);
const position = Server.client.protocol2CodeConverter.asPosition(toReveal.position);
const uri = Server.client.protocol2CodeConverter.asUri(
toReveal.textDocument.uri
);
const position = Server.client.protocol2CodeConverter.asPosition(
toReveal.position
);
const editor = vscode.window.activeTextEditor;
if (!editor || editor.document.uri.toString() !== uri.toString()) { return; }
if (!editor.selection.isEmpty) { return; }
if (!editor || editor.document.uri.toString() !== uri.toString()) {
return;
}
if (!editor.selection.isEmpty) {
return;
}
editor!.selection = new vscode.Selection(position, position);
}
}

View file

@ -14,14 +14,19 @@ interface ExtendSelectionResult {
export async function handle() {
const editor = vscode.window.activeTextEditor;
if (editor == null || editor.document.languageId !== 'rust') { return; }
if (editor == null || editor.document.languageId !== 'rust') {
return;
}
const request: ExtendSelectionParams = {
selections: editor.selections.map((s) => {
selections: editor.selections.map(s => {
return Server.client.code2ProtocolConverter.asRange(s);
}),
textDocument: { uri: editor.document.uri.toString() },
textDocument: { uri: editor.document.uri.toString() }
};
const response = await Server.client.sendRequest<ExtendSelectionResult>('m/extendSelection', request);
const response = await Server.client.sendRequest<ExtendSelectionResult>(
'm/extendSelection',
request
);
editor.selections = response.selections.map((range: Range) => {
const r = Server.client.protocol2CodeConverter.asRange(range);
return new vscode.Selection(r.start, r.end);

View file

@ -13,5 +13,5 @@ export {
matchingBrace,
parentModule,
runnables,
syntaxTree,
syntaxTree
};

View file

@ -2,7 +2,10 @@ import * as vscode from 'vscode';
import { Range, TextDocumentIdentifier } from 'vscode-languageclient';
import { Server } from '../server';
import { handle as applySourceChange, SourceChange } from './apply_source_change';
import {
handle as applySourceChange,
SourceChange
} from './apply_source_change';
interface JoinLinesParams {
textDocument: TextDocumentIdentifier;
@ -11,11 +14,16 @@ interface JoinLinesParams {
export async function handle() {
const editor = vscode.window.activeTextEditor;
if (editor == null || editor.document.languageId !== 'rust') { return; }
if (editor == null || editor.document.languageId !== 'rust') {
return;
}
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>('m/joinLines', request);
const change = await Server.client.sendRequest<SourceChange>(
'm/joinLines',
request
);
await applySourceChange(change);
}

View file

@ -10,16 +10,23 @@ interface FindMatchingBraceParams {
export async function handle() {
const editor = vscode.window.activeTextEditor;
if (editor == null || editor.document.languageId !== 'rust') { return; }
if (editor == null || editor.document.languageId !== 'rust') {
return;
}
const request: FindMatchingBraceParams = {
textDocument: { uri: editor.document.uri.toString() },
offsets: editor.selections.map((s) => {
offsets: editor.selections.map(s => {
return Server.client.code2ProtocolConverter.asPosition(s.active);
}),
})
};
const response = await Server.client.sendRequest<Position[]>('m/findMatchingBrace', request);
const response = await Server.client.sendRequest<Position[]>(
'm/findMatchingBrace',
request
);
editor.selections = editor.selections.map((sel, idx) => {
const active = Server.client.protocol2CodeConverter.asPosition(response[idx]);
const active = Server.client.protocol2CodeConverter.asPosition(
response[idx]
);
const anchor = sel.isEmpty ? active : sel.anchor;
return new vscode.Selection(anchor, active);
});

View file

@ -5,13 +5,20 @@ import { Server } from '../server';
export async function handle() {
const editor = vscode.window.activeTextEditor;
if (editor == null || editor.document.languageId !== 'rust') { return; }
if (editor == null || editor.document.languageId !== 'rust') {
return;
}
const request: TextDocumentIdentifier = {
uri: editor.document.uri.toString(),
uri: editor.document.uri.toString()
};
const response = await Server.client.sendRequest<Location[]>('m/parentModule', request);
const response = await Server.client.sendRequest<Location[]>(
'm/parentModule',
request
);
const loc = response[0];
if (loc == null) { return; }
if (loc == null) {
return;
}
const uri = Server.client.protocol2CodeConverter.asUri(loc.uri);
const range = Server.client.protocol2CodeConverter.asRange(loc.range);

View file

@ -41,39 +41,56 @@ function createTask(spec: Runnable): vscode.Task {
label: 'cargo',
command: spec.bin,
args: spec.args,
env: spec.env,
env: spec.env
};
const execCmd = `${definition.command} ${definition.args.join(' ')}`;
const execOption: vscode.ShellExecutionOptions = {
cwd: '.',
env: definition.env,
env: definition.env
};
const exec = new vscode.ShellExecution(`clear; ${execCmd}`, execOption);
const f = vscode.workspace.workspaceFolders![0];
const t = new vscode.Task(definition, f, definition.label, TASK_SOURCE, exec, ['$rustc']);
const t = new vscode.Task(
definition,
f,
definition.label,
TASK_SOURCE,
exec,
['$rustc']
);
return t;
}
let prevRunnable: RunnableQuickPick | undefined;
export async function handle() {
const editor = vscode.window.activeTextEditor;
if (editor == null || editor.document.languageId !== 'rust') { return; }
if (editor == null || editor.document.languageId !== 'rust') {
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),
position: Server.client.code2ProtocolConverter.asPosition(
editor.selection.active
)
};
const runnables = await Server.client.sendRequest<Runnable[]>('m/runnables', params);
const runnables = await Server.client.sendRequest<Runnable[]>(
'm/runnables',
params
);
const items: RunnableQuickPick[] = [];
if (prevRunnable) {
items.push(prevRunnable);
}
for (const r of runnables) {
if (prevRunnable && JSON.stringify(prevRunnable.runnable) === JSON.stringify(r)) {
if (
prevRunnable &&
JSON.stringify(prevRunnable.runnable) === JSON.stringify(r)
) {
continue;
}
items.push(new RunnableQuickPick(r));

View file

@ -5,17 +5,25 @@ import { Server } from '../server';
export const syntaxTreeUri = vscode.Uri.parse('ra-lsp://syntaxtree');
export class TextDocumentContentProvider implements vscode.TextDocumentContentProvider {
export class TextDocumentContentProvider
implements vscode.TextDocumentContentProvider {
public eventEmitter = new vscode.EventEmitter<vscode.Uri>();
public syntaxTree: string = 'Not available';
public provideTextDocumentContent(uri: vscode.Uri): vscode.ProviderResult<string> {
public provideTextDocumentContent(
uri: vscode.Uri
): vscode.ProviderResult<string> {
const editor = vscode.window.activeTextEditor;
if (editor == null) { return ''; }
if (editor == null) {
return '';
}
const request: SyntaxTreeParams = {
textDocument: { uri: editor.document.uri.toString() },
textDocument: { uri: editor.document.uri.toString() }
};
return Server.client.sendRequest<SyntaxTreeResult>('m/syntaxTree', request);
return Server.client.sendRequest<SyntaxTreeResult>(
'm/syntaxTree',
request
);
}
get onDidChange(): vscode.Event<vscode.Uri> {
@ -34,5 +42,9 @@ type SyntaxTreeResult = string;
// The contents of the file come from the `TextDocumentContentProvider`
export async function handle() {
const document = await vscode.workspace.openTextDocument(syntaxTreeUri);
return vscode.window.showTextDocument(document, vscode.ViewColumn.Two, true);
return vscode.window.showTextDocument(
document,
vscode.ViewColumn.Two,
true
);
}