@parcel/lsp 2.12.1-dev.3188 → 2.12.1-dev.3195

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 CHANGED
@@ -1,13 +1,13 @@
1
- var $2b7mS$path = require("path");
2
- var $2b7mS$fs = require("fs");
3
- var $2b7mS$os = require("os");
4
- var $2b7mS$vscodelanguageservernode = require("vscode-languageserver/node");
5
- var $2b7mS$vscodejsonrpcnode = require("vscode-jsonrpc/node");
6
- var $2b7mS$assert = require("assert");
7
- var $2b7mS$url = require("url");
8
- var $2b7mS$commonpathprefix = require("common-path-prefix");
9
- var $2b7mS$parcelwatcher = require("@parcel/watcher");
10
- var $2b7mS$parcellspprotocol = require("@parcel/lsp-protocol");
1
+ var $gVyEn$path = require("path");
2
+ var $gVyEn$fs = require("fs");
3
+ var $gVyEn$os = require("os");
4
+ var $gVyEn$vscodelanguageservernode = require("vscode-languageserver/node");
5
+ var $gVyEn$vscodejsonrpcnode = require("vscode-jsonrpc/node");
6
+ var $gVyEn$assert = require("assert");
7
+ var $gVyEn$url = require("url");
8
+ var $gVyEn$commonpathprefix = require("common-path-prefix");
9
+ var $gVyEn$parcelwatcher = require("@parcel/watcher");
10
+ var $gVyEn$parcellspprotocol = require("@parcel/lsp-protocol");
11
11
 
12
12
 
13
13
 
@@ -19,31 +19,30 @@ var $2b7mS$parcellspprotocol = require("@parcel/lsp-protocol");
19
19
 
20
20
 
21
21
 
22
- const $7fbedd6675913568$var$connection = (0, $2b7mS$vscodelanguageservernode.createConnection)((0, $2b7mS$vscodelanguageservernode.ProposedFeatures).all);
23
- const $7fbedd6675913568$var$WORKSPACE_ROOT = process.cwd();
24
- const $7fbedd6675913568$var$LSP_SENTINEL_FILENAME = "lsp-server";
22
+ const $4cbb6ff865378d50$var$connection = (0, $gVyEn$vscodelanguageservernode.createConnection)((0, $gVyEn$vscodelanguageservernode.ProposedFeatures).all);
23
+ const $4cbb6ff865378d50$var$WORKSPACE_ROOT = process.cwd();
24
+ const $4cbb6ff865378d50$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 $7fbedd6675913568$var$hasConfigurationCapability = false;
28
- let $7fbedd6675913568$var$hasWorkspaceFolderCapability = false;
27
+ let $4cbb6ff865378d50$var$hasConfigurationCapability = false;
28
+ let $4cbb6ff865378d50$var$hasWorkspaceFolderCapability = false;
29
29
  // let hasDiagnosticRelatedInformationCapability = false;
