@atlaspack/reporter-lsp 2.14.5-canary.36 → 2.14.5-canary.361

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/ipc.js CHANGED
@@ -32,7 +32,9 @@ function createClientPipeTransport(pipeName, onConnected) {
32
32
  close() {
33
33
  return new Promise((res, rej) => {
34
34
  server.close(e => {
35
- if (e) rej(e);else res();
35
+ if (e) rej(e);
36
+ // @ts-expect-error TS2794
37
+ else res();
36
38
  });
37
39
  });
38
40
  }
@@ -0,0 +1,3 @@
1
+ import { Reporter } from '@atlaspack/plugin';
2
+ declare const _default: Reporter;
3
+ export default _default;
@@ -0,0 +1,4 @@
1
+ import type { MessageConnection } from 'vscode-jsonrpc/node';
2
+ export declare function createServer(filename: string, setup: (connection: MessageConnection) => void): Promise<{
3
+ close: () => Promise<void>;
4
+ }>;
@@ -0,0 +1,38 @@
1
+ import type { DiagnosticLogEvent, FilePath } from '@atlaspack/types';
2
+ import type { ODiagnosticSeverity } from 'vscode-languageserver';
3
+ export type ParcelSeverity = DiagnosticLogEvent['level'];
4
+ export declare function parcelSeverityToLspSeverity(parcelSeverity: ParcelSeverity): ODiagnosticSeverity;
5
+ export declare function normalizeFilePath(filePath: FilePath, projectRoot: FilePath): FilePath;
6
+ export declare const DiagnosticTag: {
7
+ /**
8
+ * Unused or unnecessary code.
9
+ *
10
+ * Clients are allowed to render diagnostics with this tag faded out instead of having
11
+ * an error squiggle.
12
+ */
13
+ readonly Unnecessary: ODiagnosticTag;
14
+ /**
15
+ * Deprecated or obsolete code.
16
+ *
17
+ * Clients are allowed to rendered diagnostics with this tag strike through.
18
+ */
19
+ readonly Deprecated: ODiagnosticTag;
20
+ };
21
+ export declare const DiagnosticSeverity: {
22
+ /**
23
+ * Reports an error.
24
+ */
25
+ readonly Error: ODiagnosticSeverity;
26
+ /**
27
+ * Reports a warning.
28
+ */
29
+ readonly Warning: ODiagnosticSeverity;
30
+ /**
31
+ * Reports an information.
32
+ */
33
+ readonly Information: ODiagnosticSeverity;
34
+ /**
35
+ * Reports a hint.
36
+ */
37
+ readonly Hint: ODiagnosticSeverity;
38
+ };
package/lib/utils.js CHANGED
@@ -14,6 +14,8 @@ function _path() {
14
14
  return data;
15
15
  }
16
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
+ // @ts-expect-error TS2724
18
+
17
19
  function parcelSeverityToLspSeverity(parcelSeverity) {
18
20
  switch (parcelSeverity) {
19
21
  case 'error':
@@ -61,35 +63,31 @@ const DiagnosticTag = exports.DiagnosticTag = {
61
63
  * Clients are allowed to render diagnostics with this tag faded out instead of having
62
64
  * an error squiggle.
63
65
  */
64
- // $FlowFixMe
66
+ // @ts-expect-error TS2304
65
67
  Unnecessary: 1,
66
68
  /**
67
69
  * Deprecated or obsolete code.
68
70
  *
69
71
  * Clients are allowed to rendered diagnostics with this tag strike through.
70
72
  */
71
- // $FlowFixMe
73
+ // @ts-expect-error TS2304
72
74
  Deprecated: 2
73
75
  };
74
76
  const DiagnosticSeverity = exports.DiagnosticSeverity = {
75
77
  /**
76
78
  * Reports an error.
77
79
  */
78
- // $FlowFixMe
79
80
  Error: 1,
80
81
  /**
81
82
  * Reports a warning.
82
83
  */
83
- // $FlowFixMe
84
84
  Warning: 2,
85
85
  /**
86
86
  * Reports an information.
87
87
  */
88
- // $FlowFixMe
89
88
  Information: 3,
90
89
  /**
91
90
  * Reports a hint.
92
91
  */
93
- // $FlowFixMe
94
92
  Hint: 4
95
93
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/reporter-lsp",
3
- "version": "2.14.5-canary.36+2d10c6656",
3
+ "version": "2.14.5-canary.361+405bbaf61",
4
4
  "license": "(MIT OR Apache-2.0)",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -9,20 +9,24 @@
9
9
  "type": "git",
10
10
  "url": "https://github.com/atlassian-labs/atlaspack.git"
11
11
  },
12
- "main": "lib/LspReporter.js",
13
- "source": "src/LspReporter.js",
12
+ "main": "./lib/LspReporter.js",
13
+ "source": "./src/LspReporter.ts",
14
+ "types": "./lib/types/LspReporter.d.ts",
14
15
  "engines": {
15
16
  "node": ">= 16.0.0"
16
17
  },
17
18
  "dependencies": {
18
- "@atlaspack/lsp-protocol": "2.14.1-canary.104+2d10c6656",
19
- "@atlaspack/plugin": "2.14.5-canary.36+2d10c6656",
20
- "@atlaspack/utils": "2.14.5-canary.36+2d10c6656",
19
+ "@atlaspack/lsp-protocol": "2.14.1-canary.429+405bbaf61",
20
+ "@atlaspack/plugin": "2.14.5-canary.361+405bbaf61",
21
+ "@atlaspack/utils": "2.14.5-canary.361+405bbaf61",
21
22
  "node-ipc": "^9.1.4",
22
23
  "nullthrows": "^1.1.1",
23
24
  "ps-node": "^0.1.6",
24
25
  "vscode-jsonrpc": "^8.0.2"
25
26
  },
26
27
  "type": "commonjs",
27
- "gitHead": "2d10c6656fc58743c5dbed1d2b6c5666887f9fe4"
28
- }
28
+ "scripts": {
29
+ "build:lib": "gulp build --gulpfile ../../../gulpfile.js --cwd ."
30
+ },
31
+ "gitHead": "405bbaf619f634cf9e58cc618d9a911f7db2998d"
32
+ }
@@ -1,7 +1,6 @@
1
- // @flow strict-local
2
-
3
1
  import type {Diagnostic as ParcelDiagnostic} from '@atlaspack/diagnostic';
4
2
  import type {BundleGraph, FilePath, PackagedBundle} from '@atlaspack/types';
3
+ // @ts-expect-error TS7016
5
4
  import type {Program, Query} from 'ps-node';
6
5
  import type {Diagnostic, DocumentUri} from 'vscode-languageserver';
7
6
  import type {MessageConnection} from 'vscode-jsonrpc/node';
@@ -18,12 +17,14 @@ import os from 'os';
18
17
  import url from 'url';
19
18
  import fs from 'fs';
20
19
  import nullthrows from 'nullthrows';
20
+ // @ts-expect-error TS7016
21
21
  import * as ps from 'ps-node';
22
22
  import {promisify} from 'util';
23
23
 
24
24
  import {createServer} from './ipc';
25
25
  import {
26
- type PublishDiagnostic,
26
+ // @ts-expect-error TS2305
27
+ PublishDiagnostic,
27
28
  NotificationBuildStatus,
28
29
  NotificationWorkspaceDiagnostics,
29
30
  RequestDocumentDiagnostics,
@@ -38,12 +39,12 @@ import {
38
39
  } from './utils';
39
40
  import type {FSWatcher} from 'fs';
40
41
 
41
- const lookupPid: (Query) => Program[] = promisify(ps.lookup);
42
+ const lookupPid: (arg1: Query) => Program[] = promisify(ps.lookup);
42
43
 
43
- const ignoreFail = (func) => {
44
+ const ignoreFail = (func: () => void) => {
44
45
  try {
45
46
  func();
46
- } catch (e) {
47
+ } catch (e: any) {
47
48
  /**/
48
49
  }
49
50
  };
@@ -54,22 +55,28 @@ const META_FILE = path.join(BASEDIR, `parcel-${process.pid}.json`);
54
55
 
55
56
  let workspaceDiagnostics: DefaultMap<
56
57
  string,
57
- Array<Diagnostic>,
58
+ Array<Diagnostic>
58
59
  > = new DefaultMap(() => []);
59
60
 
60
61
  const getWorkspaceDiagnostics = (): Array<PublishDiagnostic> =>
61
- [...workspaceDiagnostics].map(([uri, diagnostics]) => ({uri, diagnostics}));
62
+ [...workspaceDiagnostics].map(([uri, diagnostics]: [any, any]) => ({
63
+ uri,
64
+ diagnostics,
65
+ }));
62
66
 
67
+ // @ts-expect-error TS7034
63
68
  let server;
64
69
  let connections: Array<MessageConnection> = [];
65
70
 
66
- let bundleGraphDeferrable =
67
- makeDeferredWithPromise<?BundleGraph<PackagedBundle>>();
68
- let bundleGraph: Promise<?BundleGraph<PackagedBundle>> =
71
+ let bundleGraphDeferrable = makeDeferredWithPromise<
72
+ BundleGraph<PackagedBundle> | null | undefined
73
+ >();
74
+ let bundleGraph: Promise<BundleGraph<PackagedBundle> | null | undefined> =
69
75
  bundleGraphDeferrable.promise;
70
76
 
71
77
  let watchStarted = false;
72
78
  let lspStarted = false;
79
+ // @ts-expect-error TS7034
73
80
  let watchStartPromise;
74
81
 
75
82
  const LSP_SENTINEL_FILENAME = 'lsp-server';
@@ -84,6 +91,7 @@ async function watchLspActive(): Promise<FSWatcher> {
84
91
  //
85
92
  }
86
93
 
94
+ // @ts-expect-error TS2769
87
95
  return fs.watch(BASEDIR, (eventType: string, filename: string) => {
88
96
  switch (eventType) {
89
97
  case 'rename':
@@ -100,7 +108,8 @@ async function watchLspActive(): Promise<FSWatcher> {
100
108
  });
101
109
  }
102
110
 
103
- async function doWatchStart(options) {
111
+ // @ts-expect-error TS2552
112
+ async function doWatchStart(options: PluginOptions) {
104
113
  await fs.promises.mkdir(BASEDIR, {recursive: true});
105
114
 
106
115
  // For each existing file, check if the pid matches a running process.
@@ -126,6 +135,7 @@ async function doWatchStart(options) {
126
135
  let graph = await bundleGraph;
127
136
  if (!graph) return;
128
137
 
138
+ // @ts-expect-error TS2345
129
139
  return getDiagnosticsUnusedExports(graph, uri);
130
140
  });
131
141
 
@@ -133,6 +143,7 @@ async function doWatchStart(options) {
133
143
  let graph = await bundleGraph;
134
144
  if (!graph) return null;
135
145
 
146
+ // @ts-expect-error TS2345
136
147
  return getImporters(graph, params);
137
148
  });
138
149
 
@@ -150,13 +161,14 @@ async function doWatchStart(options) {
150
161
 
151
162
  watchLspActive();
152
163
 
153
- export default (new Reporter({
164
+ export default new Reporter({
154
165
  async report({event, options}) {
155
166
  if (event.type === 'watchStart') {
156
167
  watchStarted = true;
157
168
  }
158
169
 
159
170
  if (watchStarted && lspStarted) {
171
+ // @ts-expect-error TS7005
160
172
  if (!watchStartPromise) {
161
173
  watchStartPromise = doWatchStart(options);
162
174
  }
@@ -189,6 +201,7 @@ export default (new Reporter({
189
201
  }
190
202
  case 'log':
191
203
  if (
204
+ // @ts-expect-error TS2339
192
205
  event.diagnostics != null &&
193
206
  (event.level === 'error' ||
194
207
  event.level === 'warn' ||
@@ -211,16 +224,17 @@ export default (new Reporter({
211
224
  }
212
225
  case 'watchEnd':
213
226
  connections.forEach((c) => c.end());
227
+ // @ts-expect-error TS7005
214
228
  await server.close();
215
229
  ignoreFail(() => fs.unlinkSync(META_FILE));
216
230
  break;
217
231
  }
218
232
  },
219
- }): Reporter);
233
+ }) as Reporter;
220
234
 
221
235
  function updateBuildState(
222
236
  state: 'start' | 'progress' | 'end',
223
- message: string | void,
237
+ message?: string,
224
238
  ) {
225
239
  connections.forEach((c) =>
226
240
  c.sendNotification(NotificationBuildStatus, state, message),
@@ -266,7 +280,8 @@ function updateDiagnostics(
266
280
  continue;
267
281
  }
268
282
 
269
- const relatedInformation = [];
283
+ // @ts-expect-error TS2304
284
+ const relatedInformation: Array<DiagnosticRelatedInformation> = [];
270
285
  for (const codeFrame of codeFrames) {
271
286
  for (const highlight of codeFrame.codeHighlights) {
272
287
  const filePath = codeFrame.filePath;
@@ -323,7 +338,7 @@ function getDiagnosticsUnusedExports(
323
338
  document: string,
324
339
  ): Array<Diagnostic> {
325
340
  let filename = url.fileURLToPath(document);
326
- let diagnostics = [];
341
+ let diagnostics: Array<Diagnostic> = [];
327
342
 
328
343
  let asset = bundleGraph.traverse((node, context, actions) => {
329
344
  if (node.type === 'asset' && node.value.filePath === filename) {
@@ -333,7 +348,8 @@ function getDiagnosticsUnusedExports(
333
348
  });
334
349
 
335
350
  if (asset) {
336
- const generateDiagnostic = (loc, type) => ({
351
+ // @ts-expect-error TS2304
352
+ const generateDiagnostic = (loc: SourceLocation, type: string) => ({
337
353
  range: {
338
354
  start: {
339
355
  line: loc.start.line - 1,
@@ -350,8 +366,10 @@ function getDiagnosticsUnusedExports(
350
366
  tags: [DiagnosticTag.Unnecessary],
351
367
  });
352
368
 
369
+ // @ts-expect-error TS2345
353
370
  let usedSymbols = bundleGraph.getUsedSymbols(asset);
354
371
  if (usedSymbols) {
372
+ // @ts-expect-error TS2339
355
373
  for (let [exported, symbol] of asset.symbols) {
356
374
  if (!usedSymbols.has(exported)) {
357
375
  if (symbol.loc) {
@@ -378,6 +396,7 @@ function getDiagnosticsUnusedExports(
378
396
  // }
379
397
  }
380
398
 
399
+ // @ts-expect-error TS2339
381
400
  for (let dep of asset.getDependencies()) {
382
401
  let usedSymbols = bundleGraph.getUsedSymbols(dep);
383
402
  if (usedSymbols) {
@@ -446,6 +465,7 @@ function getImporters(
446
465
  });
447
466
 
448
467
  if (asset) {
468
+ // @ts-expect-error TS2345
449
469
  let incoming = bundleGraph.getIncomingDependencies(asset);
450
470
  return incoming
451
471
  .filter((dep) => dep.sourcePath != null)
package/src/ipc.ts ADDED
@@ -0,0 +1,77 @@
1
+ import * as net from 'net';
2
+ import type {
3
+ MessageReader,
4
+ MessageWriter,
5
+ MessageConnection,
6
+ } from 'vscode-jsonrpc/node';
7
+ import {
8
+ createMessageConnection,
9
+ SocketMessageReader,
10
+ SocketMessageWriter,
11
+ } from 'vscode-jsonrpc/node';
12
+
13
+ function createClientPipeTransport(
14
+ pipeName: string,
15
+ onConnected: (reader: MessageReader, writer: MessageWriter) => void,
16
+ ): Promise<{
17
+ close: () => Promise<void>;
18
+ }> {
19
+ return new Promise(
20
+ (
21
+ resolve: (
22
+ result:
23
+ | Promise<{
24
+ close(): Promise<void>;
25
+ }>
26
+ | {
27
+ close(): Promise<void>;
28
+ },
29
+ ) => void,
30
+ reject: (error?: any) => void,
31
+ ) => {
32
+ let server: net.Server = net.createServer((socket: net.Socket) => {
33
+ onConnected(
34
+ new SocketMessageReader(socket),
35
+ new SocketMessageWriter(socket),
36
+ );
37
+ });
38
+ server.on('error', reject);
39
+ server.listen(pipeName, () => {
40
+ server.removeListener('error', reject);
41
+ resolve({
42
+ close() {
43
+ return new Promise(
44
+ (
45
+ res: (result: Promise<undefined> | undefined) => void,
46
+ rej: (error?: any) => void,
47
+ ) => {
48
+ server.close((e) => {
49
+ if (e) rej(e);
50
+ // @ts-expect-error TS2794
51
+ else res();
52
+ });
53
+ },
54
+ );
55
+ },
56
+ });
57
+ });
58
+ },
59
+ );
60
+ }
61
+
62
+ export function createServer(
63
+ filename: string,
64
+ setup: (connection: MessageConnection) => void,
65
+ ): Promise<{
66
+ close: () => Promise<void>;
67
+ }> {
68
+ return createClientPipeTransport(
69
+ filename,
70
+ (reader: MessageReader, writer: MessageWriter) => {
71
+ let connection = createMessageConnection(reader, writer);
72
+ connection.listen();
73
+
74
+ setup(connection);
75
+ },
76
+ );
77
+ }
@@ -1,5 +1,5 @@
1
- // @flow
2
1
  import type {DiagnosticLogEvent, FilePath} from '@atlaspack/types';
2
+ // @ts-expect-error TS2724
3
3
  import type {ODiagnosticSeverity} from 'vscode-languageserver';
4
4
 
5
5
  import path from 'path';
@@ -61,35 +61,31 @@ export const DiagnosticTag = {
61
61
  * Clients are allowed to render diagnostics with this tag faded out instead of having
62
62
  * an error squiggle.
63
63
  */
64
- // $FlowFixMe
65
- Unnecessary: (1: ODiagnosticTag),
64
+ // @ts-expect-error TS2304
65
+ Unnecessary: 1 as ODiagnosticTag,
66
66
  /**
67
67
  * Deprecated or obsolete code.
68
68
  *
69
69
  * Clients are allowed to rendered diagnostics with this tag strike through.
70
70
  */
71
- // $FlowFixMe
72
- Deprecated: (2: ODiagnosticTag),
73
- };
71
+ // @ts-expect-error TS2304
72
+ Deprecated: 2 as ODiagnosticTag,
73
+ } as const;
74
74
  export const DiagnosticSeverity = {
75
75
  /**
76
76
  * Reports an error.
77
77
  */
78
- // $FlowFixMe
79
- Error: (1: ODiagnosticSeverity),
78
+ Error: 1 as ODiagnosticSeverity,
80
79
  /**
81
80
  * Reports a warning.
82
81
  */
83
- // $FlowFixMe
84
- Warning: (2: ODiagnosticSeverity),
82
+ Warning: 2 as ODiagnosticSeverity,
85
83
  /**
86
84
  * Reports an information.
87
85
  */
88
- // $FlowFixMe
89
- Information: (3: ODiagnosticSeverity),
86
+ Information: 3 as ODiagnosticSeverity,
90
87
  /**
91
88
  * Reports a hint.
92
89
  */
93
- // $FlowFixMe
94
- Hint: (4: ODiagnosticSeverity),
95
- };
90
+ Hint: 4 as ODiagnosticSeverity,
91
+ } as const;
package/tsconfig.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "extends": "../../../tsconfig.base.json",
3
+ "include": ["src"],
4
+ "compilerOptions": {
5
+ "composite": true
6
+ },
7
+ "references": [
8
+ {
9
+ "path": "../../core/plugin/tsconfig.json"
10
+ },
11
+ {
12
+ "path": "../../core/utils/tsconfig.json"
13
+ },
14
+ {
15
+ "path": "../../utils/atlaspack-lsp-protocol/tsconfig.json"
16
+ }
17
+ ]
18
+ }