diff options
-rw-r--r-- | editors/code/src/events/change_active_text_editor.ts | 25 | ||||
-rw-r--r-- | editors/code/src/events/index.ts | 3 | ||||
-rw-r--r-- | editors/code/src/highlighting.ts | 22 | ||||
-rw-r--r-- | editors/code/src/main.ts | 9 |
4 files changed, 24 insertions, 35 deletions
diff --git a/editors/code/src/events/change_active_text_editor.ts b/editors/code/src/events/change_active_text_editor.ts deleted file mode 100644 index 4384ee567..000000000 --- a/editors/code/src/events/change_active_text_editor.ts +++ /dev/null | |||
@@ -1,25 +0,0 @@ | |||
1 | import { TextEditor } from 'vscode'; | ||
2 | import { TextDocumentIdentifier } from 'vscode-languageclient'; | ||
3 | import { Decoration } from '../highlighting'; | ||
4 | import { Server } from '../server'; | ||
5 | |||
6 | export function makeHandler() { | ||
7 | return async function handle(editor: TextEditor | undefined) { | ||
8 | if (!editor || editor.document.languageId !== 'rust') { | ||
9 | return; | ||
10 | } | ||
11 | |||
12 | if (!Server.config.highlightingOn) { | ||
13 | return; | ||
14 | } | ||
15 | |||
16 | const params: TextDocumentIdentifier = { | ||
17 | uri: editor.document.uri.toString(), | ||
18 | }; | ||
19 | const decorations = await Server.client.sendRequest<Decoration[]>( | ||
20 | 'rust-analyzer/decorationsRequest', | ||
21 | params, | ||
22 | ); | ||
23 | Server.highlighter.setHighlights(editor, decorations); | ||
24 | }; | ||
25 | } | ||
diff --git a/editors/code/src/events/index.ts b/editors/code/src/events/index.ts deleted file mode 100644 index be135474d..000000000 --- a/editors/code/src/events/index.ts +++ /dev/null | |||
@@ -1,3 +0,0 @@ | |||
1 | import * as changeActiveTextEditor from './change_active_text_editor'; | ||
2 | |||
3 | export { changeActiveTextEditor }; | ||
diff --git a/editors/code/src/highlighting.ts b/editors/code/src/highlighting.ts index 4e224a54c..ced78adc1 100644 --- a/editors/code/src/highlighting.ts +++ b/editors/code/src/highlighting.ts | |||
@@ -1,10 +1,30 @@ | |||
1 | import seedrandom = require('seedrandom'); | ||
2 | import * as vscode from 'vscode'; | 1 | import * as vscode from 'vscode'; |
3 | import * as lc from 'vscode-languageclient'; | 2 | import * as lc from 'vscode-languageclient'; |
3 | import * as seedrandom from 'seedrandom'; | ||
4 | |||
4 | import * as scopes from './scopes'; | 5 | import * as scopes from './scopes'; |
5 | import * as scopesMapper from './scopes_mapper'; | 6 | import * as scopesMapper from './scopes_mapper'; |
6 | 7 | ||
7 | import { Server } from './server'; | 8 | import { Server } from './server'; |
9 | import { Ctx } from './ctx'; | ||
10 | |||
11 | export function activateHighlighting(ctx: Ctx) { | ||
12 | vscode.window.onDidChangeActiveTextEditor( | ||
13 | async (editor: vscode.TextEditor | undefined) => { | ||
14 | if (!editor || editor.document.languageId !== 'rust') return; | ||
15 | if (!Server.config.highlightingOn) return; | ||
16 | |||
17 | const params: lc.TextDocumentIdentifier = { | ||
18 | uri: editor.document.uri.toString(), | ||
19 | }; | ||
20 | const decorations = await ctx.client.sendRequest<Decoration[]>( | ||
21 | 'rust-analyzer/decorationsRequest', | ||
22 | params, | ||
23 | ); | ||
24 | Server.highlighter.setHighlights(editor, decorations); | ||
25 | }, | ||
26 | ); | ||
27 | } | ||
8 | 28 | ||
9 | export interface Decoration { | 29 | export interface Decoration { |
10 | range: lc.Range; | 30 | range: lc.Range; |
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index 7e63a9cac..45657532e 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts | |||
@@ -4,10 +4,10 @@ import * as lc from 'vscode-languageclient'; | |||
4 | import * as commands from './commands'; | 4 | import * as commands from './commands'; |
5 | import { activateInlayHints } from './inlay_hints'; | 5 | import { activateInlayHints } from './inlay_hints'; |
6 | import { StatusDisplay } from './status_display'; | 6 | import { StatusDisplay } from './status_display'; |
7 | import * as events from './events'; | ||
8 | import * as notifications from './notifications'; | 7 | import * as notifications from './notifications'; |
9 | import { Server } from './server'; | 8 | import { Server } from './server'; |
10 | import { Ctx } from './ctx'; | 9 | import { Ctx } from './ctx'; |
10 | import { activateHighlighting } from './highlighting'; | ||
11 | 11 | ||
12 | let ctx!: Ctx; | 12 | let ctx!: Ctx; |
13 | 13 | ||
@@ -37,6 +37,8 @@ export async function activate(context: vscode.ExtensionContext) { | |||
37 | ); | 37 | ); |
38 | ctx.pushCleanup(watchStatus); | 38 | ctx.pushCleanup(watchStatus); |
39 | 39 | ||
40 | activateHighlighting(ctx); | ||
41 | |||
40 | // Notifications are events triggered by the language server | 42 | // Notifications are events triggered by the language server |
41 | const allNotifications: [string, lc.GenericNotificationHandler][] = [ | 43 | const allNotifications: [string, lc.GenericNotificationHandler][] = [ |
42 | [ | 44 | [ |
@@ -49,11 +51,6 @@ export async function activate(context: vscode.ExtensionContext) { | |||
49 | ], | 51 | ], |
50 | ]; | 52 | ]; |
51 | 53 | ||
52 | // The events below are plain old javascript events, triggered and handled by vscode | ||
53 | vscode.window.onDidChangeActiveTextEditor( | ||
54 | events.changeActiveTextEditor.makeHandler(), | ||
55 | ); | ||
56 | |||
57 | const startServer = () => Server.start(allNotifications); | 54 | const startServer = () => Server.start(allNotifications); |
58 | const reloadCommand = () => reloadServer(startServer); | 55 | const reloadCommand = () => reloadServer(startServer); |
59 | 56 | ||