-
Notifications
You must be signed in to change notification settings - Fork 116
/
server.ts
73 lines (61 loc) · 2.53 KB
/
server.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {version as tsServerVersion} from 'typescript/lib/tsserverlibrary';
import {generateHelpMessage, parseCommandLine} from './cmdline_utils';
// Parse command line arguments
const options = parseCommandLine(process.argv);
if (options.help) {
console.error(generateHelpMessage(process.argv));
process.exit(0);
}
import {createLogger} from './logger';
import {ServerHost} from './server_host';
import {Session} from './session';
import {resolveNgLangSvc, resolveTsServer} from './version_provider';
function main() {
// Create a logger that logs to file. OK to emit verbose entries.
const logger = createLogger({
logFile: options.logFile,
logVerbosity: options.logVerbosity,
});
const ts = resolveTsServer(options.tsProbeLocations, options.tsdk);
const ng = resolveNgLangSvc(options.ngProbeLocations);
const isG3 = ts.resolvedPath.includes('/google3/');
// ServerHost provides native OS functionality
const host = new ServerHost(isG3);
// Establish a new server session that encapsulates lsp connection.
const session = new Session({
host,
logger,
// TypeScript allows only package names as plugin names.
ngPlugin: '@angular/language-service',
resolvedNgLsPath: ng.resolvedPath,
logToConsole: options.logToConsole,
includeAutomaticOptionalChainCompletions: options.includeAutomaticOptionalChainCompletions,
includeCompletionsWithSnippetText: options.includeCompletionsWithSnippetText,
forceStrictTemplates: isG3 || options.forceStrictTemplates,
disableBlockSyntax: options.disableBlockSyntax,
disableLetSyntax: options.disableLetSyntax,
angularCoreVersion: options.angularCoreVersion ?? null,
suppressAngularDiagnosticCodes: options.suppressAngularDiagnosticCodes ?? null,
});
// Log initialization info
session.info(`Angular language server process ID: ${process.pid}`);
session.info(`Imported typescript/lib/tsserverlibrary is version ${tsServerVersion}.`);
session.info(`Using ${ng.name} v${ng.version} from ${ng.resolvedPath}`);
if (logger.loggingEnabled()) {
session.info(`Log file: ${logger.getLogFileName()}`);
} else {
session.info(`Logging is turned off. To enable, run command 'Open Angular server log'.`);
}
if (process.env.NG_DEBUG === 'true') {
session.info('Angular Language Service is running under DEBUG mode');
}
session.listen();
}
main();