Skip to content
This repository was archived by the owner on Aug 1, 2025. It is now read-only.

Conversation

@thenamankumar
Copy link
Member

@thenamankumar thenamankumar commented Jul 23, 2025

Re-implementing PR: https://github.com/sourcegraph/cody/pull/8037

This introduces the ability to exclude files from Cody's context based on the files.exclude, search.exclude, and .gitignore / .sourcegraph/.ignore .cody/ignore files located in the codebase root directory settings in VS Code.

The ContextFiltersProvider now utilizes these settings to determine if a file should be ignored. This is achieved by:

  • Adding minimatch as a dependency to perform pattern matching.
  • Introducing a static excludePatternGetter to fetch the exclude patterns and workspace folder.
  • Implementing isExcludedByPatterns to check if a file path matches any of the exclude patterns.
  • Adding ContextFiltersProviderError.ExcludePatternMatch to indicate when a file is excluded by the patterns.

This enhancement ensures that Cody respects the user's VS Code settings for excluding files, preventing irrelevant files from being included in the context.

Note: .sourcegraph/.ignore instead of .codyignore so that the same file can be used across sourcegraph products and not just cody

Test plan

  • Try to open a file that is listed in the .gitignore / .sourcegraph/.ignore file at the root of the repo
  • Confirm you can see the file being ignored tooltip when hovered over the cody icon at the bottom menu bar
image

await this.fetchIfNeeded()

// Check VS Code exclude patterns
if (ContextFiltersProvider.excludePatternGetter) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thenamankumar your pr description strikes-through the search exclusion but the code is still present as seen here


if (useIgnoreFiles && workspaceFolder) {
sgignoreExclude = await readIgnoreFile(
vscode.Uri.joinPath(workspaceFolder.uri, '.cody', 'ignore')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use .sourcegraph/ignore like we had in Beatrix's pr.

return
}

const useIgnoreFiles = vscode.workspace
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same it seems we rely on the vscode search exclusion which shouldn't happen based on the pr description

@ichim-david
Copy link
Contributor

There are genuine test failures where files cannot be mentioned as seen in this screenshot which needs to be fixed before this work can be merged
image (9)

@thenamankumar thenamankumar force-pushed the naman/cody-ignore branch 2 times, most recently from 3599ab9 to 960b53a Compare July 29, 2025 09:51
Copy link
Contributor

@ichim-david ichim-david left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving to unblock, the problem was always from the tests

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants