@@ -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+
1921var PowerShellLanguageId = 'powershell' ;
2022var settings = settingsManager . load ( 'powershell' ) ;
2123
22- vscode . languages . setLanguageConfiguration ( PowerShellLanguageId ,
24+ vscode . languages . setLanguageConfiguration ( PowerShellLanguageId ,
2325{
2426wordPattern : / ( - ? \d * \. \d \w * ) | ( [ ^ \` \~ \! \@ \# \% \^ \& \* \( \) \= \+ \[ \{ \] \} \\ \| \; \' \" \, \. \< \> \/ \? \s ] + ) / g,
25-
27+
2628indentationRules : {
2729// ^(.*\*/)?\s*\ }.*$
2830decreaseIndentPattern : / ^ ( .* \* \/ ) ? \s * \} .* $ / ,
2931// ^.*\{[^}"']*$
3032increaseIndentPattern : / ^ .* \{ [ ^ } " ' ] * $ /
31- } ,
32-
33+ } ,
34+
3335comments : {
3436lineComment : '#' ,
3537blockComment : [ '<#' , '#>' ]
3638} ,
37-
39+
3840brackets : [
3941[ '{' , '}' ] ,
4042[ '[' , ']' ] ,
4143[ '(' , ')' ] ,
4244] ,
43-
45+
4446__electricCharacterSupport : {
4547brackets : [
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 : {
5456autoClosingPairs : [
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+
6466let args = [ ] ;
6567if ( settings . developer . editorServicesWaitForDebugger )
6668{
6769args . push ( '/waitForDebugger' ) ;
6870}
69-
71+
7072let serverPath = resolveLanguageServerPath ( settings ) ;
7173let serverOptions = {
72- run : {
74+ run : {
7375command : serverPath ,
74- args : args
76+ args : args
7577} ,
76- debug : {
78+ debug : {
7779command : serverPath ,
7880args : [ '/waitForDebugger' ]
7981}
@@ -87,33 +89,42 @@ export function activate(context: vscode.ExtensionContext): void {
8789}
8890}
8991
90- let client =
92+ languageServerClient =
9193new LanguageClient (
92- 'PowerShell Editor Services' ,
93- serverOptions ,
94+ 'PowerShell Editor Services' ,
95+ serverOptions ,
9496clientOptions ) ;
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 {
105116var editorServicesHostPath = settings . developer . editorServicesHostPath ;
106-
117+
107118if ( editorServicesHostPath )
108- {
119+ {
109120console . log ( "Found Editor Services path from config: " + editorServicesHostPath ) ;
110-
121+
111122// Make the path absolute if it's not
112123editorServicesHostPath =
113124path . resolve (
114125__dirname ,
115126editorServicesHostPath ) ;
116-
127+
117128console . log ( " Resolved path to: " + editorServicesHostPath ) ;
118129}
119130else
@@ -125,9 +136,9 @@ function resolveLanguageServerPath(settings: settingsManager.ISettings) : string
125136'..' ,
126137'bin' ,
127138'Microsoft.PowerShell.EditorServices.Host.exe' ) ;
128-
139+
129140console . log ( "Using default Editor Services path: " + editorServicesHostPath ) ;
130141}
131-
142+
132143return editorServicesHostPath ;
133144}
0 commit comments