diff options
author | Aleksey Kladov <[email protected]> | 2019-12-30 15:43:34 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-12-30 18:07:59 +0000 |
commit | 5aebf1081dced95a71c674aba65fb5b3e40e6ff1 (patch) | |
tree | bacedf66912eee5a366a3c93c60a39ba29744f92 /editors/code/src/main.ts | |
parent | 83d2527880d86653ce00940c65620319b36afcff (diff) |
Refactor applySourceChange
Diffstat (limited to 'editors/code/src/main.ts')
-rw-r--r-- | editors/code/src/main.ts | 52 |
1 files changed, 10 insertions, 42 deletions
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index 95beb2d8f..c3f280630 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts | |||
@@ -27,34 +27,6 @@ export async function activate(context: vscode.ExtensionContext) { | |||
27 | function registerCommand(name: string, f: any) { | 27 | function registerCommand(name: string, f: any) { |
28 | disposeOnDeactivation(vscode.commands.registerCommand(name, f)); | 28 | disposeOnDeactivation(vscode.commands.registerCommand(name, f)); |
29 | } | 29 | } |
30 | function overrideCommand( | ||
31 | name: string, | ||
32 | f: (...args: any[]) => Promise<boolean>, | ||
33 | ) { | ||
34 | const defaultCmd = `default:${name}`; | ||
35 | const original = (...args: any[]) => | ||
36 | vscode.commands.executeCommand(defaultCmd, ...args); | ||
37 | |||
38 | try { | ||
39 | registerCommand(name, async (...args: any[]) => { | ||
40 | const editor = vscode.window.activeTextEditor; | ||
41 | if ( | ||
42 | !editor || | ||
43 | !editor.document || | ||
44 | editor.document.languageId !== 'rust' | ||
45 | ) { | ||
46 | return await original(...args); | ||
47 | } | ||
48 | if (!(await f(...args))) { | ||
49 | return await original(...args); | ||
50 | } | ||
51 | }); | ||
52 | } catch (_) { | ||
53 | vscode.window.showWarningMessage( | ||
54 | 'Enhanced typing feature is disabled because of incompatibility with VIM extension, consider turning off rust-analyzer.enableEnhancedTyping: https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/user/README.md#settings', | ||
55 | ); | ||
56 | } | ||
57 | } | ||
58 | 30 | ||
59 | // Commands are requests from vscode to the language server | 31 | // Commands are requests from vscode to the language server |
60 | registerCommand('rust-analyzer.parentModule', commands.parentModule.handle); | 32 | registerCommand('rust-analyzer.parentModule', commands.parentModule.handle); |
@@ -62,10 +34,6 @@ export async function activate(context: vscode.ExtensionContext) { | |||
62 | // Unlike the above this does not send requests to the language server | 34 | // Unlike the above this does not send requests to the language server |
63 | registerCommand('rust-analyzer.runSingle', commands.runnables.handleSingle); | 35 | registerCommand('rust-analyzer.runSingle', commands.runnables.handleSingle); |
64 | registerCommand( | 36 | registerCommand( |
65 | 'rust-analyzer.applySourceChange', | ||
66 | commands.applySourceChange.handle, | ||
67 | ); | ||
68 | registerCommand( | ||
69 | 'rust-analyzer.showReferences', | 37 | 'rust-analyzer.showReferences', |
70 | (uri: string, position: lc.Position, locations: lc.Location[]) => { | 38 | (uri: string, position: lc.Position, locations: lc.Location[]) => { |
71 | vscode.commands.executeCommand( | 39 | vscode.commands.executeCommand( |
@@ -78,7 +46,7 @@ export async function activate(context: vscode.ExtensionContext) { | |||
78 | ); | 46 | ); |
79 | 47 | ||
80 | if (Server.config.enableEnhancedTyping) { | 48 | if (Server.config.enableEnhancedTyping) { |
81 | overrideCommand('type', commands.onEnter.handle); | 49 | ctx.overrideCommand('type', commands.onEnter); |
82 | } | 50 | } |
83 | 51 | ||
84 | const watchStatus = new StatusDisplay( | 52 | const watchStatus = new StatusDisplay( |
@@ -91,15 +59,15 @@ export async function activate(context: vscode.ExtensionContext) { | |||
91 | string, | 59 | string, |
92 | lc.GenericNotificationHandler, | 60 | lc.GenericNotificationHandler, |
93 | ]> = [ | 61 | ]> = [ |
94 | [ | 62 | [ |
95 | 'rust-analyzer/publishDecorations', | 63 | 'rust-analyzer/publishDecorations', |
96 | notifications.publishDecorations.handle, | 64 | notifications.publishDecorations.handle, |
97 | ], | 65 | ], |
98 | [ | 66 | [ |
99 | '$/progress', | 67 | '$/progress', |
100 | params => watchStatus.handleProgressNotification(params), | 68 | params => watchStatus.handleProgressNotification(params), |
101 | ], | 69 | ], |
102 | ]; | 70 | ]; |
103 | const syntaxTreeContentProvider = new SyntaxTreeContentProvider(); | 71 | const syntaxTreeContentProvider = new SyntaxTreeContentProvider(); |
104 | const expandMacroContentProvider = new ExpandMacroContentProvider(); | 72 | const expandMacroContentProvider = new ExpandMacroContentProvider(); |
105 | 73 | ||