aboutsummaryrefslogtreecommitdiff
path: root/editors/code
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code')
-rw-r--r--editors/code/src/commands.ts17
-rw-r--r--editors/code/src/commands/apply_source_change.ts26
-rw-r--r--editors/code/src/commands/extend_selection.ts2
-rw-r--r--editors/code/src/commands/index.ts17
-rw-r--r--editors/code/src/commands/join_lines.ts2
-rw-r--r--editors/code/src/commands/matching_brace.ts2
-rw-r--r--editors/code/src/commands/parent_module.ts2
-rw-r--r--editors/code/src/commands/runnables.ts4
-rw-r--r--editors/code/src/events.ts7
-rw-r--r--editors/code/src/events/change_active_text_editor.ts2
-rw-r--r--editors/code/src/events/change_text_document.ts2
-rw-r--r--editors/code/src/events/index.ts7
-rw-r--r--editors/code/src/highlighting.ts66
-rw-r--r--editors/code/src/server.ts2
-rw-r--r--editors/code/tslint.json2
15 files changed, 82 insertions, 78 deletions
diff --git a/editors/code/src/commands.ts b/editors/code/src/commands.ts
deleted file mode 100644
index c7e27781e..000000000
--- a/editors/code/src/commands.ts
+++ /dev/null
@@ -1,17 +0,0 @@
1import * as applySourceChange from './commands/apply_source_change';
2import * as extendSelection from './commands/extend_selection';
3import * as joinLines from './commands/join_lines';
4import * as matchingBrace from './commands/matching_brace';
5import * as parentModule from './commands/parent_module';
6import * as runnables from './commands/runnables';
7import * as syntaxTree from './commands/syntaxTree';
8
9export {
10 applySourceChange,
11 extendSelection,
12 joinLines,
13 matchingBrace,
14 parentModule,
15 runnables,
16 syntaxTree,
17};
diff --git a/editors/code/src/commands/apply_source_change.ts b/editors/code/src/commands/apply_source_change.ts
index f011cbe12..67765e5a3 100644
--- a/editors/code/src/commands/apply_source_change.ts
+++ b/editors/code/src/commands/apply_source_change.ts
@@ -18,7 +18,6 @@ export interface SourceChange {
18} 18}
19 19
20export async function handle(change: SourceChange) { 20export async function handle(change: SourceChange) {
21 console.log(`applySOurceChange ${JSON.stringify(change)}`);
22 const wsEdit = new vscode.WorkspaceEdit(); 21 const wsEdit = new vscode.WorkspaceEdit();
23 for (const sourceEdit of change.sourceFileEdits) { 22 for (const sourceEdit of change.sourceFileEdits) {
24 const uri = Server.client.protocol2CodeConverter.asUri(sourceEdit.textDocument.uri); 23 const uri = Server.client.protocol2CodeConverter.asUri(sourceEdit.textDocument.uri);
@@ -28,17 +27,18 @@ export async function handle(change: SourceChange) {
28 let created; 27 let created;
29 let moved; 28 let moved;
30 for (const fsEdit of change.fileSystemEdits) { 29 for (const fsEdit of change.fileSystemEdits) {
31 if (fsEdit.type == 'createFile') { 30 switch (fsEdit.type) {
32 const uri = vscode.Uri.parse(fsEdit.uri!); 31 case 'createFile':
33 wsEdit.createFile(uri); 32 const uri = vscode.Uri.parse(fsEdit.uri!);
34 created = uri; 33 wsEdit.createFile(uri);
35 } else if (fsEdit.type == 'moveFile') { 34 created = uri;
36 const src = vscode.Uri.parse(fsEdit.src!); 35 break;
37 const dst = vscode.Uri.parse(fsEdit.dst!); 36 case 'moveFile':
38 wsEdit.renameFile(src, dst); 37 const src = vscode.Uri.parse(fsEdit.src!);
39 moved = dst; 38 const dst = vscode.Uri.parse(fsEdit.dst!);
40 } else { 39 wsEdit.renameFile(src, dst);
41 console.error(`unknown op: ${JSON.stringify(fsEdit)}`); 40 moved = dst;
41 break;
42 } 42 }
43 } 43 }
44 const toOpen = created || moved; 44 const toOpen = created || moved;
@@ -51,7 +51,7 @@ export async function handle(change: SourceChange) {
51 const uri = Server.client.protocol2CodeConverter.asUri(toReveal.textDocument.uri); 51 const uri = Server.client.protocol2CodeConverter.asUri(toReveal.textDocument.uri);
52 const position = Server.client.protocol2CodeConverter.asPosition(toReveal.position); 52 const position = Server.client.protocol2CodeConverter.asPosition(toReveal.position);
53 const editor = vscode.window.activeTextEditor; 53 const editor = vscode.window.activeTextEditor;
54 if (!editor || editor.document.uri.toString() != uri.toString()) { return; } 54 if (!editor || editor.document.uri.toString() !== uri.toString()) { return; }
55 if (!editor.selection.isEmpty) { return; } 55 if (!editor.selection.isEmpty) { return; }
56 editor!.selection = new vscode.Selection(position, position); 56 editor!.selection = new vscode.Selection(position, position);
57 } 57 }
diff --git a/editors/code/src/commands/extend_selection.ts b/editors/code/src/commands/extend_selection.ts
index b722ac172..cdc3d10fb 100644
--- a/editors/code/src/commands/extend_selection.ts
+++ b/editors/code/src/commands/extend_selection.ts
@@ -14,7 +14,7 @@ interface ExtendSelectionResult {
14 14
15export async function handle() { 15export async function handle() {
16 const editor = vscode.window.activeTextEditor; 16 const editor = vscode.window.activeTextEditor;
17 if (editor == null || editor.document.languageId != 'rust') { return; } 17 if (editor == null || editor.document.languageId !== 'rust') { return; }
18 const request: ExtendSelectionParams = { 18 const request: ExtendSelectionParams = {
19 selections: editor.selections.map((s) => { 19 selections: editor.selections.map((s) => {
20 return Server.client.code2ProtocolConverter.asRange(s); 20 return Server.client.code2ProtocolConverter.asRange(s);
diff --git a/editors/code/src/commands/index.ts b/editors/code/src/commands/index.ts
new file mode 100644
index 000000000..dfdcd6454
--- /dev/null
+++ b/editors/code/src/commands/index.ts
@@ -0,0 +1,17 @@
1import * as applySourceChange from './apply_source_change';
2import * as extendSelection from './extend_selection';
3import * as joinLines from './join_lines';
4import * as matchingBrace from './matching_brace';
5import * as parentModule from './parent_module';
6import * as runnables from './runnables';
7import * as syntaxTree from './syntaxTree';
8
9export {
10 applySourceChange,
11 extendSelection,
12 joinLines,
13 matchingBrace,
14 parentModule,
15 runnables,
16 syntaxTree,
17};
diff --git a/editors/code/src/commands/join_lines.ts b/editors/code/src/commands/join_lines.ts
index 80ad4460b..526b698cc 100644
--- a/editors/code/src/commands/join_lines.ts
+++ b/editors/code/src/commands/join_lines.ts
@@ -11,7 +11,7 @@ interface JoinLinesParams {
11 11
12export async function handle() { 12export async function handle() {
13 const editor = vscode.window.activeTextEditor; 13 const editor = vscode.window.activeTextEditor;
14 if (editor == null || editor.document.languageId != 'rust') { return; } 14 if (editor == null || editor.document.languageId !== 'rust') { return; }
15 const request: JoinLinesParams = { 15 const request: JoinLinesParams = {
16 range: Server.client.code2ProtocolConverter.asRange(editor.selection), 16 range: Server.client.code2ProtocolConverter.asRange(editor.selection),
17 textDocument: { uri: editor.document.uri.toString() }, 17 textDocument: { uri: editor.document.uri.toString() },
diff --git a/editors/code/src/commands/matching_brace.ts b/editors/code/src/commands/matching_brace.ts
index cf7f6bf8f..a80446a8f 100644
--- a/editors/code/src/commands/matching_brace.ts
+++ b/editors/code/src/commands/matching_brace.ts
@@ -10,7 +10,7 @@ interface FindMatchingBraceParams {
10 10
11export async function handle() { 11export async function handle() {
12 const editor = vscode.window.activeTextEditor; 12 const editor = vscode.window.activeTextEditor;
13 if (editor == null || editor.document.languageId != 'rust') { return; } 13 if (editor == null || editor.document.languageId !== 'rust') { return; }
14 const request: FindMatchingBraceParams = { 14 const request: FindMatchingBraceParams = {
15 textDocument: { uri: editor.document.uri.toString() }, 15 textDocument: { uri: editor.document.uri.toString() },
16 offsets: editor.selections.map((s) => { 16 offsets: editor.selections.map((s) => {
diff --git a/editors/code/src/commands/parent_module.ts b/editors/code/src/commands/parent_module.ts
index 7d413c27a..d66fb3026 100644
--- a/editors/code/src/commands/parent_module.ts
+++ b/editors/code/src/commands/parent_module.ts
@@ -5,7 +5,7 @@ import { Server } from '../server';
5 5
6export async function handle() { 6export async function handle() {
7 const editor = vscode.window.activeTextEditor; 7 const editor = vscode.window.activeTextEditor;
8 if (editor == null || editor.document.languageId != 'rust') { return; } 8 if (editor == null || editor.document.languageId !== 'rust') { return; }
9 const request: TextDocumentIdentifier = { 9 const request: TextDocumentIdentifier = {
10 uri: editor.document.uri.toString(), 10 uri: editor.document.uri.toString(),
11 }; 11 };
diff --git a/editors/code/src/commands/runnables.ts b/editors/code/src/commands/runnables.ts
index 37db6ea10..40f590dce 100644
--- a/editors/code/src/commands/runnables.ts
+++ b/editors/code/src/commands/runnables.ts
@@ -59,7 +59,7 @@ function createTask(spec: Runnable): vscode.Task {
59let prevRunnable: RunnableQuickPick | undefined; 59let prevRunnable: RunnableQuickPick | undefined;
60export async function handle() { 60export async function handle() {
61 const editor = vscode.window.activeTextEditor; 61 const editor = vscode.window.activeTextEditor;
62 if (editor == null || editor.document.languageId != 'rust') { return; } 62 if (editor == null || editor.document.languageId !== 'rust') { return; }
63 const textDocument: lc.TextDocumentIdentifier = { 63 const textDocument: lc.TextDocumentIdentifier = {
64 uri: editor.document.uri.toString(), 64 uri: editor.document.uri.toString(),
65 }; 65 };
@@ -73,7 +73,7 @@ export async function handle() {
73 items.push(prevRunnable); 73 items.push(prevRunnable);
74 } 74 }
75 for (const r of runnables) { 75 for (const r of runnables) {
76 if (prevRunnable && JSON.stringify(prevRunnable.runnable) == JSON.stringify(r)) { 76 if (prevRunnable && JSON.stringify(prevRunnable.runnable) === JSON.stringify(r)) {
77 continue; 77 continue;
78 } 78 }
79 items.push(new RunnableQuickPick(r)); 79 items.push(new RunnableQuickPick(r));
diff --git a/editors/code/src/events.ts b/editors/code/src/events.ts
deleted file mode 100644
index 8e2ac4a46..000000000
--- a/editors/code/src/events.ts
+++ /dev/null
@@ -1,7 +0,0 @@
1import * as changeActiveTextEditor from './events/change_active_text_editor';
2import * as changeTextDocument from './events/change_text_document';
3
4export {
5 changeActiveTextEditor,
6 changeTextDocument,
7};
diff --git a/editors/code/src/events/change_active_text_editor.ts b/editors/code/src/events/change_active_text_editor.ts
index 96d61126c..3440aa0c3 100644
--- a/editors/code/src/events/change_active_text_editor.ts
+++ b/editors/code/src/events/change_active_text_editor.ts
@@ -5,7 +5,7 @@ import { Decoration } from '../highlighting';
5import { Server } from '../server'; 5import { Server } from '../server';
6 6
7export async function handle(editor: TextEditor | undefined) { 7export async function handle(editor: TextEditor | undefined) {
8 if (!Server.config.highlightingOn || !editor || editor.document.languageId != 'rust') { return; } 8 if (!Server.config.highlightingOn || !editor || editor.document.languageId !== 'rust') { return; }
9 const params: TextDocumentIdentifier = { 9 const params: TextDocumentIdentifier = {
10 uri: editor.document.uri.toString(), 10 uri: editor.document.uri.toString(),
11 }; 11 };
diff --git a/editors/code/src/events/change_text_document.ts b/editors/code/src/events/change_text_document.ts
index 192fb1e8a..b3000e026 100644
--- a/editors/code/src/events/change_text_document.ts
+++ b/editors/code/src/events/change_text_document.ts
@@ -5,7 +5,7 @@ import { syntaxTreeUri, TextDocumentContentProvider } from '../commands/syntaxTr
5export function createHandler(textDocumentContentProvider: TextDocumentContentProvider) { 5export function createHandler(textDocumentContentProvider: TextDocumentContentProvider) {
6 return (event: vscode.TextDocumentChangeEvent) => { 6 return (event: vscode.TextDocumentChangeEvent) => {
7 const doc = event.document; 7 const doc = event.document;
8 if (doc.languageId != 'rust') { return; } 8 if (doc.languageId !== 'rust') { return; }
9 afterLs(() => { 9 afterLs(() => {
10 textDocumentContentProvider.eventEmitter.fire(syntaxTreeUri); 10 textDocumentContentProvider.eventEmitter.fire(syntaxTreeUri);
11 }); 11 });
diff --git a/editors/code/src/events/index.ts b/editors/code/src/events/index.ts
new file mode 100644
index 000000000..b570a7a92
--- /dev/null
+++ b/editors/code/src/events/index.ts
@@ -0,0 +1,7 @@
1import * as changeActiveTextEditor from './change_active_text_editor';
2import * as changeTextDocument from './change_text_document';
3
4export {
5 changeActiveTextEditor,
6 changeTextDocument,
7};
diff --git a/editors/code/src/highlighting.ts b/editors/code/src/highlighting.ts
index 71f8e5baa..e2ac4d629 100644
--- a/editors/code/src/highlighting.ts
+++ b/editors/code/src/highlighting.ts
@@ -9,17 +9,42 @@ export interface Decoration {
9} 9}
10 10
11export class Highlighter { 11export class Highlighter {
12 private decorations: { [index: string]: vscode.TextEditorDecorationType }; 12 private static initDecorations(): Map<string, vscode.TextEditorDecorationType> {
13 constructor() { 13 const decor = (color: string) => vscode.window.createTextEditorDecorationType({ color });
14 this.decorations = {}; 14
15 const decorations: Iterable<[string, vscode.TextEditorDecorationType]> = [
16 ['background', decor('#3F3F3F')],
17 ['error', vscode.window.createTextEditorDecorationType({
18 borderColor: 'red',
19 borderStyle: 'none none dashed none',
20 })],
21 ['comment', decor('#7F9F7F')],
22 ['string', decor('#CC9393')],
23 ['keyword', decor('#F0DFAF')],
24 ['function', decor('#93E0E3')],
25 ['parameter', decor('#94BFF3')],
26 ['builtin', decor('#DD6718')],
27 ['text', decor('#DCDCCC')],
28 ['attribute', decor('#BFEBBF')],
29 ['literal', decor('#DFAF8F')],
30 ];
31
32 return new Map<string, vscode.TextEditorDecorationType>(decorations);
15 } 33 }
16 34
35 private decorations: (Map<string, vscode.TextEditorDecorationType> | null) = null;
36
17 public removeHighlights() { 37 public removeHighlights() {
18 for (const tag in this.decorations) { 38 if (this.decorations == null) {
19 this.decorations[tag].dispose(); 39 return;
20 } 40 }
21 41
22 this.decorations = {}; 42 // Decorations are removed when the object is disposed
43 for (const decoration of this.decorations.values()) {
44 decoration.dispose();
45 }
46
47 this.decorations = null;
23 } 48 }
24 49
25 public setHighlights( 50 public setHighlights(
@@ -30,18 +55,17 @@ export class Highlighter {
30 // 55 //
31 // Note: decoration objects need to be kept around so we can dispose them 56 // Note: decoration objects need to be kept around so we can dispose them
32 // if the user disables syntax highlighting 57 // if the user disables syntax highlighting
33 if (Object.keys(this.decorations).length === 0) { 58 if (this.decorations == null) {
34 this.initDecorations(); 59 this.decorations = Highlighter.initDecorations();
35 } 60 }
36 61
37 const byTag: Map<string, vscode.Range[]> = new Map(); 62 const byTag: Map<string, vscode.Range[]> = new Map();
38 for (const tag in this.decorations) { 63 for (const tag of this.decorations.keys()) {
39 byTag.set(tag, []); 64 byTag.set(tag, []);
40 } 65 }
41 66
42 for (const d of highlights) { 67 for (const d of highlights) {
43 if (!byTag.get(d.tag)) { 68 if (!byTag.get(d.tag)) {
44 console.log(`unknown tag ${d.tag}`);
45 continue; 69 continue;
46 } 70 }
47 byTag.get(d.tag)!.push( 71 byTag.get(d.tag)!.push(
@@ -50,29 +74,9 @@ export class Highlighter {
50 } 74 }
51 75
52 for (const tag of byTag.keys()) { 76 for (const tag of byTag.keys()) {
53 const dec: vscode.TextEditorDecorationType = this.decorations[tag]; 77 const dec = this.decorations.get(tag) as vscode.TextEditorDecorationType;
54 const ranges = byTag.get(tag)!; 78 const ranges = byTag.get(tag)!;
55 editor.setDecorations(dec, ranges); 79 editor.setDecorations(dec, ranges);
56 } 80 }
57 } 81 }
58
59 private initDecorations() {
60 const decor = (obj: any) => vscode.window.createTextEditorDecorationType({ color: obj });
61 this.decorations = {
62 background: decor('#3F3F3F'),
63 error: vscode.window.createTextEditorDecorationType({
64 borderColor: 'red',
65 borderStyle: 'none none dashed none',
66 }),
67 comment: decor('#7F9F7F'),
68 string: decor('#CC9393'),
69 keyword: decor('#F0DFAF'),
70 function: decor('#93E0E3'),
71 parameter: decor('#94BFF3'),
72 builtin: decor('#DD6718'),
73 text: decor('#DCDCCC'),
74 attribute: decor('#BFEBBF'),
75 literal: decor('#DFAF8F'),
76 };
77 }
78} 82}
diff --git a/editors/code/src/server.ts b/editors/code/src/server.ts
index 3857b00a5..325023e36 100644
--- a/editors/code/src/server.ts
+++ b/editors/code/src/server.ts
@@ -34,7 +34,7 @@ export class Server {
34 'm/publishDecorations', 34 'm/publishDecorations',
35 (params: PublishDecorationsParams) => { 35 (params: PublishDecorationsParams) => {
36 const targetEditor = vscode.window.visibleTextEditors.find( 36 const targetEditor = vscode.window.visibleTextEditors.find(
37 (editor) => editor.document.uri.toString() == params.uri, 37 (editor) => editor.document.uri.toString() === params.uri,
38 ); 38 );
39 if (!Server.config.highlightingOn || !targetEditor) { return; } 39 if (!Server.config.highlightingOn || !targetEditor) { return; }
40 Server.highlighter.setHighlights( 40 Server.highlighter.setHighlights(
diff --git a/editors/code/tslint.json b/editors/code/tslint.json
index 466e1fa20..ce48dfc95 100644
--- a/editors/code/tslint.json
+++ b/editors/code/tslint.json
@@ -1,5 +1,5 @@
1{ 1{
2 "defaultSeverity": "warning", 2 "defaultSeverity": "error",
3 "extends": [ 3 "extends": [
4 "tslint:recommended" 4 "tslint:recommended"
5 ], 5 ],