@@ -14,66 +14,68 @@ import { registerExpandAliasCommand } from './features/ExpandAlias';
1414import { registerShowHelpCommand } from './features/ShowOnlineHelp' ;
1515import { registerConsoleCommands } from './features/Console' ;
1616
17+ var languageServerClient : LanguageClient = undefined ;
18+
1719export function activate ( context : vscode . ExtensionContext ) : void {
18-
20+
1921 var PowerShellLanguageId = 'powershell' ;
2022 var settings = settingsManager . load ( 'powershell' ) ;
2123
22- vscode . languages . setLanguageConfiguration ( PowerShellLanguageId ,
24+ vscode . languages . setLanguageConfiguration ( PowerShellLanguageId ,
2325 {
2426 wordPattern : / ( - ? \d * \. \d \w * ) | ( [ ^ \` \~ \! \@ \# \% \^ \& \* \( \) \= \+ \[ \{ \] \} \\ \| \; \' \" \, \. \< \> \/ \? \s ] + ) / g,
25-
27+
2628 indentationRules : {
2729 // ^(.*\*/)?\s*\ }.*$
2830 decreaseIndentPattern : / ^ ( .* \* \/ ) ? \s * \} .* $ / ,
2931 // ^.*\{[^}"']*$
3032 increaseIndentPattern : / ^ .* \{ [ ^ } " ' ] * $ /
31- } ,
32-
33+ } ,
34+
3335 comments : {
3436 lineComment : '#' ,
3537 blockComment : [ '<#' , '#>' ]
3638 } ,
37-
39+
3840 brackets : [
3941 [ '{' , '}' ] ,
4042 [ '[' , ']' ] ,
4143 [ '(' , ')' ] ,
4244 ] ,
43-
45+
4446 __electricCharacterSupport : {
4547 brackets : [
4648 { tokenType :'delimiter.curly.ts' , open : '{' , close : '}' , isElectric : true } ,
4749 { tokenType :'delimiter.square.ts' , open : '[' , close : ']' , isElectric : true } ,
4850 { tokenType :'delimiter.paren.ts' , open : '(' , close : ')' , isElectric : true }
4951 ] ,
50- docComment : { scope :'comment.documentation' , open :'/**' , lineStart :' * ' , close :' */' }
52+ docComment : { scope :'comment.documentation' , open :'/**' , lineStart :' * ' , close :' */' }
5153 } ,
52-
54+
5355 __characterPairSupport : {
5456 autoClosingPairs : [
5557 { open : '{' , close : '}' } ,
5658 { open : '[' , close : ']' } ,
5759 { open : '(' , close : ')' } ,
5860 { open : '"' , close : '"' , notIn : [ 'string' ] } ,
5961 { open : '\'' , close : '\'' , notIn : [ 'string' , 'comment' ] }
60- ]
62+ ]
6163 }
6264 } ) ;
63-
65+
6466 let args = [ ] ;
6567 if ( settings . developer . editorServicesWaitForDebugger )
6668 {
6769 args . push ( '/waitForDebugger' ) ;
6870 }
69-
71+
7072 let serverPath = resolveLanguageServerPath ( settings ) ;
7173 let serverOptions = {
72- run : {
74+ run : {
7375 command : serverPath ,
74- args : args
76+ args : args
7577 } ,
76- debug : {
78+ debug : {
7779 command : serverPath ,
7880 args : [ '/waitForDebugger' ]
7981 }
@@ -87,33 +89,42 @@ export function activate(context: vscode.ExtensionContext): void {
8789 }
8890 }
8991
90- let client =
92+ languageServerClient =
9193 new LanguageClient (
92- 'PowerShell Editor Services' ,
93- serverOptions ,
94+ 'PowerShell Editor Services' ,
95+ serverOptions ,
9496 clientOptions ) ;
95-
96- client . start ( ) ;
97+
98+ languageServerClient . start ( ) ;
9799
98100 // Register other features
99- registerExpandAliasCommand ( client ) ;
100- registerShowHelpCommand ( client ) ;
101- registerConsoleCommands ( client ) ;
101+ registerExpandAliasCommand ( languageServerClient ) ;
102+ registerShowHelpCommand ( languageServerClient ) ;
103+ registerConsoleCommands ( languageServerClient ) ;
104+ }
105+
106+ export function deactivate ( ) : void {
107+ if ( languageServerClient )
108+ {
109+ // Close the language server client
110+ languageServerClient . stop ( ) ;
111+ languageServerClient = undefined ;
112+ }
102113}
103114
104115function resolveLanguageServerPath ( settings : settingsManager . ISettings ) : string {
105116 var editorServicesHostPath = settings . developer . editorServicesHostPath ;
106-
117+
107118 if ( editorServicesHostPath )
108- {
119+ {
109120 console . log ( "Found Editor Services path from config: " + editorServicesHostPath ) ;
110-
121+
111122 // Make the path absolute if it's not
112123 editorServicesHostPath =
113124 path . resolve (
114125 __dirname ,
115126 editorServicesHostPath ) ;
116-
127+
117128 console . log ( " Resolved path to: " + editorServicesHostPath ) ;
118129 }
119130 else
@@ -125,9 +136,9 @@ function resolveLanguageServerPath(settings: settingsManager.ISettings) : string
125136 '..' ,
126137 'bin' ,
127138 'Microsoft.PowerShell.EditorServices.Host.exe' ) ;
128-
139+
129140 console . log ( "Using default Editor Services path: " + editorServicesHostPath ) ;
130141 }
131-
142+
132143 return editorServicesHostPath ;
133144}
0 commit comments