Skip to content

Commit 529b384

Browse files
committed
feat(ui): expand file display name logic for framework routing
Add support for Next.js and other framework conventional filenames (page.tsx, route.ts, views.py, etc.) to show directory context, improving file identification in chat UI file lists.
1 parent 1c089b7 commit 529b384

File tree

1 file changed

+39
-6
lines changed

1 file changed

+39
-6
lines changed

core/src/main/kotlin/cc/unitmesh/devti/gui/chat/ui/file/RelatedFileListCellRenderer.kt

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,54 @@ class RelatedFileListCellRenderer(val project: Project) : ListCellRenderer<FileP
6363

6464
/**
6565
* Constructs a display name for the given file presentation based on the associated virtual file.
66+
*
67+
* For file-system routing frameworks where files have conventional names but directories carry semantic meaning:
68+
* - Next.js: app/dashboard/page.tsx -> dashboard/page.tsx
69+
* - Django: myapp/views.py -> myapp/views.py
70+
* - Nuxt: pages/about/index.vue -> about/index.vue
71+
*
72+
* Shows directory context for conventional filenames that appear frequently across projects.
6673
*/
6774
private fun buildDisplayName(value: FilePresentation): @NlsSafe String {
6875
val filename = value.virtualFile.name
69-
if (filename.startsWith("index.")) {
76+
val filenameWithoutExtension = filename.substringBeforeLast('.')
77+
78+
// File-system routing and framework convention patterns
79+
val routingConventionFiles = setOf(
80+
// Next.js App Router
81+
"page", "layout", "loading", "error", "not-found", "route", "template", "default",
82+
// Traditional index files
83+
"index",
84+
// Django patterns
85+
"views", "models", "urls", "forms", "admin", "serializers", "tests",
86+
// Flask/FastAPI patterns
87+
"app", "main", "routes", "models", "schemas",
88+
// Vue/Nuxt patterns
89+
"middleware", "plugins", "store",
90+
// React/Vue component patterns
91+
"component", "components", "hook", "hooks", "context", "provider",
92+
// General patterns
93+
"config", "settings", "constants", "types", "utils", "helpers"
94+
)
95+
96+
if (filenameWithoutExtension in routingConventionFiles) {
7097
val parent = value.virtualFile.parent?.name
7198
if (parent != null) {
72-
val grandParent = value.virtualFile.parent?.parent?.name
73-
return if (grandParent != null) {
74-
"$grandParent/$parent/$filename"
99+
// For index files, show more context as they're especially common
100+
if (filenameWithoutExtension == "index") {
101+
val grandParent = value.virtualFile.parent?.parent?.name
102+
return if (grandParent != null) {
103+
"$grandParent/$parent/$filename"
104+
} else {
105+
"$parent/$filename"
106+
}
75107
} else {
76-
"$parent/$filename"
108+
// For other conventional files, show parent directory context
109+
return "$parent/$filename"
77110
}
78111
}
79112
}
80113

81114
return filename
82115
}
83-
}
116+
}

0 commit comments

Comments
 (0)