33 */
44
55import { existsSync } from "node:fs"
6- import { sep } from "node:path"
6+ import { basename , sep } from "node:path"
77import * as vscode from "vscode"
88import { clearImportCache } from "./core/importResolver"
99import { Parser } from "./core/parser"
@@ -16,15 +16,21 @@ import {
1616 EndpointTreeProvider ,
1717} from "./providers/EndpointTreeProvider"
1818import { TestCodeLensProvider } from "./providers/TestCodeLensProvider"
19+ import { disposeLogger , log } from "./utils/logger"
1920
2021async function discoverFastAPIApps ( parser : Parser ) : Promise < AppDefinition [ ] > {
2122 const apps : AppDefinition [ ] = [ ]
2223 const workspaceFolders = vscode . workspace . workspaceFolders
2324
2425 if ( ! workspaceFolders ) {
26+ log ( "No workspace folders found" )
2527 return apps
2628 }
2729
30+ log (
31+ `Discovering FastAPI apps in ${ workspaceFolders . length } workspace folder(s)...` ,
32+ )
33+
2834 for ( const folder of workspaceFolders ) {
2935 const config = vscode . workspace . getConfiguration ( "fastapi" , folder . uri )
3036 const customEntryPoint = config . get < string > ( "entryPoint" )
@@ -38,12 +44,14 @@ async function discoverFastAPIApps(parser: Parser): Promise<AppDefinition[]> {
3844 : vscode . Uri . joinPath ( folder . uri , customEntryPoint ) . fsPath
3945
4046 if ( ! existsSync ( entryPath ) ) {
47+ log ( `Custom entry point not found: ${ customEntryPoint } ` )
4148 vscode . window . showWarningMessage (
4249 `FastAPI entry point not found: ${ customEntryPoint } ` ,
4350 )
4451 continue
4552 }
4653
54+ log ( `Using custom entry point: ${ customEntryPoint } ` )
4755 candidates = [ entryPath ]
4856 } else {
4957 // Scan for main.py and __init__.py files (likely FastAPI entry points)
@@ -57,19 +65,37 @@ async function discoverFastAPIApps(parser: Parser): Promise<AppDefinition[]> {
5765 candidates = [ ...mainFiles , ...initFiles ]
5866 . map ( ( uri ) => uri . fsPath )
5967 . sort ( ( a , b ) => a . split ( sep ) . length - b . split ( sep ) . length )
68+ log (
69+ `Found ${ candidates . length } candidate entry file(s) in ${ basename ( folder . uri . fsPath ) } ` ,
70+ )
6071 }
6172
6273 for ( const entryPath of candidates ) {
6374 const projectRoot = findProjectRoot ( entryPath , folder . uri . fsPath )
6475 const routerNode = buildRouterGraph ( entryPath , parser , projectRoot )
6576
6677 if ( routerNode ) {
67- apps . push ( routerNodeToAppDefinition ( routerNode , folder . uri . fsPath ) )
78+ const app = routerNodeToAppDefinition ( routerNode , folder . uri . fsPath )
79+ apps . push ( app )
80+ // Count all routes: direct routes + routes in all routers (recursively)
81+ const countRoutes = ( routers : typeof app . routers ) : number =>
82+ routers . reduce (
83+ ( sum , r ) => sum + r . routes . length + countRoutes ( r . children ) ,
84+ 0 ,
85+ )
86+ const totalRoutes = app . routes . length + countRoutes ( app . routers )
87+ log (
88+ `Found FastAPI app "${ app . name } " with ${ totalRoutes } route(s) in ${ app . routers . length } router(s)` ,
89+ )
6890 break
6991 }
7092 }
7193 }
7294
95+ if ( apps . length === 0 ) {
96+ log ( "No FastAPI apps found in workspace" )
97+ }
98+
7399 return apps
74100}
75101
@@ -84,6 +110,13 @@ function navigateToLocation(location: SourceLocation): void {
84110let parserService : Parser | null = null
85111
86112export async function activate ( context : vscode . ExtensionContext ) {
113+ const extensionVersion =
114+ vscode . extensions . getExtension ( "FastAPILabs.fastapi-vscode" ) ?. packageJSON
115+ ?. version ?? "unknown"
116+ log (
117+ `FastAPI extension ${ extensionVersion } activated (VS Code ${ vscode . version } )` ,
118+ )
119+
87120 parserService = new Parser ( )
88121 await parserService . init ( {
89122 core : vscode . Uri . joinPath (
@@ -223,7 +256,9 @@ export async function activate(context: vscode.ExtensionContext) {
223256}
224257
225258export function deactivate ( ) {
259+ log ( "Extension deactivated" )
226260 parserService ?. dispose ( )
227261 parserService = null
228262 clearImportCache ( )
263+ disposeLogger ( )
229264}
0 commit comments