2 /* --------------------------------------------------------------------------------------------
3 * Copyright (c) Microsoft Corporation. All rights reserved.
4 * Licensed under the MIT License. See License.txt in the project root for license information.
5 * ------------------------------------------------------------------------------------------ */
6 /// <reference path="../../typings/thenable.d.ts" />
7 var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8 if (k2 === undefined) k2 = k;
9 Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
10 }) : (function(o, m, k, k2) {
11 if (k2 === undefined) k2 = k;
14 var __exportStar = (this && this.__exportStar) || function(m, exports) {
15 for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
17 Object.defineProperty(exports, "__esModule", { value: true });
18 exports.createConnection = exports.Files = void 0;
19 const Is = require("../common/utils/is");
20 const server_1 = require("../common/server");
21 const fm = require("./files");
22 const node_1 = require("vscode-languageserver-protocol/node");
23 __exportStar(require("vscode-languageserver-protocol/node"), exports);
24 __exportStar(require("../common/api"), exports);
27 Files.uriToFilePath = fm.uriToFilePath;
28 Files.resolveGlobalNodePath = fm.resolveGlobalNodePath;
29 Files.resolveGlobalYarnPath = fm.resolveGlobalYarnPath;
30 Files.resolve = fm.resolve;
31 Files.resolveModulePath = fm.resolveModulePath;
32 })(Files = exports.Files || (exports.Files = {}));
33 let _protocolConnection;
34 function endProtocolConnection() {
35 if (_protocolConnection === undefined) {
39 _protocolConnection.end();
42 // Ignore. The client process could have already
43 // did and we can't send an end into the connection.
46 let _shutdownReceived = false;
47 let exitTimer = undefined;
48 function setupExitTimer() {
49 const argName = '--clientProcessId';
50 function runTimer(value) {
52 let processId = parseInt(value);
53 if (!isNaN(processId)) {
54 exitTimer = setInterval(() => {
56 process.kill(processId, 0);
59 // Parent process doesn't exist anymore. Exit the server.
60 endProtocolConnection();
61 process.exit(_shutdownReceived ? 0 : 1);
70 for (let i = 2; i < process.argv.length; i++) {
71 let arg = process.argv[i];
72 if (arg === argName && i + 1 < process.argv.length) {
73 runTimer(process.argv[i + 1]);
77 let args = arg.split('=');
78 if (args[0] === argName) {
86 initialize: (params) => {
87 const processId = params.processId;
88 if (Is.number(processId) && exitTimer === undefined) {
89 // We received a parent process id. Set up a timer to periodically check
90 // if the parent is still alive.
93 process.kill(processId, 0);
96 // Parent process doesn't exist anymore. Exit the server.
97 process.exit(_shutdownReceived ? 0 : 1);
102 get shutdownReceived() {
103 return _shutdownReceived;
105 set shutdownReceived(value) {
106 _shutdownReceived = value;
109 endProtocolConnection();
113 function createConnection(arg1, arg2, arg3, arg4) {
118 if (arg1 !== void 0 && arg1.__brand === 'features') {
124 if (node_1.ConnectionStrategy.is(arg1) || node_1.ConnectionOptions.is(arg1)) {
132 return _createConnection(input, output, options, factories);
134 exports.createConnection = createConnection;
135 function _createConnection(input, output, options, factories) {
136 if (!input && !output && process.argv.length > 2) {
138 let pipeName = void 0;
139 let argv = process.argv.slice(2);
140 for (let i = 0; i < argv.length; i++) {
142 if (arg === '--node-ipc') {
143 input = new node_1.IPCMessageReader(process);
144 output = new node_1.IPCMessageWriter(process);
147 else if (arg === '--stdio') {
148 input = process.stdin;
149 output = process.stdout;
152 else if (arg === '--socket') {
153 port = parseInt(argv[i + 1]);
156 else if (arg === '--pipe') {
157 pipeName = argv[i + 1];
161 var args = arg.split('=');
162 if (args[0] === '--socket') {
163 port = parseInt(args[1]);
166 else if (args[0] === '--pipe') {
173 let transport = node_1.createServerSocketTransport(port);
174 input = transport[0];
175 output = transport[1];
178 let transport = node_1.createServerPipeTransport(pipeName);
179 input = transport[0];
180 output = transport[1];
183 var commandLineMessage = 'Use arguments of createConnection or set command line parameters: \'--node-ipc\', \'--stdio\' or \'--socket={number}\'';
185 throw new Error('Connection input stream is not set. ' + commandLineMessage);
188 throw new Error('Connection output stream is not set. ' + commandLineMessage);
190 // Backwards compatibility
191 if (Is.func(input.read) && Is.func(input.on)) {
192 let inputStream = input;
193 inputStream.on('end', () => {
194 endProtocolConnection();
195 process.exit(_shutdownReceived ? 0 : 1);
197 inputStream.on('close', () => {
198 endProtocolConnection();
199 process.exit(_shutdownReceived ? 0 : 1);
202 const connectionFactory = (logger) => {
203 const result = node_1.createProtocolConnection(input, output, logger, options);
206 return server_1.createConnection(connectionFactory, watchDog, factories);
208 //# sourceMappingURL=main.js.map