Skip to content

Commit 4b7d264

Browse files
Merge pull request #1 from fastapi/tree-view
✨ Initial frontend work for explorer view
2 parents e0b3142 + 82ca469 commit 4b7d264

13 files changed

Lines changed: 909 additions & 51 deletions

File tree

.gitignore

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,22 @@ out
66
dist
77
*.tgz
88

9-
# code coverage
10-
coverage
11-
*.lcov
12-
139
# logs
1410
logs
1511
_.log
16-
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
17-
18-
# dotenv environment variable files
19-
.env
20-
.env.development.local
21-
.env.test.local
22-
.env.production.local
23-
.env.local
2412

2513
# caches
2614
.eslintcache
2715
.cache
2816
*.tsbuildinfo
2917

30-
# IntelliJ based IDEs
31-
.idea
32-
3318
# Finder (MacOS) folder config
3419
.DS_Store
3520

3621
# VS Code extension
3722
*.vsix
3823
.vscode-test
24+
25+
/.agents/
26+
/.claude/
27+
CLAUDE.local.md

.husky/pre-commit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bunx lint-staged

.vscode/launch.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"request": "launch",
88
"args": ["--extensionDevelopmentPath=${workspaceFolder}"],
99
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
10-
"preLaunchTask": "${defaultBuildTask}"
10+
"preLaunchTask": "compile"
1111
},
1212
{
1313
"name": "Extension Tests",
@@ -18,7 +18,7 @@
1818
"--extensionTestsPath=${workspaceFolder}/dist/test/suite/index"
1919
],
2020
"outFiles": ["${workspaceFolder}/dist/test/**/*.js"],
21-
"preLaunchTask": "${defaultBuildTask}"
21+
"preLaunchTask": "compile"
2222
}
2323
]
2424
}

