@atlaspack/lsp 2.12.1-dev.3367 → 2.12.1-dev.3398
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/lib/LspServer.js +80 -80
- package/lib/LspServer.js.map +1 -1
- package/package.json +4 -4
- package/src/LspServer.ts +3 -3
package/lib/LspServer.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
var $
|
|
2
|
-
var $
|
|
3
|
-
var $
|
|
4
|
-
var $
|
|
5
|
-
var $
|
|
6
|
-
var $
|
|
7
|
-
var $
|
|
8
|
-
var $
|
|
9
|
-
var $
|
|
10
|
-
var $
|
|
1
|
+
var $3Ux6k$path = require("path");
|
|
2
|
+
var $3Ux6k$fs = require("fs");
|
|
3
|
+
var $3Ux6k$os = require("os");
|
|
4
|
+
var $3Ux6k$vscodelanguageservernode = require("vscode-languageserver/node");
|
|
5
|
+
var $3Ux6k$vscodejsonrpcnode = require("vscode-jsonrpc/node");
|
|
6
|
+
var $3Ux6k$assert = require("assert");
|
|
7
|
+
var $3Ux6k$url = require("url");
|
|
8
|
+
var $3Ux6k$commonpathprefix = require("common-path-prefix");
|
|
9
|
+
var $3Ux6k$parcelwatcher = require("@parcel/watcher");
|
|
10
|
+
var $3Ux6k$atlaspacklspprotocol = require("@atlaspack/lsp-protocol");
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
@@ -19,30 +19,30 @@ var $jklcn$atlaspacklspprotocol = require("@atlaspack/lsp-protocol");
|
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
const $
|
|
23
|
-
const $
|
|
24
|
-
const $
|
|
22
|
+
const $e98bd035b97e3541$var$connection = (0, $3Ux6k$vscodelanguageservernode.createConnection)((0, $3Ux6k$vscodelanguageservernode.ProposedFeatures).all);
|
|
23
|
+
const $e98bd035b97e3541$var$WORKSPACE_ROOT = process.cwd();
|
|
24
|
+
const $e98bd035b97e3541$var$LSP_SENTINEL_FILENAME = 'lsp-server';
|
|
25
25
|
// Create a simple text document manager.
|
|
26
26
|
// const documents: TextDocuments<TextDocument> = new TextDocuments(TextDocument);
|
|
27
|
-
let $
|
|
28
|
-
let $
|
|
27
|
+
let $e98bd035b97e3541$var$hasConfigurationCapability = false;
|
|
28
|
+
let $e98bd035b97e3541$var$hasWorkspaceFolderCapability = false;
|
|
29
29
|
// let hasDiagnosticRelatedInformationCapability = false;
|
|
30
|
-
let $
|
|
31
|
-
$
|
|
30
|
+
let $e98bd035b97e3541$var$hasDiagnosticsRefreshSupport = false;
|
|
31
|
+
$e98bd035b97e3541$var$connection.onInitialize((params)=>{
|
|
32
32
|
const capabilities = params.capabilities;
|
|
33
33
|
// Does the client support the `workspace/configuration` request?
|
|
34
34
|
// If not, we fall back using global settings.
|
|
35
|
-
$
|
|
36
|
-
$
|
|
35
|
+
$e98bd035b97e3541$var$hasConfigurationCapability = !!(capabilities.workspace && !!capabilities.workspace.configuration);
|
|
36
|
+
$e98bd035b97e3541$var$hasWorkspaceFolderCapability = !!(capabilities.workspace && !!capabilities.workspace.workspaceFolders);
|
|
37
37
|
// hasDiagnosticRelatedInformationCapability = !!(
|
|
38
38
|
// capabilities.textDocument &&
|
|
39
39
|
// capabilities.textDocument.publishDiagnostics &&
|
|
40
40
|
// capabilities.textDocument.publishDiagnostics.relatedInformation
|
|
41
41
|
// );
|
|
42
|
-
$
|
|
42
|
+
$e98bd035b97e3541$var$hasDiagnosticsRefreshSupport = Boolean(capabilities.workspace?.diagnostics?.refreshSupport);
|
|
43
43
|
const result = {
|
|
44
44
|
capabilities: {
|
|
45
|
-
textDocumentSync: (0, $
|
|
45
|
+
textDocumentSync: (0, $3Ux6k$vscodelanguageservernode.TextDocumentSyncKind).Incremental,
|
|
46
46
|
// Tell the client that this server supports code completion.
|
|
47
47
|
diagnosticProvider: {
|
|
48
48
|
workspaceDiagnostics: false,
|
|
@@ -50,31 +50,31 @@ $3061828d162c6ca6$var$connection.onInitialize((params)=>{
|
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
};
|
|
53
|
-
if ($
|
|
53
|
+
if ($e98bd035b97e3541$var$hasWorkspaceFolderCapability) result.capabilities.workspace = {
|
|
54
54
|
workspaceFolders: {
|
|
55
55
|
supported: true
|
|
56
56
|
}
|
|
57
57
|
};
|
|
58
58
|
return result;
|
|
59
59
|
});
|
|
60
|
-
$
|
|
61
|
-
if ($
|
|
62
|
-
$
|
|
63
|
-
if ($
|
|
64
|
-
$
|
|
60
|
+
$e98bd035b97e3541$var$connection.onInitialized(()=>{
|
|
61
|
+
if ($e98bd035b97e3541$var$hasConfigurationCapability) // Register for all configuration changes.
|
|
62
|
+
$e98bd035b97e3541$var$connection.client.register((0, $3Ux6k$vscodelanguageservernode.DidChangeConfigurationNotification).type, undefined);
|
|
63
|
+
if ($e98bd035b97e3541$var$hasWorkspaceFolderCapability) $e98bd035b97e3541$var$connection.workspace.onDidChangeWorkspaceFolders(()=>{
|
|
64
|
+
$e98bd035b97e3541$var$connection.console.log('Workspace folder change event received.');
|
|
65
65
|
});
|
|
66
66
|
});
|
|
67
67
|
// Proxy
|
|
68
|
-
$
|
|
69
|
-
let client = $
|
|
68
|
+
$e98bd035b97e3541$var$connection.onRequest((0, $3Ux6k$atlaspacklspprotocol.RequestImporters), async (params)=>{
|
|
69
|
+
let client = $e98bd035b97e3541$var$findClient(params);
|
|
70
70
|
if (client) {
|
|
71
|
-
let result = await client.connection.sendRequest((0, $
|
|
71
|
+
let result = await client.connection.sendRequest((0, $3Ux6k$atlaspacklspprotocol.RequestImporters), params);
|
|
72
72
|
return result;
|
|
73
73
|
}
|
|
74
74
|
return null;
|
|
75
75
|
});
|
|
76
|
-
$
|
|
77
|
-
let client = $
|
|
76
|
+
$e98bd035b97e3541$var$connection.onRequest((0, $3Ux6k$vscodelanguageservernode.DocumentDiagnosticRequest).type, async (params)=>{
|
|
77
|
+
let client = $e98bd035b97e3541$var$findClient(params.textDocument.uri);
|
|
78
78
|
let result;
|
|
79
79
|
if (client) {
|
|
80
80
|
// console.log(
|
|
@@ -83,23 +83,23 @@ $3061828d162c6ca6$var$connection.onRequest((0, $jklcn$vscodelanguageservernode.D
|
|
|
83
83
|
// params.previousResultId === client.lastBuild,
|
|
84
84
|
// );
|
|
85
85
|
if (params.previousResultId === client.lastBuild) return {
|
|
86
|
-
kind: (0, $
|
|
86
|
+
kind: (0, $3Ux6k$vscodelanguageservernode.DocumentDiagnosticReportKind).Unchanged,
|
|
87
87
|
resultId: client.lastBuild
|
|
88
88
|
};
|
|
89
|
-
result = await client.connection.sendRequest((0, $
|
|
89
|
+
result = await client.connection.sendRequest((0, $3Ux6k$atlaspacklspprotocol.RequestDocumentDiagnostics), params.textDocument.uri);
|
|
90
90
|
if (result) client.uris.add(params.textDocument.uri);
|
|
91
91
|
}
|
|
92
92
|
return {
|
|
93
|
-
kind: (0, $
|
|
93
|
+
kind: (0, $3Ux6k$vscodelanguageservernode.DocumentDiagnosticReportKind).Full,
|
|
94
94
|
resultId: client?.lastBuild,
|
|
95
95
|
items: result ?? []
|
|
96
96
|
};
|
|
97
97
|
});
|
|
98
|
-
$
|
|
99
|
-
class $
|
|
98
|
+
$e98bd035b97e3541$var$connection.listen();
|
|
99
|
+
class $e98bd035b97e3541$var$ProgressReporter {
|
|
100
100
|
begin() {
|
|
101
101
|
this.progressReporterPromise = (async ()=>{
|
|
102
|
-
let reporter = await $
|
|
102
|
+
let reporter = await $e98bd035b97e3541$var$connection.window.createWorkDoneProgress();
|
|
103
103
|
reporter.begin('Atlaspack');
|
|
104
104
|
return reporter;
|
|
105
105
|
})();
|
|
@@ -109,7 +109,7 @@ class $3061828d162c6ca6$var$ProgressReporter {
|
|
|
109
109
|
}
|
|
110
110
|
async done() {
|
|
111
111
|
if (this.progressReporterPromise == null) this.begin();
|
|
112
|
-
$
|
|
112
|
+
$3Ux6k$assert(this.progressReporterPromise != null);
|
|
113
113
|
(await this.progressReporterPromise).done();
|
|
114
114
|
this.progressReporterPromise = null;
|
|
115
115
|
}
|
|
@@ -123,17 +123,17 @@ class $3061828d162c6ca6$var$ProgressReporter {
|
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
|
-
function $
|
|
127
|
-
if ($
|
|
126
|
+
function $e98bd035b97e3541$var$sendDiagnosticsRefresh() {
|
|
127
|
+
if ($e98bd035b97e3541$var$hasDiagnosticsRefreshSupport) $e98bd035b97e3541$var$connection.sendRequest((0, $3Ux6k$vscodelanguageservernode.DiagnosticRefreshRequest).type);
|
|
128
128
|
}
|
|
129
|
-
let $
|
|
130
|
-
let $
|
|
131
|
-
function $
|
|
132
|
-
let filepath = $
|
|
129
|
+
let $e98bd035b97e3541$var$progressReporter = new $e98bd035b97e3541$var$ProgressReporter();
|
|
130
|
+
let $e98bd035b97e3541$var$clients = new Map();
|
|
131
|
+
function $e98bd035b97e3541$var$findClient(document) {
|
|
132
|
+
let filepath = $3Ux6k$url.fileURLToPath(document);
|
|
133
133
|
let longestPrefix = 0;
|
|
134
134
|
let bestClient;
|
|
135
|
-
for (let [, client] of $
|
|
136
|
-
let prefix = $
|
|
135
|
+
for (let [, client] of $e98bd035b97e3541$var$clients){
|
|
136
|
+
let prefix = $3Ux6k$commonpathprefix([
|
|
137
137
|
client.projectRoot,
|
|
138
138
|
filepath
|
|
139
139
|
]).length;
|
|
@@ -144,14 +144,14 @@ function $3061828d162c6ca6$var$findClient(document) {
|
|
|
144
144
|
}
|
|
145
145
|
return bestClient;
|
|
146
146
|
}
|
|
147
|
-
function $
|
|
148
|
-
const file = $
|
|
147
|
+
function $e98bd035b97e3541$var$loadMetafile(filepath) {
|
|
148
|
+
const file = $3Ux6k$fs.readFileSync(filepath, 'utf-8');
|
|
149
149
|
return JSON.parse(file);
|
|
150
150
|
}
|
|
151
|
-
function $
|
|
151
|
+
function $e98bd035b97e3541$var$createClient(metafilepath, metafile) {
|
|
152
152
|
let socketfilepath = metafilepath.slice(0, -5);
|
|
153
|
-
let [reader, writer] = (0, $
|
|
154
|
-
let client = (0, $
|
|
153
|
+
let [reader, writer] = (0, $3Ux6k$vscodejsonrpcnode.createServerPipeTransport)(socketfilepath);
|
|
154
|
+
let client = (0, $3Ux6k$vscodejsonrpcnode.createMessageConnection)(reader, writer);
|
|
155
155
|
client.listen();
|
|
156
156
|
let uris = new Set();
|
|
157
157
|
let result = {
|
|
@@ -160,71 +160,71 @@ function $3061828d162c6ca6$var$createClient(metafilepath, metafile) {
|
|
|
160
160
|
projectRoot: metafile.projectRoot,
|
|
161
161
|
lastBuild: '0'
|
|
162
162
|
};
|
|
163
|
-
client.onNotification((0, $
|
|
163
|
+
client.onNotification((0, $3Ux6k$atlaspacklspprotocol.NotificationBuildStatus), (state, message)=>{
|
|
164
164
|
// console.log('got NotificationBuildStatus', state, message);
|
|
165
165
|
if (state === 'start') {
|
|
166
|
-
$
|
|
167
|
-
for (let uri of uris)$
|
|
166
|
+
$e98bd035b97e3541$var$progressReporter.begin();
|
|
167
|
+
for (let uri of uris)$e98bd035b97e3541$var$connection.sendDiagnostics({
|
|
168
168
|
uri: uri,
|
|
169
169
|
diagnostics: []
|
|
170
170
|
});
|
|
171
|
-
} else if (state === 'progress' && message != null) $
|
|
171
|
+
} else if (state === 'progress' && message != null) $e98bd035b97e3541$var$progressReporter.report(message);
|
|
172
172
|
else if (state === 'end') {
|
|
173
173
|
result.lastBuild = String(Date.now());
|
|
174
|
-
$
|
|
175
|
-
$
|
|
176
|
-
$
|
|
174
|
+
$e98bd035b97e3541$var$sendDiagnosticsRefresh();
|
|
175
|
+
$e98bd035b97e3541$var$progressReporter.done();
|
|
176
|
+
$e98bd035b97e3541$var$connection.sendNotification((0, $3Ux6k$atlaspacklspprotocol.NotificationBuild));
|
|
177
177
|
}
|
|
178
178
|
});
|
|
179
|
-
client.onNotification((0, $
|
|
179
|
+
client.onNotification((0, $3Ux6k$atlaspacklspprotocol.NotificationWorkspaceDiagnostics), (diagnostics)=>{
|
|
180
180
|
// console.log('got NotificationWorkspaceDiagnostics', diagnostics);
|
|
181
181
|
for (let d of diagnostics){
|
|
182
182
|
uris.add(d.uri);
|
|
183
|
-
$
|
|
183
|
+
$e98bd035b97e3541$var$connection.sendDiagnostics(d);
|
|
184
184
|
}
|
|
185
185
|
});
|
|
186
186
|
client.onClose(()=>{
|
|
187
|
-
$
|
|
188
|
-
$
|
|
187
|
+
$e98bd035b97e3541$var$clients.delete(JSON.stringify(metafile));
|
|
188
|
+
$e98bd035b97e3541$var$sendDiagnosticsRefresh();
|
|
189
189
|
return Promise.all([
|
|
190
190
|
...uris
|
|
191
|
-
].map((uri)=>$
|
|
191
|
+
].map((uri)=>$e98bd035b97e3541$var$connection.sendDiagnostics({
|
|
192
192
|
uri: uri,
|
|
193
193
|
diagnostics: []
|
|
194
194
|
})));
|
|
195
195
|
});
|
|
196
|
-
$
|
|
197
|
-
$
|
|
196
|
+
$e98bd035b97e3541$var$sendDiagnosticsRefresh();
|
|
197
|
+
$e98bd035b97e3541$var$clients.set(JSON.stringify(metafile), result);
|
|
198
198
|
}
|
|
199
199
|
// Take realpath because to have consistent cache keys on macOS (/var -> /private/var)
|
|
200
|
-
const $
|
|
201
|
-
$
|
|
200
|
+
const $e98bd035b97e3541$var$BASEDIR = $3Ux6k$path.join($3Ux6k$fs.realpathSync($3Ux6k$os.tmpdir()), 'parcel-lsp');
|
|
201
|
+
$3Ux6k$fs.mkdirSync($e98bd035b97e3541$var$BASEDIR, {
|
|
202
202
|
recursive: true
|
|
203
203
|
});
|
|
204
|
-
$
|
|
205
|
-
// Search for currently running Atlaspack processes in the
|
|
204
|
+
$3Ux6k$fs.writeFileSync($3Ux6k$path.join($e98bd035b97e3541$var$BASEDIR, $e98bd035b97e3541$var$LSP_SENTINEL_FILENAME), '');
|
|
205
|
+
// Search for currently running Atlaspack processes in the parcel-lsp dir.
|
|
206
206
|
// Create an IPC client connection for each running process.
|
|
207
|
-
for (let filename of $
|
|
207
|
+
for (let filename of $3Ux6k$fs.readdirSync($e98bd035b97e3541$var$BASEDIR)){
|
|
208
208
|
if (!filename.endsWith('.json')) continue;
|
|
209
|
-
let filepath = $
|
|
210
|
-
const contents = $
|
|
209
|
+
let filepath = $3Ux6k$path.join($e98bd035b97e3541$var$BASEDIR, filename);
|
|
210
|
+
const contents = $e98bd035b97e3541$var$loadMetafile(filepath);
|
|
211
211
|
const { projectRoot: projectRoot } = contents;
|
|
212
|
-
if ($
|
|
212
|
+
if ($e98bd035b97e3541$var$WORKSPACE_ROOT === projectRoot) $e98bd035b97e3541$var$createClient(filepath, contents);
|
|
213
213
|
}
|
|
214
|
-
// Watch for new Atlaspack processes in the
|
|
214
|
+
// Watch for new Atlaspack processes in the parcel-lsp dir, and disconnect the
|
|
215
215
|
// client for each corresponding connection when a Atlaspack process ends
|
|
216
|
-
$
|
|
216
|
+
$3Ux6k$parcelwatcher.subscribe($e98bd035b97e3541$var$BASEDIR, async (err, events)=>{
|
|
217
217
|
if (err) throw err;
|
|
218
218
|
for (let event of events){
|
|
219
219
|
if (event.type === 'create' && event.path.endsWith('.json')) {
|
|
220
|
-
const contents = $
|
|
220
|
+
const contents = $e98bd035b97e3541$var$loadMetafile(event.path);
|
|
221
221
|
const { projectRoot: projectRoot } = contents;
|
|
222
|
-
if ($
|
|
222
|
+
if ($e98bd035b97e3541$var$WORKSPACE_ROOT === projectRoot) $e98bd035b97e3541$var$createClient(event.path, contents);
|
|
223
223
|
} else if (event.type === 'delete' && event.path.endsWith('.json')) {
|
|
224
|
-
let existing = $
|
|
224
|
+
let existing = $e98bd035b97e3541$var$clients.get(event.path);
|
|
225
225
|
console.log('existing', event.path, existing);
|
|
226
226
|
if (existing) {
|
|
227
|
-
$
|
|
227
|
+
$e98bd035b97e3541$var$clients.delete(event.path);
|
|
228
228
|
existing.connection.end();
|
|
229
229
|
}
|
|
230
230
|
}
|
package/lib/LspServer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;;;;;AA4CA,MAAMiC,mCAAa9B,CA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ourcesContent":["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';\nimport commonPathPrefix = require('common-path-prefix');\n\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\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 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 let client = findClient(params);\n if (client) {\n let result = await client.connection.sendRequest(RequestImporters, params);\n return result;\n }\n return null;\n});\n\nconnection.onRequest(\n DocumentDiagnosticRequest.type,\n async (\n params: DocumentDiagnosticParams,\n ): Promise<DocumentDiagnosticReport> => {\n let 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 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 let 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\nlet progressReporter = new ProgressReporter();\nlet clients: Map<string, Client> = new Map();\n\nfunction findClient(document: DocumentUri): Client | undefined {\n let filepath = url.fileURLToPath(document);\n\n let longestPrefix = 0;\n let bestClient;\n for (let [, client] of clients) {\n let prefix = commonPathPrefix([client.projectRoot, filepath]).length;\n if (longestPrefix < prefix) {\n longestPrefix = prefix;\n bestClient = client;\n } else if (longestPrefix === prefix) {\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 let socketfilepath = metafilepath.slice(0, -5);\n let [reader, writer] = createServerPipeTransport(socketfilepath);\n let client = createMessageConnection(reader, writer);\n client.listen();\n\n let uris = new Set<DocumentUri>();\n\n let 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 (let 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 (let 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 => connection.sendDiagnostics({uri, diagnostics: []})),\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()), 'atlaspack-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 atlaspack-lsp dir.\n// Create an IPC client connection for each running process.\nfor (let filename of fs.readdirSync(BASEDIR)) {\n if (!filename.endsWith('.json')) continue;\n let 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 atlaspack-lsp dir, and disconnect the\n// client for each corresponding connection when a Atlaspack process ends\nwatcher.subscribe(BASEDIR, async (err, events) => {\n if (err) {\n throw err;\n }\n\n for (let 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 let existing = clients.get(event.path);\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","commonPathPrefix","watcher","NotificationBuild","NotificationBuildStatus","NotificationWorkspaceDiagnostics","RequestDocumentDiagnostics","RequestImporters","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","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":"../../../../"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;;;;AA4CA,MAAMiC,mCAAa9B,CAAAA,GAAAA,gDAAAA,EAAiBU,CAAAA,GAAAA,gDAAAA,EAAiBqB,GAAG;AACxD,MAAMC,uCAAiBJ,QAAQK,GAAG;AAClC,MAAMC,8CAAwB;AAC9B,yCAAA;AACA,kFAAA;AAE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AAI;AAEtCxI,wBAAiBD,iBAAUoI,+BAAS/F,8CAAwB;AAE5D,0EAAA;AACA,4DAAA;AACA,KAAK,IAAIsG,YAAY1I,sBAAemI,+BAAU;IAC5C,IAAI,CAACO,SAASE,QAAQ,CAAC,UAAU;IACjC,IAAIzC,WAAWpG,iBAAUoI,+BAASO;IAClC,MAAMG,WAAWnC,mCAAaP;IAC9B,MAAM,eAACvE,WAAAA,EAAY,GAAGiH;IAEtB,IAAI3G,yCAAmBN,aACrBmF,mCAAaZ,UAAU0C;AAE3B;AAEA,8EAAA;AACA,yEAAA;AACAxH,+BAAkB8G,+BAAS,OAAOY,KAAKC;IACrC,IAAID,KACF,MAAMA;IAGR,KAAK,IAAIE,SAASD,OAAQ;QACxB,IAAIC,MAAMtF,IAAI,KAAK,YAAYsF,MAAMlJ,IAAI,CAAC6I,QAAQ,CAAC,UAAU;YAC3D,MAAMC,WAAWnC,mCAAauC,MAAMlJ,IAAI;YACxC,MAAM,eAAC6B,WAAAA,EAAY,GAAGiH;YAEtB,IAAI3G,yCAAmBN,aACrBmF,mCAAakC,MAAMlJ,IAAI,EAAE8I;QAE7B,OAAO,IAAII,MAAMtF,IAAI,KAAK,YAAYsF,MAAMlJ,IAAI,CAAC6I,QAAQ,CAAC,UAAU;YAClE,IAAIM,WAAWlD,8BAAQmD,GAAG,CAACF,MAAMlJ,IAAI;YACrC+D,QAAQC,GAAG,CAAC,YAAYkF,MAAMlJ,IAAI,EAAEmJ;YACpC,IAAIA,UAAU;gBACZlD,8BAAQ+B,MAAM,CAACkB,MAAMlJ,IAAI;gBACzBmJ,SAASlH,UAAU,CAACoH,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';\nimport commonPathPrefix = require('common-path-prefix');\n\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\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 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 let client = findClient(params);\n if (client) {\n let result = await client.connection.sendRequest(RequestImporters, params);\n return result;\n }\n return null;\n});\n\nconnection.onRequest(\n DocumentDiagnosticRequest.type,\n async (\n params: DocumentDiagnosticParams,\n ): Promise<DocumentDiagnosticReport> => {\n let 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 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 let 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\nlet progressReporter = new ProgressReporter();\nlet clients: Map<string, Client> = new Map();\n\nfunction findClient(document: DocumentUri): Client | undefined {\n let filepath = url.fileURLToPath(document);\n\n let longestPrefix = 0;\n let bestClient;\n for (let [, client] of clients) {\n let prefix = commonPathPrefix([client.projectRoot, filepath]).length;\n if (longestPrefix < prefix) {\n longestPrefix = prefix;\n bestClient = client;\n } else if (longestPrefix === prefix) {\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 let socketfilepath = metafilepath.slice(0, -5);\n let [reader, writer] = createServerPipeTransport(socketfilepath);\n let client = createMessageConnection(reader, writer);\n client.listen();\n\n let uris = new Set<DocumentUri>();\n\n let 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 (let 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 (let 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 => connection.sendDiagnostics({uri, diagnostics: []})),\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 (let filename of fs.readdirSync(BASEDIR)) {\n if (!filename.endsWith('.json')) continue;\n let 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\nwatcher.subscribe(BASEDIR, async (err, events) => {\n if (err) {\n throw err;\n }\n\n for (let 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 let existing = clients.get(event.path);\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","commonPathPrefix","watcher","NotificationBuild","NotificationBuildStatus","NotificationWorkspaceDiagnostics","RequestDocumentDiagnostics","RequestImporters","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","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":"../../../../"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/lsp",
|
|
3
|
-
"version": "2.12.1-dev.
|
|
3
|
+
"version": "2.12.1-dev.3398+81c73b3cd",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -18,10 +18,10 @@
|
|
|
18
18
|
},
|
|
19
19
|
"engines": {
|
|
20
20
|
"node": ">= 16.0.0",
|
|
21
|
-
"
|
|
21
|
+
"parcel": "^2.12.1-dev.3398+81c73b3cd"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@atlaspack/lsp-protocol": "2.12.1-dev.
|
|
24
|
+
"@atlaspack/lsp-protocol": "2.12.1-dev.3398+81c73b3cd",
|
|
25
25
|
"@parcel/watcher": "^2.0.7",
|
|
26
26
|
"common-path-prefix": "^3.0.0",
|
|
27
27
|
"nullthrows": "^1.1.1",
|
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
"targets": {
|
|
41
41
|
"types": false
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "81c73b3cdf93adf8b0013be9fed5422579bd5910"
|
|
44
44
|
}
|
package/src/LspServer.ts
CHANGED
|
@@ -285,12 +285,12 @@ function createClient(metafilepath: string, metafile: Metafile) {
|
|
|
285
285
|
}
|
|
286
286
|
|
|
287
287
|
// Take realpath because to have consistent cache keys on macOS (/var -> /private/var)
|
|
288
|
-
const BASEDIR = path.join(fs.realpathSync(os.tmpdir()), '
|
|
288
|
+
const BASEDIR = path.join(fs.realpathSync(os.tmpdir()), 'parcel-lsp');
|
|
289
289
|
fs.mkdirSync(BASEDIR, {recursive: true});
|
|
290
290
|
|
|
291
291
|
fs.writeFileSync(path.join(BASEDIR, LSP_SENTINEL_FILENAME), '');
|
|
292
292
|
|
|
293
|
-
// Search for currently running Atlaspack processes in the
|
|
293
|
+
// Search for currently running Atlaspack processes in the parcel-lsp dir.
|
|
294
294
|
// Create an IPC client connection for each running process.
|
|
295
295
|
for (let filename of fs.readdirSync(BASEDIR)) {
|
|
296
296
|
if (!filename.endsWith('.json')) continue;
|
|
@@ -303,7 +303,7 @@ for (let filename of fs.readdirSync(BASEDIR)) {
|
|
|
303
303
|
}
|
|
304
304
|
}
|
|
305
305
|
|
|
306
|
-
// Watch for new Atlaspack processes in the
|
|
306
|
+
// Watch for new Atlaspack processes in the parcel-lsp dir, and disconnect the
|
|
307
307
|
// client for each corresponding connection when a Atlaspack process ends
|
|
308
308
|
watcher.subscribe(BASEDIR, async (err, events) => {
|
|
309
309
|
if (err) {
|