microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
163.43k stars 28.95k forks source link

Files in .gitignore missing from search when Exclude Git Ignore is off #188273

Open fastfedora opened 1 year ago

fastfedora commented 1 year ago

Type: Bug

When searching a codebase, files in .gitignore are being excluded from the search even though Exclude Git Ignore is unchecked for the User, Workspace and Folder settings.

Expected behavior is that files in .gitignore are only excluded when Exclude Git Ignore is checked.

Disabling "Exclude Settings and Ignore Files" in the search makes the files appear.

VS Code version: Code 1.80.1 (Universal) (74f6148eb9ea00507ec113ec51c489d6ffb4b771, 2023-07-12T17:20:23.298Z) OS version: Darwin arm64 21.6.0 Modes:

System Info |Item|Value| |---|---| |CPUs|Apple M1 Pro (8 x 24)| |GPU Status|2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled| |Load (avg)|32, 29, 23| |Memory (System)|16.00GB (0.15GB free)| |Process Argv|--crash-reporter-id 77ab6b0a-7967-43bb-909c-90e75503ba8d| |Screen Reader|no| |VM|0%|
Extensions (17) Extension|Author (truncated)|Version ---|---|--- vscode-toggle-quotes|Bri|0.3.6 vscode-eslint|dba|2.4.2 vscode-html-css|ecm|1.13.1 auto-close-tag|for|0.5.14 copilot|Git|1.97.270 copilot-labs|Git|0.14.884 beautify|Hoo|1.5.0 python|ms-|2023.12.0 vscode-pylance|ms-|2023.7.20 jupyter|ms-|2023.6.1101941928 jupyter-keymap|ms-|1.1.2 jupyter-renderers|ms-|1.0.17 vscode-jupyter-cell-tags|ms-|0.1.8 vscode-jupyter-slideshow|ms-|0.1.5 vscode-fileutils|sle|3.10.2 code-spell-checker|str|2.20.5 volar|Vue|1.8.5
A/B Experiments ``` vsliv368cf:30146710 vsreu685:30147344 python383:30185418 vspor879:30202332 vspor708:30202333 vspor363:30204092 vslsvsres303:30308271 vserr242:30382549 pythontb:30283811 vsjup518:30340749 pythonptprofiler:30281270 vsdfh931cf:30280410 vshan820:30294714 vstes263:30335439 vscorecescf:30445987 vscod805cf:30301675 binariesv615:30325510 bridge0708:30335490 bridge0723:30353136 vsaa593cf:30376535 pythonvs932:30410667 py29gd2263:30792226 vsclangdf:30486550 c4g48928:30535728 dsvsc012cf:30540253 pynewext54:30695312 azure-dev_surveyone:30548225 3biah626:30602489 89544117:30613380 showlangstatbar:30737416 vsctsb:30748421 03d35959:30757346 pythonfmttext:30731395 pythoncmv:30756943 fixshowwlkth:30771522 hideindicator:30785051 pythongtdpath:30769146 i26e3531:30792625 pythonnosm12tcf:30779713 pythonidxpt:30784022 pythonnocebcf:30776496 e537b577:30786199 dsvsc013cf:30789518 dsvsc014cf:30791936 ```
lszomoru commented 1 year ago

@andreamah, could you please take an initial look at this one? Thank you!

andreamah commented 1 year ago

Do you have search.useIgnoreFiles enabled? And by "Exclude Git Ignore", I believe you mean the "Explorer: Exclude Git Ignore" (explorer.excludeGitIgnore) setting?

fastfedora commented 1 year ago

Yes, I have search.useIgnoreFiles enabled. And, yes, I mean the explorer.excludeGitIgnore setting.

Note that I have the search.useParentIgnoreFiles unchecked. I don't remember seeing that setting before. Based on its description, it's unclear exactly how it differs from search.useIgnoreFiles, which has almost the exact same description. When searching across a workspace, does "parent directory" mean directories above the folders in the workspace, or folders within the workspace that have parent folders within the workspace with .gitignore and .ignore files (which to me would be just normal .gitignore and .ignore files covered by search.useIgnoreFiles).

andreamah commented 1 year ago

Can you check the settings for search.exclude to see if your folder is excluded there?

search.useParentIgnoreFiles uses ignore files from parent directories to search. In this case, parent directories are the directories that contain your workspace (either directly or transitively). For example,

a/
├─ b/
│  ├─ workspace/
│  │  ├─ workspaceFile.txt
.gitignore

In this case, if you opened your workspace at workspace/, the gitignore in a/ would be obeyed it search.useParentIgnoreFiles was enabled.

fastfedora commented 1 year ago

No, I'm searching for a file and search.exclude doesn't exclude it.

I did just figure it out, I think. If I uncheck search.useIgnoreFiles, then it finds my file.

Now looking at the setting, that makes sense, but the wording is ambiguous: "Controls whether to use .gitignore and .ignore files when searching for files". This can be interpreted as either that searches include the files defined in .gitignore OR that searches use the fact that it is an ignore file and exclude the files defined in .gitignore.

I originally interpreted to be the former, but now see that it is probably the latter.

In general, descriptions of settings should clarify what the title means, rather than just re-stating it in a longer form.

I would propose the descriptions are changed to something like this for improved clarity:

Search: Use Ignore Files search.useIgnoreFiles When set, excludes from any search the folders and files specified by .gitignore and .ignore files.

[Note: This may need to be further clarified, since the current description says "when searching for files", but it also applies when searching through files for keywords—"from any search" applies to both]

Search: Use Global Ignore Files search.useGlobalIgnoreFiles When set, excludes from any search the folders and files specified in your global gitignore file (e.g., from $HOME/.config/ignore). Requires Search: Use Ignore Files to be enabled.

Search: Use Parent Ignore Files search.useParentIgnoreFiles When set, excludes from any search the folders and files specified in .gitignore and .ignore files located in parent directories of your current workspace file. Requires Search: Use Ignore Files to be enabled.

*[Note: This should also be clarified on whether it is the parent directories of your .code-workspace file or parent directories of the top-level folders added into that workspace]

andreamah commented 1 year ago

Makes sense. You can make a PR to fix this if you'd like.

Ghostbird commented 5 months ago

This is extremely confusing. This seems like a bug with explorer.excludeGitIgnore but it's a wrong default value for search.useIgnoreFiles. Since it overrides values that are false by default, it's extremely confusing that it's true by default. Personally I consider this a bug.