30
- let $7fbedd6675913568$var$hasDiagnosticsRefreshSupport = false;
31
- $7fbedd6675913568$var$connection.onInitialize((params)=>{
32
- var _capabilities_workspace_diagnostics, _capabilities_workspace;
30
+ let $4cbb6ff865378d50$var$hasDiagnosticsRefreshSupport = false;
31
+ $4cbb6ff865378d50$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
- $7fbedd6675913568$var$hasConfigurationCapability = !!(capabilities.workspace && !!capabilities.workspace.configuration);
37
- $7fbedd6675913568$var$hasWorkspaceFolderCapability = !!(capabilities.workspace && !!capabilities.workspace.workspaceFolders);
35
+ $4cbb6ff865378d50$var$hasConfigurationCapability = !!(capabilities.workspace && !!capabilities.workspace.configuration);
36
+ $4cbb6ff865378d50$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
- $7fbedd6675913568$var$hasDiagnosticsRefreshSupport = Boolean((_capabilities_workspace = capabilities.workspace) === null || _capabilities_workspace === void 0 ? void 0 : (_capabilities_workspace_diagnostics = _capabilities_workspace.diagnostics) === null || _capabilities_workspace_diagnostics === void 0 ? void 0 : _capabilities_workspace_diagnostics.refreshSupport);
42
+ $4cbb6ff865378d50$var$hasDiagnosticsRefreshSupport = Boolean(capabilities.workspace?.diagnostics?.refreshSupport);
44
43
  const result = {
45
44
  capabilities: {
46
- textDocumentSync: (0, $2b7mS$vscodelanguageservernode.TextDocumentSyncKind).Incremental,
45
+ textDocumentSync: (0, $gVyEn$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 @@ $7fbedd6675913568$var$connection.onInitialize((params)=>{
51
50
  }
52
51
  }
53
52
  };
54
- if ($7fbedd6675913568$var$hasWorkspaceFolderCapability) result.capabilities.workspace = {
53
+ if ($4cbb6ff865378d50$var$hasWorkspaceFolderCapability) result.capabilities.workspace = {
55
54
  workspaceFolders: {
56
55
  supported: true
57
56
  }
58
57
  };
59
58
  return result;
60
59
  });
61
- $7fbedd6675913568$var$connection.onInitialized(()=>{
62
- if ($7fbedd6675913568$var$hasConfigurationCapability) // Register for all configuration changes.
63
- $7fbedd6675913568$var$connection.client.register((0, $2b7mS$vscodelanguageservernode.DidChangeConfigurationNotification).type, undefined);
64
- if ($7fbedd6675913568$var$hasWorkspaceFolderCapability) $7fbedd6675913568$var$connection.workspace.onDidChangeWorkspaceFolders(()=>{
65
- $7fbedd6675913568$var$connection.console.log("Workspace folder change event received.");
60
+ $4cbb6ff865378d50$var$connection.onInitialized(()=>{
61
+ if ($4cbb6ff865378d50$var$hasConfigurationCapability) // Register for all configuration changes.
62
+ $4cbb6ff865378d50$var$connection.client.register((0, $gVyEn$vscodelanguageservernode.DidChangeConfigurationNotification).type, undefined);
63
+ if ($4cbb6ff865378d50$var$hasWorkspaceFolderCapability) $4cbb6ff865378d50$var$connection.workspace.onDidChangeWorkspaceFolders(()=>{
64
+ $4cbb6ff865378d50$var$connection.console.log("Workspace folder change event received.");
66
65
  });
67
66
  });
68
67
  // Proxy
69
- $7fbedd6675913568$var$connection.onRequest((0, $2b7mS$parcellspprotocol.RequestImporters), async (params)=>{
70
- let client = $7fbedd6675913568$var$findClient(params);
68
+ $4cbb6ff865378d50$var$connection.onRequest((0, $gVyEn$parcellspprotocol.RequestImporters), async (params)=>{
69
+ let client = $4cbb6ff865378d50$var$findClient(params);
71
70
  if (client) {
72
- let result = await client.connection.sendRequest((0, $2b7mS$parcellspprotocol.RequestImporters), params);
71
+ let result = await client.connection.sendRequest((0, $gVyEn$parcellspprotocol.RequestImporters), params);
73
72
  return result;
74
73
  }
75
74
  return null;
76
75
  });
77
- $7fbedd6675913568$var$connection.onRequest((0, $2b7mS$vscodelanguageservernode.DocumentDiagnosticRequest).type, async (params)=>{
78
- let client = $7fbedd6675913568$var$findClient(params.textDocument.uri);
76
+ $4cbb6ff865378d50$var$connection.onRequest((0, $gVyEn$vscodelanguageservernode.DocumentDiagnosticRequest).type, async (params)=>{
77
+ let client = $4cbb6ff865378d50$var$findClient(params.textDocument.uri);
79
78
  let result;
80
79
  if (client) {
81
80
  // console.log(
@@ -84,23 +83,23 @@ $7fbedd6675913568$var$connection.onRequest((0, $2b7mS$vscodelanguageservernode.D
84
83
  // params.previousResultId === client.lastBuild,
85
84
  // );
86
85
  if (params.previousResultId === client.lastBuild) return {
87
- kind: (0, $2b7mS$vscodelanguageservernode.DocumentDiagnosticReportKind).Unchanged,
86
+ kind: (0, $gVyEn$vscodelanguageservernode.DocumentDiagnosticReportKind).Unchanged,
88
87
  resultId: client.lastBuild
89
88
  };
90
- result = await client.connection.sendRequest((0, $2b7mS$parcellspprotocol.RequestDocumentDiagnostics), params.textDocument.uri);
89
+ result = await client.connection.sendRequest((0, $gVyEn$parcellspprotocol.RequestDocumentDiagnostics), params.textDocument.uri);
91
90
  if (result) client.uris.add(params.textDocument.uri);
92
91
  }
93
92
  return {
94
- kind: (0, $2b7mS$vscodelanguageservernode.DocumentDiagnosticReportKind).Full,
95
- resultId: client === null || client === void 0 ? void 0 : client.lastBuild,
96
- items: result !== null && result !== void 0 ? result : []
93
+ kind: (0, $gVyEn$vscodelanguageservernode.DocumentDiagnosticReportKind).Full,
94
+ resultId: client?.lastBuild,
95
+ items: result ?? []
97
96
  };
98
97
  });
99
- $7fbedd6675913568$var$connection.listen();
100
- class $7fbedd6675913568$var$ProgressReporter {
98
+ $4cbb6ff865378d50$var$connection.listen();
99
+ class $4cbb6ff865378d50$var$ProgressReporter {
101
100
  begin() {
102
101
  this.progressReporterPromise = (async ()=>{
103
- let reporter = await $7fbedd6675913568$var$connection.window.createWorkDoneProgress();
102
+ let reporter = await $4cbb6ff865378d50$var$connection.window.createWorkDoneProgress();
104
103
  reporter.begin("Parcel");
105
104
  return reporter;
106
105
  })();
@@ -110,7 +109,7 @@ class $7fbedd6675913568$var$ProgressReporter {
110
109
  }
111
110
  async done() {
112
111
  if (this.progressReporterPromise == null) this.begin();
113
- $2b7mS$assert(this.progressReporterPromise != null);
112
+ $gVyEn$assert(this.progressReporterPromise != null);
114
113
  (await this.progressReporterPromise).done();
115
114
  this.progressReporterPromise = null;
116
115
  }
@@ -124,17 +123,17 @@ class $7fbedd6675913568$var$ProgressReporter {
124
123
  }
125
124
  }
126
125
  }
127
- function $7fbedd6675913568$var$sendDiagnosticsRefresh() {
128
- if ($7fbedd6675913568$var$hasDiagnosticsRefreshSupport) $7fbedd6675913568$var$connection.sendRequest((0, $2b7mS$vscodelanguageservernode.DiagnosticRefreshRequest).type);
126
+ function $4cbb6ff865378d50$var$sendDiagnosticsRefresh() {
127
+ if ($4cbb6ff865378d50$var$hasDiagnosticsRefreshSupport) $4cbb6ff865378d50$var$connection.sendRequest((0, $gVyEn$vscodelanguageservernode.DiagnosticRefreshRequest).type);
129
128
  }
130
- let $7fbedd6675913568$var$progressReporter = new $7fbedd6675913568$var$ProgressReporter();
131
- let $7fbedd6675913568$var$clients = new Map();
132
- function $7fbedd6675913568$var$findClient(document) {
133
- let filepath = $2b7mS$url.fileURLToPath(document);
129
+ let $4cbb6ff865378d50$var$progressReporter = new $4cbb6ff865378d50$var$ProgressReporter();
130
+ let $4cbb6ff865378d50$var$clients = new Map();
131
+ function $4cbb6ff865378d50$var$findClient(document) {
132
+ let filepath = $gVyEn$url.fileURLToPath(document);
134
133
  let longestPrefix = 0;
135
134
  let bestClient;
136
- for (let [, client] of $7fbedd6675913568$var$clients){
137
- let prefix = $2b7mS$commonpathprefix([
135
+ for (let [, client] of $4cbb6ff865378d50$var$clients){
136
+ let prefix = $gVyEn$commonpathprefix([
138
137
  client.projectRoot,
139
138
  filepath
140
139
  ]).length;
@@ -145,14 +144,14 @@ function $7fbedd6675913568$var$findClient(document) {
145
144
  }
146
145
  return bestClient;
147
146
  }
148
- function $7fbedd6675913568$var$loadMetafile(filepath) {
149
- const file = $2b7mS$fs.readFileSync(filepath, "utf-8");
147
+ function $4cbb6ff865378d50$var$loadMetafile(filepath) {
148
+ const file = $gVyEn$fs.readFileSync(filepath, "utf-8");
150
149
  return JSON.parse(file);
151
150
  }
152
- function $7fbedd6675913568$var$createClient(metafilepath, metafile) {
151
+ function $4cbb6ff865378d50$var$createClient(metafilepath, metafile) {
153
152
  let socketfilepath = metafilepath.slice(0, -5);
154
- let [reader, writer] = (0, $2b7mS$vscodejsonrpcnode.createServerPipeTransport)(socketfilepath);
155
- let client = (0, $2b7mS$vscodejsonrpcnode.createMessageConnection)(reader, writer);
153
+ let [reader, writer] = (0, $gVyEn$vscodejsonrpcnode.createServerPipeTransport)(socketfilepath);
154
+ let client = (0, $gVyEn$vscodejsonrpcnode.createMessageConnection)(reader, writer);
156
155
  client.listen();
157
156
  let uris = new Set();
158
157
  let result = {
@@ -161,71 +160,71 @@ function $7fbedd6675913568$var$createClient(metafilepath, metafile) {
161
160
  projectRoot: metafile.projectRoot,
162
161
  lastBuild: "0"
163
162
  };
164
- client.onNotification((0, $2b7mS$parcellspprotocol.NotificationBuildStatus), (state, message)=>{
163
+ client.onNotification((0, $gVyEn$parcellspprotocol.NotificationBuildStatus), (state, message)=>{
165
164
  // console.log('got NotificationBuildStatus', state, message);
166
165
  if (state === "start") {
167
- $7fbedd6675913568$var$progressReporter.begin();
168
- for (let uri of uris)$7fbedd6675913568$var$connection.sendDiagnostics({
166
+ $4cbb6ff865378d50$var$progressReporter.begin();
167
+ for (let uri of uris)$4cbb6ff865378d50$var$connection.sendDiagnostics({
169
168
  uri: uri,
170
169
  diagnostics: []
171
170
  });
172
- } else if (state === "progress" && message != null) $7fbedd6675913568$var$progressReporter.report(message);
171
+ } else if (state === "progress" && message != null) $4cbb6ff865378d50$var$progressReporter.report(message);
173
172
  else if (state === "end") {
174
173
  result.lastBuild = String(Date.now());
175
- $7fbedd6675913568$var$sendDiagnosticsRefresh();
176
- $7fbedd6675913568$var$progressReporter.done();
177
- $7fbedd6675913568$var$connection.sendNotification((0, $2b7mS$parcellspprotocol.NotificationBuild));
174
+ $4cbb6ff865378d50$var$sendDiagnosticsRefresh();
175
+ $4cbb6ff865378d50$var$progressReporter.done();
176
+ $4cbb6ff865378d50$var$connection.sendNotification((0, $gVyEn$parcellspprotocol.NotificationBuild));
178
177
  }
179
178
  });
180
- client.onNotification((0, $2b7mS$parcellspprotocol.NotificationWorkspaceDiagnostics), (diagnostics)=>{
179
+ client.onNotification((0, $gVyEn$parcellspprotocol.NotificationWorkspaceDiagnostics), (diagnostics)=>{
181
180
  // console.log('got NotificationWorkspaceDiagnostics', diagnostics);
182
181
  for (let d of diagnostics){
183
182
  uris.add(d.uri);
184
- $7fbedd6675913568$var$connection.sendDiagnostics(d);
183
+ $4cbb6ff865378d50$var$connection.sendDiagnostics(d);
185
184
  }
186
185
  });
187
186
  client.onClose(()=>{
188
- $7fbedd6675913568$var$clients.delete(JSON.stringify(metafile));
189
- $7fbedd6675913568$var$sendDiagnosticsRefresh();
187
+ $4cbb6ff865378d50$var$clients.delete(JSON.stringify(metafile));
188
+ $4cbb6ff865378d50$var$sendDiagnosticsRefresh();
190
189
  return Promise.all([
191
190
  ...uris
192
- ].map((uri)=>$7fbedd6675913568$var$connection.sendDiagnostics({
191
+ ].map((uri)=>$4cbb6ff865378d50$var$connection.sendDiagnostics({
193
192
  uri: uri,
194
193
  diagnostics: []
195
194
  })));
196
195
  });
197
- $7fbedd6675913568$var$sendDiagnosticsRefresh();
198
- $7fbedd6675913568$var$clients.set(JSON.stringify(metafile), result);
196
+ $4cbb6ff865378d50$var$sendDiagnosticsRefresh();
197
+ $4cbb6ff865378d50$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 $7fbedd6675913568$var$BASEDIR = $2b7mS$path.join($2b7mS$fs.realpathSync($2b7mS$os.tmpdir()), "parcel-lsp");
202
- $2b7mS$fs.mkdirSync($7fbedd6675913568$var$BASEDIR, {
200
+ const $4cbb6ff865378d50$var$BASEDIR = $gVyEn$path.join($gVyEn$fs.realpathSync($gVyEn$os.tmpdir()), "parcel-lsp");
201
+ $gVyEn$fs.mkdirSync($4cbb6ff865378d50$var$BASEDIR, {
203
202
  recursive: true
204
203
  });
205
- $2b7mS$fs.writeFileSync($2b7mS$path.join($7fbedd6675913568$var$BASEDIR, $7fbedd6675913568$var$LSP_SENTINEL_FILENAME), "");
204
+ $gVyEn$fs.writeFileSync($gVyEn$path.join($4cbb6ff865378d50$var$BASEDIR, $4cbb6ff865378d50$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 $2b7mS$fs.readdirSync($7fbedd6675913568$var$BASEDIR)){
207
+ for (let filename of $gVyEn$fs.readdirSync($4cbb6ff865378d50$var$BASEDIR)){
209
208
  if (!filename.endsWith(".json")) continue;
210
- let filepath = $2b7mS$path.join($7fbedd6675913568$var$BASEDIR, filename);
211
- const contents = $7fbedd6675913568$var$loadMetafile(filepath);
209
+ let filepath = $gVyEn$path.join($4cbb6ff865378d50$var$BASEDIR, filename);
210
+ const contents = $4cbb6ff865378d50$var$loadMetafile(filepath);
212
211
  const { projectRoot: projectRoot } = contents;
213
- if ($7fbedd6675913568$var$WORKSPACE_ROOT === projectRoot) $7fbedd6675913568$var$createClient(filepath, contents);
212
+ if ($4cbb6ff865378d50$var$WORKSPACE_ROOT === projectRoot) $4cbb6ff865378d50$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
- $2b7mS$parcelwatcher.subscribe($7fbedd6675913568$var$BASEDIR, async (err, events)=>{
216
+ $gVyEn$parcelwatcher.subscribe($4cbb6ff865378d50$var$BASEDIR, async (err, events)=>{
218
217
  if (err) throw err;
219
218
  for (let event of events){
220
219
  if (event.type === "create" && event.path.endsWith(".json")) {
221
- const contents = $7fbedd6675913568$var$loadMetafile(event.path);
220
+ const contents = $4cbb6ff865378d50$var$loadMetafile(event.path);
222
221
  const { projectRoot: projectRoot } = contents;
223
- if ($7fbedd6675913568$var$WORKSPACE_ROOT === projectRoot) $7fbedd6675913568$var$createClient(event.path, contents);
222
+ if ($4cbb6ff865378d50$var$WORKSPACE_ROOT === projectRoot) $4cbb6ff865378d50$var$createClient(event.path, contents);
224
223
  } else if (event.type === "delete" && event.path.endsWith(".json")) {
225
- let existing = $7fbedd6675913568$var$clients.get(event.path);
224
+ let existing = $4cbb6ff865378d50$var$clients.get(event.path);
226
225
  console.log("existing", event.path, existing);
227
226
  if (existing) {
228
- $7fbedd6675913568$var$clients.delete(event.path);
227
+ $4cbb6ff865378d50$var$clients.delete(event.path);
229
228
  existing.connection.end();
230
229
  }
231
230
  }
@@ -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,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';\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,IAA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AAA;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,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":"../../../../"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcel/lsp",
3
- "version": "2.12.1-dev.3188+c422b7ff3",
3
+ "version": "2.12.1-dev.3195+7afdafedd",
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": ">= 12.0.0",
25
- "parcel": "^2.0.0-dev.1563+c422b7ff3"
24
+ "node": ">= 16.0.0",
25
+ "parcel": "^2.0.0-dev.1570+7afdafedd"
26
26
  },
27
27
  "dependencies": {
28
- "@parcel/lsp-protocol": "2.12.1-dev.3188+c422b7ff3",
28
+ "@parcel/lsp-protocol": "2.12.1-dev.3195+7afdafedd",
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": "c422b7ff3c383779781ea5169d86191508b01e5b"
47
+ "gitHead": "7afdafedd7f01d82b9868ec004b3966a88006300"
48
48
  }