11import type tslib from 'typescript/lib/tsserverlibrary'
22import { SetOptional } from 'type-fest'
33
4- export function findChildContainingPosition (
5- typescript : typeof import ( 'typescript/lib/tsserverlibrary' ) ,
6- sourceFile : ts . SourceFile ,
7- position : number ,
8- ) : ts . Node | undefined {
4+ export function findChildContainingPosition ( typescript : typeof tslib , sourceFile : ts . SourceFile , position : number ) : ts . Node | undefined {
95 function find ( node : ts . Node ) : ts . Node | undefined {
106 if ( position >= node . getStart ( ) && position < node . getEnd ( ) ) {
117 return typescript . forEachChild ( node , find ) || node
@@ -16,25 +12,41 @@ export function findChildContainingPosition(
1612 return find ( sourceFile )
1713}
1814
19- export function findChildContainingPositionMaxDepth (
20- typescript : typeof import ( 'typescript/lib/tsserverlibrary' ) ,
21- sourceFile : ts . SourceFile ,
22- position : number ,
23- maxDepth ?: number ,
24- ) : ts . Node | undefined {
15+ export function findChildContainingPositionMaxDepth ( sourceFile : ts . SourceFile , position : number , maxDepth ?: number ) : ts . Node | undefined {
2516 let currentDepth = 0
2617 function find ( node : ts . Node ) : ts . Node | undefined {
2718 if ( position >= node . getStart ( ) && position < node . getEnd ( ) ) {
2819 if ( ++ currentDepth === maxDepth ) return node
29- return typescript . forEachChild ( node , find ) || node
20+ return ts . forEachChild ( node , find ) || node
3021 }
3122
3223 return
3324 }
3425 return find ( sourceFile )
3526}
3627
37- export const getIndentFromPos = ( typescript : typeof import ( 'typescript/lib/tsserverlibrary' ) , sourceFile : ts . SourceFile , position : number ) => {
28+ export function getNodePath ( sourceFile : ts . SourceFile , position : number ) : ts . Node [ ] {
29+ const nodes : ts . Node [ ] = [ ]
30+ function find ( node : ts . Node ) : ts . Node | undefined {
31+ if ( position >= node . getStart ( ) && position < node . getEnd ( ) ) {
32+ if ( node !== sourceFile ) nodes . push ( node )
33+ return ts . forEachChild ( node , find ) || node
34+ }
35+
36+ return
37+ }
38+ find ( sourceFile )
39+ return nodes
40+ }
41+
42+ // todo not impl
43+ type MatchStringValue = keyof typeof ts . SyntaxKind | '*'
44+
45+ export const matchNodePath = ( sourceFile : ts . SourceFile , position : number , candidates : MatchStringValue [ ] [ ] ) => {
46+ const nodesPath = getNodePath ( sourceFile , position )
47+ }
48+
49+ export const getIndentFromPos = ( typescript : typeof tslib , sourceFile : ts . SourceFile , position : number ) => {
3850 const { character } = typescript . getLineAndCharacterOfPosition ( sourceFile , position )
3951 return (
4052 sourceFile
0 commit comments