@parcel/lsp 2.12.1-nightly.3142 → 2.13.1-canary.3372
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/LspServer.js +89 -90
- package/lib/LspServer.js.map +1 -1
- package/package.json +5 -5
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 $6W4Rb$path = require("path");
|
2
|
+
var $6W4Rb$fs = require("fs");
|
3
|
+
var $6W4Rb$os = require("os");
|
4
|
+
var $6W4Rb$vscodelanguageservernode = require("vscode-languageserver/node");
|
5
|
+
var $6W4Rb$vscodejsonrpcnode = require("vscode-jsonrpc/node");
|
6
|
+
var $6W4Rb$assert = require("assert");
|
7
|
+
var $6W4Rb$url = require("url");
|
8
|
+
var $6W4Rb$commonpathprefix = require("common-path-prefix");
|
9
|
+
var $6W4Rb$parcelwatcher = require("@parcel/watcher");
|
10
|
+
var $6W4Rb$parcellspprotocol = require("@parcel/lsp-protocol");
|
11
11
|
|
12
12
|
|
13
13
|
|
@@ -19,31 +19,30 @@ var $7GNTz$parcellspprotocol = require("@parcel/lsp-protocol");
|
|
19
19
|
|
20
20
|
|
21
21
|
|
22
|
-
const $
|
23
|
-
const $
|
24
|
-
const $
|
22
|
+
const $fc357773f0b6c42c$var$connection = (0, $6W4Rb$vscodelanguageservernode.createConnection)((0, $6W4Rb$vscodelanguageservernode.ProposedFeatures).all);
|
23
|
+
const $fc357773f0b6c42c$var$WORKSPACE_ROOT = process.cwd();
|
24
|
+
const $fc357773f0b6c42c$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 $fc357773f0b6c42c$var$hasConfigurationCapability = false;
|
28
|
+
let $fc357773f0b6c42c$var$hasWorkspaceFolderCapability = false;
|
29
29
|
// let hasDiagnosticRelatedInformationCapability = false;
|
30
|
-
let $
|
31
|
-
$
|
32
|
-
var _capabilities_workspace_diagnostics, _capabilities_workspace;
|
30
|
+
let $fc357773f0b6c42c$var$hasDiagnosticsRefreshSupport = false;
|
31
|
+
$fc357773f0b6c42c$var$connection.onInitialize((params)=>{
|
33
32
|
const capabilities = params.capabilities;
|
34
33
|
// Does the client support the `workspace/configuration` request?
|
35
34
|
// If not, we fall back using global settings.
|
36
|
-
$
|
37
|
-
$
|
35
|
+
$fc357773f0b6c42c$var$hasConfigurationCapability = !!(capabilities.workspace && !!capabilities.workspace.configuration);
|
36
|
+
$fc357773f0b6c42c$var$hasWorkspaceFolderCapability = !!(capabilities.workspace && !!capabilities.workspace.workspaceFolders);
|
38
37
|
// hasDiagnosticRelatedInformationCapability = !!(
|
39
38
|
// capabilities.textDocument &&
|
40
39
|
// capabilities.textDocument.publishDiagnostics &&
|
41
40
|
// capabilities.textDocument.publishDiagnostics.relatedInformation
|
42
41
|
// );
|
43
|
-
$
|
42
|
+
$fc357773f0b6c42c$var$hasDiagnosticsRefreshSupport = Boolean(capabilities.workspace?.diagnostics?.refreshSupport);
|
44
43
|
const result = {
|
45
44
|
capabilities: {
|
46
|
-
textDocumentSync: (0, $
|
45
|
+
textDocumentSync: (0, $6W4Rb$vscodelanguageservernode.TextDocumentSyncKind).Incremental,
|
47
46
|
// Tell the client that this server supports code completion.
|
48
47
|
diagnosticProvider: {
|
49
48
|
workspaceDiagnostics: false,
|
@@ -51,31 +50,31 @@ $dcbac65143fb836a$var$connection.onInitialize((params)=>{
|
|
51
50
|
}
|
52
51
|
}
|
53
52
|
};
|
54
|
-
if ($
|
53
|
+
if ($fc357773f0b6c42c$var$hasWorkspaceFolderCapability) result.capabilities.workspace = {
|
55
54
|
workspaceFolders: {
|
56
55
|
supported: true
|
57
56
|
}
|
58
57
|
};
|
59
58
|
return result;
|
60
59
|
});
|
61
|
-
$
|
62
|
-
if ($
|
63
|
-
$
|
64
|
-
if ($
|
65
|
-
$
|
60
|
+
$fc357773f0b6c42c$var$connection.onInitialized(()=>{
|
61
|
+
if ($fc357773f0b6c42c$var$hasConfigurationCapability) // Register for all configuration changes.
|
62
|
+
$fc357773f0b6c42c$var$connection.client.register((0, $6W4Rb$vscodelanguageservernode.DidChangeConfigurationNotification).type, undefined);
|
63
|
+
if ($fc357773f0b6c42c$var$hasWorkspaceFolderCapability) $fc357773f0b6c42c$var$connection.workspace.onDidChangeWorkspaceFolders(()=>{
|
64
|
+
$fc357773f0b6c42c$var$connection.console.log('Workspace folder change event received.');
|
66
65
|
});
|
67
66
|
});
|
68
67
|
// Proxy
|
69
|
-
$
|
70
|
-
let client = $
|
68
|
+
$fc357773f0b6c42c$var$connection.onRequest((0, $6W4Rb$parcellspprotocol.RequestImporters), async (params)=>{
|
69
|
+
let client = $fc357773f0b6c42c$var$findClient(params);
|
71
70
|
if (client) {
|
72
|
-
let result = await client.connection.sendRequest((0, $
|
71
|
+
let result = await client.connection.sendRequest((0, $6W4Rb$parcellspprotocol.RequestImporters), params);
|
73
72
|
return result;
|
74
73
|
}
|
75
74
|
return null;
|
76
75
|
});
|
77
|
-
$
|
78
|
-
let client = $
|
76
|
+
$fc357773f0b6c42c$var$connection.onRequest((0, $6W4Rb$vscodelanguageservernode.DocumentDiagnosticRequest).type, async (params)=>{
|
77
|
+
let client = $fc357773f0b6c42c$var$findClient(params.textDocument.uri);
|
79
78
|
let result;
|
80
79
|
if (client) {
|
81
80
|
// console.log(
|
@@ -84,24 +83,24 @@ $dcbac65143fb836a$var$connection.onRequest((0, $7GNTz$vscodelanguageservernode.D
|
|
84
83
|
// params.previousResultId === client.lastBuild,
|
85
84
|
// );
|
86
85
|
if (params.previousResultId === client.lastBuild) return {
|
87
|
-
kind: (0, $
|
86
|
+
kind: (0, $6W4Rb$vscodelanguageservernode.DocumentDiagnosticReportKind).Unchanged,
|
88
87
|
resultId: client.lastBuild
|
89
88
|
};
|
90
|
-
result = await client.connection.sendRequest((0, $
|
89
|
+
result = await client.connection.sendRequest((0, $6W4Rb$parcellspprotocol.RequestDocumentDiagnostics), params.textDocument.uri);
|
91
90
|
if (result) client.uris.add(params.textDocument.uri);
|
92
91
|
}
|
93
92
|
return {
|
94
|
-
kind: (0, $
|
95
|
-
resultId: client
|
96
|
-
items: result
|
93
|
+
kind: (0, $6W4Rb$vscodelanguageservernode.DocumentDiagnosticReportKind).Full,
|
94
|
+
resultId: client?.lastBuild,
|
95
|
+
items: result ?? []
|
97
96
|
};
|
98
97
|
});
|
99
|
-
$
|
100
|
-
class $
|
98
|
+
$fc357773f0b6c42c$var$connection.listen();
|
99
|
+
class $fc357773f0b6c42c$var$ProgressReporter {
|
101
100
|
begin() {
|
102
101
|
this.progressReporterPromise = (async ()=>{
|
103
|
-
let reporter = await $
|
104
|
-
reporter.begin(
|
102
|
+
let reporter = await $fc357773f0b6c42c$var$connection.window.createWorkDoneProgress();
|
103
|
+
reporter.begin('Parcel');
|
105
104
|
return reporter;
|
106
105
|
})();
|
107
106
|
this.progressReporterPromise.then((reporter)=>{
|
@@ -110,7 +109,7 @@ class $dcbac65143fb836a$var$ProgressReporter {
|
|
110
109
|
}
|
111
110
|
async done() {
|
112
111
|
if (this.progressReporterPromise == null) this.begin();
|
113
|
-
$
|
112
|
+
$6W4Rb$assert(this.progressReporterPromise != null);
|
114
113
|
(await this.progressReporterPromise).done();
|
115
114
|
this.progressReporterPromise = null;
|
116
115
|
}
|
@@ -124,108 +123,108 @@ class $dcbac65143fb836a$var$ProgressReporter {
|
|
124
123
|
}
|
125
124
|
}
|
126
125
|
}
|
127
|
-
function $
|
128
|
-
if ($
|
126
|
+
function $fc357773f0b6c42c$var$sendDiagnosticsRefresh() {
|
127
|
+
if ($fc357773f0b6c42c$var$hasDiagnosticsRefreshSupport) $fc357773f0b6c42c$var$connection.sendRequest((0, $6W4Rb$vscodelanguageservernode.DiagnosticRefreshRequest).type);
|
129
128
|
}
|
130
|
-
let $
|
131
|
-
let $
|
132
|
-
function $
|
133
|
-
let filepath = $
|
129
|
+
let $fc357773f0b6c42c$var$progressReporter = new $fc357773f0b6c42c$var$ProgressReporter();
|
130
|
+
let $fc357773f0b6c42c$var$clients = new Map();
|
131
|
+
function $fc357773f0b6c42c$var$findClient(document) {
|
132
|
+
let filepath = $6W4Rb$url.fileURLToPath(document);
|
134
133
|
let longestPrefix = 0;
|
135
134
|
let bestClient;
|
136
|
-
for (let [, client] of $
|
137
|
-
let prefix = $
|
135
|
+
for (let [, client] of $fc357773f0b6c42c$var$clients){
|
136
|
+
let prefix = $6W4Rb$commonpathprefix([
|
138
137
|
client.projectRoot,
|
139
138
|
filepath
|
140
139
|
]).length;
|
141
140
|
if (longestPrefix < prefix) {
|
142
141
|
longestPrefix = prefix;
|
143
142
|
bestClient = client;
|
144
|
-
} else if (longestPrefix === prefix) console.warn(
|
143
|
+
} else if (longestPrefix === prefix) console.warn('Ambiguous client for ' + filepath);
|
145
144
|
}
|
146
145
|
return bestClient;
|
147
146
|
}
|
148
|
-
function $
|
149
|
-
const file = $
|
147
|
+
function $fc357773f0b6c42c$var$loadMetafile(filepath) {
|
148
|
+
const file = $6W4Rb$fs.readFileSync(filepath, 'utf-8');
|
150
149
|
return JSON.parse(file);
|
151
150
|
}
|
152
|
-
function $
|
151
|
+
function $fc357773f0b6c42c$var$createClient(metafilepath, metafile) {
|
153
152
|
let socketfilepath = metafilepath.slice(0, -5);
|
154
|
-
let [reader, writer] = (0, $
|
155
|
-
let client = (0, $
|
153
|
+
let [reader, writer] = (0, $6W4Rb$vscodejsonrpcnode.createServerPipeTransport)(socketfilepath);
|
154
|
+
let client = (0, $6W4Rb$vscodejsonrpcnode.createMessageConnection)(reader, writer);
|
156
155
|
client.listen();
|
157
156
|
let uris = new Set();
|
158
157
|
let result = {
|
159
158
|
connection: client,
|
160
159
|
uris: uris,
|
161
160
|
projectRoot: metafile.projectRoot,
|
162
|
-
lastBuild:
|
161
|
+
lastBuild: '0'
|
163
162
|
};
|
164
|
-
client.onNotification((0, $
|
163
|
+
client.onNotification((0, $6W4Rb$parcellspprotocol.NotificationBuildStatus), (state, message)=>{
|
165
164
|
// console.log('got NotificationBuildStatus', state, message);
|
166
|
-
if (state ===
|
167
|
-
$
|
168
|
-
for (let uri of uris)$
|
165
|
+
if (state === 'start') {
|
166
|
+
$fc357773f0b6c42c$var$progressReporter.begin();
|
167
|
+
for (let uri of uris)$fc357773f0b6c42c$var$connection.sendDiagnostics({
|
169
168
|
uri: uri,
|
170
169
|
diagnostics: []
|
171
170
|
});
|
172
|
-
} else if (state ===
|
173
|
-
else if (state ===
|
171
|
+
} else if (state === 'progress' && message != null) $fc357773f0b6c42c$var$progressReporter.report(message);
|
172
|
+
else if (state === 'end') {
|
174
173
|
result.lastBuild = String(Date.now());
|
175
|
-
$
|
176
|
-
$
|
177
|
-
$
|
174
|
+
$fc357773f0b6c42c$var$sendDiagnosticsRefresh();
|
175
|
+
$fc357773f0b6c42c$var$progressReporter.done();
|
176
|
+
$fc357773f0b6c42c$var$connection.sendNotification((0, $6W4Rb$parcellspprotocol.NotificationBuild));
|
178
177
|
}
|
179
178
|
});
|
180
|
-
client.onNotification((0, $
|
179
|
+
client.onNotification((0, $6W4Rb$parcellspprotocol.NotificationWorkspaceDiagnostics), (diagnostics)=>{
|
181
180
|
// console.log('got NotificationWorkspaceDiagnostics', diagnostics);
|
182
181
|
for (let d of diagnostics){
|
183
182
|
uris.add(d.uri);
|
184
|
-
$
|
183
|
+
$fc357773f0b6c42c$var$connection.sendDiagnostics(d);
|
185
184
|
}
|
186
185
|
});
|
187
186
|
client.onClose(()=>{
|
188
|
-
$
|
189
|
-
$
|
187
|
+
$fc357773f0b6c42c$var$clients.delete(JSON.stringify(metafile));
|
188
|
+
$fc357773f0b6c42c$var$sendDiagnosticsRefresh();
|
190
189
|
return Promise.all([
|
191
190
|
...uris
|
192
|
-
].map((uri)=>$
|
191
|
+
].map((uri)=>$fc357773f0b6c42c$var$connection.sendDiagnostics({
|
193
192
|
uri: uri,
|
194
193
|
diagnostics: []
|
195
194
|
})));
|
196
195
|
});
|
197
|
-
$
|
198
|
-
$
|
196
|
+
$fc357773f0b6c42c$var$sendDiagnosticsRefresh();
|
197
|
+
$fc357773f0b6c42c$var$clients.set(JSON.stringify(metafile), result);
|
199
198
|
}
|
200
199
|
// Take realpath because to have consistent cache keys on macOS (/var -> /private/var)
|
201
|
-
const $
|
202
|
-
$
|
200
|
+
const $fc357773f0b6c42c$var$BASEDIR = $6W4Rb$path.join($6W4Rb$fs.realpathSync($6W4Rb$os.tmpdir()), 'parcel-lsp');
|
201
|
+
$6W4Rb$fs.mkdirSync($fc357773f0b6c42c$var$BASEDIR, {
|
203
202
|
recursive: true
|
204
203
|
});
|
205
|
-
$
|
204
|
+
$6W4Rb$fs.writeFileSync($6W4Rb$path.join($fc357773f0b6c42c$var$BASEDIR, $fc357773f0b6c42c$var$LSP_SENTINEL_FILENAME), '');
|
206
205
|
// Search for currently running Parcel processes in the parcel-lsp dir.
|
207
206
|
// Create an IPC client connection for each running process.
|
208
|
-
for (let filename of $
|
209
|
-
if (!filename.endsWith(
|
210
|
-
let filepath = $
|
211
|
-
const contents = $
|
207
|
+
for (let filename of $6W4Rb$fs.readdirSync($fc357773f0b6c42c$var$BASEDIR)){
|
208
|
+
if (!filename.endsWith('.json')) continue;
|
209
|
+
let filepath = $6W4Rb$path.join($fc357773f0b6c42c$var$BASEDIR, filename);
|
210
|
+
const contents = $fc357773f0b6c42c$var$loadMetafile(filepath);
|
212
211
|
const { projectRoot: projectRoot } = contents;
|
213
|
-
if ($
|
212
|
+
if ($fc357773f0b6c42c$var$WORKSPACE_ROOT === projectRoot) $fc357773f0b6c42c$var$createClient(filepath, contents);
|
214
213
|
}
|
215
214
|
// Watch for new Parcel processes in the parcel-lsp dir, and disconnect the
|
216
215
|
// client for each corresponding connection when a Parcel process ends
|
217
|
-
$
|
216
|
+
$6W4Rb$parcelwatcher.subscribe($fc357773f0b6c42c$var$BASEDIR, async (err, events)=>{
|
218
217
|
if (err) throw err;
|
219
218
|
for (let event of events){
|
220
|
-
if (event.type ===
|
221
|
-
const contents = $
|
219
|
+
if (event.type === 'create' && event.path.endsWith('.json')) {
|
220
|
+
const contents = $fc357773f0b6c42c$var$loadMetafile(event.path);
|
222
221
|
const { projectRoot: projectRoot } = contents;
|
223
|
-
if ($
|
224
|
-
} else if (event.type ===
|
225
|
-
let existing = $
|
226
|
-
console.log(
|
222
|
+
if ($fc357773f0b6c42c$var$WORKSPACE_ROOT === projectRoot) $fc357773f0b6c42c$var$createClient(event.path, contents);
|
223
|
+
} else if (event.type === 'delete' && event.path.endsWith('.json')) {
|
224
|
+
let existing = $fc357773f0b6c42c$var$clients.get(event.path);
|
225
|
+
console.log('existing', event.path, existing);
|
227
226
|
if (existing) {
|
228
|
-
$
|
227
|
+
$fc357773f0b6c42c$var$clients.delete(event.path);
|
229
228
|
existing.connection.end();
|
230
229
|
}
|
231
230
|
}
|
package/lib/LspServer.js.map
CHANGED
@@ -1 +1 @@
|
|
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;AAEA,IAAIC,mDAA6B;AACjC,IAAIC,qDAA+B;AACnC,yDAAA;AACA,IAAIC,qDAA+B;AAEnCP,iCAAWQ,YAAY,CAAC,CAACC;QAiBrBC,qCAAAA;IAhBF,MAAMA,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,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+BAASO;IAClC,MAAMG,WAAWnC,mCAAaP;IAC9B,MAAM,eAACvE,WAAAA,EAAY,GAAGiH;IAEtB,IAAI3G,yCAAmBN,aACrBmF,mCAAaZ,UAAU0C;AAE3B;AAEA,2EAAA;AACA,sEAAA;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/parcel-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 '@parcel/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('Parcel');\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 Parcel 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 Parcel processes in the parcel-lsp dir, and disconnect the\n// client for each corresponding connection when a Parcel 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;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,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,+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/parcel-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 '@parcel/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('Parcel');\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 Parcel 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 Parcel processes in the parcel-lsp dir, and disconnect the\n// client for each corresponding connection when a Parcel 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": "@parcel/lsp",
|
3
|
-
"version": "2.
|
3
|
+
"version": "2.13.1-canary.3372+a53f8f3ba",
|
4
4
|
"license": "MIT",
|
5
5
|
"publishConfig": {
|
6
6
|
"access": "public"
|
@@ -21,11 +21,11 @@
|
|
21
21
|
"lint": "eslint src --ext ts"
|
22
22
|
},
|
23
23
|
"engines": {
|
24
|
-
"node": ">=
|
25
|
-
"parcel": "2.0.0-
|
24
|
+
"node": ">= 16.0.0",
|
25
|
+
"parcel": "^2.0.0-canary.1747+a53f8f3ba"
|
26
26
|
},
|
27
27
|
"dependencies": {
|
28
|
-
"@parcel/lsp-protocol": "2.
|
28
|
+
"@parcel/lsp-protocol": "2.13.1-canary.3372+a53f8f3ba",
|
29
29
|
"@parcel/watcher": "^2.0.7",
|
30
30
|
"common-path-prefix": "^3.0.0",
|
31
31
|
"nullthrows": "^1.1.1",
|
@@ -44,5 +44,5 @@
|
|
44
44
|
"targets": {
|
45
45
|
"types": false
|
46
46
|
},
|
47
|
-
"gitHead": "
|
47
|
+
"gitHead": "a53f8f3ba1025c7ea8653e9719e0a61ef9717079"
|
48
48
|
}
|