@atlaspack/lsp 2.14.2-dev.85 → 2.14.2-dev.90

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/lsp",
3
- "version": "2.14.2-dev.85+f615781c0",
3
+ "version": "2.14.2-dev.90+5a11f33c5",
4
4
  "license": "(MIT OR Apache-2.0)",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -20,7 +20,7 @@
20
20
  "node": ">= 16.0.0"
21
21
  },
22
22
  "dependencies": {
23
- "@atlaspack/lsp-protocol": "2.14.1-dev.118+f615781c0",
23
+ "@atlaspack/lsp-protocol": "2.14.1-dev.123+5a11f33c5",
24
24
  "@parcel/watcher": "^2.0.7",
25
25
  "common-path-prefix": "^3.0.0",
26
26
  "nullthrows": "^1.1.1",
@@ -31,14 +31,14 @@
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/node": ">= 18",
34
- "@typescript-eslint/eslint-plugin": "^5.59.7",
35
- "@typescript-eslint/parser": "^5.59.7",
36
- "eslint": "^8.41.0",
34
+ "@typescript-eslint/eslint-plugin": "^8.31.1",
35
+ "@typescript-eslint/parser": "^8.31.1",
36
+ "eslint": "^8.57.0",
37
37
  "typescript": ">=3.0.0"
38
38
  },
39
39
  "targets": {
40
40
  "types": false
41
41
  },
42
42
  "type": "commonjs",
43
- "gitHead": "f615781c07b16806135476593869793c64e9f4b6"
43
+ "gitHead": "5a11f33c51ff74d1cf8d4b72cfa0fda833aa980a"
44
44
  }
