@atlaspack/lsp 2.14.2-unified-f165f7d09.0 → 2.14.3-dev-inline-requires-reuse-bdc9ca9c3.0
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 +7 -6
- package/src/LspServer.ts +8 -2
- package/tsconfig.json +2 -12
- 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.
|
|
3
|
+
"version": "2.14.3-dev-inline-requires-reuse-bdc9ca9c3.0",
|
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -10,17 +10,18 @@
|
|
|
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/types/LspServer.d.ts",
|
|
15
15
|
"scripts": {
|
|
16
16
|
"watch": "tsc -watch -p ./",
|
|
17
|
-
"lint": "eslint src --ext ts"
|
|
17
|
+
"lint": "eslint src --ext ts",
|
|
18
|
+
"build:lib": "gulp build --gulpfile ../../../gulpfile.js --cwd ."
|
|
18
19
|
},
|
|
19
20
|
"engines": {
|
|
20
21
|
"node": ">= 16.0.0"
|
|
21
22
|
},
|
|
22
23
|
"dependencies": {
|
|
23
|
-
"@atlaspack/lsp-protocol": "2.14.
|
|
24
|
+
"@atlaspack/lsp-protocol": "2.14.3-dev-inline-requires-reuse-bdc9ca9c3.0",
|
|
24
25
|
"@parcel/watcher": "^2.0.7",
|
|
25
26
|
"common-path-prefix": "^3.0.0",
|
|
26
27
|
"nullthrows": "^1.1.1",
|
|
@@ -40,5 +41,5 @@
|
|
|
40
41
|
"types": false
|
|
41
42
|
},
|
|
42
43
|
"type": "commonjs",
|
|
43
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "bdc9ca9c38f45155a6d6f280e343a29e3f030a83"
|
|
44
45
|
}
|
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": "../../../ts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AAA;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":"../../../../"}
|