MCPcopy Index your code
hub / github.com/payloadcms/payload / findNodeAtPosition

Function findNodeAtPosition

packages/typescript-plugin/src/helpers.ts:128–158  ·  view source on GitHub ↗
(
  ts: typeof tslib,
  sourceFile: tslib.SourceFile,
  position: number,
)

Source from the content-addressed store, hash-verified

126 * Returns the deepest token at a given position, reusing TypeScript's internal traversal.
127 */
128export function findNodeAtPosition(
129 ts: typeof tslib,
130 sourceFile: tslib.SourceFile,
131 position: number,
132): tslib.Node | undefined {
133 const getTokenAtPosition = (
134 ts as unknown as {
135 getTokenAtPosition: (sf: tslib.SourceFile, pos: number) => tslib.Node
136 }
137 ).getTokenAtPosition
138
139 if (getTokenAtPosition) {
140 return getTokenAtPosition(sourceFile, position)
141 }
142
143 // Fallback if the internal API is removed in a future TS version
144 function find(node: tslib.Node): tslib.Node | undefined {
145 if (position >= node.getStart() && position < node.getEnd()) {
146 let found: tslib.Node | undefined
147 node.forEachChild((child) => {
148 if (!found) {
149 found = find(child)
150 }
151 })
152 return found || node
153 }
154 return undefined
155 }
156
157 return find(sourceFile)
158}

Callers 1

createFunction · 0.85

Calls 1

findFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…