prinfer 0.5.3 → 0.6.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/dist/index.d.cts CHANGED
@@ -24,6 +24,34 @@ interface InferredTypeResult {
24
24
  /** The line number where the symbol was found */
25
25
  line?: number;
26
26
  }
27
+ /**
28
+ * Options for hover lookup
29
+ */
30
+ interface HoverOptions {
31
+ /** Optional path to tsconfig.json */
32
+ project?: string;
33
+ /** Include JSDoc/TSDoc documentation */
34
+ include_docs?: boolean;
35
+ }
36
+ /**
37
+ * Result of hover lookup at a position
38
+ */
39
+ interface HoverResult {
40
+ /** The type signature */
41
+ signature: string;
42
+ /** The return type (for functions) */
43
+ returnType?: string;
44
+ /** 1-based line number */
45
+ line: number;
46
+ /** 1-based column number */
47
+ column: number;
48
+ /** JSDoc/TSDoc documentation if requested */
49
+ documentation?: string;
50
+ /** Symbol kind (function, variable, method, etc.) */
51
+ kind: string;
52
+ /** Symbol name if available */
53
+ name?: string;
54
+ }
27
55
 
28
56
  /**
29
57
  * Find the nearest tsconfig.json from a starting directory
@@ -49,6 +77,18 @@ declare function findNodeByNameAndLine(sourceFile: ts.SourceFile, name: string,
49
77
  * Get type information for a node
50
78
  */
51
79
  declare function getTypeInfo(program: ts.Program, node: ts.Node, sourceFile?: ts.SourceFile): InferredTypeResult;
80
+ /**
81
+ * Find the node at a specific position (1-based line and column)
82
+ */
83
+ declare function findNodeAtPosition(sourceFile: ts.SourceFile, line: number, column: number): ts.Node | undefined;
84
+ /**
85
+ * Get documentation from a symbol
86
+ */
87
+ declare function getDocumentation(checker: ts.TypeChecker, symbol: ts.Symbol | undefined): string | undefined;
88
+ /**
89
+ * Get hover information at a specific position
90
+ */
91
+ declare function getHoverInfo(program: ts.Program, node: ts.Node, sourceFile: ts.SourceFile, includeDocs: boolean): HoverResult;
52
92
 
53
93
  /**
54
94
  * Infer the type of a function or variable in a TypeScript file
@@ -85,5 +125,30 @@ declare function inferType(file: string, name: string, options?: string | {
85
125
  * @returns The inferred type information
86
126
  */
87
127
  declare function inferTypeFromOptions(options: Options): InferredTypeResult;
128
+ /**
129
+ * Get type information at a specific position in a TypeScript file
130
+ *
131
+ * @param file - Path to the TypeScript file
132
+ * @param line - 1-based line number
133
+ * @param column - 1-based column number
134
+ * @param options - Optional hover options (project path, include_docs)
135
+ * @returns The hover information at the position
136
+ * @throws Error if file not found or no symbol at position
137
+ *
138
+ * @example
139
+ * ```ts
140
+ * import { hover } from "prinfer";
141
+ *
142
+ * const result = hover("./src/utils.ts", 75, 10);
143
+ * console.log(result.signature);
144
+ * // => "(x: number) => string"
145
+ *
146
+ * // With documentation
147
+ * const result2 = hover("./src/utils.ts", 75, 10, { include_docs: true });
148
+ * console.log(result2.documentation);
149
+ * // => "Formats a number as a string"
150
+ * ```
151
+ */
152
+ declare function hover(file: string, line: number, column: number, options?: HoverOptions): HoverResult;
88
153
 
89
- export { type InferredTypeResult, type Options, findFirstMatch, findNearestTsconfig, findNodeByNameAndLine, getLineNumber, getTypeInfo, inferType, inferTypeFromOptions, loadProgram };
154
+ export { type HoverOptions, type HoverResult, type InferredTypeResult, type Options, findFirstMatch, findNearestTsconfig, findNodeAtPosition, findNodeByNameAndLine, getDocumentation, getHoverInfo, getLineNumber, getTypeInfo, hover, inferType, inferTypeFromOptions, loadProgram };
package/dist/index.d.ts CHANGED
@@ -24,6 +24,34 @@ interface InferredTypeResult {
24
24
  /** The line number where the symbol was found */
25
25
  line?: number;
26
26
  }
27
+ /**
28
+ * Options for hover lookup
29
+ */
30
+ interface HoverOptions {
31
+ /** Optional path to tsconfig.json */
32
+ project?: string;
33
+ /** Include JSDoc/TSDoc documentation */
34
+ include_docs?: boolean;
35
+ }
36
+ /**
37
+ * Result of hover lookup at a position
38
+ */
39
+ interface HoverResult {
40
+ /** The type signature */
41
+ signature: string;
42
+ /** The return type (for functions) */
43
+ returnType?: string;
44
+ /** 1-based line number */
45
+ line: number;
46
+ /** 1-based column number */
47
+ column: number;
48
+ /** JSDoc/TSDoc documentation if requested */
49
+ documentation?: string;
50
+ /** Symbol kind (function, variable, method, etc.) */
51
+ kind: string;
52
+ /** Symbol name if available */
53
+ name?: string;
54
+ }
27
55
 
28
56
  /**
29
57
  * Find the nearest tsconfig.json from a starting directory
@@ -49,6 +77,18 @@ declare function findNodeByNameAndLine(sourceFile: ts.SourceFile, name: string,
49
77
  * Get type information for a node
50
78
  */
51
79
  declare function getTypeInfo(program: ts.Program, node: ts.Node, sourceFile?: ts.SourceFile): InferredTypeResult;
80
+ /**
81
+ * Find the node at a specific position (1-based line and column)
82
+ */
83
+ declare function findNodeAtPosition(sourceFile: ts.SourceFile, line: number, column: number): ts.Node | undefined;
84
+ /**
85
+ * Get documentation from a symbol
86
+ */
87
+ declare function getDocumentation(checker: ts.TypeChecker, symbol: ts.Symbol | undefined): string | undefined;
88
+ /**
89
+ * Get hover information at a specific position
90
+ */
91
+ declare function getHoverInfo(program: ts.Program, node: ts.Node, sourceFile: ts.SourceFile, includeDocs: boolean): HoverResult;
52
92
 
53
93
  /**
54
94
  * Infer the type of a function or variable in a TypeScript file
@@ -85,5 +125,30 @@ declare function inferType(file: string, name: string, options?: string | {
85
125
  * @returns The inferred type information
86
126
  */
87
127
  declare function inferTypeFromOptions(options: Options): InferredTypeResult;
128
+ /**
129
+ * Get type information at a specific position in a TypeScript file
130
+ *
131
+ * @param file - Path to the TypeScript file
132
+ * @param line - 1-based line number
133
+ * @param column - 1-based column number
134
+ * @param options - Optional hover options (project path, include_docs)
135
+ * @returns The hover information at the position
136
+ * @throws Error if file not found or no symbol at position
137
+ *
138
+ * @example
139
+ * ```ts
140
+ * import { hover } from "prinfer";
141
+ *
142
+ * const result = hover("./src/utils.ts", 75, 10);
143
+ * console.log(result.signature);
144
+ * // => "(x: number) => string"
145
+ *
146
+ * // With documentation
147
+ * const result2 = hover("./src/utils.ts", 75, 10, { include_docs: true });
148
+ * console.log(result2.documentation);
149
+ * // => "Formats a number as a string"
150
+ * ```
151
+ */
152
+ declare function hover(file: string, line: number, column: number, options?: HoverOptions): HoverResult;
88
153
 
