@atlaspack/reporter-lsp 2.14.5-canary.30 → 2.14.5-canary.301

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/CHANGELOG.md CHANGED
@@ -1,5 +1,262 @@
1
1
  # @atlaspack/reporter-lsp
2
2
 
3
+ ## 2.14.39
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`73168c2`](https://github.com/atlassian-labs/atlaspack/commit/73168c275a5d9abff9907bcf536b340bca1ed5f0), [`617a318`](https://github.com/atlassian-labs/atlaspack/commit/617a318ddc9419b38360257353fec50b9051ee13)]:
8
+ - @atlaspack/utils@3.2.0
9
+ - @atlaspack/plugin@2.14.39
10
+
11
+ ## 2.14.38
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies [[`7d7a55d`](https://github.com/atlassian-labs/atlaspack/commit/7d7a55dd6395ec391a2e4c33b3dec0d1ea477d4c)]:
16
+ - @atlaspack/utils@3.1.2
17
+ - @atlaspack/plugin@2.14.38
18
+
19
+ ## 2.14.37
20
+
21
+ ### Patch Changes
22
+
23
+ - Updated dependencies []:
24
+ - @atlaspack/utils@3.1.1
25
+ - @atlaspack/plugin@2.14.37
26
+
27
+ ## 2.14.36
28
+
29
+ ### Patch Changes
30
+
31
+ - Updated dependencies [[`5776be2`](https://github.com/atlassian-labs/atlaspack/commit/5776be21f70a3f2b9471ba33da3ba1a883f21f1a)]:
32
+ - @atlaspack/utils@3.1.0
33
+ - @atlaspack/plugin@2.14.36
34
+
35
+ ## 2.14.35
36
+
37
+ ### Patch Changes
38
+
39
+ - Updated dependencies [[`c372f3f`](https://github.com/atlassian-labs/atlaspack/commit/c372f3fd6fce8200d5cf47f41bc7895c6cbb5558), [`17dfea9`](https://github.com/atlassian-labs/atlaspack/commit/17dfea9e9f3169807808520df9c09ebf70dc8b10)]:
40
+ - @atlaspack/utils@3.0.3
41
+ - @atlaspack/plugin@2.14.35
42
+
43
+ ## 2.14.34
44
+
45
+ ### Patch Changes
46
+
47
+ - Updated dependencies []:
48
+ - @atlaspack/utils@3.0.2
49
+ - @atlaspack/plugin@2.14.34
50
+
51
+ ## 2.14.33
52
+
53
+ ### Patch Changes
54
+
55
+ - Updated dependencies [[`236e546`](https://github.com/atlassian-labs/atlaspack/commit/236e5465863dca6044a7191e05260a5b924c342e)]:
56
+ - @atlaspack/utils@3.0.1
57
+ - @atlaspack/plugin@2.14.33
58
+
59
+ ## 2.14.32
60
+
61
+ ### Patch Changes
62
+
63
+ - Updated dependencies [[`1180103`](https://github.com/atlassian-labs/atlaspack/commit/118010351ed444f8178988afb3f77807154dd933)]:
64
+ - @atlaspack/utils@3.0.0
65
+ - @atlaspack/plugin@2.14.32
66
+
67
+ ## 2.14.31
68
+
69
+ ### Patch Changes
70
+
71
+ - [#785](https://github.com/atlassian-labs/atlaspack/pull/785) [`0e7dd5e`](https://github.com/atlassian-labs/atlaspack/commit/0e7dd5ec6fbe05aa9e0bb5775a9d0975f206a922) Thanks [@matt-koko](https://github.com/matt-koko)! - We need to re-publish every package in Atlaspack with the corrected types field.
72
+
73
+ - Updated dependencies [[`0e7dd5e`](https://github.com/atlassian-labs/atlaspack/commit/0e7dd5ec6fbe05aa9e0bb5775a9d0975f206a922)]:
74
+ - @atlaspack/plugin@2.14.31
75
+ - @atlaspack/utils@2.19.3
76
+ - @atlaspack/lsp-protocol@2.14.4
77
+
78
+ ## 2.14.30
79
+
80
+ ### Patch Changes
81
+
82
+ - Updated dependencies []:
83
+ - @atlaspack/utils@2.19.2
84
+ - @atlaspack/plugin@2.14.30
85
+
86
+ ## 2.14.29
87
+
88
+ ### Patch Changes
89
+
90
+ - Updated dependencies []:
91
+ - @atlaspack/utils@2.19.1
92
+ - @atlaspack/plugin@2.14.29
93
+
94
+ ## 2.14.28
95
+
96
+ ### Patch Changes
97
+
98
+ - Updated dependencies [[`f0349a6`](https://github.com/atlassian-labs/atlaspack/commit/f0349a6b9b04755088f121095ca6301a2ada3767)]:
99
+ - @atlaspack/utils@2.19.0
100
+ - @atlaspack/plugin@2.14.28
101
+
102
+ ## 2.14.27
103
+
104
+ ### Patch Changes
105
+
106
+ - Updated dependencies []:
107
+ - @atlaspack/utils@2.18.4
108
+ - @atlaspack/plugin@2.14.27
109
+
110
+ ## 2.14.26
111
+
112
+ ### Patch Changes
113
+
114
+ - [#742](https://github.com/atlassian-labs/atlaspack/pull/742) [`ee040bb`](https://github.com/atlassian-labs/atlaspack/commit/ee040bb6428f29b57d892ddd8107e29077d08ffd) Thanks [@yamadapc](https://github.com/yamadapc)! - Internal changes and bug fixes to environmentDeduplication flag
115
+
116
+ - Updated dependencies [[`ee040bb`](https://github.com/atlassian-labs/atlaspack/commit/ee040bb6428f29b57d892ddd8107e29077d08ffd), [`889c65c`](https://github.com/atlassian-labs/atlaspack/commit/889c65cd25b811045e26a117e7404f694dde77a2)]:
117
+ - @atlaspack/lsp-protocol@2.14.3
118
+ - @atlaspack/plugin@2.14.26
119
+ - @atlaspack/utils@2.18.3
120
+
121
+ ## 2.14.25
122
+
123
+ ### Patch Changes
124
+
125
+ - Updated dependencies []:
126
+ - @atlaspack/utils@2.18.2
127
+ - @atlaspack/plugin@2.14.25
128
+
129
+ ## 2.14.24
130
+
131
+ ### Patch Changes
132
+
133
+ - Updated dependencies []:
134
+ - @atlaspack/utils@2.18.1
135
+ - @atlaspack/plugin@2.14.24
136
+
137
+ ## 2.14.23
138
+
139
+ ### Patch Changes
140
+
141
+ - Updated dependencies [[`23d561e`](https://github.com/atlassian-labs/atlaspack/commit/23d561e51e68b0c38fd1ff4e4fb173e5e7b01cf2)]:
142
+ - @atlaspack/utils@2.18.0
143
+ - @atlaspack/plugin@2.14.23
144
+
145
+ ## 2.14.22
146
+
147
+ ### Patch Changes
148
+
149
+ - [#720](https://github.com/atlassian-labs/atlaspack/pull/720) [`d2fd849`](https://github.com/atlassian-labs/atlaspack/commit/d2fd849770fe6305e9c694bd97b1bd905abd9d94) Thanks [@alshdavid](https://github.com/alshdavid)! - Migrate to TypeScript
150
+
151
+ - Updated dependencies [[`d2fd849`](https://github.com/atlassian-labs/atlaspack/commit/d2fd849770fe6305e9c694bd97b1bd905abd9d94)]:
152
+ - @atlaspack/lsp-protocol@2.14.2
153
+ - @atlaspack/plugin@2.14.22
154
+ - @atlaspack/utils@2.17.4
155
+
156
+ ## 2.14.21
157
+
158
+ ### Patch Changes
159
+
160
+ - Updated dependencies []:
161
+ - @atlaspack/utils@2.17.3
162
+ - @atlaspack/plugin@2.14.21
163
+
164
+ ## 2.14.20
165
+
166
+ ### Patch Changes
167
+
168
+ - Updated dependencies [[`daaa768`](https://github.com/atlassian-labs/atlaspack/commit/daaa7688786772d7e3713b71c5bba6b89ec704aa)]:
169
+ - @atlaspack/plugin@2.14.20
170
+ - @atlaspack/utils@2.17.2
171
+
172
+ ## 2.14.19
173
+
174
+ ### Patch Changes
175
+
176
+ - Updated dependencies []:
177
+ - @atlaspack/utils@2.17.1
178
+ - @atlaspack/plugin@2.14.19
179
+
180
+ ## 2.14.18
181
+
182
+ ### Patch Changes
183
+
184
+ - Updated dependencies [[`dbb4072`](https://github.com/atlassian-labs/atlaspack/commit/dbb40721ebeb45990a14ba04e6b44e7f836fb32d), [`de23e0c`](https://github.com/atlassian-labs/atlaspack/commit/de23e0ce49d5504fe3947ac26640a3d951087da3), [`18a57cf`](https://github.com/atlassian-labs/atlaspack/commit/18a57cf8a4789b2de5ad8e2676f317a26cc91417), [`a5ed1b4`](https://github.com/atlassian-labs/atlaspack/commit/a5ed1b414498560f393ff491af4da25b6e8dde56)]:
185
+ - @atlaspack/utils@2.17.0
186
+ - @atlaspack/plugin@2.14.18
187
+
188
+ ## 2.14.17
189
+
190
+ ### Patch Changes
191
+
192
+ - Updated dependencies []:
193
+ - @atlaspack/utils@2.16.1
194
+ - @atlaspack/plugin@2.14.17
195
+
196
+ ## 2.14.16
197
+
198
+ ### Patch Changes
199
+
200
+ - Updated dependencies [[`30ee2cf`](https://github.com/atlassian-labs/atlaspack/commit/30ee2cfcd34cf2646ded0eda13fdb80a2a5de529)]:
201
+ - @atlaspack/utils@2.16.0
202
+ - @atlaspack/plugin@2.14.16
203
+
204
+ ## 2.14.15
205
+
206
+ ### Patch Changes
207
+
208
+ - Updated dependencies []:
209
+ - @atlaspack/utils@2.15.3
210
+ - @atlaspack/plugin@2.14.15
211
+
212
+ ## 2.14.14
213
+
214
+ ### Patch Changes
215
+
216
+ - Updated dependencies []:
217
+ - @atlaspack/utils@2.15.2
218
+ - @atlaspack/plugin@2.14.14
219
+
220
+ ## 2.14.13
221
+
222
+ ### Patch Changes
223
+
224
+ - Updated dependencies []:
225
+ - @atlaspack/utils@2.15.1
226
+ - @atlaspack/plugin@2.14.13
227
+
228
+ ## 2.14.12
229
+
230
+ ### Patch Changes
231
+
232
+ - Updated dependencies [[`e39c6cf`](https://github.com/atlassian-labs/atlaspack/commit/e39c6cf05f7e95ce5420dbcea66f401b1cbd397c)]:
233
+ - @atlaspack/utils@2.15.0
234
+ - @atlaspack/plugin@2.14.12
235
+
236
+ ## 2.14.11
237
+
238
+ ### Patch Changes
239
+
240
+ - Updated dependencies []:
241
+ - @atlaspack/utils@2.14.11
242
+ - @atlaspack/plugin@2.14.11
243
+
244
+ ## 2.14.10
245
+
246
+ ### Patch Changes
247
+
248
+ - Updated dependencies []:
249
+ - @atlaspack/plugin@2.14.10
250
+ - @atlaspack/utils@2.14.10
251
+
252
+ ## 2.14.9
253
+
254
+ ### Patch Changes
255
+
256
+ - Updated dependencies []:
257
+ - @atlaspack/utils@2.14.9
258
+ - @atlaspack/plugin@2.14.9
259
+
3
260
  ## 2.14.8
4
261
 
5
262
  ### Patch Changes
@@ -0,0 +1,414 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ const utils_1 = require("@atlaspack/utils");
40
+ const plugin_1 = require("@atlaspack/plugin");
41
+ const path_1 = __importDefault(require("path"));
42
+ const os_1 = __importDefault(require("os"));
43
+ const url_1 = __importDefault(require("url"));
44
+ const fs_1 = __importDefault(require("fs"));
45
+ const nullthrows_1 = __importDefault(require("nullthrows"));
46
+ // @ts-expect-error TS7016
47
+ const ps = __importStar(require("ps-node"));
48
+ const util_1 = require("util");
49
+ const ipc_1 = require("./ipc");
50
+ const lsp_protocol_1 = require("@atlaspack/lsp-protocol");
51
+ const utils_2 = require("./utils");
52
+ const lookupPid = (0, util_1.promisify)(ps.lookup);
53
+ const ignoreFail = (func) => {
54
+ try {
55
+ func();
56
+ }
57
+ catch (e) {
58
+ /**/
59
+ }
60
+ };
61
+ const BASEDIR = fs_1.default.realpathSync(path_1.default.join(os_1.default.tmpdir(), 'parcel-lsp'));
62
+ const SOCKET_FILE = path_1.default.join(BASEDIR, `parcel-${process.pid}`);
63
+ const META_FILE = path_1.default.join(BASEDIR, `parcel-${process.pid}.json`);
64
+ let workspaceDiagnostics = new utils_1.DefaultMap(() => []);
65
+ const getWorkspaceDiagnostics = () => [...workspaceDiagnostics].map(([uri, diagnostics]) => ({
66
+ uri,
67
+ diagnostics,
68
+ }));
69
+ // @ts-expect-error TS7034
70
+ let server;
71
+ let connections = [];
72
+ let bundleGraphDeferrable = (0, utils_1.makeDeferredWithPromise)();
73
+ let bundleGraph = bundleGraphDeferrable.promise;
74
+ let watchStarted = false;
75
+ let lspStarted = false;
76
+ // @ts-expect-error TS7034
77
+ let watchStartPromise;
78
+ const LSP_SENTINEL_FILENAME = 'lsp-server';
79
+ const LSP_SENTINEL_FILE = path_1.default.join(BASEDIR, LSP_SENTINEL_FILENAME);
80
+ async function watchLspActive() {
81
+ // Check for lsp-server when reporter is first started
82
+ try {
83
+ await fs_1.default.promises.access(LSP_SENTINEL_FILE, fs_1.default.constants.F_OK);
84
+ lspStarted = true;
85
+ }
86
+ catch {
87
+ //
88
+ }
89
+ // @ts-expect-error TS2769
90
+ return fs_1.default.watch(BASEDIR, (eventType, filename) => {
91
+ switch (eventType) {
92
+ case 'rename':
93
+ if (filename === LSP_SENTINEL_FILENAME) {
94
+ fs_1.default.access(LSP_SENTINEL_FILE, fs_1.default.constants.F_OK, (err) => {
95
+ if (err) {
96
+ lspStarted = false;
97
+ }
98
+ else {
99
+ lspStarted = true;
100
+ }
101
+ });
102
+ }
103
+ }
104
+ });
105
+ }
106
+ // @ts-expect-error TS2552
107
+ async function doWatchStart(options) {
108
+ await fs_1.default.promises.mkdir(BASEDIR, { recursive: true });
109
+ // For each existing file, check if the pid matches a running process.
110
+ // If no process matches, delete the file, assuming it was orphaned
111
+ // by a process that quit unexpectedly.
112
+ for (let filename of fs_1.default.readdirSync(BASEDIR)) {
113
+ if (filename.endsWith('.json'))
114
+ continue;
115
+ let pid = parseInt(filename.slice('parcel-'.length), 10);
116
+ let resultList = await lookupPid({ pid });
117
+ if (resultList.length > 0)
118
+ continue;
119
+ fs_1.default.unlinkSync(path_1.default.join(BASEDIR, filename));
120
+ ignoreFail(() => fs_1.default.unlinkSync(path_1.default.join(BASEDIR, filename + '.json')));
121
+ }
122
+ server = await (0, ipc_1.createServer)(SOCKET_FILE, (connection) => {
123
+ // console.log('got connection');
124
+ connections.push(connection);
125
+ connection.onClose(() => {
126
+ connections = connections.filter((c) => c !== connection);
127
+ });
128
+ connection.onRequest(lsp_protocol_1.RequestDocumentDiagnostics, async (uri) => {
129
+ let graph = await bundleGraph;
130
+ if (!graph)
131
+ return;
132
+ // @ts-expect-error TS2345
133
+ return getDiagnosticsUnusedExports(graph, uri);
134
+ });
135
+ connection.onRequest(lsp_protocol_1.RequestImporters, async (params) => {
136
+ let graph = await bundleGraph;
137
+ if (!graph)
138
+ return null;
139
+ // @ts-expect-error TS2345
140
+ return getImporters(graph, params);
141
+ });
142
+ sendDiagnostics();
143
+ });
144
+ await fs_1.default.promises.writeFile(META_FILE, JSON.stringify({
145
+ projectRoot: options.projectRoot,
146
+ pid: process.pid,
147
+ argv: process.argv,
148
+ }));
149
+ }
150
+ watchLspActive();
151
+ exports.default = new plugin_1.Reporter({
152
+ async report({ event, options }) {
153
+ if (event.type === 'watchStart') {
154
+ watchStarted = true;
155
+ }
156
+ if (watchStarted && lspStarted) {
157
+ // @ts-expect-error TS7005
158
+ if (!watchStartPromise) {
159
+ watchStartPromise = doWatchStart(options);
160
+ }
161
+ await watchStartPromise;
162
+ }
163
+ switch (event.type) {
164
+ case 'watchStart': {
165
+ break;
166
+ }
167
+ case 'buildStart': {
168
+ bundleGraphDeferrable = (0, utils_1.makeDeferredWithPromise)();
169
+ bundleGraph = bundleGraphDeferrable.promise;
170
+ updateBuildState('start');
171
+ clearDiagnostics();
172
+ break;
173
+ }
174
+ case 'buildSuccess':
175
+ bundleGraphDeferrable.deferred.resolve(event.bundleGraph);
176
+ updateBuildState('end');
177
+ sendDiagnostics();
178
+ break;
179
+ case 'buildFailure': {
180
+ bundleGraphDeferrable.deferred.resolve(undefined);
181
+ updateDiagnostics(event.diagnostics, 'error', options.projectRoot);
182
+ updateBuildState('end');
183
+ sendDiagnostics();
184
+ break;
185
+ }
186
+ case 'log':
187
+ if (
188
+ // @ts-expect-error TS2339
189
+ event.diagnostics != null &&
190
+ (event.level === 'error' ||
191
+ event.level === 'warn' ||
192
+ event.level === 'info' ||
193
+ event.level === 'verbose')) {
194
+ updateDiagnostics(event.diagnostics, event.level, options.projectRoot);
195
+ }
196
+ break;
197
+ case 'buildProgress': {
198
+ let message = (0, utils_1.getProgressMessage)(event);
199
+ if (message != null) {
200
+ updateBuildState('progress', message);
201
+ }
202
+ break;
203
+ }
204
+ case 'watchEnd':
205
+ connections.forEach((c) => c.end());
206
+ // @ts-expect-error TS7005
207
+ await server.close();
208
+ ignoreFail(() => fs_1.default.unlinkSync(META_FILE));
209
+ break;
210
+ }
211
+ },
212
+ });
213
+ function updateBuildState(state, message) {
214
+ connections.forEach((c) => c.sendNotification(lsp_protocol_1.NotificationBuildStatus, state, message));
215
+ }
216
+ function clearDiagnostics() {
217
+ workspaceDiagnostics.clear();
218
+ }
219
+ function sendDiagnostics() {
220
+ // console.log('send', getWorkspaceDiagnostics());
221
+ connections.forEach((c) => c.sendNotification(lsp_protocol_1.NotificationWorkspaceDiagnostics, getWorkspaceDiagnostics()));
222
+ }
223
+ function updateDiagnostics(parcelDiagnostics, parcelSeverity, projectRoot) {
224
+ for (let diagnostic of parcelDiagnostics) {
225
+ const codeFrames = diagnostic.codeFrames;
226
+ if (codeFrames == null) {
227
+ continue;
228
+ }
229
+ const firstCodeFrame = codeFrames[0];
230
+ const filePath = firstCodeFrame.filePath;
231
+ if (filePath == null) {
232
+ continue;
233
+ }
234
+ // We use the first highlight of the first codeFrame as the main Diagnostic,
235
+ // and we place everything else in the current Parcel diagnostic
236
+ // in relatedInformation
237
+ // https://code.visualstudio.com/api/references/vscode-api#DiagnosticRelatedInformation
238
+ const firstFrameHighlight = codeFrames[0].codeHighlights[0];
239
+ if (firstFrameHighlight == null) {
240
+ continue;
241
+ }
242
+ // @ts-expect-error TS2304
243
+ const relatedInformation = [];
244
+ for (const codeFrame of codeFrames) {
245
+ for (const highlight of codeFrame.codeHighlights) {
246
+ const filePath = codeFrame.filePath;
247
+ if (highlight === firstFrameHighlight || filePath == null) {
248
+ continue;
249
+ }
250
+ relatedInformation.push({
251
+ location: {
252
+ uri: `file://${(0, utils_2.normalizeFilePath)(filePath, projectRoot)}`,
253
+ range: {
254
+ start: {
255
+ line: highlight.start.line - 1,
256
+ character: highlight.start.column - 1,
257
+ },
258
+ end: {
259
+ line: highlight.end.line - 1,
260
+ character: highlight.end.column,
261
+ },
262
+ },
263
+ },
264
+ message: highlight.message ?? diagnostic.message,
265
+ });
266
+ }
267
+ }
268
+ workspaceDiagnostics
269
+ .get(`file://${(0, utils_2.normalizeFilePath)(filePath, projectRoot)}`)
270
+ .push({
271
+ range: {
272
+ start: {
273
+ line: firstFrameHighlight.start.line - 1,
274
+ character: firstFrameHighlight.start.column - 1,
275
+ },
276
+ end: {
277
+ line: firstFrameHighlight.end.line - 1,
278
+ character: firstFrameHighlight.end.column,
279
+ },
280
+ },
281
+ source: diagnostic.origin,
282
+ severity: (0, utils_2.parcelSeverityToLspSeverity)(parcelSeverity),
283
+ message: diagnostic.message +
284
+ (firstFrameHighlight.message == null
285
+ ? ''
286
+ : ' ' + firstFrameHighlight.message),
287
+ relatedInformation,
288
+ });
289
+ }
290
+ }
291
+ function getDiagnosticsUnusedExports(bundleGraph, document) {
292
+ let filename = url_1.default.fileURLToPath(document);
293
+ let diagnostics = [];
294
+ let asset = bundleGraph.traverse((node, context, actions) => {
295
+ if (node.type === 'asset' && node.value.filePath === filename) {
296
+ actions.stop();
297
+ return node.value;
298
+ }
299
+ });
300
+ if (asset) {
301
+ // @ts-expect-error TS2304
302
+ const generateDiagnostic = (loc, type) => ({
303
+ range: {
304
+ start: {
305
+ line: loc.start.line - 1,
306
+ character: loc.start.column - 1,
307
+ },
308
+ end: {
309
+ line: loc.end.line - 1,
310
+ character: loc.end.column,
311
+ },
312
+ },
313
+ source: '@atlaspack/core',
314
+ severity: utils_2.DiagnosticSeverity.Hint,
315
+ message: `Unused ${type}.`,
316
+ tags: [utils_2.DiagnosticTag.Unnecessary],
317
+ });
318
+ // @ts-expect-error TS2345
319
+ let usedSymbols = bundleGraph.getUsedSymbols(asset);
320
+ if (usedSymbols) {
321
+ // @ts-expect-error TS2339
322
+ for (let [exported, symbol] of asset.symbols) {
323
+ if (!usedSymbols.has(exported)) {
324
+ if (symbol.loc) {
325
+ diagnostics.push(generateDiagnostic(symbol.loc, 'export'));
326
+ }
327
+ }
328
+ }
329
+ // if (usedSymbols.size === 0 && asset.sideEffects !== false) {
330
+ // diagnostics.push({
331
+ // range: {
332
+ // start: {
333
+ // line: 0,
334
+ // character: 0,
335
+ // },
336
+ // end: {
337
+ // line: 0,
338
+ // character: 1,
339
+ // },
340
+ // },
341
+ // source: '@atlaspack/core',
342
+ // severity: DiagnosticSeverity.Warning,
343
+ // message: `Asset has no used exports, but is not marked as sideEffect-free so it cannot be excluded automatically.`,
344
+ // });
345
+ // }
346
+ }
347
+ // @ts-expect-error TS2339
348
+ for (let dep of asset.getDependencies()) {
349
+ let usedSymbols = bundleGraph.getUsedSymbols(dep);
350
+ if (usedSymbols) {
351
+ for (let [exported, symbol] of dep.symbols) {
352
+ if (!usedSymbols.has(exported) && symbol.isWeak && symbol.loc) {
353
+ diagnostics.push(generateDiagnostic(symbol.loc, 'reexport'));
354
+ }
355
+ }
356
+ }
357
+ }
358
+ }
359
+ return diagnostics;
360
+ }
361
+ // function getDefinition(
362
+ // bundleGraph: BundleGraph<PackagedBundle>,
363
+ // document: string,
364
+ // position: Position,
365
+ // ): Array<LocationLink> | void {
366
+ // let filename = url.fileURLToPath(document);
367
+ // let asset = bundleGraph.traverse((node, context, actions) => {
368
+ // if (node.type === 'asset' && node.value.filePath === filename) {
369
+ // actions.stop();
370
+ // return node.value;
371
+ // }
372
+ // });
373
+ // if (asset) {
374
+ // for (let dep of bundleGraph.getDependencies(asset)) {
375
+ // let loc = dep.loc;
376
+ // if (loc && isInRange(loc, position)) {
377
+ // let resolution = bundleGraph.getResolvedAsset(dep);
378
+ // if (resolution) {
379
+ // return [
380
+ // {
381
+ // originSelectionRange: {
382
+ // start: {
383
+ // line: loc.start.line - 1,
384
+ // character: loc.start.column - 1,
385
+ // },
386
+ // end: {line: loc.end.line - 1, character: loc.end.column},
387
+ // },
388
+ // targetUri: `file://${resolution.filePath}`,
389
+ // targetRange: RANGE_DUMMY,
390
+ // targetSelectionRange: RANGE_DUMMY,
391
+ // },
392
+ // ];
393
+ // }
394
+ // }
395
+ // }
396
+ // }
397
+ // }
398
+ function getImporters(bundleGraph, document) {
399
+ let filename = url_1.default.fileURLToPath(document);
400
+ let asset = bundleGraph.traverse((node, context, actions) => {
401
+ if (node.type === 'asset' && node.value.filePath === filename) {
402
+ actions.stop();
403
+ return node.value;
404
+ }
405
+ });
406
+ if (asset) {
407
+ // @ts-expect-error TS2345
408
+ let incoming = bundleGraph.getIncomingDependencies(asset);
409
+ return incoming
410
+ .filter((dep) => dep.sourcePath != null)
411
+ .map((dep) => `file://${(0, nullthrows_1.default)(dep.sourcePath)}`);
412
+ }
413
+ return null;
414
+ }