@@ -50,6 +50,8 @@ export async function parseMentions(
5050 cwd : string ,
5151 urlContentFetcher : UrlContentFetcher ,
5252 fileContextTracker ?: FileContextTracker ,
53+ rooIgnoreController ?: any ,
54+ showRooIgnoredFiles : boolean = true ,
5355) : Promise < string > {
5456 const mentions : Set < string > = new Set ( )
5557 let parsedText = text . replace ( mentionRegexGlobal , ( match , mention ) => {
@@ -102,12 +104,11 @@ export async function parseMentions(
102104 } else if ( mention . startsWith ( "/" ) ) {
103105 const mentionPath = mention . slice ( 1 )
104106 try {
105- const content = await getFileOrFolderContent ( mentionPath , cwd )
107+ const content = await getFileOrFolderContent ( mentionPath , cwd , rooIgnoreController , showRooIgnoredFiles )
106108 if ( mention . endsWith ( "/" ) ) {
107109 parsedText += `\n\n<folder_content path="${ mentionPath } ">\n${ content } \n</folder_content>`
108110 } else {
109111 parsedText += `\n\n<file_content path="${ mentionPath } ">\n${ content } \n</file_content>`
110- // Track that this file was mentioned and its content was included
111112 if ( fileContextTracker ) {
112113 await fileContextTracker . trackFileContext ( mentionPath , "file_mentioned" )
113114 }
@@ -161,15 +162,22 @@ export async function parseMentions(
161162 return parsedText
162163}
163164
164- async function getFileOrFolderContent ( mentionPath : string , cwd : string ) : Promise < string > {
165- // Unescape spaces in the path before resolving it
165+ async function getFileOrFolderContent (
166+ mentionPath : string ,
167+ cwd : string ,
168+ rooIgnoreController ?: any ,
169+ showRooIgnoredFiles : boolean = true ,
170+ ) : Promise < string > {
166171 const unescapedPath = unescapeSpaces ( mentionPath )
167172 const absPath = path . resolve ( cwd , unescapedPath )
168173
169174 try {
170175 const stats = await fs . stat ( absPath )
171176
172177 if ( stats . isFile ( ) ) {
178+ if ( rooIgnoreController && ! rooIgnoreController . validateAccess ( absPath ) ) {
179+ return `(File ${ mentionPath } is ignored by .rooignore)`
180+ }
173181 try {
174182 const content = await extractTextFromFile ( absPath )
175183 return content
@@ -180,33 +188,51 @@ async function getFileOrFolderContent(mentionPath: string, cwd: string): Promise
180188 const entries = await fs . readdir ( absPath , { withFileTypes : true } )
181189 let folderContent = ""
182190 const fileContentPromises : Promise < string | undefined > [ ] = [ ]
183- entries . forEach ( ( entry , index ) => {
191+ const LOCK_SYMBOL = "🔒"
192+
193+ for ( let index = 0 ; index < entries . length ; index ++ ) {
194+ const entry = entries [ index ]
184195 const isLast = index === entries . length - 1
185196 const linePrefix = isLast ? "└── " : "├── "
197+ const entryPath = path . join ( absPath , entry . name )
198+
199+ let isIgnored = false
200+ if ( rooIgnoreController ) {
201+ isIgnored = ! rooIgnoreController . validateAccess ( entryPath )
202+ }
203+
204+ if ( isIgnored && ! showRooIgnoredFiles ) {
205+ continue
206+ }
207+
208+ const displayName = isIgnored ? `${ LOCK_SYMBOL } ${ entry . name } ` : entry . name
209+
186210 if ( entry . isFile ( ) ) {
187- folderContent += `${ linePrefix } ${ entry . name } \n`
188- const filePath = path . join ( mentionPath , entry . name )
189- const absoluteFilePath = path . resolve ( absPath , entry . name )
190- fileContentPromises . push (
191- ( async ( ) => {
192- try {
193- const isBinary = await isBinaryFile ( absoluteFilePath ) . catch ( ( ) => false )
194- if ( isBinary ) {
211+ folderContent += `${ linePrefix } ${ displayName } \n`
212+ if ( ! isIgnored ) {
213+ const filePath = path . join ( mentionPath , entry . name )
214+ const absoluteFilePath = path . resolve ( absPath , entry . name )
215+ fileContentPromises . push (
216+ ( async ( ) => {
217+ try {
218+ const isBinary = await isBinaryFile ( absoluteFilePath ) . catch ( ( ) => false )
219+ if ( isBinary ) {
220+ return undefined
221+ }
222+ const content = await extractTextFromFile ( absoluteFilePath )
223+ return `<file_content path="${ filePath . toPosix ( ) } ">\n${ content } \n</file_content>`
224+ } catch ( error ) {
195225 return undefined
196226 }
197- const content = await extractTextFromFile ( absoluteFilePath )
198- return `<file_content path="${ filePath . toPosix ( ) } ">\n${ content } \n</file_content>`
199- } catch ( error ) {
200- return undefined
201- }
202- } ) ( ) ,
203- )
227+ } ) ( ) ,
228+ )
229+ }
204230 } else if ( entry . isDirectory ( ) ) {
205- folderContent += `${ linePrefix } ${ entry . name } /\n`
231+ folderContent += `${ linePrefix } ${ displayName } /\n`
206232 } else {
207- folderContent += `${ linePrefix } ${ entry . name } \n`
233+ folderContent += `${ linePrefix } ${ displayName } \n`
208234 }
209- } )
235+ }
210236 const fileContents = ( await Promise . all ( fileContentPromises ) ) . filter ( ( content ) => content )
211237 return `${ folderContent } \n${ fileContents . join ( "\n\n" ) } ` . trim ( )
212238 } else {
0 commit comments