@@ -49,6 +49,18 @@ export const validateGitLabUrl = (url: string): boolean => {
4949 return gitlabUrlPattern . test ( url )
5050}
5151
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+
5264// Validate repository size and structure
5365export const validateRepositoryStructure = ( tree : TreeItem [ ] ) : RepoValidationResult => {
5466 const result : RepoValidationResult = {
@@ -131,14 +143,14 @@ const getGitLabToken = (): string | undefined => {
131143export const fetchProjectStructure = async (
132144 repoUrl : string ,
133145 repoType : "github" | "gitlab"
134- ) : Promise < { tree : TreeItem [ ] ; validation : RepoValidationResult } > => {
146+ ) : Promise < { tree : TreeItem [ ] ; validation : RepoValidationResult ; repoUrl : string } > => {
135147 const tree = repoType === "github"
136148 ? await fetchGitHubProjectStructure ( repoUrl )
137149 : await fetchGitLabProjectStructure ( repoUrl )
138150
139151 const validation = validateRepositoryStructure ( tree )
140152
141- return { tree, validation }
153+ return { tree, validation, repoUrl }
142154}
143155
144156const fetchGitHubProjectStructure = async ( repoUrl : string ) : Promise < TreeItem [ ] > => {
@@ -277,8 +289,9 @@ export const generateStructure = (tree: TreeItem[]): DirectoryMap => {
277289// Optimized structure building with chunking for large trees
278290export const buildStructureString = (
279291 map : DirectoryMap ,
292+ customizationOptions : TreeCustomizationOptions ,
293+ repoUrl = "" , // Repository URL parameter
280294 prefix = "" ,
281- options : TreeCustomizationOptions ,
282295 currentPath = "" ,
283296 maxDepth = 50 // Prevent infinite recursion
284297) : string => {
@@ -288,9 +301,11 @@ export const buildStructureString = (
288301
289302 let result = ""
290303
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`
294309 }
295310
296311 const entries = Array . from ( map . entries ( ) )
@@ -317,25 +332,25 @@ export const buildStructureString = (
317332 for ( let index = 0 ; index < sortedEntries . length ; index ++ ) {
318333 const [ key , value ] = sortedEntries [ index ]
319334 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 ) : ""
323338 const isDirectory = value instanceof Map
324339
325340 // Build current file/directory path
326341 const itemPath = currentPath ? `${ currentPath } /${ key } ` : key
327342
328343 // Add trailing slash for directories if enabled
329- const displayName = ( isDirectory && options . showTrailingSlash ) ? `${ key } /` : key
344+ const displayName = ( isDirectory && customizationOptions . showTrailingSlash ) ? `${ key } /` : key
330345
331346 // Get description for this item (cached for performance)
332347 const description = getDescription ( key , isDirectory , itemPath )
333- const descriptionText = options . showDescriptions && description ? ` # ${ description } ` : ""
348+ const descriptionText = customizationOptions . showDescriptions && description ? ` # ${ description } ` : ""
334349
335350 result += `${ prefix } ${ connector } ${ icon } ${ displayName } ${ descriptionText } \n`
336351
337352 if ( isDirectory ) {
338- result += buildStructureString ( value , `${ prefix } ${ childPrefix } ` , options , itemPath , maxDepth - 1 )
353+ result += buildStructureString ( value , customizationOptions , repoUrl , `${ prefix } ${ childPrefix } ` , itemPath , maxDepth - 1 )
339354 }
340355 }
341356
0 commit comments