Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find in Files "files to include" override .gitignore #26574

Open
borekb opened this issue May 12, 2017 · 24 comments
Open

Find in Files "files to include" override .gitignore #26574

borekb opened this issue May 12, 2017 · 24 comments
Assignees
Labels
feature-request Request for new features or functionality search Search widget and operation issues upstream-issue-linked This is an upstream issue that has been reported upstream
Milestone

Comments

@borekb
Copy link

borekb commented May 12, 2017

VSCode 1.12: I have a TypeScript project with a src folder and a .gitignore file containing this:

/src/**/*.js

If I search for something, it is OK with 'files to include' is empty:

image

but it is not OK if I scope the search:

image

While I'm searching only in some sup-tree of my project, all .gitignore rules should still be taken into account.

@roblourens roblourens added the search Search widget and operation issues label May 14, 2017
@roblourens
Copy link
Member

It seems like ripgrep will let include globs override entries in the gitignore file. I'm not sure whether that's expected or whether we can change that. But one workaround is to use ./src syntax in 'files to include'.

@roblourens roblourens added the feature-request Request for new features or functionality label Nov 21, 2017
@kompot
Copy link

kompot commented Feb 28, 2018

./src seems to be broken again - regardless of syntax put to files to include .gitignore is no longer respected by ripgrep. I'm pretty sure it worked before, maybe ripgrep API change?

@roblourens
Copy link
Member

Unfortunately that's because I changed it to not use gitignore files in parent directories which breaks that workaround.

@kompot
Copy link

kompot commented Feb 19, 2019

This was working OK up to version 1.30.
1.31 broke this.

@roblourens
Copy link
Member

Can you explain what you mean by "this"? This issue has been open for a long time.

@roblourens
Copy link
Member

roblourens commented Feb 19, 2019

Sorry I see, the workaround I mentioned above will not work anymore. The only suggestion I have right now is to add patterns to search.exclude as well. I'll have to figure out why ripgrep handles gitignore patterns differently.

@kompot
Copy link

kompot commented Feb 20, 2019

Seems like it's discussed in this ripgrep issue
BurntSushi/ripgrep#829

UPD
and there's even an unmerged PR
BurntSushi/ripgrep#963

@roblourens
Copy link
Member

roblourens commented Feb 20, 2019

I can't tell whether that's the right issue or not. vscode does not invoke rg with a path argument, the ./ syntax is converted to glob patterns.

@kompot
Copy link

kompot commented Feb 20, 2019

Right now I observe this bug/feature/behaviour both in vscode and in rg console output.

I have a file at path front/build/1.html. It contains string xxx. Directory front/build is gitignored.

rg xxx from project root finds nothing
rg xxx -g "front/**/*" finds xxx

same happens in vscode

searching with files to include being empty finds nothing
searching with ./front in files to include finds xxx

As a proposal: maybe vscode should always search from root and filter with files to include afterwards in memory just for UI. More work but it's near instant with ripgrep anyway.

@roblourens
Copy link
Member

When searching a big repo, there can actually be a large perf gain by using ./ vs searching everything.

@roblourens
Copy link
Member

I am pretty sure BurntSushi/ripgrep#829 is the correct upstream issue for this.

@roblourens roblourens added the upstream-issue-linked This is an upstream issue that has been reported upstream label Oct 9, 2019
@roblourens roblourens changed the title Find in Files 'Use Ignore Files' doesn't work with 'files to include' Find in Files "files to include" override .gitignore Oct 9, 2019
@roblourens roblourens added this to the Backlog milestone Oct 27, 2019
@emirotin
Copy link

emirotin commented Dec 6, 2019

Started happening for me even with an empty "files to include" field

@yume-chan
Copy link
Contributor

I remember that some versions ago (maybe 1.2x), I could search in node_modules with these steps:

  1. Find the folder I want to search in explorer
  2. Right-click on it and select Find in Folder... (Code will populate the files to include input box for me)
  3. Type in keyword and hit Enter

There is no need to uncheck the Use Exclude Settings and Ignore Files option.

I believed that was a "feature", and that's the behavior described in this issue.


But (at least) in current version (1.43.2 and 1.44-insider), I must uncheck the Use Exclude Settings and Ignore Files option to do this search.