package/lib/LspServer.js DELETED
@@ -1,235 +0,0 @@
1
- var $cBkJy$path = require("path");
2
- var $cBkJy$fs = require("fs");
3
- var $cBkJy$os = require("os");
4
- var $cBkJy$vscodelanguageservernode = require("vscode-languageserver/node");
5
- var $cBkJy$vscodejsonrpcnode = require("vscode-jsonrpc/node");
6
- var $cBkJy$assert = require("assert");
7
- var $cBkJy$url = require("url");
8
- var $cBkJy$commonpathprefix = require("common-path-prefix");
9
- var $cBkJy$parcelwatcher = require("@parcel/watcher");
10
- var $cBkJy$atlaspacklspprotocol = require("@atlaspack/lsp-protocol");
11
-
12
-
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
- const $7ef283f05e7b48bf$var$connection = (0, $cBkJy$vscodelanguageservernode.createConnection)((0, $cBkJy$vscodelanguageservernode.ProposedFeatures).all);
23
- const $7ef283f05e7b48bf$var$WORKSPACE_ROOT = process.cwd();
24
- const $7ef283f05e7b48bf$var$LSP_SENTINEL_FILENAME = 'lsp-server';
25
- // Create a simple text document manager.
26
- // const documents: TextDocuments<TextDocument> = new TextDocuments(TextDocument);
27
- let $7ef283f05e7b48bf$var$hasConfigurationCapability = false;
28
- let $7ef283f05e7b48bf$var$hasWorkspaceFolderCapability = false;
29
- // let hasDiagnosticRelatedInformationCapability = false;
30
- let $7ef283f05e7b48bf$var$hasDiagnosticsRefreshSupport = false;
31
- $7ef283f05e7b48bf$var$connection.onInitialize((params)=>{
32
- const capabilities = params.capabilities;
33
- // Does the client support the `workspace/configuration` request?
34
- // If not, we fall back using global settings.
35
- $7ef283f05e7b48bf$var$hasConfigurationCapability = !!(capabilities.workspace && !!capabilities.workspace.configuration);
36
- $7ef283f05e7b48bf$var$hasWorkspaceFolderCapability = !!(capabilities.workspace && !!capabilities.workspace.workspaceFolders);
37
- // hasDiagnosticRelatedInformationCapability = !!(
38
- // capabilities.textDocument &&
39
- // capabilities.textDocument.publishDiagnostics &&
40
- // capabilities.textDocument.publishDiagnostics.relatedInformation
41
- // );
42
- $7ef283f05e7b48bf$var$hasDiagnosticsRefreshSupport = Boolean(capabilities.workspace?.diagnostics?.refreshSupport);
43
- const result = {
44
- capabilities: {
45
- textDocumentSync: (0, $cBkJy$vscodelanguageservernode.TextDocumentSyncKind).Incremental,
46
- // Tell the client that this server supports code completion.
47
- diagnosticProvider: {
48
- workspaceDiagnostics: false,
49
- interFileDependencies: true
50
- }
51
- }
52
- };
53
- if ($7ef283f05e7b48bf$var$hasWorkspaceFolderCapability) result.capabilities.workspace = {
54
- workspaceFolders: {
55
- supported: true
56
- }
57
- };
58
- return result;
59
- });
60
- $7ef283f05e7b48bf$var$connection.onInitialized(()=>{
61
- if ($7ef283f05e7b48bf$var$hasConfigurationCapability) // Register for all configuration changes.
62
- $7ef283f05e7b48bf$var$connection.client.register((0, $cBkJy$vscodelanguageservernode.DidChangeConfigurationNotification).type, undefined);
63
- if ($7ef283f05e7b48bf$var$hasWorkspaceFolderCapability) $7ef283f05e7b48bf$var$connection.workspace.onDidChangeWorkspaceFolders(()=>{
64
- $7ef283f05e7b48bf$var$connection.console.log('Workspace folder change event received.');
65
- });
66
- });
67
- // Proxy
68
- $7ef283f05e7b48bf$var$connection.onRequest((0, $cBkJy$atlaspacklspprotocol.RequestImporters), async (params)=>{
69
- let client = $7ef283f05e7b48bf$var$findClient(params);
70
- if (client) {
71
- let result = await client.connection.sendRequest((0, $cBkJy$atlaspacklspprotocol.RequestImporters), params);
72
- return result;
73
- }
74
- return null;
75
- });
76
- $7ef283f05e7b48bf$var$connection.onRequest((0, $cBkJy$vscodelanguageservernode.DocumentDiagnosticRequest).type, async (params)=>{
77
- let client = $7ef283f05e7b48bf$var$findClient(params.textDocument.uri);
78
- let result;
79
- if (client) {
80
- // console.log(
81
- // 'DocumentDiagnosticRequest',
82
- // params.textDocument.uri,
83
- // params.previousResultId === client.lastBuild,
84
- // );
85
- if (params.previousResultId === client.lastBuild) return {
86
- kind: (0, $cBkJy$vscodelanguageservernode.DocumentDiagnosticReportKind).Unchanged,
87
- resultId: client.lastBuild
88
- };
89
- result = await client.connection.sendRequest((0, $cBkJy$atlaspacklspprotocol.RequestDocumentDiagnostics), params.textDocument.uri);
90
- if (result) client.uris.add(params.textDocument.uri);
91
- }
92
- return {
93
- kind: (0, $cBkJy$vscodelanguageservernode.DocumentDiagnosticReportKind).Full,
94
- resultId: client?.lastBuild,
95
- items: result ?? []
96
- };
97
- });
98
- $7ef283f05e7b48bf$var$connection.listen();
99
- class $7ef283f05e7b48bf$var$ProgressReporter {
100
- begin() {
101
- this.progressReporterPromise = (async ()=>{
102
- let reporter = await $7ef283f05e7b48bf$var$connection.window.createWorkDoneProgress();
103
- reporter.begin('Atlaspack');
104
- return reporter;
105
- })();
106
- this.progressReporterPromise.then((reporter)=>{
107
- if (this.lastMessage != null) reporter.report(this.lastMessage);
108
- });
109
- }
110
- async done() {
111
- if (this.progressReporterPromise == null) this.begin();
112
- $cBkJy$assert(this.progressReporterPromise != null);
113
- (await this.progressReporterPromise).done();
114
- this.progressReporterPromise = null;
115
- }
116
- async report(message) {
117
- if (this.progressReporterPromise == null) {
118
- this.lastMessage = message;
119
- this.begin();
120
- } else {
121
- let r = await this.progressReporterPromise;
122
- r.report(message);
123
- }
124
- }
125
- }
126
- function $7ef283f05e7b48bf$var$sendDiagnosticsRefresh() {
127
- if ($7ef283f05e7b48bf$var$hasDiagnosticsRefreshSupport) $7ef283f05e7b48bf$var$connection.sendRequest((0, $cBkJy$vscodelanguageservernode.DiagnosticRefreshRequest).type);
128
- }
129
- let $7ef283f05e7b48bf$var$progressReporter = new $7ef283f05e7b48bf$var$ProgressReporter();
130
- let $7ef283f05e7b48bf$var$clients = new Map();
131
- function $7ef283f05e7b48bf$var$findClient(document) {
132
- let filepath = $cBkJy$url.fileURLToPath(document);
133
- let longestPrefix = 0;
134
- let bestClient;
135
- for (let [, client] of $7ef283f05e7b48bf$var$clients){
136
- let prefix = $cBkJy$commonpathprefix([
137
- client.projectRoot,
138
- filepath
139
- ]).length;
140
- if (longestPrefix < prefix) {
141
- longestPrefix = prefix;
142
- bestClient = client;
143
- } else if (longestPrefix === prefix) console.warn('Ambiguous client for ' + filepath);
144
- }
145
- return bestClient;
146
- }
147
- function $7ef283f05e7b48bf$var$loadMetafile(filepath) {
148
- const file = $cBkJy$fs.readFileSync(filepath, 'utf-8');
149
- return JSON.parse(file);
150
- }
151
- function $7ef283f05e7b48bf$var$createClient(metafilepath, metafile) {
152
- let socketfilepath = metafilepath.slice(0, -5);
153
- let [reader, writer] = (0, $cBkJy$vscodejsonrpcnode.createServerPipeTransport)(socketfilepath);
154
- let client = (0, $cBkJy$vscodejsonrpcnode.createMessageConnection)(reader, writer);
155
- client.listen();
156
- let uris = new Set();
157
- let result = {
158
- connection: client,
159
- uris: uris,
160
- projectRoot: metafile.projectRoot,
161
- lastBuild: '0'
162
- };
163
- client.onNotification((0, $cBkJy$atlaspacklspprotocol.NotificationBuildStatus), (state, message)=>{
164
- // console.log('got NotificationBuildStatus', state, message);
165
- if (state === 'start') {
166
- $7ef283f05e7b48bf$var$progressReporter.begin();
167
- for (let uri of uris)$7ef283f05e7b48bf$var$connection.sendDiagnostics({
168
- uri: uri,
169
- diagnostics: []
170
- });
171
- } else if (state === 'progress' && message != null) $7ef283f05e7b48bf$var$progressReporter.report(message);
172
- else if (state === 'end') {
173
- result.lastBuild = String(Date.now());
174
- $7ef283f05e7b48bf$var$sendDiagnosticsRefresh();
175
- $7ef283f05e7b48bf$var$progressReporter.done();
176
- $7ef283f05e7b48bf$var$connection.sendNotification((0, $cBkJy$atlaspacklspprotocol.NotificationBuild));
177
- }
178
- });
179
- client.onNotification((0, $cBkJy$atlaspacklspprotocol.NotificationWorkspaceDiagnostics), (diagnostics)=>{
180
- // console.log('got NotificationWorkspaceDiagnostics', diagnostics);
181
- for (let d of diagnostics){
182
- uris.add(d.uri);
183
- $7ef283f05e7b48bf$var$connection.sendDiagnostics(d);
184
- }
185
- });
186
- client.onClose(()=>{
187
- $7ef283f05e7b48bf$var$clients.delete(JSON.stringify(metafile));
188
- $7ef283f05e7b48bf$var$sendDiagnosticsRefresh();
189
- return Promise.all([
190
- ...uris
191
- ].map((uri)=>$7ef283f05e7b48bf$var$connection.sendDiagnostics({
192
- uri: uri,
193
- diagnostics: []
194
- })));
195
- });
196
- $7ef283f05e7b48bf$var$sendDiagnosticsRefresh();
197
- $7ef283f05e7b48bf$var$clients.set(JSON.stringify(metafile), result);
198
- }
199
- // Take realpath because to have consistent cache keys on macOS (/var -> /private/var)
200
- const $7ef283f05e7b48bf$var$BASEDIR = $cBkJy$path.join($cBkJy$fs.realpathSync($cBkJy$os.tmpdir()), 'parcel-lsp');
201
- $cBkJy$fs.mkdirSync($7ef283f05e7b48bf$var$BASEDIR, {
202
- recursive: true
203
- });
204
- $cBkJy$fs.writeFileSync($cBkJy$path.join($7ef283f05e7b48bf$var$BASEDIR, $7ef283f05e7b48bf$var$LSP_SENTINEL_FILENAME), '');
205
- // Search for currently running Atlaspack processes in the parcel-lsp dir.
206
- // Create an IPC client connection for each running process.
207
- for (let filename of $cBkJy$fs.readdirSync($7ef283f05e7b48bf$var$BASEDIR)){
208
- if (!filename.endsWith('.json')) continue;
209
- let filepath = $cBkJy$path.join($7ef283f05e7b48bf$var$BASEDIR, filename);
210
- const contents = $7ef283f05e7b48bf$var$loadMetafile(filepath);
211
- const { projectRoot: projectRoot } = contents;
212
- if ($7ef283f05e7b48bf$var$WORKSPACE_ROOT === projectRoot) $7ef283f05e7b48bf$var$createClient(filepath, contents);
213
- }
214
- // Watch for new Atlaspack processes in the parcel-lsp dir, and disconnect the
215
- // client for each corresponding connection when a Atlaspack process ends
216
- $cBkJy$parcelwatcher.subscribe($7ef283f05e7b48bf$var$BASEDIR, async (err, events)=>{
217
- if (err) throw err;
218
- for (let event of events){
219
- if (event.type === 'create' && event.path.endsWith('.json')) {
220
- const contents = $7ef283f05e7b48bf$var$loadMetafile(event.path);
221
- const { projectRoot: projectRoot } = contents;
222
- if ($7ef283f05e7b48bf$var$WORKSPACE_ROOT === projectRoot) $7ef283f05e7b48bf$var$createClient(event.path, contents);
223
- } else if (event.type === 'delete' && event.path.endsWith('.json')) {
224
- let existing = $7ef283f05e7b48bf$var$clients.get(event.path);
225
- console.log('existing', event.path, existing);
226
- if (existing) {
227
- $7ef283f05e7b48bf$var$clients.delete(event.path);
228
- existing.connection.end();
229
- }
230
- }
231
- }
232
- });
233
-
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MAAMlJ,IAAI;gBACzBmJ,SAASlH,UAAU,CAACoH,GAAG;YACzB;QACF;IACF;AACF","sources":["packages/utils/atlaspack-lsp/src/LspServer.ts"],"sourcesContent":["import * as path from 'path';\nimport * as fs from 'fs';\nimport * as os from 'os';\nimport {\n createConnection,\n DiagnosticRefreshRequest,\n DidChangeConfigurationNotification,\n DocumentDiagnosticParams,\n DocumentDiagnosticReport,\n DocumentDiagnosticReportKind,\n DocumentDiagnosticRequest,\n DocumentUri,\n InitializeParams,\n InitializeResult,\n ProposedFeatures,\n TextDocumentSyncKind,\n WorkDoneProgressServerReporter,\n} from 'vscode-languageserver/node';\n\nimport {\n createServerPipeTransport,\n createMessageConnection,\n MessageConnection,\n} from 'vscode-jsonrpc/node';\nimport * as invariant from 'assert';\nimport * as url from 'url';\nimport commonPathPrefix = require('common-path-prefix');\n\n// import {TextDocument} from 'vscode-languageserver-textdocument';\nimport * as watcher from '@parcel/watcher';\nimport {\n NotificationBuild,\n NotificationBuildStatus,\n NotificationWorkspaceDiagnostics,\n RequestDocumentDiagnostics,\n RequestImporters,\n} from '@atlaspack/lsp-protocol';\n\ntype Metafile = {\n projectRoot: string;\n pid: typeof process['pid'];\n argv: typeof process['argv'];\n};\n\nconst connection = createConnection(ProposedFeatures.all);\nconst WORKSPACE_ROOT = process.cwd();\nconst LSP_SENTINEL_FILENAME = 'lsp-server';\n// Create a simple text document manager.\n// const documents: TextDocuments<TextDocument> = new TextDocuments(TextDocument);\n\nlet hasConfigurationCapability = false;\nlet hasWorkspaceFolderCapability = false;\n// let hasDiagnosticRelatedInformationCapability = false;\nlet hasDiagnosticsRefreshSupport = false;\n\nconnection.onInitialize((params: InitializeParams) => {\n const capabilities = params.capabilities;\n\n // Does the client support the `workspace/configuration` request?\n // If not, we fall back using global settings.\n hasConfigurationCapability = !!(\n capabilities.workspace && !!capabilities.workspace.configuration\n );\n hasWorkspaceFolderCapability = !!(\n capabilities.workspace && !!capabilities.workspace.workspaceFolders\n );\n // hasDiagnosticRelatedInformationCapability = !!(\n // capabilities.textDocument &&\n // capabilities.textDocument.publishDiagnostics &&\n // capabilities.textDocument.publishDiagnostics.relatedInformation\n // );\n hasDiagnosticsRefreshSupport = Boolean(\n capabilities.workspace?.diagnostics?.refreshSupport,\n );\n\n const result: InitializeResult = {\n capabilities: {\n textDocumentSync: TextDocumentSyncKind.Incremental,\n // Tell the client that this server supports code completion.\n diagnosticProvider: {\n workspaceDiagnostics: false,\n interFileDependencies: true,\n },\n },\n };\n\n if (hasWorkspaceFolderCapability) {\n result.capabilities.workspace = {\n workspaceFolders: {\n supported: true,\n },\n };\n }\n return result;\n});\n\nconnection.onInitialized(() => {\n if (hasConfigurationCapability) {\n // Register for all configuration changes.\n connection.client.register(\n DidChangeConfigurationNotification.type,\n undefined,\n );\n }\n if (hasWorkspaceFolderCapability) {\n connection.workspace.onDidChangeWorkspaceFolders((_event) => {\n connection.console.log('Workspace folder change event received.');\n });\n }\n});\n\n// Proxy\nconnection.onRequest(RequestImporters, async (params) => {\n let client = findClient(params);\n if (client) {\n let result = await client.connection.sendRequest(RequestImporters, params);\n return result;\n }\n return null;\n});\n\nconnection.onRequest(\n DocumentDiagnosticRequest.type,\n async (\n params: DocumentDiagnosticParams,\n ): Promise<DocumentDiagnosticReport> => {\n let client = findClient(params.textDocument.uri);\n let result;\n if (client) {\n // console.log(\n // 'DocumentDiagnosticRequest',\n // params.textDocument.uri,\n // params.previousResultId === client.lastBuild,\n // );\n\n if (params.previousResultId === client.lastBuild) {\n return {\n kind: DocumentDiagnosticReportKind.Unchanged,\n resultId: client.lastBuild,\n };\n }\n\n result = await client.connection.sendRequest(\n RequestDocumentDiagnostics,\n params.textDocument.uri,\n );\n\n if (result) {\n client.uris.add(params.textDocument.uri);\n }\n }\n\n return {\n kind: DocumentDiagnosticReportKind.Full,\n resultId: client?.lastBuild,\n items: result ?? [],\n };\n },\n);\n\nconnection.listen();\n\nclass ProgressReporter {\n progressReporterPromise?: Promise<WorkDoneProgressServerReporter> | null;\n lastMessage?: string;\n begin() {\n this.progressReporterPromise = (async () => {\n let reporter = await connection.window.createWorkDoneProgress();\n reporter.begin('Atlaspack');\n return reporter;\n })();\n this.progressReporterPromise.then((reporter) => {\n if (this.lastMessage != null) {\n reporter.report(this.lastMessage);\n }\n });\n }\n async done() {\n if (this.progressReporterPromise == null) {\n this.begin();\n }\n invariant(this.progressReporterPromise != null);\n (await this.progressReporterPromise).done();\n this.progressReporterPromise = null;\n }\n async report(message: string) {\n if (this.progressReporterPromise == null) {\n this.lastMessage = message;\n this.begin();\n } else {\n let r = await this.progressReporterPromise;\n r.report(message);\n }\n }\n}\n\nfunction sendDiagnosticsRefresh() {\n if (hasDiagnosticsRefreshSupport) {\n connection.sendRequest(DiagnosticRefreshRequest.type);\n }\n}\n\ntype Client = {\n connection: MessageConnection;\n projectRoot: string;\n uris: Set<DocumentUri>;\n lastBuild: string;\n};\n\nlet progressReporter = new ProgressReporter();\nlet clients: Map<string, Client> = new Map();\n\nfunction findClient(document: DocumentUri): Client | undefined {\n let filepath = url.fileURLToPath(document);\n\n let longestPrefix = 0;\n let bestClient;\n for (let [, client] of clients) {\n let prefix = commonPathPrefix([client.projectRoot, filepath]).length;\n if (longestPrefix < prefix) {\n longestPrefix = prefix;\n bestClient = client;\n } else if (longestPrefix === prefix) {\n console.warn('Ambiguous client for ' + filepath);\n }\n }\n return bestClient;\n}\n\nfunction loadMetafile(filepath: string) {\n const file = fs.readFileSync(filepath, 'utf-8');\n return JSON.parse(file);\n}\n\nfunction createClient(metafilepath: string, metafile: Metafile) {\n let socketfilepath = metafilepath.slice(0, -5);\n let [reader, writer] = createServerPipeTransport(socketfilepath);\n let client = createMessageConnection(reader, writer);\n client.listen();\n\n let uris = new Set<DocumentUri>();\n\n let result = {\n connection: client,\n uris,\n projectRoot: metafile.projectRoot,\n lastBuild: '0',\n };\n\n client.onNotification(NotificationBuildStatus, (state, message) => {\n // console.log('got NotificationBuildStatus', state, message);\n if (state === 'start') {\n progressReporter.begin();\n for (let uri of uris) {\n connection.sendDiagnostics({uri, diagnostics: []});\n }\n } else if (state === 'progress' && message != null) {\n progressReporter.report(message);\n } else if (state === 'end') {\n result.lastBuild = String(Date.now());\n sendDiagnosticsRefresh();\n progressReporter.done();\n connection.sendNotification(NotificationBuild);\n }\n });\n\n client.onNotification(NotificationWorkspaceDiagnostics, (diagnostics) => {\n // console.log('got NotificationWorkspaceDiagnostics', diagnostics);\n for (let d of diagnostics) {\n uris.add(d.uri);\n connection.sendDiagnostics(d);\n }\n });\n\n client.onClose(() => {\n clients.delete(JSON.stringify(metafile));\n sendDiagnosticsRefresh();\n return Promise.all(\n [...uris].map((uri) =>\n connection.sendDiagnostics({uri, diagnostics: []}),\n ),\n );\n });\n\n sendDiagnosticsRefresh();\n clients.set(JSON.stringify(metafile), result);\n}\n\n// Take realpath because to have consistent cache keys on macOS (/var -> /private/var)\nconst BASEDIR = path.join(fs.realpathSync(os.tmpdir()), 'parcel-lsp');\nfs.mkdirSync(BASEDIR, {recursive: true});\n\nfs.writeFileSync(path.join(BASEDIR, LSP_SENTINEL_FILENAME), '');\n\n// Search for currently running Atlaspack processes in the parcel-lsp dir.\n// Create an IPC client connection for each running process.\nfor (let filename of fs.readdirSync(BASEDIR)) {\n if (!filename.endsWith('.json')) continue;\n let filepath = path.join(BASEDIR, filename);\n const contents = loadMetafile(filepath);\n const {projectRoot} = contents;\n\n if (WORKSPACE_ROOT === projectRoot) {\n createClient(filepath, contents);\n }\n}\n\n// Watch for new Atlaspack processes in the parcel-lsp dir, and disconnect the\n// client for each corresponding connection when a Atlaspack process ends\nwatcher.subscribe(BASEDIR, async (err, events) => {\n if (err) {\n throw err;\n }\n\n for (let event of events) {\n if (event.type === 'create' && event.path.endsWith('.json')) {\n const contents = loadMetafile(event.path);\n const {projectRoot} = contents;\n\n if (WORKSPACE_ROOT === projectRoot) {\n createClient(event.path, contents);\n }\n } else if (event.type === 'delete' && event.path.endsWith('.json')) {\n let existing = clients.get(event.path);\n console.log('existing', event.path, existing);\n if (existing) {\n clients.delete(event.path);\n existing.connection.end();\n }\n }\n }\n});\n"],"names":["path","fs","os","createConnection","DiagnosticRefreshRequest","DidChangeConfigurationNotification","DocumentDiagnosticParams","DocumentDiagnosticReport","DocumentDiagnosticReportKind","DocumentDiagnosticRequest","DocumentUri","InitializeParams","InitializeResult","ProposedFeatures","TextDocumentSyncKind","WorkDoneProgressServerReporter","createServerPipeTransport","createMessageConnection","MessageConnection","invariant","url","commonPathPrefix","watcher","NotificationBuild","NotificationBuildStatus","NotificationWorkspaceDiagnostics","RequestDocumentDiagnostics","RequestImporters","Metafile","projectRoot","pid","process","argv","connection","all","WORKSPACE_ROOT","cwd","LSP_SENTINEL_FILENAME","hasConfigurationCapability","hasWorkspaceFolderCapability","hasDiagnosticsRefreshSupport","onInitialize","params","capabilities","workspace","configuration","workspaceFolders","Boolean","diagnostics","refreshSupport","result","textDocumentSync","Incremental","diagnosticProvider","workspaceDiagnostics","interFileDependencies","supported","onInitialized","client","register","type","undefined","onDidChangeWorkspaceFolders","console","log","onRequest","findClient","sendRequest","Promise","textDocument","uri","previousResultId","lastBuild","kind","Unchanged","resultId","uris","add","Full","items","listen","ProgressReporter","begin","progressReporterPromise","reporter","window","createWorkDoneProgress","then","lastMessage","report","done","message","r","sendDiagnosticsRefresh","Client","Set","progressReporter","clients","Map","document","filepath","fileURLToPath","longestPrefix","bestClient","prefix","length","warn","loadMetafile","file","readFileSync","JSON","parse","createClient","metafilepath","metafile","socketfilepath","slice","reader","writer","onNotification","state","sendDiagnostics","String","Date","now","sendNotification","d","onClose","delete","stringify","map","set","BASEDIR","join","realpathSync","tmpdir","mkdirSync","recursive","writeFileSync","filename","readdirSync","endsWith","contents","subscribe","err","events","event","existing","get","end"],"version":3,"file":"LspServer.js.map","sourceRoot":"../../../../"}