@@ -49,6 +49,18 @@ export const validateGitLabUrl = (url: string): boolean => {
49
49
return gitlabUrlPattern . test ( url )
50
50
}
51
51
52
+ // Extract repository name from URL
53
+ export const extractRepoName = ( repoUrl : string ) : string => {
54
+ try {
55
+ // Handle both GitHub and GitLab URLs
56
+ const urlParts = repoUrl . replace ( / \/ $ / , '' ) . split ( '/' )
57
+ const repoName = urlParts [ urlParts . length - 1 ]
58
+ return repoName || 'Repository'
59
+ } catch {
60
+ return 'Repository'
61
+ }
62
+ }
63
+
52
64
// Validate repository size and structure
53
65
export const validateRepositoryStructure = ( tree : TreeItem [ ] ) : RepoValidationResult => {
54
66
const result : RepoValidationResult = {
@@ -131,14 +143,14 @@ const getGitLabToken = (): string | undefined => {
131
143
export const fetchProjectStructure = async (
132
144
repoUrl : string ,
133
145
repoType : "github" | "gitlab"
134
- ) : Promise < { tree : TreeItem [ ] ; validation : RepoValidationResult } > => {
146
+ ) : Promise < { tree : TreeItem [ ] ; validation : RepoValidationResult ; repoUrl : string } > => {
135
147
const tree = repoType === "github"
136
148
? await fetchGitHubProjectStructure ( repoUrl )
137
149
: await fetchGitLabProjectStructure ( repoUrl )
138
150
139
151
const validation = validateRepositoryStructure ( tree )
140
152
141
- return { tree, validation }
153
+ return { tree, validation, repoUrl }
142
154
}
143
155
144
156
const fetchGitHubProjectStructure = async ( repoUrl : string ) : Promise < TreeItem [ ] > => {
@@ -277,8 +289,9 @@ export const generateStructure = (tree: TreeItem[]): DirectoryMap => {
277
289
// Optimized structure building with chunking for large trees
278
290
export const buildStructureString = (
279
291
map : DirectoryMap ,
292
+ customizationOptions : TreeCustomizationOptions ,
293
+ repoUrl = "" , // Repository URL parameter
280
294
prefix = "" ,
281
- options : TreeCustomizationOptions ,
282
295
currentPath = "" ,
283
296
maxDepth = 50 // Prevent infinite recursion
284
297
) : string => {
@@ -288,9 +301,11 @@ export const buildStructureString = (
288
301
289
302
let result = ""
290
303
291
- // Add root directory indicator if enabled
292
- if ( prefix === "" && options . showRootDirectory ) {
293
- result += "./\n"
304
+ // Add root folder name if enabled and at root level
305
+ if ( prefix === "" && customizationOptions . showRootDirectory && repoUrl ) {
306
+ const repoName = extractRepoName ( repoUrl )
307
+ const icon = customizationOptions . useIcons ? "📂 " : ""
308
+ result += `${ icon } ${ repoName } \n`
294
309
}
295
310
296
311
const entries = Array . from ( map . entries ( ) )
@@ -317,25 +332,25 @@ export const buildStructureString = (
317
332
for ( let index = 0 ; index < sortedEntries . length ; index ++ ) {
318
333
const [ key , value ] = sortedEntries [ index ]
319
334
const isLast = index === lastIndex
320
- const connector = getConnector ( isLast , options . asciiStyle )
321
- const childPrefix = getChildPrefix ( isLast , options . asciiStyle )
322
- const icon = options . useIcons ? getIcon ( value instanceof Map ) : ""
335
+ const connector = getConnector ( isLast , customizationOptions . asciiStyle )
336
+ const childPrefix = getChildPrefix ( isLast , customizationOptions . asciiStyle )
337
+ const icon = customizationOptions . useIcons ? getIcon ( value instanceof Map ) : ""
323
338
const isDirectory = value instanceof Map
324
339
325
340
// Build current file/directory path
326
341
const itemPath = currentPath ? `${ currentPath } /${ key } ` : key
327
342
328
343
// Add trailing slash for directories if enabled
329
- const displayName = ( isDirectory && options . showTrailingSlash ) ? `${ key } /` : key
344
+ const displayName = ( isDirectory && customizationOptions . showTrailingSlash ) ? `${ key } /` : key
330
345
331
346
// Get description for this item (cached for performance)
332
347
const description = getDescription ( key , isDirectory , itemPath )
333
- const descriptionText = options . showDescriptions && description ? ` # ${ description } ` : ""
348
+ const descriptionText = customizationOptions . showDescriptions && description ? ` # ${ description } ` : ""
334
349
335
350
result += `${ prefix } ${ connector } ${ icon } ${ displayName } ${ descriptionText } \n`
336
351
337
352
if ( isDirectory ) {
338
- result += buildStructureString ( value , `${ prefix } ${ childPrefix } ` , options , itemPath , maxDepth - 1 )
353
+ result += buildStructureString ( value , customizationOptions , repoUrl , `${ prefix } ${ childPrefix } ` , itemPath , maxDepth - 1 )
339
354
}
340
355
}
341
356
0 commit comments