aboutsummaryrefslogtreecommitdiff
path: root/editors/code
diff options
context:
space:
mode:
authorAdolfo OchagavĂ­a <[email protected]>2018-10-09 21:56:15 +0100
committerAdolfo OchagavĂ­a <[email protected]>2018-10-09 21:56:22 +0100
commitf2d719b24afd404dbaf26332ff314a6161c74b71 (patch)
tree54c1381ec3d57cbd0722053900e02f3a7ad10cd2 /editors/code
parent31c8ebb743572ef07ac4ca77ddd17eddbcf4b24c (diff)
Format vscode extension and add npm run fix
Diffstat (limited to 'editors/code')
-rw-r--r--editors/code/package.json1
-rw-r--r--editors/code/src/commands/index.ts4
-rw-r--r--editors/code/src/commands/on_enter.ts17
-rw-r--r--editors/code/src/extension.ts21
4 files changed, 29 insertions, 14 deletions
diff --git a/editors/code/package.json b/editors/code/package.json
index cd07e3be9..eeb6dd816 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -18,6 +18,7 @@
18 "compile": "tsc -p ./", 18 "compile": "tsc -p ./",
19 "watch": "tsc -watch -p ./", 19 "watch": "tsc -watch -p ./",
20 "postinstall": "node ./node_modules/vscode/bin/install", 20 "postinstall": "node ./node_modules/vscode/bin/install",
21 "fix": "prettier **/*.{json,ts} --write && tslint --project . --fix",
21 "lint": "tslint --project .", 22 "lint": "tslint --project .",
22 "prettier": "prettier **/*.{json,ts}", 23 "prettier": "prettier **/*.{json,ts}",
23 "travis": "npm run compile && npm run lint && npm run prettier --list-different" 24 "travis": "npm run compile && npm run lint && npm run prettier --list-different"
diff --git a/editors/code/src/commands/index.ts b/editors/code/src/commands/index.ts
index d78a64c3e..33e2b34a2 100644
--- a/editors/code/src/commands/index.ts
+++ b/editors/code/src/commands/index.ts
@@ -2,7 +2,7 @@ import * as applySourceChange from './apply_source_change';
2import * as extendSelection from './extend_selection'; 2import * as extendSelection from './extend_selection';
3import * as joinLines from './join_lines'; 3import * as joinLines from './join_lines';
4import * as matchingBrace from './matching_brace'; 4import * as matchingBrace from './matching_brace';
5import * as on_enter from './on_enter'; 5import * as onEnter from './on_enter';
6import * as parentModule from './parent_module'; 6import * as parentModule from './parent_module';
7import * as runnables from './runnables'; 7import * as runnables from './runnables';
8import * as syntaxTree from './syntaxTree'; 8import * as syntaxTree from './syntaxTree';
@@ -15,5 +15,5 @@ export {
15 parentModule, 15 parentModule,
16 runnables, 16 runnables,
17 syntaxTree, 17 syntaxTree,
18 on_enter, 18 onEnter
19}; 19};
diff --git a/editors/code/src/commands/on_enter.ts b/editors/code/src/commands/on_enter.ts
index 2666797fe..fe6aca63d 100644
--- a/editors/code/src/commands/on_enter.ts
+++ b/editors/code/src/commands/on_enter.ts
@@ -1,7 +1,10 @@
1import * as vscode from 'vscode'; 1import * as vscode from 'vscode';
2import * as lc from 'vscode-languageclient'; 2import * as lc from 'vscode-languageclient';
3import { Server } from '../server'; 3import { Server } from '../server';
4import { handle as applySourceChange, SourceChange } from './apply_source_change'; 4import {
5 handle as applySourceChange,
6 SourceChange
7} from './apply_source_change';
5 8
6interface OnEnterParams { 9interface OnEnterParams {
7 textDocument: lc.TextDocumentIdentifier; 10 textDocument: lc.TextDocumentIdentifier;
@@ -10,12 +13,18 @@ interface OnEnterParams {
10 13
11export async function handle(event: { text: string }): Promise<boolean> { 14export async function handle(event: { text: string }): Promise<boolean> {
12 const editor = vscode.window.activeTextEditor; 15 const editor = vscode.window.activeTextEditor;
13 if (editor == null || editor.document.languageId !== 'rust' || event.text !== '\n') { 16 if (
17 editor == null ||
18 editor.document.languageId !== 'rust' ||
19 event.text !== '\n'
20 ) {
14 return false; 21 return false;
15 } 22 }
16 const request: OnEnterParams = { 23 const request: OnEnterParams = {
17 textDocument: { uri: editor.document.uri.toString() }, 24 textDocument: { uri: editor.document.uri.toString() },
18 position: Server.client.code2ProtocolConverter.asPosition(editor.selection.active), 25 position: Server.client.code2ProtocolConverter.asPosition(
26 editor.selection.active
27 )
19 }; 28 };
20 const change = await Server.client.sendRequest<undefined | SourceChange>( 29 const change = await Server.client.sendRequest<undefined | SourceChange>(
21 'm/onEnter', 30 'm/onEnter',
@@ -25,5 +34,5 @@ export async function handle(event: { text: string }): Promise<boolean> {
25 return false; 34 return false;
26 } 35 }
27 await applySourceChange(change); 36 await applySourceChange(change);
28 return true 37 return true;
29} 38}
diff --git a/editors/code/src/extension.ts b/editors/code/src/extension.ts
index 3e5767535..ff8f23c7a 100644
--- a/editors/code/src/extension.ts
+++ b/editors/code/src/extension.ts
@@ -16,21 +16,26 @@ export function activate(context: vscode.ExtensionContext) {
16 disposeOnDeactivation(vscode.commands.registerCommand(name, f)); 16 disposeOnDeactivation(vscode.commands.registerCommand(name, f));
17 } 17 }
18 function overrideCommand( 18 function overrideCommand(
19
20 name: string, 19 name: string,
21 f: (...args: any[]) => Promise<boolean>, 20 f: (...args: any[]) => Promise<boolean>
22 ) { 21 ) {
23 const defaultCmd = `default:${name}`; 22 const defaultCmd = `default:${name}`;
24 const original = async (...args: any[]) => await vscode.commands.executeCommand(defaultCmd, ...args); 23 const original = async (...args: any[]) =>
24 await vscode.commands.executeCommand(defaultCmd, ...args);
25
25 registerCommand(name, async (...args: any[]) => { 26 registerCommand(name, async (...args: any[]) => {
26 const editor = vscode.window.activeTextEditor; 27 const editor = vscode.window.activeTextEditor;
27 if (!editor || !editor.document || editor.document.languageId !== 'rust') { 28 if (
29 !editor ||
30 !editor.document ||
31 editor.document.languageId !== 'rust'
32 ) {
28 return await original(...args); 33 return await original(...args);
29 } 34 }
30 if (!await f(...args)) { 35 if (!(await f(...args))) {
31 return await original(...args); 36 return await original(...args);
32 } 37 }
33 }) 38 });
34 } 39 }
35 40
36 // Commands are requests from vscode to the language server 41 // Commands are requests from vscode to the language server
@@ -44,12 +49,12 @@ export function activate(context: vscode.ExtensionContext) {
44 'ra-lsp.applySourceChange', 49 'ra-lsp.applySourceChange',
45 commands.applySourceChange.handle 50 commands.applySourceChange.handle
46 ); 51 );
47 overrideCommand('type', commands.on_enter.handle) 52 overrideCommand('type', commands.onEnter.handle);
48 53
49 // Notifications are events triggered by the language server 54 // Notifications are events triggered by the language server
50 const allNotifications: Iterable< 55 const allNotifications: Iterable<
51 [string, lc.GenericNotificationHandler] 56 [string, lc.GenericNotificationHandler]
52 > = [['m/publishDecorations', notifications.publishDecorations.handle]]; 57 > = [['m/publishDecorations', notifications.publishDecorations.handle]];
53 58
54 // The events below are plain old javascript events, triggered and handled by vscode 59 // The events below are plain old javascript events, triggered and handled by vscode
55 vscode.window.onDidChangeActiveTextEditor( 60 vscode.window.onDidChangeActiveTextEditor(