@parcel/lsp 2.8.3 → 2.8.4-nightly.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/LspServer.js CHANGED
@@ -1,13 +1,13 @@
1
- var $7GXw8$path = require("path");
2
- var $7GXw8$fs = require("fs");
3
- var $7GXw8$os = require("os");
4
- var $7GXw8$vscodelanguageservernode = require("vscode-languageserver/node");
5
- var $7GXw8$vscodejsonrpcnode = require("vscode-jsonrpc/node");
6
- var $7GXw8$assert = require("assert");
7
- var $7GXw8$url = require("url");
8
- var $7GXw8$commonpathprefix = require("common-path-prefix");
9
- var $7GXw8$parcelwatcher = require("@parcel/watcher");
10
- var $7GXw8$parcellspprotocol = require("@parcel/lsp-protocol");
1
+ var $e9En9$path = require("path");
2
+ var $e9En9$fs = require("fs");
3
+ var $e9En9$os = require("os");
4
+ var $e9En9$vscodelanguageservernode = require("vscode-languageserver/node");
5
+ var $e9En9$vscodejsonrpcnode = require("vscode-jsonrpc/node");
6
+ var $e9En9$assert = require("assert");
7
+ var $e9En9$url = require("url");
8
+ var $e9En9$commonpathprefix = require("common-path-prefix");
9
+ var $e9En9$parcelwatcher = require("@parcel/watcher");
10
+ var $e9En9$parcellspprotocol = require("@parcel/lsp-protocol");
11
11
 
12
12
 
13
13
 
@@ -19,25 +19,25 @@ var $7GXw8$parcellspprotocol = require("@parcel/lsp-protocol");
19
19
 
20
20
 
21
21
 
22
- const $f26b521ea1c81a56$var$connection = (0, $7GXw8$vscodelanguageservernode.createConnection)((0, $7GXw8$vscodelanguageservernode.ProposedFeatures).all); // Create a simple text document manager.
22
+ const $c87764a44f7435f7$var$connection = (0, $e9En9$vscodelanguageservernode.createConnection)((0, $e9En9$vscodelanguageservernode.ProposedFeatures).all); // Create a simple text document manager.
23
23
  // const documents: TextDocuments<TextDocument> = new TextDocuments(TextDocument);
