6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
8
9
+ import * as fs from 'fs' ;
9
10
import * as path from 'path' ;
10
11
import * as vscode from 'vscode' ;
11
12
import * as lsp from 'vscode-languageclient' ;
@@ -17,35 +18,8 @@ export function activate(context: vscode.ExtensionContext) {
17
18
// If the extension is launched in debug mode then the debug server options are used
18
19
// Otherwise the run options are used
19
20
const serverOptions : lsp . ServerOptions = {
20
- run : {
21
- module : context . asAbsolutePath ( path . join ( 'server' ) ) ,
22
- transport : lsp . TransportKind . ipc ,
23
- args : constructArgs ( context , false /* debug */ ) ,
24
- options : {
25
- env : {
26
- // Force TypeScript to use the non-polling version of the file watchers.
27
- TSC_NONPOLLING_WATCHER : true ,
28
- } ,
29
- } ,
30
- } ,
31
- debug : {
32
- module : context . asAbsolutePath ( path . join ( 'server' , 'out' , 'server.js' ) ) ,
33
- transport : lsp . TransportKind . ipc ,
34
- args : constructArgs ( context , true /* debug */ ) ,
35
- options : {
36
- env : {
37
- // Force TypeScript to use the non-polling version of the file watchers.
38
- TSC_NONPOLLING_WATCHER : true ,
39
- NG_DEBUG : true ,
40
- } ,
41
- execArgv : [
42
- // do not lazily evaluate the code so all breakpoints are respected
43
- '--nolazy' ,
44
- // If debugging port is changed, update .vscode/launch.json as well
45
- '--inspect=6009' ,
46
- ]
47
- } ,
48
- } ,
21
+ run : getServerOptions ( context , false /* debug */ ) ,
22
+ debug : getServerOptions ( context , true /* debug */ ) ,
49
23
} ;
50
24
51
25
// Options to control the language client
@@ -171,3 +145,40 @@ function constructArgs(ctx: vscode.ExtensionContext, debug: boolean): string[] {
171
145
172
146
return args ;
173
147
}
148
+
149
+ function getServerOptions ( ctx : vscode . ExtensionContext , debug : boolean ) : lsp . NodeModule {
150
+ // Environment variables for server process
151
+ const prodEnv = {
152
+ // Force TypeScript to use the non-polling version of the file watchers.
153
+ TSC_NONPOLLING_WATCHER : true ,
154
+ } ;
155
+ const devEnv = {
156
+ ...prodEnv ,
157
+ NG_DEBUG : true ,
158
+ } ;
159
+
160
+ // Node module for the language server
161
+ const prodBundle = ctx . asAbsolutePath ( 'server' ) ;
162
+ const devBundle = ctx . asAbsolutePath ( path . join ( 'server' , 'out' , 'server.js' ) ) ;
163
+
164
+ // Argv options for Node.js
165
+ const prodExecArgv : string [ ] = [ ] ;
166
+ const devExecArgv : string [ ] = [
167
+ // do not lazily evaluate the code so all breakpoints are respected
168
+ '--nolazy' ,
169
+ // If debugging port is changed, update .vscode/launch.json as well
170
+ '--inspect=6009' ,
171
+ ] ;
172
+
173
+ return {
174
+ // VS Code Insider launches extensions in debug mode by default but users
175
+ // install prod bundle so we have to check whether dev bundle exists.
176
+ module : debug && fs . existsSync ( devBundle ) ? devBundle : prodBundle ,
177
+ transport : lsp . TransportKind . ipc ,
178
+ args : constructArgs ( ctx , debug ) ,
179
+ options : {
180
+ env : debug ? devEnv : prodEnv ,
181
+ execArgv : debug ? devExecArgv : prodExecArgv ,
182
+ } ,
183
+ } ;
184
+ }
0 commit comments