blob: ac23c9fb68d772f089f1599089e799e3992c2ff4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
import type { Node } from 'ts-morph';
import { FILE_PATH_PROJECT } from '../utils/paths';
/**
* Represents a source element in the raw API docs.
*/
export interface RawApiDocsSource {
/**
* The file path of the target element.
*/
filePath: string;
/**
* The line number of the target element.
*/
line: number;
/**
* The column number of the target element.
*/
column: number;
}
export type SourceableNode = Pick<Node, 'getSourceFile' | 'getStart'>;
export function getSourcePath(node: SourceableNode): RawApiDocsSource {
const sourceFile = node.getSourceFile();
const filePath = sourceFile
.getFilePath()
.substring(FILE_PATH_PROJECT.length + 1);
const startPosition = node.getStart();
const { line, column } = sourceFile.getLineAndColumnAtPos(startPosition);
return {
filePath,
line,
column,
};
}
|