24
- let $f26b521ea1c81a56$var$hasConfigurationCapability = false;
25
- let $f26b521ea1c81a56$var$hasWorkspaceFolderCapability = false; // let hasDiagnosticRelatedInformationCapability = false;
26
- let $f26b521ea1c81a56$var$hasDiagnosticsRefreshSupport = false;
27
- $f26b521ea1c81a56$var$connection.onInitialize((params)=>{
24
+ let $c87764a44f7435f7$var$hasConfigurationCapability = false;
25
+ let $c87764a44f7435f7$var$hasWorkspaceFolderCapability = false; // let hasDiagnosticRelatedInformationCapability = false;
26
+ let $c87764a44f7435f7$var$hasDiagnosticsRefreshSupport = false;
27
+ $c87764a44f7435f7$var$connection.onInitialize((params)=>{
28
28
  var _capabilities_workspace, _capabilities_workspace_diagnostics;
29
29
  const capabilities = params.capabilities; // Does the client support the `workspace/configuration` request?
30
30
  // If not, we fall back using global settings.
31
- $f26b521ea1c81a56$var$hasConfigurationCapability = !!(capabilities.workspace && !!capabilities.workspace.configuration);
32
- $f26b521ea1c81a56$var$hasWorkspaceFolderCapability = !!(capabilities.workspace && !!capabilities.workspace.workspaceFolders); // hasDiagnosticRelatedInformationCapability = !!(
31
+ $c87764a44f7435f7$var$hasConfigurationCapability = !!(capabilities.workspace && !!capabilities.workspace.configuration);
32
+ $c87764a44f7435f7$var$hasWorkspaceFolderCapability = !!(capabilities.workspace && !!capabilities.workspace.workspaceFolders); // hasDiagnosticRelatedInformationCapability = !!(
33
33
  // capabilities.textDocument &&
34
34
  // capabilities.textDocument.publishDiagnostics &&
35
35
  // capabilities.textDocument.publishDiagnostics.relatedInformation
36
36
  // );
37
- $f26b521ea1c81a56$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);
37
+ $c87764a44f7435f7$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);
38
38
  const result = {
39
39
  capabilities: {
40
- textDocumentSync: (0, $7GXw8$vscodelanguageservernode.TextDocumentSyncKind).Incremental,
40
+ textDocumentSync: (0, $e9En9$vscodelanguageservernode.TextDocumentSyncKind).Incremental,
41
41
  // Tell the client that this server supports code completion.
42
42
  diagnosticProvider: {
43
43
  workspaceDiagnostics: false,
@@ -45,30 +45,30 @@ $f26b521ea1c81a56$var$connection.onInitialize((params)=>{
45
45
  }
46
46
  }
47
47
  };
48
- if ($f26b521ea1c81a56$var$hasWorkspaceFolderCapability) result.capabilities.workspace = {
48
+ if ($c87764a44f7435f7$var$hasWorkspaceFolderCapability) result.capabilities.workspace = {
49
49
  workspaceFolders: {
50
50
  supported: true
51
51
  }
52
52
  };
53
53
  return result;
54
54
  });
55
- $f26b521ea1c81a56$var$connection.onInitialized(()=>{
56
- if ($f26b521ea1c81a56$var$hasConfigurationCapability) // Register for all configuration changes.
57
- $f26b521ea1c81a56$var$connection.client.register((0, $7GXw8$vscodelanguageservernode.DidChangeConfigurationNotification).type, undefined);
58
- if ($f26b521ea1c81a56$var$hasWorkspaceFolderCapability) $f26b521ea1c81a56$var$connection.workspace.onDidChangeWorkspaceFolders(()=>{
59
- $f26b521ea1c81a56$var$connection.console.log("Workspace folder change event received.");
55
+ $c87764a44f7435f7$var$connection.onInitialized(()=>{
56
+ if ($c87764a44f7435f7$var$hasConfigurationCapability) // Register for all configuration changes.
57
+ $c87764a44f7435f7$var$connection.client.register((0, $e9En9$vscodelanguageservernode.DidChangeConfigurationNotification).type, undefined);
58
+ if ($c87764a44f7435f7$var$hasWorkspaceFolderCapability) $c87764a44f7435f7$var$connection.workspace.onDidChangeWorkspaceFolders(()=>{
59
+ $c87764a44f7435f7$var$connection.console.log("Workspace folder change event received.");
60
60
  });
61
61
  }); // Proxy
62
- $f26b521ea1c81a56$var$connection.onRequest((0, $7GXw8$parcellspprotocol.RequestImporters), async (params)=>{
63
- let client = $f26b521ea1c81a56$var$findClient(params);
62
+ $c87764a44f7435f7$var$connection.onRequest((0, $e9En9$parcellspprotocol.RequestImporters), async (params)=>{
63
+ let client = $c87764a44f7435f7$var$findClient(params);
64
64
  if (client) {
65
- let result = await client.connection.sendRequest((0, $7GXw8$parcellspprotocol.RequestImporters), params);
65
+ let result = await client.connection.sendRequest((0, $e9En9$parcellspprotocol.RequestImporters), params);
66
66
  return result;
67
67
  }
68
68
  return null;
69
69
  });
70
- $f26b521ea1c81a56$var$connection.onRequest((0, $7GXw8$vscodelanguageservernode.DocumentDiagnosticRequest).type, async (params)=>{
71
- let client = $f26b521ea1c81a56$var$findClient(params.textDocument.uri);
70
+ $c87764a44f7435f7$var$connection.onRequest((0, $e9En9$vscodelanguageservernode.DocumentDiagnosticRequest).type, async (params)=>{
71
+ let client = $c87764a44f7435f7$var$findClient(params.textDocument.uri);
72
72
  let result;
73
73
  if (client) {
74
74
  // console.log(
@@ -77,23 +77,23 @@ $f26b521ea1c81a56$var$connection.onRequest((0, $7GXw8$vscodelanguageservernode.D
77
77
  // params.previousResultId === client.lastBuild,
78
78
  // );
79
79
  if (params.previousResultId === client.lastBuild) return {
80
- kind: (0, $7GXw8$vscodelanguageservernode.DocumentDiagnosticReportKind).Unchanged,
80
+ kind: (0, $e9En9$vscodelanguageservernode.DocumentDiagnosticReportKind).Unchanged,
81
81
  resultId: client.lastBuild
82
82
  };
83
- result = await client.connection.sendRequest((0, $7GXw8$parcellspprotocol.RequestDocumentDiagnostics), params.textDocument.uri);
83
+ result = await client.connection.sendRequest((0, $e9En9$parcellspprotocol.RequestDocumentDiagnostics), params.textDocument.uri);
84
84
  if (result) client.uris.add(params.textDocument.uri);
85
85
  }
86
86
  return {
87
- kind: (0, $7GXw8$vscodelanguageservernode.DocumentDiagnosticReportKind).Full,
87
+ kind: (0, $e9En9$vscodelanguageservernode.DocumentDiagnosticReportKind).Full,
88
88
  resultId: client === null || client === void 0 ? void 0 : client.lastBuild,
89
89
  items: result !== null && result !== void 0 ? result : []
90
90
  };
91
91
  });
92
- $f26b521ea1c81a56$var$connection.listen();
93
- class $f26b521ea1c81a56$var$ProgressReporter {
92
+ $c87764a44f7435f7$var$connection.listen();
93
+ class $c87764a44f7435f7$var$ProgressReporter {
94
94
  begin() {
95
95
  this.progressReporterPromise = (async ()=>{
96
- let reporter = await $f26b521ea1c81a56$var$connection.window.createWorkDoneProgress();
96
+ let reporter = await $c87764a44f7435f7$var$connection.window.createWorkDoneProgress();
97
97
  reporter.begin("Parcel");
98
98
  return reporter;
99
99
  })();
@@ -103,7 +103,7 @@ class $f26b521ea1c81a56$var$ProgressReporter {
103
103
  }
104
104
  async done() {
105
105
  if (this.progressReporterPromise == null) this.begin();
106
- $7GXw8$assert(this.progressReporterPromise != null);
106
+ $e9En9$assert(this.progressReporterPromise != null);
107
107
  (await this.progressReporterPromise).done();
108
108
  this.progressReporterPromise = null;
109
109
  }
@@ -117,17 +117,17 @@ class $f26b521ea1c81a56$var$ProgressReporter {
117
117
  }
118
118
  }
119
119
  }
120
- function $f26b521ea1c81a56$var$sendDiagnosticsRefresh() {
121
- if ($f26b521ea1c81a56$var$hasDiagnosticsRefreshSupport) $f26b521ea1c81a56$var$connection.sendRequest((0, $7GXw8$vscodelanguageservernode.DiagnosticRefreshRequest).type);
120
+ function $c87764a44f7435f7$var$sendDiagnosticsRefresh() {
121
+ if ($c87764a44f7435f7$var$hasDiagnosticsRefreshSupport) $c87764a44f7435f7$var$connection.sendRequest((0, $e9En9$vscodelanguageservernode.DiagnosticRefreshRequest).type);
122
122
  }
123
- let $f26b521ea1c81a56$var$progressReporter = new $f26b521ea1c81a56$var$ProgressReporter();
124
- let $f26b521ea1c81a56$var$clients = new Map();
125
- function $f26b521ea1c81a56$var$findClient(document) {
126
- let filepath = $7GXw8$url.fileURLToPath(document);
123
+ let $c87764a44f7435f7$var$progressReporter = new $c87764a44f7435f7$var$ProgressReporter();
124
+ let $c87764a44f7435f7$var$clients = new Map();
125
+ function $c87764a44f7435f7$var$findClient(document) {
126
+ let filepath = $e9En9$url.fileURLToPath(document);
127
127
  let longestPrefix = 0;
128
128
  let bestClient;
129
- for (let [, client] of $f26b521ea1c81a56$var$clients){
130
- let prefix = $7GXw8$commonpathprefix([
129
+ for (let [, client] of $c87764a44f7435f7$var$clients){
130
+ let prefix = $e9En9$commonpathprefix([
131
131
  client.projectRoot,
132
132
  filepath
133
133
  ]).length;
@@ -138,11 +138,11 @@ function $f26b521ea1c81a56$var$findClient(document) {
138
138
  }
139
139
  return bestClient;
140
140
  }
141
- function $f26b521ea1c81a56$var$createClient(metafilepath) {
142
- let metafile = JSON.parse($7GXw8$fs.readFileSync(metafilepath, "utf8"));
141
+ function $c87764a44f7435f7$var$createClient(metafilepath) {
142
+ let metafile = JSON.parse($e9En9$fs.readFileSync(metafilepath, "utf8"));
143
143
  let socketfilepath = metafilepath.slice(0, -5);
144
- let [reader, writer] = (0, $7GXw8$vscodejsonrpcnode.createServerPipeTransport)(socketfilepath);
145
- let client = (0, $7GXw8$vscodejsonrpcnode.createMessageConnection)(reader, writer);
144
+ let [reader, writer] = (0, $e9En9$vscodejsonrpcnode.createServerPipeTransport)(socketfilepath);
145
+ let client = (0, $e9En9$vscodejsonrpcnode.createMessageConnection)(reader, writer);
146
146
  client.listen();
147
147
  let uris = new Set();
148
148
  let result = {
@@ -151,61 +151,61 @@ function $f26b521ea1c81a56$var$createClient(metafilepath) {
151
151
  projectRoot: metafile.projectRoot,
152
152
  lastBuild: "0"
153
153
  };
154
- client.onNotification((0, $7GXw8$parcellspprotocol.NotificationBuildStatus), (state, message)=>{
154
+ client.onNotification((0, $e9En9$parcellspprotocol.NotificationBuildStatus), (state, message)=>{
155
155
  // console.log('got NotificationBuildStatus', state, message);
156
156
  if (state === "start") {
157
- $f26b521ea1c81a56$var$progressReporter.begin();
158
- for (let uri of uris)$f26b521ea1c81a56$var$connection.sendDiagnostics({
157
+ $c87764a44f7435f7$var$progressReporter.begin();
158
+ for (let uri of uris)$c87764a44f7435f7$var$connection.sendDiagnostics({
159
159
  uri: uri,
160
160
  diagnostics: []
161
161
  });
162
- } else if (state === "progress" && message != null) $f26b521ea1c81a56$var$progressReporter.report(message);
162
+ } else if (state === "progress" && message != null) $c87764a44f7435f7$var$progressReporter.report(message);
163
163
  else if (state === "end") {
164
164
  result.lastBuild = String(Date.now());
165
- $f26b521ea1c81a56$var$sendDiagnosticsRefresh();
166
- $f26b521ea1c81a56$var$progressReporter.done();
167
- $f26b521ea1c81a56$var$connection.sendNotification((0, $7GXw8$parcellspprotocol.NotificationBuild));
165
+ $c87764a44f7435f7$var$sendDiagnosticsRefresh();
166
+ $c87764a44f7435f7$var$progressReporter.done();
167
+ $c87764a44f7435f7$var$connection.sendNotification((0, $e9En9$parcellspprotocol.NotificationBuild));
168
168
  }
169
169
  });
170
- client.onNotification((0, $7GXw8$parcellspprotocol.NotificationWorkspaceDiagnostics), (diagnostics)=>{
170
+ client.onNotification((0, $e9En9$parcellspprotocol.NotificationWorkspaceDiagnostics), (diagnostics)=>{
171
171
  // console.log('got NotificationWorkspaceDiagnostics', diagnostics);
172
172
  for (let d of diagnostics){
173
173
  uris.add(d.uri);
174
- $f26b521ea1c81a56$var$connection.sendDiagnostics(d);
174
+ $c87764a44f7435f7$var$connection.sendDiagnostics(d);
175
175
  }
176
176
  });
177
177
  client.onClose(()=>{
178
- $f26b521ea1c81a56$var$clients.delete(metafile);
179
- $f26b521ea1c81a56$var$sendDiagnosticsRefresh();
178
+ $c87764a44f7435f7$var$clients.delete(metafile);
179
+ $c87764a44f7435f7$var$sendDiagnosticsRefresh();
180
180
  return Promise.all([
181
181
  ...uris
182
- ].map((uri)=>$f26b521ea1c81a56$var$connection.sendDiagnostics({
182
+ ].map((uri)=>$c87764a44f7435f7$var$connection.sendDiagnostics({
183
183
  uri: uri,
184
184
  diagnostics: []
185
185
  })));
186
186
  });
187
- $f26b521ea1c81a56$var$sendDiagnosticsRefresh();
188
- $f26b521ea1c81a56$var$clients.set(metafile, result);
187
+ $c87764a44f7435f7$var$sendDiagnosticsRefresh();
188
+ $c87764a44f7435f7$var$clients.set(metafile, result);
189
189
  } // Take realpath because to have consistent cache keys on macOS (/var -> /private/var)
190
- const $f26b521ea1c81a56$var$BASEDIR = $7GXw8$path.join($7GXw8$fs.realpathSync($7GXw8$os.tmpdir()), "parcel-lsp");
191
- $7GXw8$fs.mkdirSync($f26b521ea1c81a56$var$BASEDIR, {
190
+ const $c87764a44f7435f7$var$BASEDIR = $e9En9$path.join($e9En9$fs.realpathSync($e9En9$os.tmpdir()), "parcel-lsp");
191
+ $e9En9$fs.mkdirSync($c87764a44f7435f7$var$BASEDIR, {
192
192
  recursive: true
193
193
  }); // Search for currently running Parcel processes in the parcel-lsp dir.
194
194
  // Create an IPC client connection for each running process.
195
- for (let filename of $7GXw8$fs.readdirSync($f26b521ea1c81a56$var$BASEDIR)){
195
+ for (let filename of $e9En9$fs.readdirSync($c87764a44f7435f7$var$BASEDIR)){
196
196
  if (!filename.endsWith(".json")) continue;
197
- let filepath = $7GXw8$path.join($f26b521ea1c81a56$var$BASEDIR, filename);
198
- $f26b521ea1c81a56$var$createClient(filepath); // console.log('connected initial', filepath);
197
+ let filepath = $e9En9$path.join($c87764a44f7435f7$var$BASEDIR, filename);
198
+ $c87764a44f7435f7$var$createClient(filepath); // console.log('connected initial', filepath);
199
199
  } // Watch for new Parcel processes in the parcel-lsp dir, and disconnect the
200
200
  // client for each corresponding connection when a Parcel process ends
201
- $7GXw8$parcelwatcher.subscribe($f26b521ea1c81a56$var$BASEDIR, async (err, events)=>{
201
+ $e9En9$parcelwatcher.subscribe($c87764a44f7435f7$var$BASEDIR, async (err, events)=>{
202
202
  if (err) throw err;
203
203
  for (let event of events){
204
- if (event.type === "create" && event.path.endsWith(".json")) $f26b521ea1c81a56$var$createClient(event.path); // console.log('connected watched', event.path);
204
+ if (event.type === "create" && event.path.endsWith(".json")) $c87764a44f7435f7$var$createClient(event.path); // console.log('connected watched', event.path);
205
205
  else if (event.type === "delete" && event.path.endsWith(".json")) {
206
- let existing = $f26b521ea1c81a56$var$clients.get(event.path); // console.log('existing', event.path, existing);
206
+ let existing = $c87764a44f7435f7$var$clients.get(event.path); // console.log('existing', event.path, existing);
207
207
  if (existing) {
208
- $f26b521ea1c81a56$var$clients.delete(event.path);
208
+ $c87764a44f7435f7$var$clients.delete(event.path);
209
209
  existing.connection.end(); // console.log('disconnected watched', event.path);
210
210
  }
211
211
  }
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;AAsCA,MAAM4B,mCAAazB,CAAAA,GAAAA,gDAAAA,EAAiBU,CAAAA,GAAAA,gDAAgB,AAAhBA,EAAiBgB,GAAlB,GAEnC,yCAFA;AAGA,kFAAA;AAEA,IAAIC,mDAA6B,KAAjC;AACA,IAAIC,qDAA+B,KAAnC,EACA,yDADA;AAEA,IAAIC,qDAA+B,KAAnC;AAEAJ,iCAAWK,YAAX,CAAwB,CAACC,SAA6B;QAiBlDC;IAhBF,MAAMA,eAAeD,OAAOC,YAA5B,EAEA,iEAFA;IAGA,8CAAA;IACAL,mDAA6B,CAAC,CAC5BK,CAAAA,aAAaC,SAAb,IAA0B,CAAC,CAACD,aAAaC,SAAb,CAAuBC,aADvB,AACuBA;IAErDN,qDAA+B,CAAC,CAC9BI,CAAAA,aAAaC,SAAb,IAA0B,CAAC,CAACD,aAAaC,SAAb,CAAuBE,gBADrB,AACqBA,GAErD,kDAHAP;IAIA,iCAAA;IACA,oDAAA;IACA,oEAAA;IACA,KAAA;IACAC,qDAA+BO,QAC7BJ,CAAAA,0BAAAA,aAAaC,SAAb,cAAAD,qCAAAA,KAAAA,IAAAA,uCAAAA,wBAAwBK,0EAAxBL,KAAAA,wCAAqCM,cAArC;IAGF,MAAMC,SAA2B;QAC/BP,cAAc;YACZQ,kBAAkB7B,CAAAA,GAAAA,oDAAoB,AAApBA,EAAqB8B,WAD3B;YAEZ,6DAAA;YACAC,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,SAASD,OAAQ;QACxB,IAAIC,MAAMlF,IAAN,KAAe,YAAYkF,MAAMtI,IAAN,CAAWkI,QAAX,CAAoB,UACjD9B,mCAAakC,MAAMtI,IAAP,GACZ,gDADAoG;aAEK,IAAIkC,MAAMlF,IAAN,KAAe,YAAYkF,MAAMtI,IAAN,CAAWkI,QAAX,CAAoB,UAAU;YAClE,IAAIK,WAAW7C,8BAAQ8C,GAAR,CAAYF,MAAMtI,IAAlB,GACf,iDADA;YAEA,IAAIuI,UAAU;gBACZ7C,8BAAQ6B,MAAR,CAAee,MAAMtI,IAArB;gBACAuI,SAAS3G,UAAT,CAAoB6G,GAApB,IACA,mDADAF;YAED,CAAA;QACF,CAAA;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\nconst connection = createConnection(ProposedFeatures.all);\n\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 createClient(metafilepath: string) {\n let metafile = JSON.parse(fs.readFileSync(metafilepath, 'utf8'));\n\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(metafile);\n sendDiagnosticsRefresh();\n return Promise.all(\n [...uris].map(uri => connection.sendDiagnostics({uri, diagnostics: []})),\n );\n });\n\n sendDiagnosticsRefresh();\n clients.set(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// 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 createClient(filepath);\n // console.log('connected initial', filepath);\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 createClient(event.path);\n // console.log('connected watched', event.path);\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 // console.log('disconnected watched', event.path);\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","connection","all","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","projectRoot","Set","progressReporter","clients","Map","document","filepath","fileURLToPath","longestPrefix","bestClient","prefix","length","warn","createClient","metafilepath","metafile","JSON","parse","readFileSync","socketfilepath","slice","reader","writer","onNotification","state","sendDiagnostics","String","Date","now","sendNotification","d","onClose","delete","map","set","BASEDIR","join","realpathSync","tmpdir","mkdirSync","recursive","filename","readdirSync","endsWith","subscribe","err","events","event","existing","get","end"],"version":3,"file":"LspServer.js.map","sourceRoot":"../../../../"}
1
+ {"mappings":";;;;;;;;;;;;;;;;;;;;;AAsCA,MAAM4B,mCAAazB,CAAAA,GAAAA,gDAAAA,EAAiBU,CAAAA,GAAAA,gDAAgB,AAAhBA,EAAiBgB,GAAlB,GAEnC,yCAFA;AAGA,kFAAA;AAEA,IA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\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\nconst connection = createConnection(ProposedFeatures.all);\n\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 createClient(metafilepath: string) {\n let metafile = JSON.parse(fs.readFileSync(metafilepath, 'utf8'));\n\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(metafile);\n sendDiagnosticsRefresh();\n return Promise.all(\n [...uris].map(uri => connection.sendDiagnostics({uri, diagnostics: []})),\n );\n });\n\n sendDiagnosticsRefresh();\n clients.set(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// 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 createClient(filepath);\n // console.log('connected initial', filepath);\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 createClient(event.path);\n // console.log('connected watched', event.path);\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 // console.log('disconnected watched', event.path);\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","connection","all","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","projectRoot","Set","progressReporter","clients","Map","document","filepath","fileURLToPath","longestPrefix","bestClient","prefix","length","warn","createClient","metafilepath","metafile","JSON","parse","readFileSync","socketfilepath","slice","reader","writer","onNotification","state","sendDiagnostics","String","Date","now","sendNotification","d","onClose","delete","map","set","BASEDIR","join","realpathSync","tmpdir","mkdirSync","recursive","filename","readdirSync","endsWith","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.8.3",
3
+ "version": "2.8.4-nightly.0+7b79c6d",
4
4
  "license": "MIT",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -22,10 +22,10 @@
22
22
  },
23
23
  "engines": {
24
24
  "node": ">= 12.0.0",
25
- "parcel": "^2.8.3"
25
+ "parcel": "2.8.4-nightly.0+7b79c6d"
26
26
  },
27
27
  "dependencies": {
28
- "@parcel/lsp-protocol": "2.8.3",
28
+ "@parcel/lsp-protocol": "2.8.4-nightly.0+7b79c6d",
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": "349a6caf40ec8abb6a49fcae0765f8f8deb2073d"
47
+ "gitHead": "7b79c6d69ffabef89810a8db61e9abdeb70d6990"
48
48
  }