Skip to content

Commit b99e2be

Browse files
Fix memory leak on deactivation
1 parent b048d67 commit b99e2be

4 files changed

Lines changed: 26 additions & 16 deletions

File tree

src/core/internal.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type { RouteMethod } from "./types"
99
* Valid HTTP methods plus WEBSOCKET, used for decorator validation.
1010
* Lowercase for case-insensitive comparison during extraction.
1111
*/
12-
export const ROUTE_METHODS = new Set([
12+
export const ROUTE_METHODS: ReadonlySet<string> = new Set([
1313
"get",
1414
"post",
1515
"put",

src/core/parser.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,6 @@ export class Parser {
3232

3333
dispose() {
3434
this.parser?.delete()
35+
this.parser = null
3536
}
3637
}

src/extension.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,10 @@ function navigateToLocation(location: SourceLocation): void {
8080
})
8181
}
8282

83+
let parserService: Parser | null = null
84+
8385
export async function activate(context: vscode.ExtensionContext) {
84-
const parserService = new Parser()
86+
parserService = new Parser()
8587
await parserService.init({
8688
core: vscode.Uri.joinPath(
8789
context.extensionUri,
@@ -111,6 +113,9 @@ export async function activate(context: vscode.ExtensionContext) {
111113
vscode.commands.registerCommand(
112114
"fastapi-vscode.refreshEndpoints",
113115
async () => {
116+
if (!parserService) {
117+
return
118+
}
114119
clearImportCache()
115120
const newApps = await discoverFastAPIApps(parserService)
116121
endpointProvider.setApps(newApps)
@@ -152,4 +157,8 @@ export async function activate(context: vscode.ExtensionContext) {
152157
)
153158
}
154159

155-
export function deactivate() {}
160+
export function deactivate() {
161+
parserService?.dispose()
162+
parserService = null
163+
clearImportCache()
164+
}

src/test/fixtures/mockEndpointData.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const mockApps: AppDefinition[] = [
1919
routes: [
2020
{
2121
method: "GET",
22-
path: "/",
22+
path: "/api/v1/users/",
2323
functionName: "list_users",
2424
location: {
2525
filePath: "/Users/dev/ecommerce-api/app/routers/users.py",
@@ -29,7 +29,7 @@ export const mockApps: AppDefinition[] = [
2929
},
3030
{
3131
method: "POST",
32-
path: "/",
32+
path: "/api/v1/users/",
3333
functionName: "create_user",
3434
location: {
3535
filePath: "/Users/dev/ecommerce-api/app/routers/users.py",
@@ -39,7 +39,7 @@ export const mockApps: AppDefinition[] = [
3939
},
4040
{
4141
method: "GET",
42-
path: "/{user_id}",
42+
path: "/api/v1/users/{user_id}",
4343
functionName: "get_user",
4444
location: {
4545
filePath: "/Users/dev/ecommerce-api/app/routers/users.py",
@@ -49,7 +49,7 @@ export const mockApps: AppDefinition[] = [
4949
},
5050
{
5151
method: "PUT",
52-
path: "/{user_id}",
52+
path: "/api/v1/users/{user_id}",
5353
functionName: "update_user",
5454
location: {
5555
filePath: "/Users/dev/ecommerce-api/app/routers/users.py",
@@ -59,7 +59,7 @@ export const mockApps: AppDefinition[] = [
5959
},
6060
{
6161
method: "DELETE",
62-
path: "/{user_id}",
62+
path: "/api/v1/users/{user_id}",
6363
functionName: "delete_user",
6464
location: {
6565
filePath: "/Users/dev/ecommerce-api/app/routers/users.py",
@@ -82,7 +82,7 @@ export const mockApps: AppDefinition[] = [
8282
routes: [
8383
{
8484
method: "GET",
85-
path: "/",
85+
path: "/api/v1/items/",
8686
functionName: "list_items",
8787
location: {
8888
filePath: "/Users/dev/ecommerce-api/app/routers/items.py",
@@ -92,7 +92,7 @@ export const mockApps: AppDefinition[] = [
9292
},
9393
{
9494
method: "POST",
95-
path: "/",
95+
path: "/api/v1/items/",
9696
functionName: "create_item",
9797
location: {
9898
filePath: "/Users/dev/ecommerce-api/app/routers/items.py",
@@ -102,7 +102,7 @@ export const mockApps: AppDefinition[] = [
102102
},
103103
{
104104
method: "GET",
105-
path: "/{item_id}",
105+
path: "/api/v1/items/{item_id}",
106106
functionName: "get_item",
107107
location: {
108108
filePath: "/Users/dev/ecommerce-api/app/routers/items.py",
@@ -125,7 +125,7 @@ export const mockApps: AppDefinition[] = [
125125
routes: [
126126
{
127127
method: "WEBSOCKET",
128-
path: "/chat",
128+
path: "/ws/chat",
129129
functionName: "websocket_chat",
130130
location: {
131131
filePath: "/Users/dev/ecommerce-api/app/routers/websocket.py",
@@ -135,7 +135,7 @@ export const mockApps: AppDefinition[] = [
135135
},
136136
{
137137
method: "WEBSOCKET",
138-
path: "/notifications",
138+
path: "/ws/notifications",
139139
functionName: "websocket_notifications",
140140
location: {
141141
filePath: "/Users/dev/ecommerce-api/app/routers/websocket.py",
@@ -215,7 +215,7 @@ export const mockApps: AppDefinition[] = [
215215
routes: [
216216
{
217217
method: "GET",
218-
path: "/daily",
218+
path: "/api/metrics/daily",
219219
functionName: "get_daily_metrics",
220220
location: {
221221
filePath: "/Users/dev/analytics-service/src/routers/metrics.py",
@@ -225,7 +225,7 @@ export const mockApps: AppDefinition[] = [
225225
},
226226
{
227227
method: "GET",
228-
path: "/weekly",
228+
path: "/api/metrics/weekly",
229229
functionName: "get_weekly_metrics",
230230
location: {
231231
filePath: "/Users/dev/analytics-service/src/routers/metrics.py",
@@ -235,7 +235,7 @@ export const mockApps: AppDefinition[] = [
235235
},
236236
{
237237
method: "POST",
238-
path: "/export",
238+
path: "/api/metrics/export",
239239
functionName: "export_metrics",
240240
location: {
241241
filePath: "/Users/dev/analytics-service/src/routers/metrics.py",

0 commit comments

Comments
 (0)