89
- export { type InferredTypeResult, type Options, findFirstMatch, findNearestTsconfig, findNodeByNameAndLine, getLineNumber, getTypeInfo, inferType, inferTypeFromOptions, loadProgram };
154
+ export { type HoverOptions, type HoverResult, type InferredTypeResult, type Options, findFirstMatch, findNearestTsconfig, findNodeAtPosition, findNodeByNameAndLine, getDocumentation, getHoverInfo, getLineNumber, getTypeInfo, hover, inferType, inferTypeFromOptions, loadProgram };
package/dist/index.js CHANGED
@@ -70,6 +70,14 @@ function isVariableNamed(node, name) {
70
70
  function isNamedNode(node, name) {
71
71
  return isFunctionLikeNamed(node, name) || isVariableNamed(node, name);
72
72
  }
73
+ function isCallExpressionNamed(node, name) {
74
+ if (!ts.isCallExpression(node)) return false;
75
+ const expr = node.expression;
76
+ if (ts.isIdentifier(expr) && expr.text === name) return true;
77
+ if (ts.isPropertyAccessExpression(expr) && expr.name.text === name)
78
+ return true;
79
+ return false;
80
+ }
73
81
  function getLineNumber(sourceFile, node) {
74
82
  const { line } = sourceFile.getLineAndCharacterOfPosition(
75
83
  node.getStart(sourceFile)
@@ -91,19 +99,19 @@ function findFirstMatch(sourceFile, name) {
91
99
  }
92
100
  function findNodeByNameAndLine(sourceFile, name, line) {
93
101
  let found;
102
+ const matchesLine = (node) => {
103
+ if (line === void 0) return true;
104
+ return getLineNumber(sourceFile, node) === line;
105
+ };
94
106
  const visit = (node) => {
95
107
  if (found) return;
96
- if (isNamedNode(node, name)) {
97
- if (line !== void 0) {
98
- const nodeLine = getLineNumber(sourceFile, node);
99
- if (nodeLine === line) {
100
- found = node;
101
- return;
102
- }
103
- } else {
104
- found = node;
105
- return;
106
- }
108
+ if (isNamedNode(node, name) && matchesLine(node)) {
109
+ found = node;
110
+ return;
111
+ }
112
+ if (isCallExpressionNamed(node, name) && matchesLine(node)) {
113
+ found = node;
114
+ return;
107
115
  }
108
116
  ts.forEachChild(node, visit);
109
117
  };
@@ -114,6 +122,18 @@ function getTypeInfo(program, node, sourceFile) {
114
122
  const checker = program.getTypeChecker();
115
123
  const sf = sourceFile ?? node.getSourceFile();
116
124
  const line = getLineNumber(sf, node);
125
+ const flags = ts.TypeFormatFlags.NoTruncation;
126
+ if (ts.isCallExpression(node)) {
127
+ const sig2 = checker.getResolvedSignature(node);
128
+ if (sig2) {
129
+ const signature = checker.signatureToString(sig2, void 0, flags);
130
+ const ret = checker.getReturnTypeOfSignature(sig2);
131
+ const returnType = checker.typeToString(ret, void 0, flags);
132
+ return { signature, returnType, line };
133
+ }
134
+ const t2 = checker.getTypeAtLocation(node);
135
+ return { signature: checker.typeToString(t2, void 0, flags), line };
136
+ }
117
137
  let sig;
118
138
  if (ts.isFunctionDeclaration(node) || ts.isMethodDeclaration(node)) {
119
139
  sig = checker.getSignatureFromDeclaration(node) ?? void 0;
@@ -128,7 +148,6 @@ function getTypeInfo(program, node, sourceFile) {
128
148
  } else if (ts.isMethodSignature(node)) {
129
149
  sig = checker.getSignatureFromDeclaration(node) ?? void 0;
130
150
  }
131
- const flags = ts.TypeFormatFlags.NoTruncation;
132
151
  if (sig) {
133
152
  const signature = checker.signatureToString(sig, void 0, flags);
134
153
  const ret = checker.getReturnTypeOfSignature(sig);
@@ -143,6 +162,246 @@ function getTypeInfo(program, node, sourceFile) {
143
162
  const t = checker.getTypeAtLocation(nameNode);
144
163
  return { signature: checker.typeToString(t, void 0, flags), line };
145
164
  }
165
+ function findSmallestNodeAtPosition(sourceFile, position) {
166
+ let result;
167
+ function visit(node) {
168
+ const start = node.getStart(sourceFile);
169
+ const end = node.getEnd();
170
+ if (position < start || position >= end) {
171
+ return;
172
+ }
173
+ if (!result || node.getWidth(sourceFile) <= result.getWidth(sourceFile)) {
174
+ result = node;
175
+ }
176
+ ts.forEachChild(node, visit);
177
+ }
178
+ visit(sourceFile);
179
+ return result;
180
+ }
181
+ function findHoverableAncestor(sourceFile, position) {
182
+ const smallestNode = findSmallestNodeAtPosition(sourceFile, position);
183
+ if (!smallestNode) return void 0;
184
+ let bestMatch = smallestNode;
185
+ function visit(n) {
186
+ const start = n.getStart(sourceFile);
187
+ const end = n.getEnd();
188
+ if (position < start || position >= end) {
189
+ return false;
190
+ }
191
+ if (ts.isCallExpression(n)) {
192
+ const expr = n.expression;
193
+ if (ts.isIdentifier(expr)) {
194
+ if (position >= expr.getStart(sourceFile) && position < expr.getEnd()) {
195
+ bestMatch = n;
196
+ }
197
+ } else if (ts.isPropertyAccessExpression(expr)) {
198
+ if (position >= expr.name.getStart(sourceFile) && position < expr.name.getEnd()) {
199
+ bestMatch = n;
200
+ }
201
+ }
202
+ }
203
+ if (ts.isFunctionDeclaration(n) && n.name) {
204
+ if (position >= n.name.getStart(sourceFile) && position < n.name.getEnd()) {
205
+ bestMatch = n;
206
+ }
207
+ }
208
+ if (ts.isVariableDeclaration(n) && ts.isIdentifier(n.name)) {
209
+ if (position >= n.name.getStart(sourceFile) && position < n.name.getEnd()) {
210
+ bestMatch = n;
211
+ }
212
+ }
213
+ if ((ts.isMethodDeclaration(n) || ts.isMethodSignature(n)) && ts.isIdentifier(n.name)) {
214
+ if (position >= n.name.getStart(sourceFile) && position < n.name.getEnd()) {
215
+ bestMatch = n;
216
+ }
217
+ }
218
+ if (ts.isClassDeclaration(n) && n.name) {
219
+ if (position >= n.name.getStart(sourceFile) && position < n.name.getEnd()) {
220
+ bestMatch = n;
221
+ }
222
+ }
223
+ if (ts.isInterfaceDeclaration(n) && n.name) {
224
+ if (position >= n.name.getStart(sourceFile) && position < n.name.getEnd()) {
225
+ bestMatch = n;
226
+ }
227
+ }
228
+ ts.forEachChild(n, visit);
229
+ return true;
230
+ }
231
+ visit(sourceFile);
232
+ return bestMatch;
233
+ }
234
+ function findNodeAtPosition(sourceFile, line, column) {
235
+ const lineCount = sourceFile.getLineStarts().length;
236
+ if (line < 1 || line > lineCount) {
237
+ return void 0;
238
+ }
239
+ const lineStart = sourceFile.getLineStarts()[line - 1];
240
+ const lineEnd = line < lineCount ? sourceFile.getLineStarts()[line] : sourceFile.getEnd();
241
+ const lineLength = lineEnd - lineStart;
242
+ if (column < 1 || column > lineLength + 1) {
243
+ return void 0;
244
+ }
245
+ const position = sourceFile.getPositionOfLineAndCharacter(
246
+ line - 1,
247
+ column - 1
248
+ );
249
+ return findHoverableAncestor(sourceFile, position);
250
+ }
251
+ function getSymbolKind(node) {
252
+ if (ts.isFunctionDeclaration(node)) return "function";
253
+ if (ts.isArrowFunction(node)) return "function";
254
+ if (ts.isFunctionExpression(node)) return "function";
255
+ if (ts.isMethodDeclaration(node)) return "method";
256
+ if (ts.isMethodSignature(node)) return "method";
257
+ if (ts.isVariableDeclaration(node)) {
258
+ const init = node.initializer;
259
+ if (init && (ts.isArrowFunction(init) || ts.isFunctionExpression(init))) {
260
+ return "function";
261
+ }
262
+ return "variable";
263
+ }
264
+ if (ts.isParameter(node)) return "parameter";
265
+ if (ts.isPropertyDeclaration(node)) return "property";
266
+ if (ts.isPropertySignature(node)) return "property";
267
+ if (ts.isPropertyAccessExpression(node)) return "property";
268
+ if (ts.isCallExpression(node)) return "call";
269
+ if (ts.isTypeAliasDeclaration(node)) return "type";
270
+ if (ts.isInterfaceDeclaration(node)) return "interface";
271
+ if (ts.isClassDeclaration(node)) return "class";
272
+ if (ts.isIdentifier(node)) return "identifier";
273
+ return "unknown";
274
+ }
275
+ function getNodeName(node) {
276
+ if (ts.isFunctionDeclaration(node) && node.name) {
277
+ return node.name.text;
278
+ }
279
+ if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name)) {
280
+ return node.name.text;
281
+ }
282
+ if ((ts.isMethodDeclaration(node) || ts.isMethodSignature(node)) && ts.isIdentifier(node.name)) {
283
+ return node.name.text;
284
+ }
285
+ if (ts.isPropertyAccessExpression(node)) {
286
+ return node.name.text;
287
+ }
288
+ if (ts.isCallExpression(node)) {
289
+ const expr = node.expression;
290
+ if (ts.isIdentifier(expr)) return expr.text;
291
+ if (ts.isPropertyAccessExpression(expr)) return expr.name.text;
292
+ }
293
+ if (ts.isParameter(node) && ts.isIdentifier(node.name)) {
294
+ return node.name.text;
295
+ }
296
+ if (ts.isIdentifier(node)) {
297
+ return node.text;
298
+ }
299
+ if (ts.isTypeAliasDeclaration(node) || ts.isInterfaceDeclaration(node) || ts.isClassDeclaration(node)) {
300
+ return node.name?.text;
301
+ }
302
+ return void 0;
303
+ }
304
+ function getDocumentation(checker, symbol) {
305
+ if (!symbol) return void 0;
306
+ const docs = symbol.getDocumentationComment(checker);
307
+ if (docs.length === 0) return void 0;
308
+ return ts.displayPartsToString(docs);
309
+ }
310
+ function getHoverInfo(program, node, sourceFile, includeDocs) {
311
+ const checker = program.getTypeChecker();
312
+ const sf = sourceFile;
313
+ const { line, character } = sf.getLineAndCharacterOfPosition(
314
+ node.getStart(sf)
315
+ );
316
+ const flags = ts.TypeFormatFlags.NoTruncation;
317
+ const kind = getSymbolKind(node);
318
+ const name = getNodeName(node);
319
+ let symbol;
320
+ if (ts.isCallExpression(node)) {
321
+ const expr = node.expression;
322
+ if (ts.isPropertyAccessExpression(expr)) {
323
+ symbol = checker.getSymbolAtLocation(expr.name);
324
+ } else {
325
+ symbol = checker.getSymbolAtLocation(expr);
326
+ }
327
+ } else {
328
+ const nodeWithName2 = node;
329
+ if (nodeWithName2.name) {
330
+ symbol = checker.getSymbolAtLocation(nodeWithName2.name);
331
+ } else {
332
+ symbol = checker.getSymbolAtLocation(node);
333
+ }
334
+ }
335
+ const documentation = includeDocs ? getDocumentation(checker, symbol) : void 0;
336
+ if (ts.isCallExpression(node)) {
337
+ const sig2 = checker.getResolvedSignature(node);
338
+ if (sig2) {
339
+ const signature = checker.signatureToString(sig2, void 0, flags);
340
+ const ret = checker.getReturnTypeOfSignature(sig2);
341
+ const returnType = checker.typeToString(ret, void 0, flags);
342
+ return {
343
+ signature,
344
+ returnType,
345
+ line: line + 1,
346
+ column: character + 1,
347
+ documentation,
348
+ kind,
349
+ name
350
+ };
351
+ }
352
+ const t2 = checker.getTypeAtLocation(node);
353
+ return {
354
+ signature: checker.typeToString(t2, void 0, flags),
355
+ line: line + 1,
356
+ column: character + 1,
357
+ documentation,
358
+ kind,
359
+ name
360
+ };
361
+ }
362
+ let sig;
363
+ if (ts.isFunctionDeclaration(node) || ts.isMethodDeclaration(node)) {
364
+ sig = checker.getSignatureFromDeclaration(node) ?? void 0;
365
+ } else if (ts.isVariableDeclaration(node)) {
366
+ const init = node.initializer;
367
+ if (isArrowOrFnExpr(init))
368
+ sig = checker.getSignatureFromDeclaration(init) ?? void 0;
369
+ } else if (ts.isPropertyAssignment(node)) {
370
+ const init = node.initializer;
371
+ if (isArrowOrFnExpr(init))
372
+ sig = checker.getSignatureFromDeclaration(init) ?? void 0;
373
+ } else if (ts.isMethodSignature(node)) {
374
+ sig = checker.getSignatureFromDeclaration(node) ?? void 0;
375
+ }
376
+ if (sig) {
377
+ const signature = checker.signatureToString(sig, void 0, flags);
378
+ const ret = checker.getReturnTypeOfSignature(sig);
379
+ const returnType = checker.typeToString(ret, void 0, flags);
380
+ return {
381
+ signature,
382
+ returnType,
383
+ line: line + 1,
384
+ column: character + 1,
385
+ documentation,
386
+ kind,
387
+ name
388
+ };
389
+ }
390
+ const nodeWithName = node;
391
+ let targetNode = node;
392
+ if (nodeWithName.name && ts.isIdentifier(nodeWithName.name)) {
393
+ targetNode = nodeWithName.name;
394
+ }
395
+ const t = checker.getTypeAtLocation(targetNode);
396
+ return {
397
+ signature: checker.typeToString(t, void 0, flags),
398
+ line: line + 1,
399
+ column: character + 1,
400
+ documentation,
401
+ kind,
402
+ name
403
+ };
404
+ }
146
405
 
147
406
  // src/index.ts
148
407
  function inferType(file, name, options) {
@@ -174,12 +433,35 @@ function inferTypeFromOptions(options) {
174
433
  project: options.project
175
434
  });
176
435
  }
436
+ function hover(file, line, column, options) {
437
+ const { project, include_docs = false } = options ?? {};
438
+ const entryFileAbs = path2.resolve(process.cwd(), file);
439
+ if (!fs.existsSync(entryFileAbs)) {
440
+ throw new Error(`File not found: ${entryFileAbs}`);
441
+ }
442
+ const program = loadProgram(entryFileAbs, project);
443
+ const sourceFile = program.getSourceFile(entryFileAbs);
444
+ if (!sourceFile) {
445
+ throw new Error(
446
+ `Could not load source file into the program (check tsconfig include/exclude): ${entryFileAbs}`
447
+ );
448
+ }
449
+ const node = findNodeAtPosition(sourceFile, line, column);
450
+ if (!node) {
451
+ throw new Error(`No symbol found at ${entryFileAbs}:${line}:${column}`);
452
+ }
453
+ return getHoverInfo(program, node, sourceFile, include_docs);
454
+ }
177
455
  export {
178
456
  findFirstMatch,
179
457
  findNearestTsconfig,
458
+ findNodeAtPosition,
180
459
  findNodeByNameAndLine,
460
+ getDocumentation,
461
+ getHoverInfo,
181
462
  getLineNumber,
182
463
  getTypeInfo,
464
+ hover,
183
465
  inferType,
184
466
  inferTypeFromOptions,
185
467
  loadProgram
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/core.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { findNodeByNameAndLine, getTypeInfo, loadProgram } from \"./core.js\";\nimport type { InferredTypeResult, Options } from \"./types.js\";\n\n// Re-export types\nexport type { Options, InferredTypeResult };\n\n// Re-export core utilities\nexport {\n\tfindFirstMatch,\n\tfindNearestTsconfig,\n\tfindNodeByNameAndLine,\n\tgetLineNumber,\n\tgetTypeInfo,\n\tloadProgram,\n} from \"./core.js\";\n\n/**\n * Infer the type of a function or variable in a TypeScript file\n *\n * @param file - Path to the TypeScript file\n * @param name - Name of the function/variable to inspect\n * @param options - Optional: project path (string) or options object with line and project\n * @returns The inferred type information\n * @throws Error if file not found or symbol not found\n *\n * @example\n * ```ts\n * import { inferType } from \"prinfer\";\n *\n * // By name only\n * const result = inferType(\"./src/utils.ts\", \"myFunction\");\n * console.log(result.signature);\n * // => \"(x: number, y: string) => boolean\"\n *\n * // By name and line number\n * const result2 = inferType(\"./src/utils.ts\", \"commandResult\", { line: 75 });\n * console.log(result2.signature);\n * // => \"Result<VaultAction[], CommandError>\"\n * ```\n */\nexport function inferType(\n\tfile: string,\n\tname: string,\n\toptions?: string | { line?: number; project?: string },\n): InferredTypeResult {\n\t// Normalize options for backward compatibility\n\tconst opts =\n\t\ttypeof options === \"string\" ? { project: options } : (options ?? {});\n\tconst { line, project } = opts;\n\n\tconst entryFileAbs = path.resolve(process.cwd(), file);\n\n\tif (!fs.existsSync(entryFileAbs)) {\n\t\tthrow new Error(`File not found: ${entryFileAbs}`);\n\t}\n\n\tconst program = loadProgram(entryFileAbs, project);\n\tconst sourceFile = program.getSourceFile(entryFileAbs);\n\n\tif (!sourceFile) {\n\t\tthrow new Error(\n\t\t\t`Could not load source file into the program (check tsconfig include/exclude): ${entryFileAbs}`,\n\t\t);\n\t}\n\n\tconst node = findNodeByNameAndLine(sourceFile, name, line);\n\tif (!node) {\n\t\tconst lineInfo = line !== undefined ? ` at line ${line}` : \"\";\n\t\tthrow new Error(\n\t\t\t`No symbol named \"${name}\"${lineInfo} found in ${entryFileAbs}`,\n\t\t);\n\t}\n\n\treturn getTypeInfo(program, node, sourceFile);\n}\n\n/**\n * Infer the type using an options object\n *\n * @param options - Options for type inference\n * @returns The inferred type information\n */\nexport function inferTypeFromOptions(options: Options): InferredTypeResult {\n\treturn inferType(options.file, options.name, {\n\t\tline: options.line,\n\t\tproject: options.project,\n\t});\n}\n","import path from \"node:path\";\nimport ts from \"typescript\";\nimport type { InferredTypeResult } from \"./types.js\";\n\n/**\n * Find the nearest tsconfig.json from a starting directory\n */\nexport function findNearestTsconfig(startDir: string): string | undefined {\n\treturn (\n\t\tts.findConfigFile(startDir, ts.sys.fileExists, \"tsconfig.json\") ??\n\t\tundefined\n\t);\n}\n\n/**\n * Load a TypeScript program from an entry file\n */\nexport function loadProgram(\n\tentryFileAbs: string,\n\tproject?: string,\n): ts.Program {\n\tconst fileDir = path.dirname(entryFileAbs);\n\tconst tsconfigPath = project\n\t\t? path.resolve(process.cwd(), project)\n\t\t: findNearestTsconfig(fileDir);\n\n\tif (!tsconfigPath) {\n\t\t// Fallback: single-file program\n\t\treturn ts.createProgram([entryFileAbs], {\n\t\t\ttarget: ts.ScriptTarget.ES2022,\n\t\t\tmodule: ts.ModuleKind.ESNext,\n\t\t\tstrict: true,\n\t\t\tallowJs: true,\n\t\t\tcheckJs: false,\n\t\t\tmoduleResolution: ts.ModuleResolutionKind.Bundler,\n\t\t\tskipLibCheck: true,\n\t\t});\n\t}\n\n\tconst cfg = ts.readConfigFile(tsconfigPath, ts.sys.readFile);\n\tif (cfg.error) {\n\t\tthrow new Error(\n\t\t\tts.flattenDiagnosticMessageText(cfg.error.messageText, \"\\n\"),\n\t\t);\n\t}\n\n\tconst parsed = ts.parseJsonConfigFileContent(\n\t\tcfg.config,\n\t\tts.sys,\n\t\tpath.dirname(tsconfigPath),\n\t);\n\treturn ts.createProgram({\n\t\trootNames: parsed.fileNames,\n\t\toptions: parsed.options,\n\t});\n}\n\nfunction isArrowOrFnExpr(\n\tn: ts.Node | undefined,\n): n is ts.ArrowFunction | ts.FunctionExpression {\n\treturn !!n && (ts.isArrowFunction(n) || ts.isFunctionExpression(n));\n}\n\nfunction nodeNameText(\n\tn: ts.PropertyName | ts.BindingName | undefined,\n): string | undefined {\n\tif (!n) return undefined;\n\tif (ts.isIdentifier(n)) return n.text;\n\tif (ts.isStringLiteral(n)) return n.text;\n\tif (ts.isNumericLiteral(n)) return n.text;\n\treturn undefined; // ignore computed names etc.\n}\n\nfunction isFunctionLikeNamed(node: ts.Node, name: string): boolean {\n\t// function foo() {}\n\tif (ts.isFunctionDeclaration(node) && node.name?.text === name) return true;\n\n\t// const foo = () => {} / function() {}\n\tif (\n\t\tts.isVariableDeclaration(node) &&\n\t\tts.isIdentifier(node.name) &&\n\t\tnode.name.text === name\n\t) {\n\t\treturn isArrowOrFnExpr(node.initializer);\n\t}\n\n\t// class C { foo() {} } / interface signatures\n\tif (\n\t\t(ts.isMethodDeclaration(node) || ts.isMethodSignature(node)) &&\n\t\tnodeNameText(node.name) === name\n\t) {\n\t\treturn true;\n\t}\n\n\t// object literal { foo() {} } via MethodDeclaration inside object literal is also MethodDeclaration\n\t// property assignment: { foo: () => {} }\n\tif (ts.isPropertyAssignment(node) && nodeNameText(node.name) === name) {\n\t\treturn isArrowOrFnExpr(node.initializer);\n\t}\n\n\treturn false;\n}\n\n/**\n * Check if a node is any variable declaration with the given name\n */\nfunction isVariableNamed(node: ts.Node, name: string): boolean {\n\tif (\n\t\tts.isVariableDeclaration(node) &&\n\t\tts.isIdentifier(node.name) &&\n\t\tnode.name.text === name\n\t) {\n\t\treturn true;\n\t}\n\treturn false;\n}\n\n/**\n * Check if a node matches the given name (function-like or variable)\n */\nfunction isNamedNode(node: ts.Node, name: string): boolean {\n\treturn isFunctionLikeNamed(node, name) || isVariableNamed(node, name);\n}\n\n/**\n * Get the 1-based line number for a node\n */\nexport function getLineNumber(\n\tsourceFile: ts.SourceFile,\n\tnode: ts.Node,\n): number {\n\tconst { line } = sourceFile.getLineAndCharacterOfPosition(\n\t\tnode.getStart(sourceFile),\n\t);\n\treturn line + 1;\n}\n\n/**\n * Find the first function-like node with the given name in a source file\n */\nexport function findFirstMatch(\n\tsourceFile: ts.SourceFile,\n\tname: string,\n): ts.Node | undefined {\n\tlet found: ts.Node | undefined;\n\n\tconst visit = (node: ts.Node) => {\n\t\tif (found) return;\n\t\tif (isFunctionLikeNamed(node, name)) {\n\t\t\tfound = node;\n\t\t\treturn;\n\t\t}\n\t\tts.forEachChild(node, visit);\n\t};\n\n\tvisit(sourceFile);\n\treturn found;\n}\n\n/**\n * Find a node by name and optionally by line number\n */\nexport function findNodeByNameAndLine(\n\tsourceFile: ts.SourceFile,\n\tname: string,\n\tline?: number,\n): ts.Node | undefined {\n\tlet found: ts.Node | undefined;\n\n\tconst visit = (node: ts.Node) => {\n\t\tif (found) return;\n\t\tif (isNamedNode(node, name)) {\n\t\t\tif (line !== undefined) {\n\t\t\t\tconst nodeLine = getLineNumber(sourceFile, node);\n\t\t\t\tif (nodeLine === line) {\n\t\t\t\t\tfound = node;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfound = node;\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tts.forEachChild(node, visit);\n\t};\n\n\tvisit(sourceFile);\n\treturn found;\n}\n\n/**\n * Get type information for a node\n */\nexport function getTypeInfo(\n\tprogram: ts.Program,\n\tnode: ts.Node,\n\tsourceFile?: ts.SourceFile,\n): InferredTypeResult {\n\tconst checker = program.getTypeChecker();\n\tconst sf = sourceFile ?? node.getSourceFile();\n\tconst line = getLineNumber(sf, node);\n\n\tlet sig: ts.Signature | undefined;\n\n\t// Prefer getting the signature from a declaration/expression directly\n\tif (ts.isFunctionDeclaration(node) || ts.isMethodDeclaration(node)) {\n\t\tsig = checker.getSignatureFromDeclaration(node) ?? undefined;\n\t} else if (ts.isVariableDeclaration(node)) {\n\t\tconst init = node.initializer;\n\t\tif (isArrowOrFnExpr(init))\n\t\t\tsig = checker.getSignatureFromDeclaration(init) ?? undefined;\n\t} else if (ts.isPropertyAssignment(node)) {\n\t\tconst init = node.initializer;\n\t\tif (isArrowOrFnExpr(init))\n\t\t\tsig = checker.getSignatureFromDeclaration(init) ?? undefined;\n\t} else if (ts.isMethodSignature(node)) {\n\t\t// interfaces/types\n\t\tsig = checker.getSignatureFromDeclaration(node) ?? undefined;\n\t}\n\n\tconst flags = ts.TypeFormatFlags.NoTruncation;\n\n\tif (sig) {\n\t\tconst signature = checker.signatureToString(sig, undefined, flags);\n\t\tconst ret = checker.getReturnTypeOfSignature(sig);\n\t\tconst returnType = checker.typeToString(ret, undefined, flags);\n\t\treturn { signature, returnType, line };\n\t}\n\n\t// Fallback: type at the name location\n\tconst nodeWithName = node as unknown as { name?: ts.Node };\n\tlet nameNode: ts.Node = node;\n\tif (nodeWithName.name && ts.isIdentifier(nodeWithName.name)) {\n\t\tnameNode = nodeWithName.name;\n\t}\n\n\tconst t = checker.getTypeAtLocation(n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AAM,eAAe;AACrB,MAAI,WAAoB;AACxB,MAAI,aAAa,QAAQ,GAAG,aAAa,aAAa,IAAI,GAAG;AAC5D,eAAW,aAAa;AAAA,EACzB;AAEA,QAAM,IAAI,QAAQ,kBAAkB,QAAQ;AAC5C,SAAO,EAAE,WAAW,QAAQ,aAAa,GAAG,QAAW,KAAK,GAAG,KAAK;AACrE;;;ADpMO,SAAS,UACf,MACA,MACA,SACqB;AAErB,QAAM,OACL,OAAO,YAAY,WAAW,EAAE,SAAS,QAAQ,IAAK,WAAW,CAAC;AACnE,QAAM,EAAE,MAAM,QAAQ,IAAI;AAE1B,QAAM,eAAeC,MAAK,QAAQ,QAAQ,IAAI,GAAG,IAAI;AAErD,MAAI,CAAC,GAAG,WAAW,YAAY,GAAG;AACjC,UAAM,IAAI,MAAM,mBAAmB,YAAY,EAAE;AAAA,EAClD;AAEA,QAAM,UAAU,YAAY,cAAc,OAAO;AACjD,QAAM,aAAa,QAAQ,cAAc,YAAY;AAErD,MAAI,CAAC,YAAY;AAChB,UAAM,IAAI;AAAA,MACT,iFAAiF,YAAY;AAAA,IAC9F;AAAA,EACD;AAEA,QAAM,OAAO,sBAAsB,YAAY,MAAM,IAAI;AACzD,MAAI,CAAC,MAAM;AACV,UAAM,WAAW,SAAS,SAAY,YAAY,IAAI,KAAK;AAC3D,UAAM,IAAI;AAAA,MACT,oBAAoB,IAAI,IAAI,QAAQ,aAAa,YAAY;AAAA,IAC9D;AAAA,EACD;AAEA,SAAO,YAAY,SAAS,MAAM,UAAU;AAC7C;AAQO,SAAS,qBAAqB,SAAsC;AAC1E,SAAO,UAAU,QAAQ,MAAM,QAAQ,MAAM;AAAA,IAC5C,MAAM,QAAQ;AAAA,IACd,SAAS,QAAQ;AAAA,EAClB,CAAC;AACF;","names":["path","path"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/core.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport {\n\tfindNodeAtPosition,\n\tfindNodeByNameAndLine,\n\tgetHoverInfo,\n\tgetTypeInfo,\n\tloadProgram,\n} from \"./core.js\";\nimport type {\n\tHoverOptions,\n\tHoverResult,\n\tInferredTypeResult,\n\tOptions,\n} from \"./types.js\";\n\n// Re-export types\nexport type { HoverOptions, HoverResult, InferredTypeResult, Options };\n\n// Re-export core utilities\nexport {\n\tfindFirstMatch,\n\tfindNearestTsconfig,\n\tfindNodeAtPosition,\n\tfindNodeByNameAndLine,\n\tgetDocumentation,\n\tgetHoverInfo,\n\tgetLineNumber,\n\tgetTypeInfo,\n\tloadProgram,\n} from \"./core.js\";\n\n/**\n * Infer the type of a function or variable in a TypeScript file\n *\n * @param file - Path to the TypeScript file\n * @param name - Name of the function/variable to inspect\n * @param options - Optional: project path (string) or options object with line and project\n * @returns The inferred type information\n * @throws Error if file not found or symbol not found\n *\n * @example\n * ```ts\n * import { inferType } from \"prinfer\";\n *\n * // By name only\n * const result = inferType(\"./src/utils.ts\", \"myFunction\");\n * console.log(result.signature);\n * // => \"(x: number, y: string) => boolean\"\n *\n * // By name and line number\n * const result2 = inferType(\"./src/utils.ts\", \"commandResult\", { line: 75 });\n * console.log(result2.signature);\n * // => \"Result<VaultAction[], CommandError>\"\n * ```\n */\nexport function inferType(\n\tfile: string,\n\tname: string,\n\toptions?: string | { line?: number; project?: string },\n): InferredTypeResult {\n\t// Normalize options for backward compatibility\n\tconst opts =\n\t\ttypeof options === \"string\" ? { project: options } : (options ?? {});\n\tconst { line, project } = opts;\n\n\tconst entryFileAbs = path.resolve(process.cwd(), file);\n\n\tif (!fs.existsSync(entryFileAbs)) {\n\t\tthrow new Error(`File not found: ${entryFileAbs}`);\n\t}\n\n\tconst program = loadProgram(entryFileAbs, project);\n\tconst sourceFile = program.getSourceFile(entryFileAbs);\n\n\tif (!sourceFile) {\n\t\tthrow new Error(\n\t\t\t`Could not load source file into the program (check tsconfig include/exclude): ${entryFileAbs}`,\n\t\t);\n\t}\n\n\tconst node = findNodeByNameAndLine(sourceFile, name, line);\n\tif (!node) {\n\t\tconst lineInfo = line !== undefined ? ` at line ${line}` : \"\";\n\t\tthrow new Error(\n\t\t\t`No symbol named \"${name}\"${lineInfo} found in ${entryFileAbs}`,\n\t\t);\n\t}\n\n\treturn getTypeInfo(program, node, sourceFile);\n}\n\n/**\n * Infer the type using an options object\n *\n * @param options - Options for type inference\n * @returns The inferred type information\n */\nexport function inferTypeFromOptions(options: Options): InferredTypeResult {\n\treturn inferType(options.file, options.name, {\n\t\tline: options.line,\n\t\tproject: options.project,\n\t});\n}\n\n/**\n * Get type information at a specific position in a TypeScript file\n *\n * @param file - Path to the TypeScript file\n * @param line - 1-based line number\n * @param column - 1-based column number\n * @param options - Optional hover options (project path, include_docs)\n * @returns The hover information at the position\n * @throws Error if file not found or no symbol at position\n *\n * @example\n * ```ts\n * import { hover } from \"prinfer\";\n *\n * const result = hover(\"./src/utils.ts\", 75, 10);\n * console.log(result.signature);\n * // => \"(x: number) => string\"\n *\n * // With documentation\n * const result2 = hover(\"./src/utils.ts\", 75, 10, { include_docs: true });\n * console.log(result2.documentation);\n * // => \"Formats a number as a string\"\n * ```\n */\nexport function hover(\n\tfile: string,\n\tline: number,\n\tcolumn: number,\n\toptions?: HoverOptions,\n): HoverResult {\n\tconst { project, include_docs = false } = options ?? {};\n\n\tconst entryFileAbs = path.resolve(process.cwd(), file);\n\n\tif (!fs.existsSync(entryFileAbs)) {\n\t\tthrow new Error(`File not found: ${entryFileAbs}`);\n\t}\n\n\tconst program = loadProgram(entryFileAbs, project);\n\tconst sourceFile = program.getSourceFile(entryFileAbs);\n\n\tif (!sourceFile) {\n\t\tthrow new Error(\n\t\t\t`Could not load source file into the program (check tsconfig include/exclude): ${entryFileAbs}`,\n\t\t);\n\t}\n\n\tconst node = findNodeAtPosition(sourceFile, line, column);\n\tif (!node) {\n\t\tthrow new Error(`No symbol found at ${entryFileAbs}:${line}:${column}`);\n\t}\n\n\treturn getHoverInfo(program, node, sourceFile, include_docs);\n}\n","import path from \"node:path\";\nimport ts from \"typescript\";\nimport type { HoverResult, InferredTypeResult } from \"./types.js\";\n\n/**\n * Find the nearest tsconfig.json from a starting directory\n */\nexport function findNearestTsconfig(startDir: string): string | undefined {\n\treturn (\n\t\tts.findConfigFile(startDir, ts.sys.fileExists, \"tsconfig.json\") ??\n\t\tundefined\n\t);\n}\n\n/**\n * Load a TypeScript program from an entry file\n */\nexport function loadProgram(\n\tentryFileAbs: string,\n\tproject?: string,\n): ts.Program {\n\tconst fileDir = path.dirname(entryFileAbs);\n\tconst tsconfigPath = project\n\t\t? path.resolve(process.cwd(), project)\n\t\t: findNearestTsconfig(fileDir);\n\n\tif (!tsconfigPath) {\n\t\t// Fallback: single-file program\n\t\treturn ts.createProgram([entryFileAbs], {\n\t\t\ttarget: ts.ScriptTarget.ES2022,\n\t\t\tmodule: ts.ModuleKind.ESNext,\n\t\t\tstrict: true,\n\t\t\tallowJs: true,\n\t\t\tcheckJs: false,\n\t\t\tmoduleResolution: ts.ModuleResolutionKind.Bundler,\n\t\t\tskipLibCheck: true,\n\t\t});\n\t}\n\n\tconst cfg = ts.readConfigFile(tsconfigPath, ts.sys.readFile);\n\tif (cfg.error) {\n\t\tthrow new Error(\n\t\t\tts.flattenDiagnosticMessageText(cfg.error.messageText, \"\\n\"),\n\t\t);\n\t}\n\n\tconst parsed = ts.parseJsonConfigFileContent(\n\t\tcfg.config,\n\t\tts.sys,\n\t\tpath.dirname(tsconfigPath),\n\t);\n\treturn ts.createProgram({\n\t\trootNames: parsed.fileNames,\n\t\toptions: parsed.options,\n\t});\n}\n\nfunction isArrowOrFnExpr(\n\tn: ts.Node | undefined,\n): n is ts.ArrowFunction | ts.FunctionExpression {\n\treturn !!n && (ts.isArrowFunction(n) || ts.isFunctionExpression(n));\n}\n\nfunction nodeNameText(\n\tn: ts.PropertyName | ts.BindingName | undefined,\n): string | undefined {\n\tif (!n) return undefined;\n\tif (ts.isIdentifier(n)) return n.text;\n\tif (ts.isStringLiteral(n)) return n.text;\n\tif (ts.isNumericLiteral(n)) return n.text;\n\treturn undefined; // ignore computed names etc.\n}\n\nfunction isFunctionLikeNamed(node: ts.Node, name: string): boolean {\n\t// function foo() {}\n\tif (ts.isFunctionDeclaration(node) && node.name?.text === name) return true;\n\n\t// const foo = () => {} / function() {}\n\tif (\n\t\tts.isVariableDeclaration(node) &&\n\t\tts.isIdentifier(node.name) &&\n\t\tnode.name.text === name\n\t) {\n\t\treturn isArrowOrFnExpr(node.initializer);\n\t}\n\n\t// class C { foo() {} } / interface signatures\n\tif (\n\t\t(ts.isMethodDeclaration(node) || ts.isMethodSignature(node)) &&\n\t\tnodeNameText(node.name) === name\n\t) {\n\t\treturn true;\n\t}\n\n\t// object literal { foo() {} } via MethodDeclaration inside object literal is also MethodDeclaration\n\t// property assignment: { foo: () => {} }\n\tif (ts.isPropertyAssignment(node) && nodeNameText(node.name) === name) {\n\t\treturn isArrowOrFnExpr(node.initializer);\n\t}\n\n\treturn false;\n}\n\n/**\n * Check if a node is any variable declaration with the given name\n */\nfunction isVariableNamed(node: ts.Node, name: string): boolean {\n\tif (\n\t\tts.isVariableDeclaration(node) &&\n\t\tts.isIdentifier(node.name) &&\n\t\tnode.name.text === name\n\t) {\n\t\treturn true;\n\t}\n\treturn false;\n}\n\n/**\n * Check if a node matches the given name (function-like or variable)\n */\nfunction isNamedNode(node: ts.Node, name: string): boolean {\n\treturn isFunctionLikeNamed(node, name) || isVariableNamed(node, name);\n}\n\n/**\n * Check if a node is a call expression with the given name\n */\nfunction isCallExpressionNamed(node: ts.Node, name: string): boolean {\n\tif (!ts.isCallExpression(node)) return false;\n\tconst expr = node.expression;\n\n\t// Direct call: foo()\n\tif (ts.isIdentifier(expr) && expr.text === name) return true;\n\n\t// Property access: this.foo() or obj.foo()\n\tif (ts.isPropertyAccessExpression(expr) && expr.name.text === name)\n\t\treturn true;\n\n\treturn false;\n}\n\n/**\n * Get the 1-based line number for a node\n */\nexport function getLineNumber(\n\tsourceFile: ts.SourceFile,\n\tnode: ts.Node,\n): number {\n\tconst { line } = sourceFile.getLineAndCharacterOfPosition(\n\t\tnode.getStart(sourceFile),\n\t);\n\treturn line + 1;\n}\n\n/**\n * Find the first function-like node with the given name in a source file\n */\nexport function findFirstMatch(\n\tsourceFile: ts.SourceFile,\n\tname: string,\n): ts.Node | undefined {\n\tlet found: ts.Node | undefined;\n\n\tconst visit = (node: ts.Node) => {\n\t\tif (found) return;\n\t\tif (isFunctionLikeNamed(node, name)) {\n\t\t\tfound = node;\n\t\t\treturn;\n\t\t}\n\t\tts.forEachChild(node, visit);\n\t};\n\n\tvisit(sourceFile);\n\treturn found;\n}\n\n/**\n * Find a node by name and optionally by line number\n */\nexport function findNodeByNameAndLine(\n\tsourceFile: ts.SourceFile,\n\tname: string,\n\tline?: number,\n): ts.Node | undefined {\n\tlet found: ts.Node | undefined;\n\n\tconst matchesLine = (node: ts.Node): boolean => {\n\t\tif (line === undefined) return true;\n\t\treturn getLineNumber(sourceFile, node) === line;\n\t};\n\n\tconst visit = (node: ts.Node) => {\n\t\tif (found) return;\n\n\t\t// Check declarations (existing logic)\n\t\tif (isNamedNode(node, name) && matchesLine(node)) {\n\t\t\tfound = node;\n\t\t\treturn;\n\t\t}\n\n\t\t// Check call expressions (new)\n\t\tif (isCallExpressionNamed(node, name) && matchesLine(node)) {\n\t\t\tfound = node;\n\t\t\treturn;\n\t\t}\n\n\t\tts.forEachChild(node, visit);\n\t};\n\n\tvisit(sourceFile);\n\treturn found;\n}\n\n/**\n * Get type information for a node\n */\nexport function getTypeInfo(\n\tprogram: ts.Program,\n\tnode: ts.Node,\n\tsourceFile?: ts.SourceFile,\n): InferredTypeResult {\n\tconst checker = program.getTypeChecker();\n\tconst sf = sourceFile ?? node.getSourceFile();\n\tconst line = getLineNumber(sf, node);\n\tconst flags = ts.TypeFormatFlags.NoTruncation;\n\n\t// Handle call expressions - get instantiated signature\n\tif (ts.isCallExpression(node)) {\n\t\tconst sig = checker.getResolvedSignature(node);\n\t\tif (sig) {\n\t\t\tconst signature = checker.signatureToString(sig, undefined, flags);\n\t\t\tconst ret = checker.getReturnTypeOfSignature(sig);\n\t\t\tconst returnType = checker.typeToString(ret, undefined, flags);\n\t\t\treturn { signature, returnType, line };\n\t\t}\n\t\t// Fallback: get type of the call result\n\t\tconst t = checker.getTypeAtLocation(node);\n\t\treturn { signature: checker.typeToString(t, undefined, flags), line };\n\t}\n\n\tlet sig: ts.Signature | undefined;\n\n\t// Prefer getting the signature from a declaration/expression directly\n\tif (ts.isFunctionDeclaration(node) || ts.isMethodDeclaration(node)) {\n\t\tsig = checker.getSignatureFromDeclaration(node) ?? undefined;\n\t} else if (ts.isVariableDeclaration(node)) {\n\t\tconst init = node.initializer;\n\t\tif (isArrowOrFnExpr(init))\n\t\t\tsig = checker.getSignatureFromDeclaration(init) ?? undefined;\n\t} else if (ts.isPropertyAssignment(node)) {\n\t\tconst init = node.initializer;\n\t\tif (isArrowOrFnExpr(init))\n\t\t\tsig = checker.getSignatureFromDeclaration(init) ?? undefined;\n\t} else if (ts.isMethodSignature(node)) {\n\t\t// interfaces/types\n\t\tsig = checker.getSignatureFromDeclaration(node) ?? undefined;\n\t}\n\n\tif (sig) {\n\t\tconst signature = checker.signatureToString(sig, undefined, flags);\n\t\tconst ret = checker.getReturnTypeOfSignature(sig);\n\t\tconst returnType = checker.typeToString(ret, undefined, flags);\n\t\treturn { signature, returnType, line };\n\t}\n\n\t// Fallback: type at the name location\n\tconst nodeWithName = node as unknown as { name?: ts.Node };\n\tlet nameNode: ts.Node = node;\n\tif (nodeWithName.name && ts.isIdentifier(nodeWithName.name)) {\n\t\tnameNode = nodeWithName.name;\n\t}\n\n\tconst t = checker.getTypeAtLocation(nameNode);\n\treturn { signature: checker.typeToString(t, undefined, flags), line };\n}\n\n/**\n * Find the most specific node containing a position by walking the AST\n */\nfunction findSmallestNodeAtPosition(\n\tsourceFile: ts.SourceFile,\n\tposition: number,\n): ts.Node | undefined {\n\tlet result: ts.Node | undefined;\n\n\tfunction visit(node: ts.Node): void {\n\t\tconst start = node.getStart(sourceFile);\n\t\tconst end = node.getEnd();\n\n\t\t// Position must be within this node's range\n\t\tif (position < start || position >= end) {\n\t\t\treturn;\n\t\t}\n\n\t\t// This node contains the position - check if it's more specific than current result\n\t\tif (\n\t\t\t!result ||\n\t\t\tnode.getWidth(sourceFile) <= result.getWidth(sourceFile)\n\t\t) {\n\t\t\tresult = node;\n\t\t}\n\n\t\t// Continue to check children for more specific nodes\n\t\tts.forEachChild(node, visit);\n\t}\n\n\tvisit(sourceFile);\n\treturn result;\n}\n\n/**\n * Walk up from a token to find the most useful node for hover info\n */\nfunction findHoverableAncestor(\n\tsourceFile: ts.SourceFile,\n\tposition: number,\n): ts.Node | undefined {\n\tconst smallestNode = findSmallestNodeAtPosition(sourceFile, position);\n\tif (!smallestNode) return undefined;\n\n\t// Walk up the tree to find the most useful hoverable node\n\tlet bestMatch: ts.Node | undefined = smallestNode;\n\n\t// Visit ancestors\n\tfunction visit(n: ts.Node): boolean {\n\t\tconst start = n.getStart(sourceFile);\n\t\tconst end = n.getEnd();\n\n\t\tif (position < start || position >= end) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Check if this is a call expression with our node as the callee\n\t\tif (ts.isCallExpression(n)) {\n\t\t\tconst expr = n.expression;\n\t\t\t// Check if position is on the function name part\n\t\t\tif (ts.isIdentifier(expr)) {\n\t\t\t\tif (\n\t\t\t\t\tposition >= expr.getStart(sourceFile) &&\n\t\t\t\t\tposition < expr.getEnd()\n\t\t\t\t) {\n\t\t\t\t\tbestMatch = n;\n\t\t\t\t}\n\t\t\t} else if (ts.isPropertyAccessExpression(expr)) {\n\t\t\t\tif (\n\t\t\t\t\tposition >= expr.name.getStart(sourceFile) &&\n\t\t\t\t\tposition < expr.name.getEnd()\n\t\t\t\t) {\n\t\t\t\t\tbestMatch = n;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// If this is a declaration and the position is on its name, use this declaration\n\t\tif (ts.isFunctionDeclaration(n) && n.name) {\n\t\t\tif (\n\t\t\t\tposition >= n.name.getStart(sourceFile) &&\n\t\t\t\tposition < n.name.getEnd()\n\t\t\t) {\n\t\t\t\tbestMatch = n;\n\t\t\t}\n\t\t}\n\t\tif (ts.isVariableDeclaration(n) && ts.isIdentifier(n.name)) {\n\t\t\tif (\n\t\t\t\tposition >= n.name.getStart(sourceFile) &&\n\t\t\t\tposition < n.name.getEnd()\n\t\t\t) {\n\t\t\t\tbestMatch = n;\n\t\t\t}\n\t\t}\n\t\tif (\n\t\t\t(ts.isMethodDeclaration(n) || ts.isMethodSignature(n)) &&\n\t\t\tts.isIdentifier(n.name)\n\t\t) {\n\t\t\tif (\n\t\t\t\tposition >= n.name.getStart(sourceFile) &&\n\t\t\t\tposition < n.name.getEnd()\n\t\t\t) {\n\t\t\t\tbestMatch = n;\n\t\t\t}\n\t\t}\n\t\tif (ts.isClassDeclaration(n) && n.name) {\n\t\t\tif (\n\t\t\t\tposition >= n.name.getStart(sourceFile) &&\n\t\t\t\tposition < n.name.getEnd()\n\t\t\t) {\n\t\t\t\tbestMatch = n;\n\t\t\t}\n\t\t}\n\t\tif (ts.isInterfaceDeclaration(n) && n.name) {\n\t\t\tif (\n\t\t\t\tposition >= n.name.getStart(sourceFile) &&\n\t\t\t\tposition < n.name.getEnd()\n\t\t\t) {\n\t\t\t\tbestMatch = n;\n\t\t\t}\n\t\t}\n\n\t\tts.forEachChild(n, visit);\n\t\treturn true;\n\t}\n\n\tvisit(sourceFile);\n\treturn bestMatch;\n}\n\n/**\n * Find the node at a specific position (1-based line and column)\n */\nexport function findNodeAtPosition(\n\tsourceFile: ts.SourceFile,\n\tline: number,\n\tcolumn: number,\n): ts.Node | undefined {\n\t// Validate line/column bounds\n\tconst lineCount = sourceFile.getLineStarts().length;\n\tif (line < 1 || line > lineCount) {\n\t\treturn undefined;\n\t}\n\n\tconst lineStart = sourceFile.getLineStarts()[line - 1];\n\tconst lineEnd =\n\t\tline < lineCount\n\t\t\t? sourceFile.getLineStarts()[line]\n\t\t\t: sourceFile.getEnd();\n\tconst lineLength = lineEnd - lineStart;\n\n\tif (column < 1 || column > lineLength + 1) {\n\t\treturn undefined;\n\t}\n\n\t// Convert 1-based line/column to 0-based position\n\tconst position = sourceFile.getPositionOfLineAndCharacter(\n\t\tline - 1,\n\t\tcolumn - 1,\n\t);\n\n\treturn findHoverableAncestor(sourceFile, position);\n}\n\n/**\n * Get the symbol kind as a string\n */\nfunction getSymbolKind(node: ts.Node): string {\n\tif (ts.isFunctionDeclaration(node)) return \"function\";\n\tif (ts.isArrowFunction(node)) return \"function\";\n\tif (ts.isFunctionExpression(node)) return \"function\";\n\tif (ts.isMethodDeclaration(node)) return \"method\";\n\tif (ts.isMethodSignature(node)) return \"method\";\n\tif (ts.isVariableDeclaration(node)) {\n\t\tconst init = node.initializer;\n\t\tif (\n\t\t\tinit &&\n\t\t\t(ts.isArrowFunction(init) || ts.isFunctionExpression(init))\n\t\t) {\n\t\t\treturn \"function\";\n\t\t}\n\t\treturn \"variable\";\n\t}\n\tif (ts.isParameter(node)) return \"parameter\";\n\tif (ts.isPropertyDeclaration(node)) return \"property\";\n\tif (ts.isPropertySignature(node)) return \"property\";\n\tif (ts.isPropertyAccessExpression(node)) return \"property\";\n\tif (ts.isCallExpression(node)) return \"call\";\n\tif (ts.isTypeAliasDeclaration(node)) return \"type\";\n\tif (ts.isInterfaceDeclaration(node)) return \"interface\";\n\tif (ts.isClassDeclaration(node)) return \"class\";\n\tif (ts.isIdentifier(node)) return \"identifier\";\n\treturn \"unknown\";\n}\n\n/**\n * Get the name of a node if it has one\n */\nfunction getNodeName(node: ts.Node): string | undefined {\n\tif (ts.isFunctionDeclaration(node) && node.name) {\n\t\treturn node.name.text;\n\t}\n\tif (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name)) {\n\t\treturn node.name.text;\n\t}\n\tif (\n\t\t(ts.isMethodDeclaration(node) || ts.isMethodSignature(node)) &&\n\t\tts.isIdentifier(node.name)\n\t) {\n\t\treturn node.name.text;\n\t}\n\tif (ts.isPropertyAccessExpression(node)) {\n\t\treturn node.name.text;\n\t}\n\tif (ts.isCallExpression(node)) {\n\t\tconst expr = node.expression;\n\t\tif (ts.isIdentifier(expr)) return expr.text;\n\t\tif (ts.isPropertyAccessExpression(expr)) return expr.name.text;\n\t}\n\tif (ts.isParameter(node) && ts.isIdentifier(node.name)) {\n\t\treturn node.name.text;\n\t}\n\tif (ts.isIdentifier(node)) {\n\t\treturn node.text;\n\t}\n\tif (\n\t\tts.isTypeAliasDeclaration(node) ||\n\t\tts.isInterfaceDeclaration(node) ||\n\t\tts.isClassDeclaration(node)\n\t) {\n\t\treturn node.name?.text;\n\t}\n\treturn undefined;\n}\n\n/**\n * Get documentation from a symbol\n */\nexport function getDocumentation(\n\tchecker: ts.TypeChecker,\n\tsymbol: ts.Symbol | undefined,\n): string | undefined {\n\tif (!symbol) return undefined;\n\n\tconst docs = symbol.getDocumentationComment(checker);\n\tif (docs.length === 0) return undefined;\n\n\treturn ts.displayPartsToString(docs);\n}\n\n/**\n * Get hover information at a specific position\n */\nexport function getHoverInfo(\n\tprogram: ts.Program,\n\tnode: ts.Node,\n\tsourceFile: ts.SourceFile,\n\tincludeDocs: boolean,\n): HoverResult {\n\tconst checker = program.getTypeChecker();\n\tconst sf = sourceFile;\n\tconst { line, character } = sf.getLineAndCharacterOfPosition(\n\t\tnode.getStart(sf),\n\t);\n\tconst flags = ts.TypeFormatFlags.NoTruncation;\n\n\tconst kind = getSymbolKind(node);\n\tconst name = getNodeName(node);\n\n\t// Get symbol for documentation\n\tlet symbol: ts.Symbol | undefined;\n\tif (ts.isCallExpression(node)) {\n\t\t// For calls, get symbol from the expression\n\t\tconst expr = node.expression;\n\t\tif (ts.isPropertyAccessExpression(expr)) {\n\t\t\tsymbol = checker.getSymbolAtLocation(expr.name);\n\t\t} else {\n\t\t\tsymbol = checker.getSymbolAtLocation(expr);\n\t\t}\n\t} else {\n\t\tconst nodeWithName = node as unknown as { name?: ts.Node };\n\t\tif (nodeWithName.name) {\n\t\t\tsymbol = checker.getSymbolAtLocation(nodeWithName.name);\n\t\t} else {\n\t\t\tsymbol = checker.getSymbolAtLocation(node);\n\t\t}\n\t}\n\n\tconst documentation = includeDocs\n\t\t? getDocumentation(checker, symbol)\n\t\t: undefined;\n\n\t// Handle call expressions - get instantiated signature\n\tif (ts.isCallExpression(node)) {\n\t\tconst sig = checker.getResolvedSignature(node);\n\t\tif (sig) {\n\t\t\tconst signature = checker.signatureToString(sig, undefined, flags);\n\t\t\tconst ret = checker.getReturnTypeOfSignature(sig);\n\t\t\tconst returnType = checker.typeToString(ret, undefined, flags);\n\t\t\treturn {\n\t\t\t\tsignature,\n\t\t\t\treturnType,\n\t\t\t\tline: line + 1,\n\t\t\t\tcolumn: character + 1,\n\t\t\t\tdocumentation,\n\t\t\t\tkind,\n\t\t\t\tname,\n\t\t\t};\n\t\t}\n\t\t// Fallback: get type of the call result\n\t\tconst t = checker.getTypeAtLocation(node);\n\t\treturn {\n\t\t\tsignature: checker.typeToString(t, undefined, flags),\n\t\t\tline: line + 1,\n\t\t\tcolumn: character + 1,\n\t\t\tdocumentation,\n\t\t\tkind,\n\t\t\tname,\n\t\t};\n\t}\n\n\tlet sig: ts.Signature | undefined;\n\n\t// Prefer getting the signature from a declaration/expression directly\n\tif (ts.isFunctionDeclaration(node) || ts.isMethodDeclaration(node)) {\n\t\tsig = checker.getSignatureFromDeclaration(node) ?? undefined;\n\t} else if (ts.isVariableDeclaration(node)) {\n\t\tconst init = node.initializer;\n\t\tif (isArrowOrFnExpr(init))\n\t\t\tsig = checker.getSignatureFromDeclaration(init) ?? undefined;\n\t} else if (ts.isPropertyAssignment(node)) {\n\t\tconst init = node.initializer;\n\t\tif (isArrowOrFnExpr(init))\n\t\t\tsig = checker.getSignatureFromDeclaration(init) ?? undefined;\n\t} else if (ts.isMethodSignature(node)) {\n\t\tsig = checker.getSignatureFromDeclaration(node) ?? undefined;\n\t}\n\n\tif (sig) {\n\t\tconst signature = checker.signatureToString(sig, undefined, flags);\n\t\tconst ret = checker.getReturnTypeOfSignature(sig);\n\t\tconst returnType = checker.typeToString(ret, undefined, flags);\n\t\treturn {\n\t\t\tsignature,\n\t\t\treturnType,\n\t\t\tline: line + 1,\n\t\t\tcolumn: character + 1,\n\t\t\tdocumentation,\n\t\t\tkind,\n\t\t\tname,\n\t\t};\n\t}\n\n\t// Fallback: type at the node location\n\tconst nodeWithName = node as unknown as { name?: ts.Node };\n\tlet targetNode: ts.Node = node;\n\tif (nodeWithName.name && ts.isIdentifier(nodeWithName.name)) {\n\t\ttargetNode = nodeWithName.name;\n\t}\n\n\tconst t = checker.getTypeAtLocation(targetNode);\n\treturn {\n\t\tsignature: checker.typeToString(t, undefined, flags),\n\t\tline: line + 1,\n\t\tcolumn: character + 1,\n\t\tdocumentation,\n\t\tkind,\n\t\tname,\n\t};\n}\n"],"mappings":";AAAA,OAAO,QAAQ;AACf,OAAOA,WAAU;;;ACDjB,OAAO,UAAU;AACjB,OAAO,QAAQ;AAMR,SAAS,oBAAoB,UAAsC;AACzE,SACC,GAAG,eAAe,UAAU,GAAG,IAAI,YAAY,eAAe,KAC9D;AAEF;AAKO,SAAS,YACf,cACA,SACa;AACb,QAAM,UAAU,KAAK,QAAQ,YAAY;AACzC,QAAM,eAAe,UAClB,KAAK,QAAQ,QAAQ,IAAI,GAAG,OAAO,IACnC,oBAAoB,OAAO;AAE9B,MAAI,CAAC,cAAc;AAElB,WAAO,GAAG,cAAc,CAAC,YAAY,GAAG;AAAA,MACvC,QAAQ,GAAG,aAAa;AAAA,MACxB,QAAQ,GAAG,WAAW;AAAA,MACtB,QAAQ;AAAA,MACR,SAAS;AAAA,MACT,SAAS;AAAA,MACT,kBAAkB,GAAG,qBAAqB;AAAA,MAC1C,cAAc;AAAA,IACf,CAAC;AAAA,EACF;AAEA,QAAM,MAAM,GAAG,eAAe,cAAc,GAAG,IAAI,QAAQ;AAC3D,MAAI,IAAI,OAAO;AACd,UAAM,IAAI;AAA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