@spences10/pi-lsp 0.0.22 → 0.0.24

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.
@@ -0,0 +1,17 @@
1
+ import type { EventEmitter } from 'node:events';
2
+ import type { LspRange } from './protocol.js';
3
+ export interface LspDiagnostic {
4
+ range: LspRange;
5
+ severity?: 1 | 2 | 3 | 4;
6
+ code?: string | number;
7
+ source?: string;
8
+ message: string;
9
+ }
10
+ export declare class LspDiagnosticsStore {
11
+ #private;
12
+ constructor(events: EventEmitter);
13
+ get(uri: string): LspDiagnostic[];
14
+ publish(uri: string, diagnostics: LspDiagnostic[]): void;
15
+ wait(uri: string, timeout_ms?: number): Promise<LspDiagnostic[]>;
16
+ flush_waiters(): void;
17
+ }
@@ -0,0 +1,46 @@
1
+ export class LspDiagnosticsStore {
2
+ #diagnostics_by_uri = new Map();
3
+ #diagnostic_waiters = new Set();
4
+ #events;
5
+ constructor(events) {
6
+ this.#events = events;
7
+ }
8
+ get(uri) {
9
+ return this.#diagnostics_by_uri.get(uri) ?? [];
10
+ }
11
+ publish(uri, diagnostics) {
12
+ this.#diagnostics_by_uri.set(uri, diagnostics);
13
+ this.#events.emit('diagnostics', uri);
14
+ }
15
+ async wait(uri, timeout_ms = 1500) {
16
+ if (this.#diagnostics_by_uri.has(uri)) {
17
+ return this.get(uri);
18
+ }
19
+ return new Promise((resolve) => {
20
+ let active = true;
21
+ const cleanup = () => {
22
+ if (!active)
23
+ return;
24
+ active = false;
25
+ this.#events.off('diagnostics', handler);
26
+ clearTimeout(timer);
27
+ this.#diagnostic_waiters.delete(cleanup);
28
+ resolve(this.get(uri));
29
+ };
30
+ const handler = (event_uri) => {
31
+ if (event_uri !== uri)
32
+ return;
33
+ cleanup();
34
+ };
35
+ const timer = setTimeout(cleanup, timeout_ms);
36
+ this.#events.on('diagnostics', handler);
37
+ this.#diagnostic_waiters.add(cleanup);
38
+ });
39
+ }
40
+ flush_waiters() {
41
+ for (const cleanup of Array.from(this.#diagnostic_waiters)) {
42
+ cleanup();
43
+ }
44
+ }
45
+ }
46
+ //# sourceMappingURL=diagnostics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diagnostics.js","sourceRoot":"","sources":["../../src/client/diagnostics.ts"],"names":[],"mappings":"AAWA,MAAM,OAAO,mBAAmB;IACtB,mBAAmB,GAAG,IAAI,GAAG,EAA2B,CAAC;IACzD,mBAAmB,GAAG,IAAI,GAAG,EAAc,CAAC;IAC5C,OAAO,CAAe;IAE/B,YAAY,MAAoB;QAC/B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,GAAG,CAAC,GAAW;QACd,OAAO,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;IAChD,CAAC;IAED,OAAO,CAAC,GAAW,EAAE,WAA4B;QAChD,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;QAC/C,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC;IACvC,CAAC;IAED,KAAK,CAAC,IAAI,CACT,GAAW,EACX,UAAU,GAAG,IAAI;QAEjB,IAAI,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YACvC,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACtB,CAAC;QACD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC9B,IAAI,MAAM,GAAG,IAAI,CAAC;YAClB,MAAM,OAAO,GAAG,GAAG,EAAE;gBACpB,IAAI,CAAC,MAAM;oBAAE,OAAO;gBACpB,MAAM,GAAG,KAAK,CAAC;gBACf,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;gBACzC,YAAY,CAAC,KAAK,CAAC,CAAC;gBACpB,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;gBACzC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;YACxB,CAAC,CAAC;YACF,MAAM,OAAO,GAAG,CAAC,SAAiB,EAAE,EAAE;gBACrC,IAAI,SAAS,KAAK,GAAG;oBAAE,OAAO;gBAC9B,OAAO,EAAE,CAAC;YACX,CAAC,CAAC;YACF,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;YAC9C,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;YACxC,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QACvC,CAAC,CAAC,CAAC;IACJ,CAAC;IAED,aAAa;QACZ,KAAK,MAAM,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,mBAAmB,CAAC,EAAE,CAAC;YAC5D,OAAO,EAAE,CAAC;QACX,CAAC;IACF,CAAC;CACD"}
@@ -0,0 +1,28 @@
1
+ import { type ChildProcess } from 'node:child_process';
2
+ export interface LspClientOptions {
3
+ command: string;
4
+ args: string[];
5
+ root_uri: string;
6
+ language_id_for_uri: (uri: string) => string | undefined;
7
+ request_timeout_ms?: number;
8
+ }
9
+ export declare class LspClientStartError extends Error {
10
+ command: string;
11
+ args: string[];
12
+ code?: string;
13
+ constructor(message: string, options: {
14
+ command: string;
15
+ args: string[];
16
+ cause?: unknown;
17
+ code?: string;
18
+ });
19
+ }
20
+ export interface LspProcessHandlers {
21
+ on_stdout: (chunk: Buffer) => void;
22
+ on_error: (error: Error) => void;
23
+ on_close: () => void;
24
+ }
25
+ export declare function start_lsp_process(options: LspClientOptions, handlers: LspProcessHandlers): ChildProcess;
26
+ export declare function create_start_error(options: LspClientOptions, message: string, cause?: unknown, code?: string): LspClientStartError;
27
+ export declare function create_initialize_params(options: LspClientOptions): unknown;
28
+ export declare function error_code(error: unknown): string | undefined;
@@ -0,0 +1,70 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { create_child_process_env } from '../env.js';
3
+ export class LspClientStartError extends Error {
4
+ command;
5
+ args;
6
+ code;
7
+ constructor(message, options) {
8
+ super(message, options.cause ? { cause: options.cause } : undefined);
9
+ this.name = 'LspClientStartError';
10
+ this.command = options.command;
11
+ this.args = options.args;
12
+ this.code = options.code;
13
+ }
14
+ }
15
+ export function start_lsp_process(options, handlers) {
16
+ const proc = spawn(options.command, options.args, {
17
+ stdio: ['pipe', 'pipe', 'pipe'],
18
+ env: create_child_process_env(),
19
+ });
20
+ proc.on('error', handlers.on_error);
21
+ proc.on('close', handlers.on_close);
22
+ proc.stderr?.on('data', () => {
23
+ // Discard stderr; many servers are chatty.
24
+ });
25
+ proc.stdout.on('data', handlers.on_stdout);
26
+ return proc;
27
+ }
28
+ export function create_start_error(options, message, cause, code) {
29
+ return new LspClientStartError(message, {
30
+ command: options.command,
31
+ args: options.args,
32
+ cause,
33
+ code,
34
+ });
35
+ }
36
+ export function create_initialize_params(options) {
37
+ return {
38
+ processId: process.pid,
39
+ rootUri: options.root_uri,
40
+ capabilities: {
41
+ textDocument: {
42
+ publishDiagnostics: {
43
+ relatedInformation: true,
44
+ },
45
+ hover: {
46
+ contentFormat: ['markdown', 'plaintext'],
47
+ },
48
+ definition: { linkSupport: false },
49
+ references: {},
50
+ documentSymbol: {
51
+ hierarchicalDocumentSymbolSupport: true,
52
+ },
53
+ },
54
+ workspace: {
55
+ workspaceFolders: true,
56
+ symbol: {},
57
+ },
58
+ },
59
+ workspaceFolders: [{ uri: options.root_uri, name: 'workspace' }],
60
+ };
61
+ }
62
+ export function error_code(error) {
63
+ return typeof error === 'object' &&
64
+ error !== null &&
65
+ 'code' in error &&
66
+ typeof error.code === 'string'
67
+ ? error.code
68
+ : undefined;
69
+ }
70
+ //# sourceMappingURL=lifecycle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lifecycle.js","source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E5C,OAAO,IAAI,CAAC;AACb,CAAC;AAED,MAAM,UAAU,kBAAkB,CACjC,OAAyB,EACzB,OAAe,EACf,KAAe,EACf,IAAa;IAEb,OAAO,IAAI,mBAAmB,CAAC,OAAO,EAAE;QACvC,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,KAAK;QACL,IAAI;KACJ,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,wBAAwB,CACvC,OAAyB;IAEzB,OAAO;QACN,SAAS,EAAE,OAAO,CAAC,GAAG;QACtB,OAAO,EAAE,OAAO,CAAC,QAAQ;QACzB,YAAY,EAAE;YACb,YAAY,EAAE;gBACb,kBAAkB,EAAE;oBACnB,kBAAkB,EAAE,IAAI;iBACxB;gBACD,KAAK,EAAE;oBACN,aAAa,EAAE,CAAC,UAAU,EAAE,WAAW,CAAC;iBACxC;gBACD,UAAU,EAAE,EAAE,WAAW,EAAE,KAAK,EAAE;gBAClC,UAAU,EAAE,EAAE;gBACd,cAAc,EAAE;oBACf,iCAAiC,EAAE,IAAI;iBACvC;aACD;YACD,SAAS,EAAE;gBACV,gBAAgB,EAAE,IAAI;gBACtB,MAAM,EAAE,EAAE;aACV;SACD;QACD,gBAAgB,EAAE,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;KAChE,CAAC;AACH,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,KAAc;IACxC,OAAO,OAAO,KAAK,KAAK,QAAQ;QAC/B,KAAK,KAAK,IAAI;QACd,MAAM,IAAI,KAAK;QACf,OAAQ,KAA4B,CAAC,IAAI,KAAK,QAAQ;QACtD,CAAC,CAAE,KAA0B,CAAC,IAAI;QAClC,CAAC,CAAC,SAAS,CAAC;AACd,CAAC"}
@@ -0,0 +1,65 @@
1
+ import type { ChildProcess } from 'node:child_process';
2
+ export interface LspPosition {
3
+ line: number;
4
+ character: number;
5
+ }
6
+ export interface LspRange {
7
+ start: LspPosition;
8
+ end: LspPosition;
9
+ }
10
+ export interface LspLocation {
11
+ uri: string;
12
+ range: LspRange;
13
+ }
14
+ export interface LspLocationLink {
15
+ targetUri: string;
16
+ targetRange: LspRange;
17
+ targetSelectionRange?: LspRange;
18
+ originSelectionRange?: LspRange;
19
+ }
20
+ export interface LspHover {
21
+ contents: string | {
22
+ language?: string;
23
+ value: string;
24
+ } | {
25
+ kind: string;
26
+ value: string;
27
+ } | Array<string | {
28
+ language?: string;
29
+ value: string;
30
+ } | {
31
+ kind: string;
32
+ value: string;
33
+ }>;
34
+ range?: LspRange;
35
+ }
36
+ export interface JsonRpcMessage {
37
+ jsonrpc: '2.0';
38
+ id?: number | string;
39
+ method?: string;
40
+ params?: unknown;
41
+ result?: unknown;
42
+ error?: {
43
+ code: number;
44
+ message: string;
45
+ data?: unknown;
46
+ };
47
+ }
48
+ export interface JsonRpcProtocolOptions {
49
+ request_timeout_ms?: number;
50
+ on_error: (error: unknown) => void;
51
+ on_notification: (message: JsonRpcMessage) => boolean;
52
+ }
53
+ export declare class JsonRpcProtocol {
54
+ #private;
55
+ constructor(options: JsonRpcProtocolOptions);
56
+ attach(proc: ChildProcess): void;
57
+ receive(chunk: Buffer): void;
58
+ detach(): void;
59
+ reject_pending(error: Error): void;
60
+ request(method: string, params: unknown, timeout_override?: number): Promise<unknown>;
61
+ notify(method: string, params: unknown): void;
62
+ send(message: JsonRpcMessage): void;
63
+ drain_buffer(): void;
64
+ handle_message(message: JsonRpcMessage): void;
65
+ }
@@ -0,0 +1,118 @@
1
+ export class JsonRpcProtocol {
2
+ #proc = null;
3
+ #next_id = 1;
4
+ #pending = new Map();
5
+ #buffer = Buffer.alloc(0);
6
+ #options;
7
+ constructor(options) {
8
+ this.#options = options;
9
+ }
10
+ attach(proc) {
11
+ this.#proc = proc;
12
+ }
13
+ receive(chunk) {
14
+ this.#buffer = Buffer.concat([this.#buffer, chunk]);
15
+ this.drain_buffer();
16
+ }
17
+ detach() {
18
+ this.#proc = null;
19
+ }
20
+ reject_pending(error) {
21
+ for (const pending of this.#pending.values()) {
22
+ clearTimeout(pending.timer);
23
+ pending.reject(error);
24
+ }
25
+ this.#pending.clear();
26
+ }
27
+ request(method, params, timeout_override) {
28
+ return new Promise((resolve, reject) => {
29
+ const id = this.#next_id++;
30
+ const timeout_ms = timeout_override ??
31
+ this.#options.request_timeout_ms ??
32
+ 30_000;
33
+ const timer = setTimeout(() => {
34
+ if (this.#pending.has(id)) {
35
+ this.#pending.delete(id);
36
+ reject(new Error(`LSP request ${method} timed out`));
37
+ }
38
+ }, timeout_ms);
39
+ this.#pending.set(id, { resolve, reject, timer });
40
+ try {
41
+ this.send({ jsonrpc: '2.0', id, method, params });
42
+ }
43
+ catch (error) {
44
+ clearTimeout(timer);
45
+ this.#pending.delete(id);
46
+ reject(error);
47
+ }
48
+ });
49
+ }
50
+ notify(method, params) {
51
+ this.send({ jsonrpc: '2.0', method, params });
52
+ }
53
+ send(message) {
54
+ if (!this.#proc?.stdin?.writable) {
55
+ throw new Error('LSP server not connected');
56
+ }
57
+ const body = Buffer.from(JSON.stringify(message), 'utf8');
58
+ const header = Buffer.from(`Content-Length: ${body.length}\r\n\r\n`, 'ascii');
59
+ this.#proc.stdin.write(Buffer.concat([header, body]));
60
+ }
61
+ drain_buffer() {
62
+ while (true) {
63
+ const header_end = this.#buffer.indexOf('\r\n\r\n');
64
+ if (header_end === -1)
65
+ return;
66
+ const header = this.#buffer
67
+ .subarray(0, header_end)
68
+ .toString('ascii');
69
+ const match = header.match(/Content-Length:\s*(\d+)/i);
70
+ if (!match) {
71
+ this.#buffer = this.#buffer.subarray(header_end + 4);
72
+ continue;
73
+ }
74
+ const length = Number(match[1]);
75
+ const body_start = header_end + 4;
76
+ if (this.#buffer.length < body_start + length)
77
+ return;
78
+ const body = this.#buffer.subarray(body_start, body_start + length);
79
+ this.#buffer = this.#buffer.subarray(body_start + length);
80
+ try {
81
+ this.handle_message(JSON.parse(body.toString('utf8')));
82
+ }
83
+ catch (error) {
84
+ this.#options.on_error(error);
85
+ }
86
+ }
87
+ }
88
+ handle_message(message) {
89
+ const numeric_id = typeof message.id === 'number'
90
+ ? message.id
91
+ : typeof message.id === 'string' && /^-?\d+$/.test(message.id)
92
+ ? Number(message.id)
93
+ : null;
94
+ if (numeric_id != null && this.#pending.has(numeric_id)) {
95
+ const pending = this.#pending.get(numeric_id);
96
+ this.#pending.delete(numeric_id);
97
+ clearTimeout(pending.timer);
98
+ if (message.error) {
99
+ pending.reject(new Error(`LSP error ${message.error.code}: ${message.error.message}`));
100
+ }
101
+ else {
102
+ pending.resolve(message.result);
103
+ }
104
+ return;
105
+ }
106
+ if (this.#options.on_notification(message))
107
+ return;
108
+ if (message.method && message.id != null) {
109
+ // Respond to server-to-client requests we don't implement so it doesn't block.
110
+ this.send({
111
+ jsonrpc: '2.0',
112
+ id: message.id,
113
+ result: null,
114
+ });
115
+ }
116
+ }
117
+ }
118
+ //# sourceMappingURL=protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../src/client/protocol.ts"],"names":[],"mappings":"AA0DA,MAAM,OAAO,eAAe;IAC3B,KAAK,GAAwB,IAAI,CAAC;IAClC,QAAQ,GAAG,CAAC,CAAC;IACb,QAAQ,GAAG,IAAI,GAAG,EAA0B,CAAC;IAC7C,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACjB,QAAQ,CAAyB;IAE1C,YAAY,OAA+B;QAC1C,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,MAAM,CAAC,IAAkB;QACxB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,OAAO,CAAC,KAAa;QACpB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;QACpD,IAAI,CAAC,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AAQ,CAAC,GAAG,CAAC,UAAU,CAAE,CAAC;YAC/C,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;YACjC,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YAC5B,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;gBACnB,OAAO,CAAC,MAAM,CACb,IAAI,KAAK,CACR,aAAa,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,CAC3D,CACD,CAAC;YACH,CAAC;iBAAM,CAAC;gBACP,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YACjC,CAAC;YACD,OAAO;QACR,CAAC;QAED,IAAI,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,OAAO,CAAC;YAAE,OAAO;QAEnD,IAAI,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,EAAE,IAAI,IAAI,EAAE,CAAC;YAC1C,+EAA+E;YAC/E,IAAI,CAAC,IAAI,CAAC;gBACT,OAAO,EAAE,KAAK;gBACd,EAAE,EAAE,OAAO,CAAC,EAAE;gBACd,MAAM,EAAE,IAAI;aACZ,CAAC,CAAC;QACJ,CAAC;IACF,CAAC;CACD"}
@@ -0,0 +1,18 @@
1
+ import type { LspLocation, LspLocationLink, LspRange } from './protocol.js';
2
+ export interface LspDocumentSymbol {
3
+ name: string;
4
+ kind: number;
5
+ detail?: string;
6
+ range: LspRange;
7
+ selectionRange: LspRange;
8
+ children?: LspDocumentSymbol[];
9
+ uri?: string;
10
+ containerName?: string;
11
+ }
12
+ export declare function normalize_location_result(result: LspLocation | LspLocation[] | LspLocationLink | LspLocationLink[] | null): LspLocation[];
13
+ export declare function normalize_document_symbol_result(result: LspDocumentSymbol[] | Array<{
14
+ name: string;
15
+ kind: number;
16
+ location: LspLocation;
17
+ containerName?: string;
18
+ }> | null): LspDocumentSymbol[];
@@ -0,0 +1,31 @@
1
+ export function normalize_location_result(result) {
2
+ if (!result)
3
+ return [];
4
+ const entries = Array.isArray(result) ? result : [result];
5
+ return entries.map((entry) => {
6
+ if ('uri' in entry)
7
+ return entry;
8
+ return {
9
+ uri: entry.targetUri,
10
+ range: entry.targetSelectionRange ?? entry.targetRange,
11
+ };
12
+ });
13
+ }
14
+ export function normalize_document_symbol_result(result) {
15
+ if (!result)
16
+ return [];
17
+ if (result.length === 0 ||
18
+ ('range' in result[0] && 'selectionRange' in result[0])) {
19
+ return result;
20
+ }
21
+ const symbol_info = result;
22
+ return symbol_info.map((entry) => ({
23
+ name: entry.name,
24
+ kind: entry.kind,
25
+ range: entry.location.range,
26
+ selectionRange: entry.location.range,
27
+ containerName: entry.containerName,
28
+ uri: entry.location.uri,
29
+ }));
30
+ }
31
+ //# sourceMappingURL=symbols.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"symbols.js","sourceRoot":"","sources":["../../src/client/symbols.ts"],"names":[],"mappings":"AAiBA,MAAM,UAAU,yBAAyB,CACxC,MAKO;IAEP,IAAI,CAAC,MAAM;QAAE,OAAO,EAAE,CAAC;IACvB,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IAC1D,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;QAC5B,IAAI,KAAK,IAAI,KAAK;YAAE,OAAO,KAAK,CAAC;QACjC,OAAO;YACN,GAAG,EAAE,KAAK,CAAC,SAAS;YACpB,KAAK,EAAE,KAAK,CAAC,oBAAoB,IAAI,KAAK,CAAC,WAAW;SACtD,CAAC;IACH,CAAC,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,gCAAgC,CAC/C,MAQO;IAEP,IAAI,CAAC,MAAM;QAAE,OAAO,EAAE,CAAC;IACvB,IACC,MAAM,CAAC,MAAM,KAAK,CAAC;QACnB,CAAC,OAAO,IAAI,MAAM,CAAC,CAAC,CAAC,IAAI,gBAAgB,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,EACtD,CAAC;QACF,OAAO,MAA6B,CAAC;IACtC,CAAC;IACD,MAAM,WAAW,GAAG,MAKlB,CAAC;IACH,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAClC,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,KAAK,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK;QAC3B,cAAc,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK;QACpC,aAAa,EAAE,KAAK,CAAC,aAAa;QAClC,GAAG,EAAE,KAAK,CAAC,QAAQ,CAAC,GAAG;KACvB,CAAC,CAAC,CAAC;AACL,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spences10/pi-lsp",
3
- "version": "0.0.22",
3
+ "version": "0.0.24",
4
4
  "description": "Pi extension that exposes Language Server Protocol diagnostics, hover, definition, and reference tools",
5
5
  "keywords": [
6
6
  "language-server",
@@ -34,7 +34,7 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "@spences10/pi-child-env": "0.1.4",
37
- "@spences10/pi-tui-modal": "0.0.13",
37
+ "@spences10/pi-tui-modal": "0.0.15",
38
38
  "@spences10/pi-project-trust": "0.0.6"
39
39
  },
40
40
  "devDependencies": {
@@ -61,6 +61,8 @@
61
61
  "check": "pnpm --filter \"$npm_package_name^...\" run build:self && pnpm run check:self",
62
62
  "check:self": "tsc --noEmit -p tsconfig.json",
63
63
  "test": "pnpm --filter \"$npm_package_name^...\" run build:self && pnpm run test:self",
64
- "test:self": "vitest run"
64
+ "test:self": "vitest run",
65
+ "coverage:self": "vitest run --coverage",
66
+ "coverage": "pnpm --filter \"$npm_package_name^...\" run build:self && pnpm run coverage:self"
65
67
  }
66
68
  }