1
1
'use strict' ;
2
2
3
3
import * as path from 'path' ;
4
- import { getExecutablePath } from './executable' ;
4
+ import { getExecutablePath } from './executable' ;
5
5
6
6
import * as vscode from 'vscode' ;
7
7
import {
@@ -27,9 +27,9 @@ import {
27
27
LanguageClientOptions ,
28
28
ServerOptions
29
29
} from 'vscode-languageclient/node' ;
30
- import { getHubSrc } from './hub' ;
31
- import { RuleInputProvider } from "./rule-search"
32
- import { ScanResultProvider } from "./rule-search-results" ;
30
+ import { getHubSrc } from './hub' ;
31
+ import { RuleInputProvider } from "./rule-search"
32
+ import { ScanResultProvider } from "./rule-search-results" ;
33
33
34
34
function createLangServer ( ) : LanguageClient {
35
35
@@ -53,16 +53,16 @@ function createLangServer(): LanguageClient {
53
53
const clientOptions : LanguageClientOptions = {
54
54
diagnosticCollectionName : "sourcery" ,
55
55
documentSelector : [
56
- { language : 'python' , scheme : 'file' } ,
57
- { language : 'javascript' , scheme : 'file' } ,
58
- { language : 'typescript' , scheme : 'file' } ,
59
- { language : 'javascriptreact' , scheme : 'file' } ,
60
- { language : 'typescriptreact' , scheme : 'file' } ,
61
- { language : 'python' , scheme : 'untitled' } ,
62
- { language : 'python' , scheme : 'vscode-notebook-cell' } ,
63
- { language : 'yaml' , pattern : '**/.sourcery.yaml' } ,
64
- { language : 'yaml' , pattern : '**/sourcery.yaml' } ,
65
- { language : 'yaml' , pattern : '**/.sourcery/rules/*.yaml' }
56
+ { language : 'python' , scheme : 'file' } ,
57
+ { language : 'javascript' , scheme : 'file' } ,
58
+ { language : 'typescript' , scheme : 'file' } ,
59
+ { language : 'javascriptreact' , scheme : 'file' } ,
60
+ { language : 'typescriptreact' , scheme : 'file' } ,
61
+ { language : 'python' , scheme : 'untitled' } ,
62
+ { language : 'python' , scheme : 'vscode-notebook-cell' } ,
63
+ { language : 'yaml' , pattern : '**/.sourcery.yaml' } ,
64
+ { language : 'yaml' , pattern : '**/sourcery.yaml' } ,
65
+ { language : 'yaml' , pattern : '**/.sourcery/rules/*.yaml' }
66
66
] ,
67
67
synchronize : {
68
68
configurationSection : 'sourcery'
@@ -110,6 +110,11 @@ function registerNotifications(languageClient: LanguageClient, tree: ScanResultP
110
110
commands . executeCommand ( command , ...args )
111
111
} ) ;
112
112
113
+
114
+ languageClient . onNotification ( 'sourcery/vscode/showSettings' , ( ) => {
115
+ commands . executeCommand ( 'workbench.action.openSettings' , 'sourcery' ) ;
116
+ } ) ;
117
+
113
118
languageClient . onNotification ( 'sourcery/vscode/scanResults' , ( params ) => {
114
119
if ( params . diagnostics . length > 0 ) {
115
120
tree . update ( params ) ;
@@ -139,7 +144,7 @@ function registerNotifications(languageClient: LanguageClient, tree: ScanResultP
139
144
function registerCommands ( context : ExtensionContext , riProvider : RuleInputProvider , languageClient : LanguageClient , tree : ScanResultProvider , treeView : TreeView < TreeItem > , hubWebviewPanel : WebviewPanel ) {
140
145
context . subscriptions . push (
141
146
vscode . window . registerWebviewViewProvider (
142
- RuleInputProvider . viewType , riProvider , { webviewOptions : { retainContextWhenHidden : true } }
147
+ RuleInputProvider . viewType , riProvider , { webviewOptions : { retainContextWhenHidden : true } }
143
148
)
144
149
) ;
145
150
@@ -162,21 +167,21 @@ function registerCommands(context: ExtensionContext, riProvider: RuleInputProvid
162
167
const items = [ 'python' , 'javascript' ] ;
163
168
164
169
window . showQuickPick ( items , {
165
- canPickMany : false ,
166
- placeHolder : 'Select language'
170
+ canPickMany : false ,
171
+ placeHolder : 'Select language'
167
172
} ) . then ( ( selected ) => {
168
- riProvider . setLanguage ( selected ) ;
169
- }
173
+ riProvider . setLanguage ( selected ) ;
174
+ }
170
175
) ;
171
176
172
177
} ) ) ;
173
178
174
179
// Enable/disable effects
175
180
context . subscriptions . push (
176
- commands . registerCommand ( 'sourcery.effects.enable' , ( ) => effects_set_enabled ( true ) )
181
+ commands . registerCommand ( 'sourcery.effects.enable' , ( ) => effects_set_enabled ( true ) )
177
182
) ;
178
183
context . subscriptions . push (
179
- commands . registerCommand ( 'sourcery.effects.disable' , ( ) => effects_set_enabled ( false ) )
184
+ commands . registerCommand ( 'sourcery.effects.disable' , ( ) => effects_set_enabled ( false ) )
180
185
) ;
181
186
function effects_set_enabled ( enabled : boolean ) {
182
187
vscode . commands . executeCommand ( 'setContext' , 'sourcery.effects.enabled' , enabled ) ;
@@ -215,10 +220,10 @@ function registerCommands(context: ExtensionContext, riProvider: RuleInputProvid
215
220
'sourceryRulesActive' ,
216
221
true ) ;
217
222
218
- vscode . commands . executeCommand ( "sourcery.rules.focus" ) . then ( ( ) => {
223
+ vscode . commands . executeCommand ( "sourcery.rules.focus" ) . then ( ( ) => {
219
224
const input = getValidInput ( ) ;
220
225
riProvider . setPattern ( input ) ;
221
- }
226
+ }
222
227
) ;
223
228
} ) ) ;
224
229
@@ -240,28 +245,28 @@ function registerCommands(context: ExtensionContext, riProvider: RuleInputProvid
240
245
context . subscriptions . push ( commands . registerCommand ( 'sourcery.rule.create' , ( rule , advanced : boolean , language : string ) => {
241
246
242
247
vscode . window . showInputBox ( {
243
- title : "What would you like to call your rule?" ,
244
- prompt : "This should be lowercase, with words separated by hyphens (e.g. my-brilliant-rule)"
248
+ title : "What would you like to call your rule?" ,
249
+ prompt : "This should be lowercase, with words separated by hyphens (e.g. my-brilliant-rule)"
245
250
} ) . then ( ( name ) => {
246
- if ( name ) {
247
- let request : ExecuteCommandParams = {
248
- command : 'config/rule/create' ,
249
- arguments : [ {
250
- "rule_id" : name ,
251
- 'rule' : rule ,
252
- "inplace" : false ,
253
- 'advanced' : advanced ,
254
- "language" : language
255
- }
256
- ]
257
- } ;
258
- languageClient . sendRequest ( ExecuteCommandRequest . type , request ) . then ( ( result ) => {
259
- const openPath = Uri . file ( result ) ;
260
- workspace . openTextDocument ( openPath ) . then ( doc => {
261
- window . showTextDocument ( doc ) ;
251
+ if ( name ) {
252
+ let request : ExecuteCommandParams = {
253
+ command : 'config/rule/create' ,
254
+ arguments : [ {
255
+ "rule_id" : name ,
256
+ 'rule' : rule ,
257
+ "inplace" : false ,
258
+ 'advanced' : advanced ,
259
+ "language" : language
260
+ }
261
+ ]
262
+ } ;
263
+ languageClient . sendRequest ( ExecuteCommandRequest . type , request ) . then ( ( result ) => {
264
+ const openPath = Uri . file ( result ) ;
265
+ workspace . openTextDocument ( openPath ) . then ( doc => {
266
+ window . showTextDocument ( doc ) ;
267
+ } ) ;
262
268
} ) ;
263
- } ) ;
264
- }
269
+ }
265
270
} ) ;
266
271
267
272
} ) ) ;
@@ -368,12 +373,12 @@ export function activate(context: ExtensionContext) {
368
373
let tree = new ScanResultProvider ( ) ;
369
374
370
375
let treeView = vscode . window . createTreeView ( 'sourcery.rules.treeview' , {
371
- treeDataProvider : tree
376
+ treeDataProvider : tree
372
377
} ) ;
373
378
374
379
const riProvider = new RuleInputProvider (
375
380
context ,
376
- ) ;
381
+ ) ;
377
382
registerCommands ( context , riProvider , languageClient , tree , treeView , hubWebviewPanel ) ;
378
383
379
384
showSourceryStatusBarItem ( context ) ;
@@ -384,12 +389,12 @@ export function activate(context: ExtensionContext) {
384
389
}
385
390
386
391
function openWelcomeFile ( context : ExtensionContext ) {
387
- openDocument ( path . join ( context . extensionPath , 'welcome-to-sourcery.py' ) ) ;
392
+ openDocument ( path . join ( context . extensionPath , 'welcome-to-sourcery.py' ) ) ;
388
393
}
389
394
390
395
function openDocument ( document_path : string ) {
391
- const openPath = Uri . file ( document_path ) ;
392
- workspace . openTextDocument ( openPath ) . then ( doc => {
393
- window . showTextDocument ( doc ) ;
394
- } ) ;
396
+ const openPath = Uri . file ( document_path ) ;
397
+ workspace . openTextDocument ( openPath ) . then ( doc => {
398
+ window . showTextDocument ( doc ) ;
399
+ } ) ;
395
400
}
0 commit comments