forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.ts
More file actions
60 lines (52 loc) · 2.6 KB
/
server.ts
File metadata and controls
60 lines (52 loc) · 2.6 KB
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
import * as ts from "../typescript/typescript";
import {
StartInput,
} from "./common";
import {
initializeNodeSystem,
} from "./nodeServer";
function findArgumentStringArray(argName: string): readonly string[] {
const arg = ts.server.findArgument(argName);
if (arg === undefined) {
return ts.emptyArray;
}
return arg.split(",").filter(name => name !== "");
}
function start({ args, logger, cancellationToken, serverMode, unknownServerMode, startSession: startServer }: StartInput, platform: string) {
logger.info(`Starting TS Server`);
logger.info(`Version: ${ts.version}`);
logger.info(`Arguments: ${args.join(" ")}`);
logger.info(`Platform: ${platform} NodeVersion: ${process.version} CaseSensitive: ${ts.sys.useCaseSensitiveFileNames}`);
logger.info(`ServerMode: ${serverMode} hasUnknownServerMode: ${unknownServerMode}`);
ts.setStackTraceLimit();
if (ts.Debug.isDebugging) {
ts.Debug.enableDebugInfo();
}
if (ts.sys.tryEnableSourceMapsForHost && /^development$/i.test(ts.sys.getEnvironmentVariable("NODE_ENV"))) {
ts.sys.tryEnableSourceMapsForHost();
}
// Overwrites the current console messages to instead write to
// the log. This is so that language service plugins which use
// console.log don't break the message passing between tsserver
// and the client
console.log = (...args) => logger.msg(args.length === 1 ? args[0] : args.join(", "), ts.server.Msg.Info);
console.warn = (...args) => logger.msg(args.length === 1 ? args[0] : args.join(", "), ts.server.Msg.Err);
console.error = (...args) => logger.msg(args.length === 1 ? args[0] : args.join(", "), ts.server.Msg.Err);
startServer(
{
globalPlugins: findArgumentStringArray("--globalPlugins"),
pluginProbeLocations: findArgumentStringArray("--pluginProbeLocations"),
allowLocalPluginLoads: ts.server.hasArgument("--allowLocalPluginLoads"),
useSingleInferredProject: ts.server.hasArgument("--useSingleInferredProject"),
useInferredProjectPerProjectRoot: ts.server.hasArgument("--useInferredProjectPerProjectRoot"),
suppressDiagnosticEvents: ts.server.hasArgument("--suppressDiagnosticEvents"),
noGetErrOnBackgroundUpdate: ts.server.hasArgument("--noGetErrOnBackgroundUpdate"),
canUseWatchEvents: ts.server.hasArgument("--canUseWatchEvents"),
serverMode,
},
logger,
cancellationToken,
);
}
ts.setStackTraceLimit();
start(initializeNodeSystem(), require("os").platform());