@atlaspack/lsp 2.14.2-unified-f165f7d09.0 → 2.14.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/lib/LspServer.js +299 -210
- package/package.json +6 -7
- package/src/LspServer.ts +8 -2
- package/tsconfig.json +2 -12
- package/LICENSE +0 -201
- package/lib/LspServer.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @atlaspack/lsp
|
|
2
2
|
|
|
3
|
+
## 2.14.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#720](https://github.com/atlassian-labs/atlaspack/pull/720) [`d2fd849`](https://github.com/atlassian-labs/atlaspack/commit/d2fd849770fe6305e9c694bd97b1bd905abd9d94) Thanks [@alshdavid](https://github.com/alshdavid)! - Migrate to TypeScript
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`d2fd849`](https://github.com/atlassian-labs/atlaspack/commit/d2fd849770fe6305e9c694bd97b1bd905abd9d94)]:
|
|
10
|
+
- @atlaspack/lsp-protocol@2.14.2
|
|
11
|
+
|
|
3
12
|
## 2.14.1
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
package/lib/LspServer.js
CHANGED
|
@@ -1,240 +1,329 @@
|
|
|
1
|
-
|
|
2
|
-
var $cBkJy$fs = require("fs");
|
|
3
|
-
var $cBkJy$os = require("os");
|
|
4
|
-
var $cBkJy$vscodelanguageservernode = require("vscode-languageserver/node");
|
|
5
|
-
var $cBkJy$vscodejsonrpcnode = require("vscode-jsonrpc/node");
|
|
6
|
-
var $cBkJy$assert = require("assert");
|
|
7
|
-
var $cBkJy$url = require("url");
|
|
8
|
-
var $cBkJy$parcelwatcher = require("@parcel/watcher");
|
|
9
|
-
var $cBkJy$atlaspacklspprotocol = require("@atlaspack/lsp-protocol");
|
|
10
|
-
var $cBkJy$commonpathprefix = require("common-path-prefix");
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
"use strict";
|
|
20
2
|
|
|
3
|
+
function path() {
|
|
4
|
+
const data = _interopRequireWildcard(require("path"));
|
|
5
|
+
path = function () {
|
|
6
|
+
return data;
|
|
7
|
+
};
|
|
8
|
+
return data;
|
|
9
|
+
}
|
|
10
|
+
function fs() {
|
|
11
|
+
const data = _interopRequireWildcard(require("fs"));
|
|
12
|
+
fs = function () {
|
|
13
|
+
return data;
|
|
14
|
+
};
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
function os() {
|
|
18
|
+
const data = _interopRequireWildcard(require("os"));
|
|
19
|
+
os = function () {
|
|
20
|
+
return data;
|
|
21
|
+
};
|
|
22
|
+
return data;
|
|
23
|
+
}
|
|
24
|
+
function _node() {
|
|
25
|
+
const data = require("vscode-languageserver/node");
|
|
26
|
+
_node = function () {
|
|
27
|
+
return data;
|
|
28
|
+
};
|
|
29
|
+
return data;
|
|
30
|
+
}
|
|
31
|
+
function _node2() {
|
|
32
|
+
const data = require("vscode-jsonrpc/node");
|
|
33
|
+
_node2 = function () {
|
|
34
|
+
return data;
|
|
35
|
+
};
|
|
36
|
+
return data;
|
|
37
|
+
}
|
|
38
|
+
function invariant() {
|
|
39
|
+
const data = _interopRequireWildcard(require("assert"));
|
|
40
|
+
invariant = function () {
|
|
41
|
+
return data;
|
|
42
|
+
};
|
|
43
|
+
return data;
|
|
44
|
+
}
|
|
45
|
+
function url() {
|
|
46
|
+
const data = _interopRequireWildcard(require("url"));
|
|
47
|
+
url = function () {
|
|
48
|
+
return data;
|
|
49
|
+
};
|
|
50
|
+
return data;
|
|
51
|
+
}
|
|
52
|
+
function watcher() {
|
|
53
|
+
const data = _interopRequireWildcard(require("@parcel/watcher"));
|
|
54
|
+
watcher = function () {
|
|
55
|
+
return data;
|
|
56
|
+
};
|
|
57
|
+
return data;
|
|
58
|
+
}
|
|
59
|
+
function _lspProtocol() {
|
|
60
|
+
const data = require("@atlaspack/lsp-protocol");
|
|
61
|
+
_lspProtocol = function () {
|
|
62
|
+
return data;
|
|
63
|
+
};
|
|
64
|
+
return data;
|
|
65
|
+
}
|
|
66
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
67
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
68
|
+
// import {TextDocument} from 'vscode-languageserver-textdocument';
|
|
21
69
|
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
const
|
|
70
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
71
|
+
const commonPathPrefix = require('common-path-prefix');
|
|
72
|
+
const connection = (0, _node().createConnection)(_node().ProposedFeatures.all);
|
|
73
|
+
const WORKSPACE_ROOT = process.cwd();
|
|
74
|
+
const LSP_SENTINEL_FILENAME = 'lsp-server';
|
|
25
75
|
// Create a simple text document manager.
|
|
26
76
|
// const documents: TextDocuments<TextDocument> = new TextDocuments(TextDocument);
|
|
27
|
-
|
|
28
|
-
let
|
|
77
|
+
|
|
78
|
+
let hasConfigurationCapability = false;
|
|
79
|
+
let hasWorkspaceFolderCapability = false;
|
|
29
80
|
// let hasDiagnosticRelatedInformationCapability = false;
|
|
30
|
-
let
|
|
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
|
-
|
|
81
|
+
let hasDiagnosticsRefreshSupport = false;
|
|
82
|
+
connection.onInitialize(params => {
|
|
83
|
+
var _capabilities$workspa;
|
|
84
|
+
const capabilities = params.capabilities;
|
|
85
|
+
|
|
86
|
+
// Does the client support the `workspace/configuration` request?
|
|
87
|
+
// If not, we fall back using global settings.
|
|
88
|
+
hasConfigurationCapability = !!(capabilities.workspace && !!capabilities.workspace.configuration);
|
|
89
|
+
hasWorkspaceFolderCapability = !!(capabilities.workspace && !!capabilities.workspace.workspaceFolders);
|
|
90
|
+
// hasDiagnosticRelatedInformationCapability = !!(
|
|
91
|
+
// capabilities.textDocument &&
|
|
92
|
+
// capabilities.textDocument.publishDiagnostics &&
|
|
93
|
+
// capabilities.textDocument.publishDiagnostics.relatedInformation
|
|
94
|
+
// );
|
|
95
|
+
hasDiagnosticsRefreshSupport = Boolean((_capabilities$workspa = capabilities.workspace) === null || _capabilities$workspa === void 0 || (_capabilities$workspa = _capabilities$workspa.diagnostics) === null || _capabilities$workspa === void 0 ? void 0 : _capabilities$workspa.refreshSupport);
|
|
96
|
+
const result = {
|
|
97
|
+
capabilities: {
|
|
98
|
+
textDocumentSync: _node().TextDocumentSyncKind.Incremental,
|
|
99
|
+
// Tell the client that this server supports code completion.
|
|
100
|
+
diagnosticProvider: {
|
|
101
|
+
workspaceDiagnostics: false,
|
|
102
|
+
interFileDependencies: true
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
if (hasWorkspaceFolderCapability) {
|
|
107
|
+
result.capabilities.workspace = {
|
|
108
|
+
workspaceFolders: {
|
|
109
|
+
supported: true
|
|
110
|
+
}
|
|
57
111
|
};
|
|
58
|
-
|
|
112
|
+
}
|
|
113
|
+
return result;
|
|
59
114
|
});
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
115
|
+
connection.onInitialized(() => {
|
|
116
|
+
if (hasConfigurationCapability) {
|
|
117
|
+
// Register for all configuration changes.
|
|
118
|
+
connection.client.register(_node().DidChangeConfigurationNotification.type, undefined);
|
|
119
|
+
}
|
|
120
|
+
if (hasWorkspaceFolderCapability) {
|
|
121
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
122
|
+
connection.workspace.onDidChangeWorkspaceFolders(_event => {
|
|
123
|
+
connection.console.log('Workspace folder change event received.');
|
|
66
124
|
});
|
|
125
|
+
}
|
|
67
126
|
});
|
|
127
|
+
|
|
68
128
|
// Proxy
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
129
|
+
connection.onRequest(_lspProtocol().RequestImporters, async params => {
|
|
130
|
+
// @ts-expect-error TS2345
|
|
131
|
+
const client = findClient(params);
|
|
132
|
+
if (client) {
|
|
133
|
+
const result = await client.connection.sendRequest(_lspProtocol().RequestImporters, params);
|
|
134
|
+
return result;
|
|
135
|
+
}
|
|
136
|
+
return null;
|
|
76
137
|
});
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
138
|
+
connection.onRequest(_node().DocumentDiagnosticRequest.type, async params => {
|
|
139
|
+
const client = findClient(params.textDocument.uri);
|
|
140
|
+
let result;
|
|
141
|
+
if (client) {
|
|
142
|
+
// console.log(
|
|
143
|
+
// 'DocumentDiagnosticRequest',
|
|
144
|
+
// params.textDocument.uri,
|
|
145
|
+
// params.previousResultId === client.lastBuild,
|
|
146
|
+
// );
|
|
147
|
+
|
|
148
|
+
if (params.previousResultId === client.lastBuild) {
|
|
149
|
+
return {
|
|
150
|
+
kind: _node().DocumentDiagnosticReportKind.Unchanged,
|
|
151
|
+
resultId: client.lastBuild
|
|
152
|
+
};
|
|
92
153
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
items: result ?? []
|
|
97
|
-
};
|
|
98
|
-
});
|
|
99
|
-
$7ef283f05e7b48bf$var$connection.listen();
|
|
100
|
-
class $7ef283f05e7b48bf$var$ProgressReporter {
|
|
101
|
-
begin() {
|
|
102
|
-
this.progressReporterPromise = (async ()=>{
|
|
103
|
-
// eslint-disable-next-line prefer-const
|
|
104
|
-
let reporter = await $7ef283f05e7b48bf$var$connection.window.createWorkDoneProgress();
|
|
105
|
-
reporter.begin('Atlaspack');
|
|
106
|
-
return reporter;
|
|
107
|
-
})();
|
|
108
|
-
this.progressReporterPromise.then((reporter)=>{
|
|
109
|
-
if (this.lastMessage != null) reporter.report(this.lastMessage);
|
|
110
|
-
});
|
|
154
|
+
result = await client.connection.sendRequest(_lspProtocol().RequestDocumentDiagnostics, params.textDocument.uri);
|
|
155
|
+
if (result) {
|
|
156
|
+
client.uris.add(params.textDocument.uri);
|
|
111
157
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
158
|
+
}
|
|
159
|
+
return {
|
|
160
|
+
kind: _node().DocumentDiagnosticReportKind.Full,
|
|
161
|
+
resultId: client === null || client === void 0 ? void 0 : client.lastBuild,
|
|
162
|
+
// @ts-expect-error TS2740
|
|
163
|
+
items: result ?? []
|
|
164
|
+
};
|
|
165
|
+
});
|
|
166
|
+
connection.listen();
|
|
167
|
+
class ProgressReporter {
|
|
168
|
+
begin() {
|
|
169
|
+
this.progressReporterPromise = (async () => {
|
|
170
|
+
// eslint-disable-next-line prefer-const
|
|
171
|
+
let reporter = await connection.window.createWorkDoneProgress();
|
|
172
|
+
reporter.begin('Atlaspack');
|
|
173
|
+
return reporter;
|
|
174
|
+
})();
|
|
175
|
+
this.progressReporterPromise.then(reporter => {
|
|
176
|
+
if (this.lastMessage != null) {
|
|
177
|
+
reporter.report(this.lastMessage);
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
async done() {
|
|
182
|
+
if (this.progressReporterPromise == null) {
|
|
183
|
+
this.begin();
|
|
117
184
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
185
|
+
// @ts-expect-error TS2349
|
|
186
|
+
invariant()(this.progressReporterPromise != null);
|
|
187
|
+
// @ts-expect-error TS2533
|
|
188
|
+
(await this.progressReporterPromise).done();
|
|
189
|
+
this.progressReporterPromise = null;
|
|
190
|
+
}
|
|
191
|
+
async report(message) {
|
|
192
|
+
if (this.progressReporterPromise == null) {
|
|
193
|
+
this.lastMessage = message;
|
|
194
|
+
this.begin();
|
|
195
|
+
} else {
|
|
196
|
+
const r = await this.progressReporterPromise;
|
|
197
|
+
r.report(message);
|
|
126
198
|
}
|
|
199
|
+
}
|
|
127
200
|
}
|
|
128
|
-
function
|
|
129
|
-
|
|
201
|
+
function sendDiagnosticsRefresh() {
|
|
202
|
+
if (hasDiagnosticsRefreshSupport) {
|
|
203
|
+
connection.sendRequest(_node().DiagnosticRefreshRequest.type);
|
|
204
|
+
}
|
|
130
205
|
}
|
|
131
|
-
const
|
|
132
|
-
const
|
|
133
|
-
function
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
} else if (longestPrefix === prefix) // eslint-disable-next-line no-console
|
|
146
|
-
console.warn('Ambiguous client for ' + filepath);
|
|
206
|
+
const progressReporter = new ProgressReporter();
|
|
207
|
+
const clients = new Map();
|
|
208
|
+
function findClient(document) {
|
|
209
|
+
const filepath = url().fileURLToPath(document);
|
|
210
|
+
let longestPrefix = 0;
|
|
211
|
+
let bestClient;
|
|
212
|
+
for (const [, client] of clients) {
|
|
213
|
+
const prefix = commonPathPrefix([client.projectRoot, filepath]).length;
|
|
214
|
+
if (longestPrefix < prefix) {
|
|
215
|
+
longestPrefix = prefix;
|
|
216
|
+
bestClient = client;
|
|
217
|
+
} else if (longestPrefix === prefix) {
|
|
218
|
+
// eslint-disable-next-line no-console
|
|
219
|
+
console.warn('Ambiguous client for ' + filepath);
|
|
147
220
|
}
|
|
148
|
-
|
|
221
|
+
}
|
|
222
|
+
return bestClient;
|
|
149
223
|
}
|
|
150
|
-
function
|
|
151
|
-
|
|
152
|
-
|
|
224
|
+
function loadMetafile(filepath) {
|
|
225
|
+
const file = fs().readFileSync(filepath, 'utf-8');
|
|
226
|
+
return JSON.parse(file);
|
|
153
227
|
}
|
|
154
|
-
function
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
228
|
+
function createClient(metafilepath, metafile) {
|
|
229
|
+
const socketfilepath = metafilepath.slice(0, -5);
|
|
230
|
+
const [reader, writer] = (0, _node2().createServerPipeTransport)(socketfilepath);
|
|
231
|
+
const client = (0, _node2().createMessageConnection)(reader, writer);
|
|
232
|
+
client.listen();
|
|
233
|
+
const uris = new Set();
|
|
234
|
+
const result = {
|
|
235
|
+
connection: client,
|
|
236
|
+
uris,
|
|
237
|
+
projectRoot: metafile.projectRoot,
|
|
238
|
+
lastBuild: '0'
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
// @ts-expect-error TS7006
|
|
242
|
+
client.onNotification(_lspProtocol().NotificationBuildStatus, (state, message) => {
|
|
243
|
+
// console.log('got NotificationBuildStatus', state, message);
|
|
244
|
+
if (state === 'start') {
|
|
245
|
+
progressReporter.begin();
|
|
246
|
+
for (const uri of uris) {
|
|
247
|
+
connection.sendDiagnostics({
|
|
248
|
+
uri,
|
|
249
|
+
diagnostics: []
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
} else if (state === 'progress' && message != null) {
|
|
253
|
+
progressReporter.report(message);
|
|
254
|
+
} else if (state === 'end') {
|
|
255
|
+
result.lastBuild = String(Date.now());
|
|
256
|
+
sendDiagnosticsRefresh();
|
|
257
|
+
progressReporter.done();
|
|
258
|
+
connection.sendNotification(_lspProtocol().NotificationBuild);
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
// @ts-expect-error TS7006
|
|
263
|
+
client.onNotification(_lspProtocol().NotificationWorkspaceDiagnostics, diagnostics => {
|
|
264
|
+
// console.log('got NotificationWorkspaceDiagnostics', diagnostics);
|
|
265
|
+
for (const d of diagnostics) {
|
|
266
|
+
uris.add(d.uri);
|
|
267
|
+
connection.sendDiagnostics(d);
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
client.onClose(() => {
|
|
271
|
+
clients.delete(JSON.stringify(metafile));
|
|
272
|
+
sendDiagnosticsRefresh();
|
|
273
|
+
return Promise.all([...uris].map(uri => connection.sendDiagnostics({
|
|
274
|
+
uri,
|
|
275
|
+
diagnostics: []
|
|
276
|
+
})));
|
|
277
|
+
});
|
|
278
|
+
sendDiagnosticsRefresh();
|
|
279
|
+
clients.set(JSON.stringify(metafile), result);
|
|
201
280
|
}
|
|
281
|
+
|
|
202
282
|
// Take realpath because to have consistent cache keys on macOS (/var -> /private/var)
|
|
203
|
-
const
|
|
204
|
-
|
|
205
|
-
|
|
283
|
+
const BASEDIR = path().join(fs().realpathSync(os().tmpdir()), 'parcel-lsp');
|
|
284
|
+
fs().mkdirSync(BASEDIR, {
|
|
285
|
+
recursive: true
|
|
206
286
|
});
|
|
207
|
-
|
|
287
|
+
fs().writeFileSync(path().join(BASEDIR, LSP_SENTINEL_FILENAME), '');
|
|
288
|
+
|
|
208
289
|
// Search for currently running Atlaspack processes in the parcel-lsp dir.
|
|
209
290
|
// Create an IPC client connection for each running process.
|
|
210
|
-
for (const filename of
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
291
|
+
for (const filename of fs().readdirSync(BASEDIR)) {
|
|
292
|
+
if (!filename.endsWith('.json')) continue;
|
|
293
|
+
const filepath = path().join(BASEDIR, filename);
|
|
294
|
+
const contents = loadMetafile(filepath);
|
|
295
|
+
const {
|
|
296
|
+
projectRoot
|
|
297
|
+
} = contents;
|
|
298
|
+
if (WORKSPACE_ROOT === projectRoot) {
|
|
299
|
+
createClient(filepath, contents);
|
|
300
|
+
}
|
|
216
301
|
}
|
|
302
|
+
|
|
217
303
|
// Watch for new Atlaspack processes in the parcel-lsp dir, and disconnect the
|
|
218
304
|
// client for each corresponding connection when a Atlaspack process ends
|
|
219
305
|
// eslint-disable-next-line require-await
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
306
|
+
watcher().subscribe(BASEDIR, async (err, events) => {
|
|
307
|
+
if (err) {
|
|
308
|
+
throw err;
|
|
309
|
+
}
|
|
310
|
+
for (const event of events) {
|
|
311
|
+
if (event.type === 'create' && event.path.endsWith('.json')) {
|
|
312
|
+
const contents = loadMetafile(event.path);
|
|
313
|
+
const {
|
|
314
|
+
projectRoot
|
|
315
|
+
} = contents;
|
|
316
|
+
if (WORKSPACE_ROOT === projectRoot) {
|
|
317
|
+
createClient(event.path, contents);
|
|
318
|
+
}
|
|
319
|
+
} else if (event.type === 'delete' && event.path.endsWith('.json')) {
|
|
320
|
+
const existing = clients.get(event.path);
|
|
321
|
+
// eslint-disable-next-line no-console
|
|
322
|
+
console.log('existing', event.path, existing);
|
|
323
|
+
if (existing) {
|
|
324
|
+
clients.delete(event.path);
|
|
325
|
+
existing.connection.end();
|
|
326
|
+
}
|
|
236
327
|
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
//# sourceMappingURL=LspServer.js.map
|
|
328
|
+
}
|
|
329
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/lsp",
|
|
3
|
-
"version": "2.14.2
|
|
3
|
+
"version": "2.14.2",
|
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
"url": "https://github.com/atlassian-labs/atlaspack.git"
|
|
11
11
|
},
|
|
12
12
|
"main": "./lib/LspServer.js",
|
|
13
|
-
"source": "src/LspServer.ts",
|
|
14
|
-
"types": "
|
|
13
|
+
"source": "./src/LspServer.ts",
|
|
14
|
+
"types": "./lib/LspServer.d.ts",
|
|
15
15
|
"scripts": {
|
|
16
16
|
"watch": "tsc -watch -p ./",
|
|
17
17
|
"lint": "eslint src --ext ts"
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"node": ">= 16.0.0"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@atlaspack/lsp-protocol": "2.14.2
|
|
23
|
+
"@atlaspack/lsp-protocol": "2.14.2",
|
|
24
24
|
"@parcel/watcher": "^2.0.7",
|
|
25
25
|
"common-path-prefix": "^3.0.0",
|
|
26
26
|
"nullthrows": "^1.1.1",
|
|
@@ -39,6 +39,5 @@
|
|
|
39
39
|
"targets": {
|
|
40
40
|
"types": false
|
|
41
41
|
},
|
|
42
|
-
"type": "commonjs"
|
|
43
|
-
|
|
44
|
-
}
|
|
42
|
+
"type": "commonjs"
|
|
43
|
+
}
|
package/src/LspServer.ts
CHANGED
|
@@ -39,8 +39,8 @@ const commonPathPrefix = require('common-path-prefix');
|
|
|
39
39
|
|
|
40
40
|
type Metafile = {
|
|
41
41
|
projectRoot: string;
|
|
42
|
-
pid: typeof process['pid'];
|
|
43
|
-
argv: typeof process['argv'];
|
|
42
|
+
pid: (typeof process)['pid'];
|
|
43
|
+
argv: (typeof process)['argv'];
|
|
44
44
|
};
|
|
45
45
|
|
|
46
46
|
const connection = createConnection(ProposedFeatures.all);
|
|
@@ -113,6 +113,7 @@ connection.onInitialized(() => {
|
|
|
113
113
|
|
|
114
114
|
// Proxy
|
|
115
115
|
connection.onRequest(RequestImporters, async (params) => {
|
|
116
|
+
// @ts-expect-error TS2345
|
|
116
117
|
const client = findClient(params);
|
|
117
118
|
if (client) {
|
|
118
119
|
const result = await client.connection.sendRequest(
|
|
@@ -158,6 +159,7 @@ connection.onRequest(
|
|
|
158
159
|
return {
|
|
159
160
|
kind: DocumentDiagnosticReportKind.Full,
|
|
160
161
|
resultId: client?.lastBuild,
|
|
162
|
+
// @ts-expect-error TS2740
|
|
161
163
|
items: result ?? [],
|
|
162
164
|
};
|
|
163
165
|
},
|
|
@@ -185,7 +187,9 @@ class ProgressReporter {
|
|
|
185
187
|
if (this.progressReporterPromise == null) {
|
|
186
188
|
this.begin();
|
|
187
189
|
}
|
|
190
|
+
// @ts-expect-error TS2349
|
|
188
191
|
invariant(this.progressReporterPromise != null);
|
|
192
|
+
// @ts-expect-error TS2533
|
|
189
193
|
(await this.progressReporterPromise).done();
|
|
190
194
|
this.progressReporterPromise = null;
|
|
191
195
|
}
|
|
@@ -254,6 +258,7 @@ function createClient(metafilepath: string, metafile: Metafile) {
|
|
|
254
258
|
lastBuild: '0',
|
|
255
259
|
};
|
|
256
260
|
|
|
261
|
+
// @ts-expect-error TS7006
|
|
257
262
|
client.onNotification(NotificationBuildStatus, (state, message) => {
|
|
258
263
|
// console.log('got NotificationBuildStatus', state, message);
|
|
259
264
|
if (state === 'start') {
|
|
@@ -271,6 +276,7 @@ function createClient(metafilepath: string, metafile: Metafile) {
|
|
|
271
276
|
}
|
|
272
277
|
});
|
|
273
278
|
|
|
279
|
+
// @ts-expect-error TS7006
|
|
274
280
|
client.onNotification(NotificationWorkspaceDiagnostics, (diagnostics) => {
|
|
275
281
|
// console.log('got NotificationWorkspaceDiagnostics', diagnostics);
|
|
276
282
|
for (const d of diagnostics) {
|
package/tsconfig.json
CHANGED
|
@@ -1,14 +1,4 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
3
|
-
|
|
4
|
-
"target": "es6",
|
|
5
|
-
"outDir": "lib",
|
|
6
|
-
"lib": ["es6"],
|
|
7
|
-
"sourceMap": true,
|
|
8
|
-
"rootDir": "src",
|
|
9
|
-
"strict": true,
|
|
10
|
-
"allowJs": true
|
|
11
|
-
},
|
|
12
|
-
"include": ["src/*"],
|
|
13
|
-
"exclude": ["node_modules", ".vscode-test"]
|
|
2
|
+
"extends": "../../../tsconfig.json",
|
|
3
|
+
"include": ["src"]
|
|
14
4
|
}
|
package/LICENSE
DELETED
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
Apache License
|
|
2
|
-
Version 2.0, January 2004
|
|
3
|
-
http://www.apache.org/licenses/
|
|
4
|
-
|
|
5
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
-
|
|
7
|
-
1. Definitions.
|
|
8
|
-
|
|
9
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
-
|
|
12
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
-
the copyright owner that is granting the License.
|
|
14
|
-
|
|
15
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
-
other entities that control, are controlled by, or are under common
|
|
17
|
-
control with that entity. For the purposes of this definition,
|
|
18
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
-
direction or management of such entity, whether by contract or
|
|
20
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
-
|
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
-
exercising permissions granted by this License.
|
|
25
|
-
|
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
-
including but not limited to software source code, documentation
|
|
28
|
-
source, and configuration files.
|
|
29
|
-
|
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
|
31
|
-
transformation or translation of a Source form, including but
|
|
32
|
-
not limited to compiled object code, generated documentation,
|
|
33
|
-
and conversions to other media types.
|
|
34
|
-
|
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
-
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
-
(an example is provided in the Appendix below).
|
|
39
|
-
|
|
40
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
-
form, that is based on (or derived from) the Work and for which the
|
|
42
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
-
of this License, Derivative Works shall not include works that remain
|
|
45
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
-
the Work and Derivative Works thereof.
|
|
47
|
-
|
|
48
|
-
"Contribution" shall mean any work of authorship, including
|
|
49
|
-
the original version of the Work and any modifications or additions
|
|
50
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
-
means any form of electronic, verbal, or written communication sent
|
|
55
|
-
to the Licensor or its representatives, including but not limited to
|
|
56
|
-
communication on electronic mailing lists, source code control systems,
|
|
57
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
-
excluding communication that is conspicuously marked or otherwise
|
|
60
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
-
|
|
62
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
-
subsequently incorporated within the Work.
|
|
65
|
-
|
|
66
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
-
Work and such Derivative Works in Source or Object form.
|
|
72
|
-
|
|
73
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
-
(except as stated in this section) patent license to make, have made,
|
|
77
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
-
where such license applies only to those patent claims licensable
|
|
79
|
-
by such Contributor that are necessarily infringed by their
|
|
80
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
-
institute patent litigation against any entity (including a
|
|
83
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
-
or contributory patent infringement, then any patent licenses
|
|
86
|
-
granted to You under this License for that Work shall terminate
|
|
87
|
-
as of the date such litigation is filed.
|
|
88
|
-
|
|
89
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
-
modifications, and in Source or Object form, provided that You
|
|
92
|
-
meet the following conditions:
|
|
93
|
-
|
|
94
|
-
(a) You must give any other recipients of the Work or
|
|
95
|
-
Derivative Works a copy of this License; and
|
|
96
|
-
|
|
97
|
-
(b) You must cause any modified files to carry prominent notices
|
|
98
|
-
stating that You changed the files; and
|
|
99
|
-
|
|
100
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
-
that You distribute, all copyright, patent, trademark, and
|
|
102
|
-
attribution notices from the Source form of the Work,
|
|
103
|
-
excluding those notices that do not pertain to any part of
|
|
104
|
-
the Derivative Works; and
|
|
105
|
-
|
|
106
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
-
distribution, then any Derivative Works that You distribute must
|
|
108
|
-
include a readable copy of the attribution notices contained
|
|
109
|
-
within such NOTICE file, excluding those notices that do not
|
|
110
|
-
pertain to any part of the Derivative Works, in at least one
|
|
111
|
-
of the following places: within a NOTICE text file distributed
|
|
112
|
-
as part of the Derivative Works; within the Source form or
|
|
113
|
-
documentation, if provided along with the Derivative Works; or,
|
|
114
|
-
within a display generated by the Derivative Works, if and
|
|
115
|
-
wherever such third-party notices normally appear. The contents
|
|
116
|
-
of the NOTICE file are for informational purposes only and
|
|
117
|
-
do not modify the License. You may add Your own attribution
|
|
118
|
-
notices within Derivative Works that You distribute, alongside
|
|
119
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
-
that such additional attribution notices cannot be construed
|
|
121
|
-
as modifying the License.
|
|
122
|
-
|
|
123
|
-
You may add Your own copyright statement to Your modifications and
|
|
124
|
-
may provide additional or different license terms and conditions
|
|
125
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
-
the conditions stated in this License.
|
|
129
|
-
|
|
130
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
-
this License, without any additional terms or conditions.
|
|
134
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
-
the terms of any separate license agreement you may have executed
|
|
136
|
-
with Licensor regarding such Contributions.
|
|
137
|
-
|
|
138
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
-
except as required for reasonable and customary use in describing the
|
|
141
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
-
|
|
143
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
-
implied, including, without limitation, any warranties or conditions
|
|
148
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
-
appropriateness of using or redistributing the Work and assume any
|
|
151
|
-
risks associated with Your exercise of permissions under this License.
|
|
152
|
-
|
|
153
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
-
unless required by applicable law (such as deliberate and grossly
|
|
156
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
-
liable to You for damages, including any direct, indirect, special,
|
|
158
|
-
incidental, or consequential damages of any character arising as a
|
|
159
|
-
result of this License or out of the use or inability to use the
|
|
160
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
-
other commercial damages or losses), even if such Contributor
|
|
163
|
-
has been advised of the possibility of such damages.
|
|
164
|
-
|
|
165
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
-
or other liability obligations and/or rights consistent with this
|
|
169
|
-
License. However, in accepting such obligations, You may act only
|
|
170
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
-
defend, and hold each Contributor harmless for any liability
|
|
173
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
-
of your accepting any such warranty or additional liability.
|
|
175
|
-
|
|
176
|
-
END OF TERMS AND CONDITIONS
|
|
177
|
-
|
|
178
|
-
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
-
|
|
180
|
-
To apply the Apache License to your work, attach the following
|
|
181
|
-
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
-
replaced with your own identifying information. (Don't include
|
|
183
|
-
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
-
comment syntax for the file format. We also recommend that a
|
|
185
|
-
file or class name and description of purpose be included on the
|
|
186
|
-
same "printed page" as the copyright notice for easier
|
|
187
|
-
identification within third-party archives.
|
|
188
|
-
|
|
189
|
-
Copyright (c) 2024 Atlassian US., Inc.
|
|
190
|
-
|
|
191
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
-
you may not use this file except in compliance with the License.
|
|
193
|
-
You may obtain a copy of the License at
|
|
194
|
-
|
|
195
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
-
|
|
197
|
-
Unless required by applicable law or agreed to in writing, software
|
|
198
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
-
See the License for the specific language governing permissions and
|
|
201
|
-
limitations under the License.
|
package/lib/LspServer.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;;;;;AA6CA,MAAMkC,mCAAa/B,CAAAA,GAAAA,gDAAAA,EAAiBU,CAAAA,GAAAA,gDAAAA,EAAiBsB,GAAG;AACxD,MAAMC,uCAAiBJ,QAAQK,GAAG;AAClC,MAAMC,8CAAwB;AAC9B,yCAAA;AACA,kFAAA;AAEA,IAAIC,mDAA6B;AACjC,IAAIC,qDAA+B;AACnC,yDAAA;AACA,IAAIC,qDAA+B;AAEnCP,iCAAWQ,YAAY,CAAC,CAACC;IACvB,MAAMC,eAAeD,OAAOC,YAAY;IAExC,iEAAA;IACA,8CAAA;IACAL,mDAA6B,CAAC,CAC5BK,CAAAA,aAAaC,SAAS,IAAI,CAAC,CAACD,aAAaC,SAAS,CAACC,aAAa,AAAbA;IAErDN,qDAA+B,CAAC,CAC9BI,CAAAA,aAAaC,SAAS,IAAI,CAAC,CAACD,aAAaC,SAAS,CAACE,gBAAgB,AAAhBA;IAErD,kDAAA;IACA,iCAAA;IACA,oDAAA;IACA,oEAAA;IACA,KAAA;IACAN,qDAA+BO,QAC7BJ,aAAaC,SAAS,EAAEI,aAAaC;IAGvC,MAAMC,SAA2B;QAC/BP,cAAc;YACZQ,kBAAkBtC,CAAAA,GAAAA,oDAAAA,EAAqBuC,WAAW;YAClD,6DAAA;YACAC,oBAAoB;gBAClBC,sBAAsB;gBACtBC,uBAAuB;YACzB;QACF;IACF;IAEA,IAAIhB,oDACFW,OAAOP,YAAY,CAACC,SAAS,GAAG;QAC9BE,kBAAkB;YAChBU,WAAW;QACb;IACF;IAEF,OAAON;AACT;AAEA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,MAAMvF,IAAI,KAAK,YAAYuF,MAAMpJ,IAAI,CAAC+I,QAAQ,CAAC,UAAU;YAClE,MAAMM,WAAWlD,8BAAQmD,GAAG,CAACF,MAAMpJ,IAAI;YACvC,sCAAA;YACAiE,QAAQC,GAAG,CAAC,YAAYkF,MAAMpJ,IAAI,EAAEqJ;YACpC,IAAIA,UAAU;gBACZlD,8BAAQ+B,MAAM,CAACkB,MAAMpJ,IAAI;gBACzBqJ,SAASnH,UAAU,CAACqH,GAAG;YACzB;QACF;IACF;AACF","sources":["packages/utils/atlaspack-lsp/src/LspServer.ts"],"sourcesContent":["import * as path from 'path';\nimport * as fs from 'fs';\nimport * as os from 'os';\nimport {\n createConnection,\n DiagnosticRefreshRequest,\n DidChangeConfigurationNotification,\n DocumentDiagnosticParams,\n DocumentDiagnosticReport,\n DocumentDiagnosticReportKind,\n DocumentDiagnosticRequest,\n DocumentUri,\n InitializeParams,\n InitializeResult,\n ProposedFeatures,\n TextDocumentSyncKind,\n WorkDoneProgressServerReporter,\n} from 'vscode-languageserver/node';\n\nimport {\n createServerPipeTransport,\n createMessageConnection,\n MessageConnection,\n} from 'vscode-jsonrpc/node';\nimport * as invariant from 'assert';\nimport * as url from 'url';\n// import {TextDocument} from 'vscode-languageserver-textdocument';\nimport * as watcher from '@parcel/watcher';\nimport {\n NotificationBuild,\n NotificationBuildStatus,\n NotificationWorkspaceDiagnostics,\n RequestDocumentDiagnostics,\n RequestImporters,\n} from '@atlaspack/lsp-protocol';\n\n// eslint-disable-next-line @typescript-eslint/no-require-imports\nconst commonPathPrefix = require('common-path-prefix');\n\ntype Metafile = {\n projectRoot: string;\n pid: typeof process['pid'];\n argv: typeof process['argv'];\n};\n\nconst connection = createConnection(ProposedFeatures.all);\nconst WORKSPACE_ROOT = process.cwd();\nconst LSP_SENTINEL_FILENAME = 'lsp-server';\n// Create a simple text document manager.\n// const documents: TextDocuments<TextDocument> = new TextDocuments(TextDocument);\n\nlet hasConfigurationCapability = false;\nlet hasWorkspaceFolderCapability = false;\n// let hasDiagnosticRelatedInformationCapability = false;\nlet hasDiagnosticsRefreshSupport = false;\n\nconnection.onInitialize((params: InitializeParams) => {\n const capabilities = params.capabilities;\n\n // Does the client support the `workspace/configuration` request?\n // If not, we fall back using global settings.\n hasConfigurationCapability = !!(\n capabilities.workspace && !!capabilities.workspace.configuration\n );\n hasWorkspaceFolderCapability = !!(\n capabilities.workspace && !!capabilities.workspace.workspaceFolders\n );\n // hasDiagnosticRelatedInformationCapability = !!(\n // capabilities.textDocument &&\n // capabilities.textDocument.publishDiagnostics &&\n // capabilities.textDocument.publishDiagnostics.relatedInformation\n // );\n hasDiagnosticsRefreshSupport = Boolean(\n capabilities.workspace?.diagnostics?.refreshSupport,\n );\n\n const result: InitializeResult = {\n capabilities: {\n textDocumentSync: TextDocumentSyncKind.Incremental,\n // Tell the client that this server supports code completion.\n diagnosticProvider: {\n workspaceDiagnostics: false,\n interFileDependencies: true,\n },\n },\n };\n\n if (hasWorkspaceFolderCapability) {\n result.capabilities.workspace = {\n workspaceFolders: {\n supported: true,\n },\n };\n }\n return result;\n});\n\nconnection.onInitialized(() => {\n if (hasConfigurationCapability) {\n // Register for all configuration changes.\n connection.client.register(\n DidChangeConfigurationNotification.type,\n undefined,\n );\n }\n if (hasWorkspaceFolderCapability) {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n connection.workspace.onDidChangeWorkspaceFolders((_event) => {\n connection.console.log('Workspace folder change event received.');\n });\n }\n});\n\n// Proxy\nconnection.onRequest(RequestImporters, async (params) => {\n const client = findClient(params);\n if (client) {\n const result = await client.connection.sendRequest(\n RequestImporters,\n params,\n );\n return result;\n }\n return null;\n});\n\nconnection.onRequest(\n DocumentDiagnosticRequest.type,\n async (\n params: DocumentDiagnosticParams,\n ): Promise<DocumentDiagnosticReport> => {\n const client = findClient(params.textDocument.uri);\n let result;\n if (client) {\n // console.log(\n // 'DocumentDiagnosticRequest',\n // params.textDocument.uri,\n // params.previousResultId === client.lastBuild,\n // );\n\n if (params.previousResultId === client.lastBuild) {\n return {\n kind: DocumentDiagnosticReportKind.Unchanged,\n resultId: client.lastBuild,\n };\n }\n\n result = await client.connection.sendRequest(\n RequestDocumentDiagnostics,\n params.textDocument.uri,\n );\n\n if (result) {\n client.uris.add(params.textDocument.uri);\n }\n }\n\n return {\n kind: DocumentDiagnosticReportKind.Full,\n resultId: client?.lastBuild,\n items: result ?? [],\n };\n },\n);\n\nconnection.listen();\n\nclass ProgressReporter {\n progressReporterPromise?: Promise<WorkDoneProgressServerReporter> | null;\n lastMessage?: string;\n begin() {\n this.progressReporterPromise = (async () => {\n // eslint-disable-next-line prefer-const\n let reporter = await connection.window.createWorkDoneProgress();\n reporter.begin('Atlaspack');\n return reporter;\n })();\n this.progressReporterPromise.then((reporter) => {\n if (this.lastMessage != null) {\n reporter.report(this.lastMessage);\n }\n });\n }\n async done() {\n if (this.progressReporterPromise == null) {\n this.begin();\n }\n invariant(this.progressReporterPromise != null);\n (await this.progressReporterPromise).done();\n this.progressReporterPromise = null;\n }\n async report(message: string) {\n if (this.progressReporterPromise == null) {\n this.lastMessage = message;\n this.begin();\n } else {\n const r = await this.progressReporterPromise;\n r.report(message);\n }\n }\n}\n\nfunction sendDiagnosticsRefresh() {\n if (hasDiagnosticsRefreshSupport) {\n connection.sendRequest(DiagnosticRefreshRequest.type);\n }\n}\n\ntype Client = {\n connection: MessageConnection;\n projectRoot: string;\n uris: Set<DocumentUri>;\n lastBuild: string;\n};\n\nconst progressReporter = new ProgressReporter();\nconst clients: Map<string, Client> = new Map();\n\nfunction findClient(document: DocumentUri): Client | undefined {\n const filepath = url.fileURLToPath(document);\n\n let longestPrefix = 0;\n let bestClient;\n for (const [, client] of clients) {\n const prefix = commonPathPrefix([client.projectRoot, filepath]).length;\n if (longestPrefix < prefix) {\n longestPrefix = prefix;\n bestClient = client;\n } else if (longestPrefix === prefix) {\n // eslint-disable-next-line no-console\n console.warn('Ambiguous client for ' + filepath);\n }\n }\n return bestClient;\n}\n\nfunction loadMetafile(filepath: string) {\n const file = fs.readFileSync(filepath, 'utf-8');\n return JSON.parse(file);\n}\n\nfunction createClient(metafilepath: string, metafile: Metafile) {\n const socketfilepath = metafilepath.slice(0, -5);\n const [reader, writer] = createServerPipeTransport(socketfilepath);\n const client = createMessageConnection(reader, writer);\n client.listen();\n\n const uris = new Set<DocumentUri>();\n\n const result = {\n connection: client,\n uris,\n projectRoot: metafile.projectRoot,\n lastBuild: '0',\n };\n\n client.onNotification(NotificationBuildStatus, (state, message) => {\n // console.log('got NotificationBuildStatus', state, message);\n if (state === 'start') {\n progressReporter.begin();\n for (const uri of uris) {\n connection.sendDiagnostics({uri, diagnostics: []});\n }\n } else if (state === 'progress' && message != null) {\n progressReporter.report(message);\n } else if (state === 'end') {\n result.lastBuild = String(Date.now());\n sendDiagnosticsRefresh();\n progressReporter.done();\n connection.sendNotification(NotificationBuild);\n }\n });\n\n client.onNotification(NotificationWorkspaceDiagnostics, (diagnostics) => {\n // console.log('got NotificationWorkspaceDiagnostics', diagnostics);\n for (const d of diagnostics) {\n uris.add(d.uri);\n connection.sendDiagnostics(d);\n }\n });\n\n client.onClose(() => {\n clients.delete(JSON.stringify(metafile));\n sendDiagnosticsRefresh();\n return Promise.all(\n [...uris].map((uri) =>\n connection.sendDiagnostics({uri, diagnostics: []}),\n ),\n );\n });\n\n sendDiagnosticsRefresh();\n clients.set(JSON.stringify(metafile), result);\n}\n\n// Take realpath because to have consistent cache keys on macOS (/var -> /private/var)\nconst BASEDIR = path.join(fs.realpathSync(os.tmpdir()), 'parcel-lsp');\nfs.mkdirSync(BASEDIR, {recursive: true});\n\nfs.writeFileSync(path.join(BASEDIR, LSP_SENTINEL_FILENAME), '');\n\n// Search for currently running Atlaspack processes in the parcel-lsp dir.\n// Create an IPC client connection for each running process.\nfor (const filename of fs.readdirSync(BASEDIR)) {\n if (!filename.endsWith('.json')) continue;\n const filepath = path.join(BASEDIR, filename);\n const contents = loadMetafile(filepath);\n const {projectRoot} = contents;\n\n if (WORKSPACE_ROOT === projectRoot) {\n createClient(filepath, contents);\n }\n}\n\n// Watch for new Atlaspack processes in the parcel-lsp dir, and disconnect the\n// client for each corresponding connection when a Atlaspack process ends\n// eslint-disable-next-line require-await\nwatcher.subscribe(BASEDIR, async (err, events) => {\n if (err) {\n throw err;\n }\n\n for (const event of events) {\n if (event.type === 'create' && event.path.endsWith('.json')) {\n const contents = loadMetafile(event.path);\n const {projectRoot} = contents;\n\n if (WORKSPACE_ROOT === projectRoot) {\n createClient(event.path, contents);\n }\n } else if (event.type === 'delete' && event.path.endsWith('.json')) {\n const existing = clients.get(event.path);\n // eslint-disable-next-line no-console\n console.log('existing', event.path, existing);\n if (existing) {\n clients.delete(event.path);\n existing.connection.end();\n }\n }\n }\n});\n"],"names":["path","fs","os","createConnection","DiagnosticRefreshRequest","DidChangeConfigurationNotification","DocumentDiagnosticParams","DocumentDiagnosticReport","DocumentDiagnosticReportKind","DocumentDiagnosticRequest","DocumentUri","InitializeParams","InitializeResult","ProposedFeatures","TextDocumentSyncKind","WorkDoneProgressServerReporter","createServerPipeTransport","createMessageConnection","MessageConnection","invariant","url","watcher","NotificationBuild","NotificationBuildStatus","NotificationWorkspaceDiagnostics","RequestDocumentDiagnostics","RequestImporters","commonPathPrefix","require","Metafile","projectRoot","pid","process","argv","connection","all","WORKSPACE_ROOT","cwd","LSP_SENTINEL_FILENAME","hasConfigurationCapability","hasWorkspaceFolderCapability","hasDiagnosticsRefreshSupport","onInitialize","params","capabilities","workspace","configuration","workspaceFolders","Boolean","diagnostics","refreshSupport","result","textDocumentSync","Incremental","diagnosticProvider","workspaceDiagnostics","interFileDependencies","supported","onInitialized","client","register","type","undefined","onDidChangeWorkspaceFolders","_event","console","log","onRequest","findClient","sendRequest","Promise","textDocument","uri","previousResultId","lastBuild","kind","Unchanged","resultId","uris","add","Full","items","listen","ProgressReporter","begin","progressReporterPromise","reporter","window","createWorkDoneProgress","then","lastMessage","report","done","message","r","sendDiagnosticsRefresh","Client","Set","progressReporter","clients","Map","document","filepath","fileURLToPath","longestPrefix","bestClient","prefix","length","warn","loadMetafile","file","readFileSync","JSON","parse","createClient","metafilepath","metafile","socketfilepath","slice","reader","writer","onNotification","state","sendDiagnostics","String","Date","now","sendNotification","d","onClose","delete","stringify","map","set","BASEDIR","join","realpathSync","tmpdir","mkdirSync","recursive","writeFileSync","filename","readdirSync","endsWith","contents","subscribe","err","events","event","existing","get","end"],"version":3,"file":"LspServer.js.map","sourceRoot":"../../../../"}
|