66 * found in the LICENSE file at https://angular.io/license
77 */
88
9+ import { generateHelpMessage , parseCommandLine } from './cmdline_utils' ;
910import { createLogger } from './logger' ;
1011import { ServerHost } from './server_host' ;
1112import { Session } from './session' ;
1213import { resolveWithMinMajor } from './version_provider' ;
1314
1415// Parse command line arguments
15- const help = hasArgument ( '--help' ) ;
16- const logFile = findArgument ( '--logFile' ) ;
17- const logVerbosity = findArgument ( '--logVerbosity' ) ;
18- const ngProbeLocations = parseStringArray ( '--ngProbeLocations' ) ;
19- const tsProbeLocations = parseStringArray ( '--tsProbeLocations' ) ;
16+ const options = parseCommandLine ( process . argv ) ;
2017
21- if ( help ) {
22- const { argv} = process ;
23- console . error ( `Angular Language Service that implements the Language Server Protocol (LSP).
24-
25- Usage: ${ argv [ 0 ] } ${ argv [ 1 ] } [options]
26-
27- Options:
28- --help: Prints help message.
29- --logFile: Location to log messages. Logging is disabled if not provided.
30- --logVerbosity: terse|normal|verbose|requestTime. See ts.server.LogLevel.
31- --ngProbeLocations: Path of @angular/language-service. Required.
32- --tsProbeLocations: Path of typescript. Required.
33-
34- Additional options supported by vscode-languageserver:
35- --clientProcessId=<number>: Automatically kills the server if the client process dies.
36- --node-ipc: Communicate using Node's IPC. This is the default.
37- --stdio: Communicate over stdin/stdout.
38- --socket=<number>: Communicate using Unix socket.
39- ` ) ;
18+ if ( options . help ) {
19+ console . error ( generateHelpMessage ( process . argv ) ) ;
4020 process . exit ( 0 ) ;
4121}
4222
4323// Create a logger that logs to file. OK to emit verbose entries.
44- const logger = createLogger ( { logFile, logVerbosity} ) ;
24+ const logger = createLogger ( {
25+ logFile : options . logFile ,
26+ logVerbosity : options . logVerbosity ,
27+ } ) ;
4528
29+ const { tsProbeLocations, ngProbeLocations} = options ;
4630const ts = resolveWithMinMajor ( 'typescript' , 3 , tsProbeLocations ) ;
4731const ng = resolveWithMinMajor ( '@angular/language-service' , 9 , ngProbeLocations ) ;
4832
@@ -69,23 +53,3 @@ if (process.env.TSC_NONPOLLING_WATCHER !== 'true') {
6953}
7054
7155session . listen ( ) ;
72-
73- function hasArgument ( argName : string ) : boolean {
74- return process . argv . includes ( argName ) ;
75- }
76-
77- function findArgument ( argName : string ) : string | undefined {
78- const index = process . argv . indexOf ( argName ) ;
79- if ( index < 0 || index === process . argv . length - 1 ) {
80- return ;
81- }
82- return process . argv [ index + 1 ] ;
83- }
84-
85- function parseStringArray ( argName : string ) : string [ ] {
86- const arg = findArgument ( argName ) ;
87- if ( ! arg ) {
88- return [ ] ;
89- }
90- return arg . split ( ',' ) ;
91- }
0 commit comments