@@ -17,6 +17,8 @@ import { UrlContentFetcher } from "../../services/browser/UrlContentFetcher"
1717
1818import { FileContextTracker } from "../context-tracking/FileContextTracker"
1919
20+ import { RooIgnoreController } from "../ignore/RooIgnoreController"
21+
2022export async function openMention ( mention ?: string ) : Promise < void > {
2123 if ( ! mention ) {
2224 return
@@ -50,6 +52,8 @@ export async function parseMentions(
5052 cwd : string ,
5153 urlContentFetcher : UrlContentFetcher ,
5254 fileContextTracker ?: FileContextTracker ,
55+ rooIgnoreController ?: RooIgnoreController ,
56+ showRooIgnoredFiles : boolean = true ,
5357) : Promise < string > {
5458 const mentions : Set < string > = new Set ( )
5559 let parsedText = text . replace ( mentionRegexGlobal , ( match , mention ) => {
@@ -102,12 +106,11 @@ export async function parseMentions(
102106 } else if ( mention . startsWith ( "/" ) ) {
103107 const mentionPath = mention . slice ( 1 )
104108 try {
105- const content = await getFileOrFolderContent ( mentionPath , cwd )
109+ const content = await getFileOrFolderContent ( mentionPath , cwd , rooIgnoreController , showRooIgnoredFiles )
106110 if ( mention . endsWith ( "/" ) ) {
107111 parsedText += `\n\n<folder_content path="${ mentionPath } ">\n${ content } \n</folder_content>`
108112 } else {
109113 parsedText += `\n\n<file_content path="${ mentionPath } ">\n${ content } \n</file_content>`
110- // Track that this file was mentioned and its content was included
111114 if ( fileContextTracker ) {
112115 await fileContextTracker . trackFileContext ( mentionPath , "file_mentioned" )
113116 }
@@ -161,15 +164,22 @@ export async function parseMentions(
161164 return parsedText
162165}
163166
164- async function getFileOrFolderContent ( mentionPath : string , cwd : string ) : Promise < string > {
165- // Unescape spaces in the path before resolving it
167+ async function getFileOrFolderContent (
168+ mentionPath : string ,
169+ cwd : string ,
170+ rooIgnoreController ?: any ,
171+ showRooIgnoredFiles : boolean = true ,
172+ ) : Promise < string > {
166173 const unescapedPath = unescapeSpaces ( mentionPath )
167174 const absPath = path . resolve ( cwd , unescapedPath )
168175
169176 try {
170177 const stats = await fs . stat ( absPath )
171178
172179 if ( stats . isFile ( ) ) {
180+ if ( rooIgnoreController && ! rooIgnoreController . validateAccess ( absPath ) ) {
181+ return `(File ${ mentionPath } is ignored by .rooignore)`
182+ }
173183 try {
174184 const content = await extractTextFromFile ( absPath )
175185 return content
@@ -180,33 +190,51 @@ async function getFileOrFolderContent(mentionPath: string, cwd: string): Promise
180190 const entries = await fs . readdir ( absPath , { withFileTypes : true } )
181191 let folderContent = ""
182192 const fileContentPromises : Promise < string | undefined > [ ] = [ ]
183- entries . forEach ( ( entry , index ) => {
193+ const LOCK_SYMBOL = "🔒"
194+
195+ for ( let index = 0 ; index < entries . length ; index ++ ) {
196+ const entry = entries [ index ]
184197 const isLast = index === entries . length - 1
185198 const linePrefix = isLast ? "└── " : "├── "
199+ const entryPath = path . join ( absPath , entry . name )
200+
201+ let isIgnored = false
202+ if ( rooIgnoreController ) {
203+ isIgnored = ! rooIgnoreController . validateAccess ( entryPath )
204+ }
205+
206+ if ( isIgnored && ! showRooIgnoredFiles ) {
207+ continue
208+ }
209+
210+ const displayName = isIgnored ? `${ LOCK_SYMBOL } ${ entry . name } ` : entry . name
211+
186212 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 ) {
213+ folderContent += `${ linePrefix } ${ displayName } \n`
214+ if ( ! isIgnored ) {
215+ const filePath = path . join ( mentionPath , entry . name )
216+ const absoluteFilePath = path . resolve ( absPath , entry . name )
217+ fileContentPromises . push (
218+ ( async ( ) => {
219+ try {
220+ const isBinary = await isBinaryFile ( absoluteFilePath ) . catch ( ( ) => false )
221+ if ( isBinary ) {
222+ return undefined
223+ }
224+ const content = await extractTextFromFile ( absoluteFilePath )
225+ return `<file_content path="${ filePath . toPosix ( ) } ">\n${ content } \n</file_content>`
226+ } catch ( error ) {
195227 return undefined
196228 }
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- )
229+ } ) ( ) ,
230+ )
231+ }
204232 } else if ( entry . isDirectory ( ) ) {
205- folderContent += `${ linePrefix } ${ entry . name } /\n`
233+ folderContent += `${ linePrefix } ${ displayName } /\n`
206234 } else {
207- folderContent += `${ linePrefix } ${ entry . name } \n`
235+ folderContent += `${ linePrefix } ${ displayName } \n`
208236 }
209- } )
237+ }
210238 const fileContents = ( await Promise . all ( fileContentPromises ) ) . filter ( ( content ) => content )
211239 return `${ folderContent } \n${ fileContents . join ( "\n\n" ) } ` . trim ( )
212240 } else {
0 commit comments