11'use strict' ;
22
33import * as path from 'path' ;
4- import { getExecutablePath } from './executable' ;
4+ import { getExecutablePath } from './executable' ;
55
66import * as vscode from 'vscode' ;
77import {
@@ -27,9 +27,9 @@ import {
2727 LanguageClientOptions ,
2828 ServerOptions
2929} 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" ;
3333
3434function createLangServer ( ) : LanguageClient {
3535
@@ -53,16 +53,16 @@ function createLangServer(): LanguageClient {
5353 const clientOptions : LanguageClientOptions = {
5454 diagnosticCollectionName : "sourcery" ,
5555 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' }
6666 ] ,
6767 synchronize : {
6868 configurationSection : 'sourcery'
@@ -110,6 +110,11 @@ function registerNotifications(languageClient: LanguageClient, tree: ScanResultP
110110 commands . executeCommand ( command , ...args )
111111 } ) ;
112112
113+
114+ languageClient . onNotification ( 'sourcery/vscode/showSettings' , ( ) => {
115+ commands . executeCommand ( 'workbench.action.openSettings' , 'sourcery' ) ;
116+ } ) ;
117+
113118 languageClient . onNotification ( 'sourcery/vscode/scanResults' , ( params ) => {
114119 if ( params . diagnostics . length > 0 ) {
115120 tree . update ( params ) ;
@@ -139,7 +144,7 @@ function registerNotifications(languageClient: LanguageClient, tree: ScanResultP
139144function registerCommands ( context : ExtensionContext , riProvider : RuleInputProvider , languageClient : LanguageClient , tree : ScanResultProvider , treeView : TreeView < TreeItem > , hubWebviewPanel : WebviewPanel ) {
140145 context . subscriptions . push (
141146 vscode . window . registerWebviewViewProvider (
142- RuleInputProvider . viewType , riProvider , { webviewOptions : { retainContextWhenHidden : true } }
147+ RuleInputProvider . viewType , riProvider , { webviewOptions : { retainContextWhenHidden : true } }
143148 )
144149 ) ;
145150
@@ -162,21 +167,21 @@ function registerCommands(context: ExtensionContext, riProvider: RuleInputProvid
162167 const items = [ 'python' , 'javascript' ] ;
163168
164169 window . showQuickPick ( items , {
165- canPickMany : false ,
166- placeHolder : 'Select language'
170+ canPickMany : false ,
171+ placeHolder : 'Select language'
167172 } ) . then ( ( selected ) => {
168- riProvider . setLanguage ( selected ) ;
169- }
173+ riProvider . setLanguage ( selected ) ;
174+ }
170175 ) ;
171176
172177 } ) ) ;
173178
174179 // Enable/disable effects
175180 context . subscriptions . push (
176- commands . registerCommand ( 'sourcery.effects.enable' , ( ) => effects_set_enabled ( true ) )
181+ commands . registerCommand ( 'sourcery.effects.enable' , ( ) => effects_set_enabled ( true ) )
177182 ) ;
178183 context . subscriptions . push (
179- commands . registerCommand ( 'sourcery.effects.disable' , ( ) => effects_set_enabled ( false ) )
184+ commands . registerCommand ( 'sourcery.effects.disable' , ( ) => effects_set_enabled ( false ) )
180185 ) ;
181186 function effects_set_enabled ( enabled : boolean ) {
182187 vscode . commands . executeCommand ( 'setContext' , 'sourcery.effects.enabled' , enabled ) ;
@@ -215,10 +220,10 @@ function registerCommands(context: ExtensionContext, riProvider: RuleInputProvid
215220 'sourceryRulesActive' ,
216221 true ) ;
217222
218- vscode . commands . executeCommand ( "sourcery.rules.focus" ) . then ( ( ) => {
223+ vscode . commands . executeCommand ( "sourcery.rules.focus" ) . then ( ( ) => {
219224 const input = getValidInput ( ) ;
220225 riProvider . setPattern ( input ) ;
221- }
226+ }
222227 ) ;
223228 } ) ) ;
224229
@@ -240,28 +245,28 @@ function registerCommands(context: ExtensionContext, riProvider: RuleInputProvid
240245 context . subscriptions . push ( commands . registerCommand ( 'sourcery.rule.create' , ( rule , advanced : boolean , language : string ) => {
241246
242247 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)"
245250 } ) . 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+ } ) ;
262268 } ) ;
263- } ) ;
264- }
269+ }
265270 } ) ;
266271
267272 } ) ) ;
@@ -368,12 +373,12 @@ export function activate(context: ExtensionContext) {
368373 let tree = new ScanResultProvider ( ) ;
369374
370375 let treeView = vscode . window . createTreeView ( 'sourcery.rules.treeview' , {
371- treeDataProvider : tree
376+ treeDataProvider : tree
372377 } ) ;
373378
374379 const riProvider = new RuleInputProvider (
375380 context ,
376- ) ;
381+ ) ;
377382 registerCommands ( context , riProvider , languageClient , tree , treeView , hubWebviewPanel ) ;
378383
379384 showSourceryStatusBarItem ( context ) ;
@@ -384,12 +389,12 @@ export function activate(context: ExtensionContext) {
384389}
385390
386391function openWelcomeFile ( context : ExtensionContext ) {
387- openDocument ( path . join ( context . extensionPath , 'welcome-to-sourcery.py' ) ) ;
392+ openDocument ( path . join ( context . extensionPath , 'welcome-to-sourcery.py' ) ) ;
388393}
389394
390395function 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+ } ) ;
395400}
0 commit comments