.vscode/tasks.json

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,22 @@
22
"version": "2.0.0",
33
"tasks": [
44
{
5-
"type": "npm",
6-
"script": "watch",
7-
"problemMatcher": "$tsc-watch",
5+
"label": "watch",
6+
"type": "shell",
7+
"command": "bun run watch",
88
"isBackground": true,
9+
"problemMatcher": {
10+
"owner": "esbuild",
11+
"pattern": {
12+
"regexp": "^✘ \\[ERROR\\] (.*)$",
13+
"message": 1
14+
},
15+
"background": {
16+
"activeOnStart": true,
17+
"beginsPattern": "^\\[watch\\]",
18+
"endsPattern": "Watching for changes\\.\\.\\."
19+
}
20+
},
921
"presentation": {
1022
"reveal": "never"
1123
},
@@ -15,9 +27,10 @@
1527
}
1628
},
1729
{
18-
"type": "npm",
19-
"script": "compile",
20-
"problemMatcher": "$tsc",
30+
"label": "compile",
31+
"type": "shell",
32+
"command": "bun run compile",
33+
"problemMatcher": [],
2134
"presentation": {
2235
"reveal": "silent"
2336
},

bun.lock

Lines changed: 45 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

esbuild.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ const watch = process.argv.includes("--watch")
55

66
async function main() {
77
const ctx = await esbuild.context({
8-
entryPoints: ["src/extension.ts", "src/test/extension.test.ts"],
8+
entryPoints: [
9+
"src/extension.ts",
10+
"src/test/extension.test.ts",
11+
"src/test/EndpointTreeProvider.test.ts",
12+
],
913
bundle: true,
1014
format: "cjs",
1115
minify: production,

package.json

Lines changed: 82 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"version": "0.0.1",
66
"publisher": "FastAPI Labs",
77
"engines": {
8-
"vscode": "^1.107.0"
8+
"vscode": "^1.85.0"
99
},
1010
"categories": [
1111
"Other"
@@ -17,29 +17,97 @@
1717
"contributes": {
1818
"commands": [
1919
{
20-
"command": "fastapi-vscode.helloWorld",
21-
"title": "Hello World"
20+
"command": "fastapi-vscode.refreshEndpoints",
21+
"title": "Refresh Endpoints",
22+
"icon": "$(refresh)"
23+
},
24+
{
25+
"command": "fastapi-vscode.goToEndpoint",
26+
"title": "Go to Definition"
27+
},
28+
{
29+
"command": "fastapi-vscode.copyEndpointPath",
30+
"title": "Copy Path"
31+
},
32+
{
33+
"command": "fastapi-vscode.goToRouter",
34+
"title": "Go to Router Definition"
35+
},
36+
{
37+
"command": "fastapi-vscode.copyRouterPrefix",
38+
"title": "Copy Prefix"
2239
}
23-
]
40+
],
41+
"menus": {
42+
"view/title": [
43+
{
44+
"command": "fastapi-vscode.refreshEndpoints",
45+
"when": "view == endpoint-explorer",
46+
"group": "navigation"
47+
}
48+
],
49+
"view/item/context": [
50+
{
51+
"command": "fastapi-vscode.goToEndpoint",
52+
"when": "view == endpoint-explorer && viewItem == route",
53+
"group": "navigation"
54+
},
55+
{
56+
"command": "fastapi-vscode.copyEndpointPath",
57+
"when": "view == endpoint-explorer && viewItem == route",
58+
"group": "navigation"
59+
},
60+
{
61+
"command": "fastapi-vscode.goToRouter",
62+
"when": "view == endpoint-explorer && viewItem == router",
63+
"group": "navigation"
64+
},
65+
{
66+
"command": "fastapi-vscode.copyRouterPrefix",
67+
"when": "view == endpoint-explorer && viewItem == router",
68+
"group": "navigation"
69+
}
70+
]
71+
},
72+
"viewsContainers": {
73+
"activitybar": [
74+
{
75+
"id": "fastapi",
76+
"title": "FastAPI",
77+
"icon": "$(zap)"
78+
}
79+
]
80+
},
81+
"views": {
82+
"fastapi": [
83+
{
84+
"id": "endpoint-explorer",
85+
"name": "Endpoint Explorer"
86+
}
87+
]
88+
}
2489
},
2590
"scripts": {
2691
"vscode:prepublish": "bun run esbuild.js --production",
2792
"compile": "bun run esbuild.js",
2893
"watch": "bun run esbuild.js --watch",
2994
"package": "vsce package",
3095
"publish:marketplace": "vsce publish",
31-
"lint": "biome check --write --unsafe --no-errors-on-unmatched --files-ignore-unknown=true ./",
32-
"test": "vscode-test"
96+
"lint": "biome check --write --unsafe --no-errors-on-unmatched --files-ignore-unknown=true src/",
97+
"test": "vscode-test",
98+
"prepare": "husky"
3399
},
34100
"devDependencies": {
35101
"@biomejs/biome": "^2.3.11",
36102
"@types/bun": "latest",
37103
"@types/mocha": "^10.0.10",
38-
"@types/vscode": "^1.107.0",
104+
"@types/vscode": "^1.85.0",
39105
"@vscode/test-cli": "^0.0.12",
40106
"@vscode/test-electron": "^2.5.2",
41107
"@vscode/vsce": "^3.7.1",
42-
"esbuild": "^0.27.2"
108+
"esbuild": "^0.27.2",
109+
"husky": "^9.1.7",
110+
"lint-staged": "^16.2.7"
43111
},
44112
"peerDependencies": {
45113
"typescript": "^5"
@@ -52,5 +120,10 @@
52120
"bugs": {
53121
"url": "https://github.com/fastapi/fastapi-vscode/issues"
54122
},
55-
"homepage": "https://github.com/fastapi/fastapi-vscode#readme"
123+
"homepage": "https://github.com/fastapi/fastapi-vscode#readme",
124+
"lint-staged": {
125+
"*.{ts,js,json}": [
126+
"biome check --write"
127+
]
128+
}
56129
}

src/extension.ts

Lines changed: 71 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,79 @@
11
import * as vscode from "vscode"
2+
import { EndpointTreeProvider } from "./providers/EndpointTreeProvider"
3+
// TODO: Replace with real endpoint discovery service
4+
import {
5+
groupAppsByWorkspace,
6+
mockApps,
7+
} from "./test/fixtures/mockEndpointData"
8+
import type { EndpointTreeItem, SourceLocation } from "./types/endpoint"
29

10+
function navigateToLocation(location: SourceLocation): void {
11+
if (!location.filePath) {
12+
vscode.window.showErrorMessage("File path is missing for the endpoint.")
13+
return
14+
}
15+
const uri = vscode.Uri.file(location.filePath)
16+
const position = new vscode.Position(location.line - 1, location.column)
17+
vscode.window.showTextDocument(uri, {
18+
selection: new vscode.Range(position, position),
19+
})
20+
}
21+
22+
// This method is called when your extension is activated
323
export function activate(context: vscode.ExtensionContext) {
4-
console.log("FastAPI extension is now active!")
5-
6-
const disposable = vscode.commands.registerCommand(
7-
"fastapi-vscode.helloWorld",
8-
() => {
9-
vscode.window.showInformationMessage(
10-
"Hello World from FastAPI Extension!",
11-
)
12-
},
24+
const endpointProvider = new EndpointTreeProvider(
25+
mockApps,
26+
groupAppsByWorkspace,
1327
)
1428

15-
context.subscriptions.push(disposable)
29+
context.subscriptions.push(
30+
vscode.window.registerTreeDataProvider(
31+
"endpoint-explorer",
32+
endpointProvider,
33+
),
34+
35+
vscode.commands.registerCommand("fastapi-vscode.refreshEndpoints", () => {
36+
endpointProvider.refresh()
37+
}),
38+
39+
vscode.commands.registerCommand(
40+
"fastapi-vscode.goToEndpoint",
41+
(item: EndpointTreeItem) => {
42+
if (item.type === "route") {
43+
navigateToLocation(item.route.location)
44+
}
45+
},
46+
),
47+
48+
vscode.commands.registerCommand(
49+
"fastapi-vscode.copyEndpointPath",
50+
(item: EndpointTreeItem) => {
51+
if (item.type === "route") {
52+
vscode.env.clipboard.writeText(item.route.path)
53+
vscode.window.showInformationMessage(`Copied: ${item.route.path}`)
54+
}
55+
},
56+
),
57+
58+
vscode.commands.registerCommand(
59+
"fastapi-vscode.goToRouter",
60+
(item: EndpointTreeItem) => {
61+
if (item.type === "router") {
62+
navigateToLocation(item.router.location)
63+
}
64+
},
65+
),
66+
67+
vscode.commands.registerCommand(
68+
"fastapi-vscode.copyRouterPrefix",
69+
(item: EndpointTreeItem) => {
70+
if (item.type === "router") {
71+
vscode.env.clipboard.writeText(item.router.prefix)
72+
vscode.window.showInformationMessage(`Copied: ${item.router.prefix}`)
73+
}
74+
},
75+
),
76+
)
1677
}
1778

1879
export function deactivate() {}

0 commit comments

Comments
 (0)