@EsrefDurna
Copy link

Could we prioritize this issue? Because it definitely blocks effective development.
For example, I’m having an error from an module that I installed. I have to disable then enable ignore file search again and again.
Evetytime I need to search on node modules folder its so annoying. And I believe most people though that the thing what they are searching doesn’t exists on node modules folder, which can lead to many hours of frustration and waste of time for each developer.

Thank you

@mifi
Copy link

mifi commented Feb 4, 2021

As a workaround, is there any way to hook into the exclude pattern so that we can write our own ignore logic in an extension or similar?

@localjo
Copy link

localjo commented Apr 14, 2021

For anyone wondering about the status of this issue, it looks like the underlying ripgrep issue is a bit stale. In the meantime, I found a workaround that works for me to exclude irrelevant files from search in my multi-root workspace.

My workaround is adding this to my workspace settings.json:

  "search.exclude": {
    "**/.git": true,
    "**/node_modules": true,
    "**/tmp": true,
    "**/dist": true,
    "**/lib": true,
    "**/generated": true
  }

It's not perfect, and doesn't take into account any .gitignore files, but excluding those common patterns works well enough for me to find the files I'm looking for without sifting through loads of irrelevant results.

@mcandre
Copy link

mcandre commented Aug 11, 2021

There is no need to uncheck the Use Exclude Settings and Ignore Files option.

Lol, when I try to enable this option then VSCode stupidly resets it back again. Every time.

@RalfJung
Copy link

RalfJung commented Apr 2, 2022

I am pretty sure BurntSushi/ripgrep#829 is the correct upstream issue for this.

I don't think it is. I have *.glob in my root gitignore, and when I do rg rpc_proof src/program_proof/ it all behaves as expected. However when I search for rpc_proof in vscode and specify src/program_proof/ or ./src/program_proof/ as the "files to include", then it also shows results from *.glob files that I want to have excluded.

I don't know how vscode passes "files to ignore" to ripgrep, but it doesn't seem to be as a path argument, and hence that is not the right issue.

@RalfJung
Copy link

RalfJung commented Apr 2, 2022

Ah, it seems to be via globs: rg rpc_proof -g 'src/program_proof/**' replicates the vscode behavior.

@RalfJung
Copy link

RalfJung commented Apr 2, 2022

Based on my above observations, solving this issue would be possible by making vscode pass things from "files to include" as directory arguments to ripgrep, rather than passing them via -g. From the comments above, it almost sounds like this used to be the case with things like ./src/program_proof, but in current vscode even the explicit ./ makes no difference. Maybe behavior was changed during the last years?

Version: 1.65.2
Commit: c722ca6c7eed3d7987c0d5c3df5c45f6b15e77d1
Date: 2022-03-10T15:36:26.048Z
Electron: 13.5.2
Chromium: 91.0.4472.164
Node.js: 14.16.0
V8: 9.1.269.39-electron.0
OS: Linux x64 5.16.0-4-amd64

@angelayanpan
Copy link

angelayanpan commented Aug 17, 2022

we are using VScode with Yarn Workspace. so we have many workspaces living inside 1 root and our .gitignore file was setup to ignore dist in many different paths. This issue has cause some very slow code search experience. because whenever a teammate specify a subfolder to search, it will bring in the not needed dist

we are working around with the search.exclude mentioned earlier. But would be good to have this issue resolved. or made more obvious to developers that file to include override .gitignore

@leonheess
Copy link

leonheess commented Sep 2, 2022

this is so needed, it annoys me every single day. Why would I want my ignore rules disabled just because I'm searching in a specific path??

@segevfiner
Copy link
Contributor

This is even worse in multi-folder workspaces, as it will exclude a .gitignore from higher up in the repository, when opening multiple folder inside a repository, which a direct ripgrep invocation won't.

@Weetbix
Copy link

Weetbix commented Dec 3, 2024

This is so annoying, and I run into this bug daily. When in a monorepo, I often want to search project folders only, but doing this includes all build files, assets, node_module files and folders etc...

@rebornix rebornix assigned osortega and unassigned andreamah Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality search Search widget and operation issues upstream-issue-linked This is an upstream issue that has been reported upstream
Projects
None yet
Development

No branches or pull requests