MCPcopy Index your code
hub / github.com/CopilotKit/CopilotKit / findTypeDeclaration

Method findTypeDeclaration

scripts/docs/lib/source.ts:226–255  ·  view source on GitHub ↗

* Finds the absolute declaration file path of a type if imported.

(typeName: string)

Source from the content-addressed store, hash-verified

224 * Finds the absolute declaration file path of a type if imported.
225 */
226 findTypeDeclaration(typeName: string): string | null {
227 for (const statement of this.sourceFile.statements) {
228 if (ts.isImportDeclaration(statement) && statement.importClause) {
229 const namedBindings = statement.importClause.namedBindings;
230 if (namedBindings && ts.isNamedImports(namedBindings)) {
231 const imports = namedBindings.elements.filter(
232 (element) => element.name.text === typeName,
233 );
234 if (imports.length > 0) {
235 const moduleSpecifier = (
236 statement.moduleSpecifier as ts.StringLiteral
237 ).text;
238 // Resolve the path relative to the directory of the current source file
239 let resolvedPath = resolve(
240 dirname(this.sourceFile.fileName),
241 moduleSpecifier,
242 );
243
244 if (existsSync(resolvedPath + ".ts")) {
245 return resolvedPath + ".ts";
246 } else if (existsSync(resolvedPath + ".tsx")) {
247 return resolvedPath + ".tsx";
248 }
249 return null;
250 }
251 }
252 }
253 }
254 return null;
255 }
256
257 /**
258 * Get the public method definitions of a class.

Callers 2

getArg0InterfaceMethod · 0.95
visitMethod · 0.95

Calls 2

filterMethod · 0.80
resolveFunction · 0.50

Tested by

no test coverage detected