Vscode: use .gitignore to ignore search inside files and folders

Created on 18 Nov 2015  ·  79Comments  ·  Source: microsoft/vscode

use .gitignore to know which files and folders not to search into (think node_modules or packages)

feature-request search

Most helpful comment

@luisrudge reopening. We haven't fully figured out what to discuss on user voice and what to discuss in a feature request issue.

This feature request is better discussed here. In particular since the last comment in user voice is not correct :disappointed: .

I could imagine a meta property 'USE_GITIGNORE' and that would be a great opportunity for a pull request:

    "files.exclude": {
        "USE_GITIGNORE": true
    },

@bpasero fyi.

All 79 comments

I don't think .gitignore should dictate this, in other text editors it's normally done on a project setting or editor setting-level.

atom does this. there's no need for project settings or editor settings. If I'm git-ignoring it, there's no need to make this searchable or "autocompletable" (I just invented that word)

Huh it does too, I guess I'm thinking of sublime.

This is a feature request, not a bug report/issue. Feature suggestions already have a place over at vscodes uservoice.

Ops! Sorry. I didn't know there was a uservoice.

image

@luisrudge reopening. We haven't fully figured out what to discuss on user voice and what to discuss in a feature request issue.

This feature request is better discussed here. In particular since the last comment in user voice is not correct :disappointed: .

I could imagine a meta property 'USE_GITIGNORE' and that would be a great opportunity for a pull request:

    "files.exclude": {
        "USE_GITIGNORE": true
    },

@bpasero fyi.

+1

I'm not sure I like the idea of having this as a opt-in flag.. This really should be the default behavior, since searching inside node_modules is not a good thing and certainly isn't the most common use case. Maybe we can add a flag to opt-out this behavior?

Also, I'd like to do this! Can you help me understand which parts of vscode would have to change? THanks!

I think in the example above it should really be search.exlude and not files.exclude because the former will exclude it from search but the latter from everywhere in the UI including the explorer.

We are reading this setting in from https://github.com/Microsoft/vscode/blob/master/src/vs/workbench/parts/search/common/searchQuery.ts#L18 and I think we could add code there to check for another setting that - if enabled - would mix in anything from .gitignore.

as @luisrudge already said, this should be the default behaviour like in atom and sublime.

@bpasero so.. just add code to read from .gitignore and push that files/folders to searchExcludes ?

@luisrudge well we also have to convert it to the glob pattern format we use in VS Code. If you look at the default settings and how we ignore the .git folder there you can get an idea of the syntax.

I agree with @luisrudge that this should be the default behavior, but perhaps there is an intermediate solution we can go for first:

Results from tracked files should come first. Results from git-ignored files should come last.

This is a lower-risk change that, IMO, can be implemented immediately and yield a notable user experience benefit for search.

Currently, results from git-ignored files are mixed in with results from tracked files. This is super noisy, for example, if you're developing in Python and have a virtual environment or build folder within your project folder with all kinds of code that matches almost anything you might search for.

If you're searching for a string across your project, I wager in 100% of cases you want results from your tracked files first, perhaps followed by results from untracked but not ignored files.

Would it make sense to implement this behavior first? Basically, just tweaking the order in which in the results are displayed. I don't think we would even need a new setting for that.

I think the behavior I described should also apply to the behavior of Command + P, when you want to switch to a file and there are multiple possible matches for the user's search term.

Currently the sorting is based on our scoring algorithm. I do not think it would make sense to change the sorting based on other criteria unless there is a good way to explain this to the user.

the sorting can stay the same, just ignore the files listed in .gitignore. this is the absolute main thing that keeps me from using code.

@bpasero - Could you elaborate? I think the change I'm describing is very easy to explain.

Here's take 2 at explaining the change, simplifying what I said earlier:

Search results are divided into 2 sections--tracked files and everything else. Results within each section are sorted according to the current scoring algorithm. The tracked files section always shows up first.

In addition to being easy to explain, this is the behavior I wager most people would expect.

As I commented earlier, Python projects generally have venv, dist, and build subfolders which contain many Python files, some of which are even copies of the main project files from the last packaging build. These are not part of the project and you don't check these files in because they are copied from third-parties or auto-generated.

Treating these files as equal to the main project files severely detracts from the usability of search. No one wants to see results from these files at the top, if even at all.

I'm sure other languages have similar problems as well.

If ignoring these files in search results is too big of a step to take, then I think the tweak I'm describing here yields the same usability benefit while being straightforward to explain.

@nchammas I do think that the right fix is to just exclude those files when .gitignore is present and the setting to respect it. otherwise one could also argue why we are not doing the same sorting trick for the search/files exclude setting.

The real work here is to translate .gitignore patterns into our ignore patterns and making sure the solution scales. I have seen .gitignore files with 1000+ rules that would need to be applied many times over many paths.

Adding my :+1:. This would solve one of the issues I encountered in the ember-cli test tour, saving devs from setting up a vscode-specific config file. Related PR: https://github.com/ember-cli/ember-cli/pull/5643

Would be nice to not show git ignored files in the project explorer :)

@bpasero tried fixing this as this https://github.com/asotog/vscode/commit/d3cac5b26e57521dc39f8390e3cdf76c1f917342 so from settings default to

      "files.exclude": {
        "**/.git": true,
        "**/.DS_Store": true,
        "VCS": true
    },

I think Atom behavior is a reasonable default configuration. .gitignored files and directories are still accessible from the sidebar explorer, but greyed out in the UI and not findable with project-level search.

About parsing, there are libraries like https://www.npmjs.com/package/gitignore-parser but I don’t know if their implementation is completely correct.

I would like to start working on it.
I'll read through the relevant code and try sending a PR within a week or two.

+1

I think this I'll leave this one to someone more capable than me. The size of the project is kind of overwhelming for me and this doesn't look like a monkey-patching issue. :pensive:

Estimates on completion of this? It's the only thing I still need atom installed on my PC for.

is someone working on this ? i would like to help on this one :P @bpasero, played on this https://github.com/Microsoft/vscode/pull/4871 worked somehow but not best approach, this is a nice feature to have, today we as developers rely a lot of on transpilers, so you dont want to see the generated files in your dev editor

It is not being worked on currently. My main concern is how to make a large .gitignore list performant enough against our glob exclude matching.

@bpasero can you define large? Here are some common examples https://github.com/github/gitignore

@Tyriar yup (https://chromium.googlesource.com/chromium/src.git/+/master/.gitignore):

*.gypcmd
*.mk
*.ncb
*.opensdf
*.orig
*.pdb
*.props
*.pyc
*.pyproj
*.rules
*.sdf
*.sln
*.sublime-project
*.sublime-workspace
*.suo
*.targets
*.user
*.vc.opendb
*.vcproj
*.vcxproj
*.vcxproj.filters
*.vpj
*.vpw
*.vpwhistu
*.vtg
*.xcodeproj
*.xcworkspace
*.VC.db
*_proto.xml
*_proto_cpp.xml
*~
!Android.mk
.*.sw?
.DS_Store
.classpath
.cproject
.gdb_history
.gdbinit
.landmines
.metadata
.project
.pydevproject
.checkstyle
cscope.*
GPATH
GRTAGS
GSYMS
GTAGS
Session.vim
tags
Thumbs.db
v8.log
vs-chromium-project.txt
# Settings directories for eclipse
/.externalToolBuilders/
/.settings/
/.vs/
# Visual Studio Code
/.vscode/
/_out
/android_emulator_sdk
/ash/ash_unittests_run.xml
/base/base_unittests_run.xml
/breakpad/src/
/build/android/bin
/build/Debug
/build/Debug_x64
/build/goma
/build/gomacc.lock
/build/ipch/
/build/Release
/build/Release_x64
/build/win_toolchain.json
/build/util/LASTCHANGE*
/build/util/support
/build/x64/
/build/linux/bin/eu-strip
/build/linux/debian_*-sysroot/
/build/linux/ubuntu_*-sysroot/
/build/mac_files
/buildtools
# The Chrome OS build creates a /c symlink due to http://crbug.com/54866.
/c
/cdm
/ceee/internal/
/chrome/angle_unittests_run.xml
/chrome/content_gl_tests_run.xml
/chrome/gl_tests_run.xml
/chrome/gles2_conform_test_run.xml
/chrome/tab_capture_performance_tests_run.xml
/chrome/telemetry_gpu_test_run.xml
/chrome/app/theme/default_100_percent/google_chrome
/chrome/app/theme/default_200_percent/google_chrome
/chrome/app/theme/google_chrome
/chrome/browser/autofill/internal
/chrome/browser/chromeos/login/screenshot_testing/golden_screenshots/*.png
/chrome/browser/chromeos/login/screenshot_testing/artifacts
/chrome/browser/extensions/api/ledger/
/chrome/browser/extensions/default_extensions/chromeos
/chrome/browser/google/linkdoctor_internal
/chrome/browser/internal
/chrome/browser/performance_monitor/performance_monitor.xml
/chrome/browser/protector/internal
/chrome/browser/resources/chromeos/quickoffice
/chrome/browser/resources/pdf/html_office
/chrome/browser/resources/media_router_internal/
/chrome/browser/resources/settings_internal/
/chrome/browser/resources/software_rendering_list
/chrome/browser/spellchecker/internal
/chrome/browser_tests_run.xml
/chrome/chrome_run.xml
/chrome/chrome_user32_delay_imports.xml
/chrome/chrome_version_resources.xml
/chrome/common/extensions/api/api.xml
/chrome/common/extensions/api/ledger/
/chrome/Hammer
/chrome/installer/linux/internal
/chrome/installer/mac/internal
/chrome/installer/mac/third_party/xz/xz
/chrome/installer/mini_installer.xml
/chrome/installer/mini_installer/mini_installer.aps
/chrome/installer/mini_installer/support
/chrome/installer/mini_installer_syzygy.xml
/chrome/installer/mini_installer_tests_run.xml
/chrome/installer_util_strings.xml
/chrome/interactive_ui_tests_run.xml
/chrome/setup.xml
/chrome/setup_unittests.xml
/chrome/supplement.gypi
/chrome/sync_integration_tests_run.xml
/chrome/test/android/telemetry_tests/browser_tests/*.wpr
/chrome/test/chromeos/autotest/files/client/deps/chrome_test/test_src/
/chrome/test/chromeos/autotest/files/client/deps/page_cycler_dep/test_src/
/chrome/test/chromeos/autotest/files/client/deps/perf_data_dep/test_src/
/chrome/test/chromeos/autotest/files/client/deps/pyauto_dep/test_src/
/chrome/test/chromeos/autotest/files/client/deps/telemetry_dep/test_src/
/chrome/test/data/extensions/api_test/permissions/nacl_enabled/bin
/chrome/test/data/firefox2_profile/searchplugins
/chrome/test/data/firefox2_searchplugins
/chrome/test/data/firefox3_profile/searchplugins
/chrome/test/data/firefox3_searchplugins
/chrome/test/data/gpu/vectortown_endurance/
/chrome/test/data/gpu/vt/
/chrome/test/data/layout_tests
/chrome/test/data/osdd
/chrome/test/data/pdf_private
/chrome/test/data/perf/canvas_bench
/chrome/test/data/perf/frame_rate/content
/chrome/test/data/perf/frame_rate/private
/chrome/test/data/perf/private/
/chrome/test/data/perf/third_party/
/chrome/test/data/plugin/
/chrome/test/data/webrtc/resources
/chrome/test/media_router/internal
/chrome/tools/memory
/chrome/tools/test/reference_build
/chrome/unit_tests_run.xml
/chrome/web_ui_mojo_bindings.xml
/chrome_elf/chrome_elf_resources.xml
/chromecast/internal
/clank
/cloud_print/cloud_print_version_resources.xml
/components/chrome_settings_proto_generated_compile.xml
/components/cloud_policy_proto_generated_compile.xml
/components/gcm_driver.xml
/components/leveldb_proto_test_support.xml
/components/rappor.xml
/components/resources/default_100_percent/google_chrome
/components/resources/default_200_percent/google_chrome
/components/search_engines/prepopulated_engines.xml
/components/suggestions.xml
/components/variations.xml
/content/browser/service_worker/proto.xml
/content/content_browsertests_run.xml
/content/content_common_mojo_bindings.xml
/content/content_unittests_run.xml
/content/test/data/gpu/generated/
/content/test/data/gpu/gpu_reference/
/content/test/data/layout_tests/
/content/test/data/plugin/
/content/web_ui_test_mojo_bindings.xml
/data
/delegate_execute
/device/serial/device_serial_mojo.xml
/google_apis/gcm/gcm.xml
/google_apis/internal
/googleurl
/gpu/gles2_conform_test
/infra/.recipe_deps
/internal_gyp
/ios/third_party/earl_grey/src
/ios/third_party/fishhook/src
/ios/third_party/gcdwebserver/src
/ios/third_party/material_text_accessibility_ios/src
/ios/third_party/ochamcrest/src
/ios_internal
/llvm
/media/cast/logging/cast_logging_proto_lib.xml
/media/cdm/api
/media/media_asm.xml
/media/media_mojo_bindings.xml
/media/test/data/internal
/media/yuv_convert_simd_x86.xml
/metro_driver
/mojo/hello_world_service.xml
/mojo/mojo_application_bindings.xml
/mojo/mojo_application_manager_unittests.xml
/mojo/mojo_apps_js_bindings.xml
/mojo/mojo_apps_js_unittests_run.xml
/mojo/mojo_clipboard_bindings.xml
/mojo/mojo_content_handler_bindings.xml
/mojo/mojo_core_window_manager_bindings.xml
/mojo/mojo_echo_service_bindings.xml
/mojo/mojo_example_service_bindings.xml
/mojo/mojo_external_service_bindings.xml
/mojo/mojo_geometry_bindings.xml
/mojo/mojo_gles2_bindings.xml
/mojo/mojo_gpu_bindings.xml
/mojo/mojo_input_events_bindings.xml
/mojo/mojo_js_unittests_run.xml
/mojo/mojo_keyboard_bindings.xml
/mojo/mojo_launcher_bindings.xml
/mojo/mojo_media_viewer_bindings.xml
/mojo/mojo_native_viewport_bindings.xml
/mojo/mojo_navigation_bindings.xml
/mojo/mojo_network_bindings.xml
/mojo/mojo_public_bindings_unittests.xml
/mojo/mojo_public_test_interfaces.xml
/mojo/mojo_public_unittests.xml
/mojo/mojo_sample_service.xml
/mojo/mojo_shell_bindings.xml
/mojo/mojo_shell_lib.xml
/mojo/mojo_spy.xml
/mojo/mojo_surface_id_bindings.xml
/mojo/mojo_surfaces_app_bindings.xml
/mojo/mojo_surfaces_bindings.xml
/mojo/mojo_test_service_bindings.xml
/mojo/mojo_view_manager_bindings.xml
/mojo/mojo_window_manager_bindings.xml
/mojo/mojo_wm_flow_embeddee_bindings.xml
/mojo/mojo_wm_flow_embedder_bindings.xml
/mojo/mojom_test.xml
/mojo/sample_service.xml
/native_client
/net/Debug
/net/net_derived_sources.xml
/net/net_unittests_run.xml
/net/Release
/net/testserver.log
/out*
/ppapi/native_client/nacl_irt.xml
/ppapi/native_client/ppapi_lib.xml
/remoting/android/internal/
/remoting/appengine/
/remoting/host/installer/linux/internal/
/remoting/ios/
/remoting/internal/
/remoting/proto/chromotocol_proto_lib.xml
/remoting/remoting_core_resources.xml
/remoting/remoting_elevated_controller.xml
/remoting/remoting_host.xml
/remoting/remoting_host_event_logger.xml
/remoting/remoting_host_installation.xml
/remoting/remoting_host_messages.xml
/remoting/remoting_infoplist_strings.xml
/remoting/remoting_lib_idl.xml
/remoting/remoting_lib_rc.xml
/remoting/remoting_me2me_host.xml
/remoting/remoting_native_messaging_manifests.xml
/remoting/remoting_version_resources.xml
/remoting/remoting_windows_resources.xml
/remoting/test/internal/
/remoting/tools/internal/
/remoting/webapp/app_remoting/internal/
/sandbox/linux/seccomp-legacy/
/sdch/open-vcdiff
/seccompsandbox
/signing_keys
/skia/tools/clusterfuzz-data/
/sql/sql_unittests_run.xml
/sync/sync.xml
/sync_testserver.log
/testing/gmock
/testing/gtest
/testserver.log
/tools/luci-go/linux64/isolate
/tools/luci-go/mac64/isolate
/tools/luci-go/win64/isolate.exe
/third_party/__START__
/third_party/accessibility-developer-tools/
/third_party/accessibility_test_framework/lib/*.jar
/third_party/adobe/flash/binaries
/third_party/adobe/flash/symbols
/third_party/amd/
/third_party/android_protobuf/src
/third_party/android_support_test_runner/lib/*.aar
/third_party/android_support_test_runner/lib/*.jar
/third_party/android_tools/
/third_party/android_tools_internal/
/third_party/android_webview_glue/src
/third_party/angle
/third_party/angle_dx11
/third_party/apache-mime4j
/third_party/apache-portable-runtime/src
/third_party/apache_velocity/lib/*.jar
/third_party/apache-win32/bin/*.exe
/third_party/apache-win32/bin/*.dll
/third_party/apache-win32/bin/iconv/*.so
/third_party/apache-win32/modules/*.so
/third_party/apache-win32/modules/*.dll
/third_party/asan
/third_party/bidichecker
/third_party/bison
/third_party/boringssl/src
/third_party/bouncycastle/lib/*.jar
/third_party/byte_buddy/lib/*.jar
/third_party/cacheinvalidation/cacheinvalidation_unittests_run.xml
/third_party/cardboard-java/src
/third_party/catapult
/third_party/ced/src
/third_party/chromeos_login_manager
/third_party/chromeos_text_input
/third_party/chromite
/third_party/cld_2/src
/third_party/cld_3/src
/third_party/colorama/src
/third_party/cros
/third_party/cros_system_api
/third_party/custom_tabs_client/src
/third_party/cygwin
/third_party/deqp/src
/third_party/directxsdk
/third_party/dom_distiller_js/dist
/third_party/drmemory/drmemory-windows-sfx.exe
/third_party/drmemory/unpacked
/third_party/elfutils/src
/third_party/errorprone/lib
/third_party/espresso/lib/*.jar
/third_party/eyesfree/src
/third_party/ffmpeg
/third_party/findbugs
/third_party/flac
/third_party/flatbuffers/src
/third_party/fontconfig/src
/third_party/freetype-android/src
/third_party/freetype2/src
/third_party/gles2_conform
/third_party/glslang/src
/third_party/gnu_binutils/
/third_party/google_appengine_cloudstorage
/third_party/google_toolbox_for_mac/src
/third_party/googlemac
/third_party/gvr-android-sdk/src
/third_party/gperf
/third_party/grpc
/third_party/guava/lib/*.jar
/third_party/hamcrest/lib/*.jar
/third_party/httpcomponents-client
/third_party/httpcomponents-core
/third_party/hunspell_dictionaries
/third_party/icu
/third_party/icu4j/lib/*.jar
/third_party/intellij/lib/*.jar
/third_party/jarjar
/third_party/javax_inject/lib/*.jar
/third_party/jsoncpp/source
/third_party/jsr-305/src
/third_party/junit/src
/third_party/kasko
/third_party/khronos_glcts
/third_party/leakcanary/src
/third_party/leveldatabase/src
/third_party/leveldb
/third_party/libc++-static/libc++.a
/third_party/libaddressinput/src
/third_party/libexif/sources
/third_party/libFuzzer/src
/third_party/libjingle/source
/third_party/libjpeg_turbo
/third_party/liblouis/src
/third_party/libphonenumber/dist
/third_party/libsrtp
/third_party/libupnp
/third_party/libvpx/source/libvpx
/third_party/libwebm/source
/third_party/libyuv
/third_party/lighttpd
/third_party/llvm
/third_party/llvm-allocated-type
/third_party/llvm-bootstrap
/third_party/llvm-build
/third_party/lss
/third_party/mesa/src
/third_party/mingw-w64
/third_party/minigbm/src
/third_party/mkl
/third_party/mocha
/third_party/mockito/src
/third_party/nacl_sdk_binaries/
/third_party/netty-tcnative/src
/third_party/netty4/src
/third_party/nss
/third_party/objenesis/lib/*.jar
/third_party/omaha/src/omaha
/third_party/openmax_dl/
/third_party/openh264/src
/third_party/ow2_asm/lib/*.jar
/third_party/pdfsqueeze
/third_party/pdfium
/third_party/pefile
/third_party/perl
/third_party/platformsdk_win7
/third_party/platformsdk_win8
/third_party/ppapi
/third_party/psyco_win32
/third_party/pthreads-win32
/third_party/py_trace_event/src
/third_party/pyelftools
/third_party/pyftpdlib/src
/third_party/pylib
/third_party/pymox/src
/third_party/python_24
/third_party/python_26
/third_party/pywebsocket/src
/third_party/pywebsocket/src
/third_party/re2/src
/third_party/requests/src
/third_party/robolectric/lib/*.jar
/third_party/robolectric/robolectric
/third_party/scons-2.0.1
/third_party/sfntly/src
/third_party/shaderc/src
/third_party/skia
/third_party/smhasher/src
/third_party/snappy/src
/third_party/SPIRV-Tools/src
/third_party/sqlite4java/lib/**/*.dll
/third_party/sqlite4java/lib/**/*.jar
/third_party/sqlite4java/lib/**/*.jnilib
/third_party/sqlite4java/lib/**/*.so
/third_party/swiftshader/
/third_party/syzygy
/third_party/syzygy/binaries
/third_party/tsan/
/third_party/ub-uiautomator/lib
/third_party/usb_ids
/third_party/usrsctp/usrsctplib
/third_party/v8-i18n
/third_party/valgrind
/third_party/v4l2capture
/third_party/visualmetrics
/third_party/wayland/src
/third_party/wayland-protocols/src
/third_party/wds/src
/third_party/webdriver/pylib
/third_party/webdriver/python/selenium
/third_party/webgl
/third_party/webgl/src
/third_party/webpagereplay/
/third_party/webrtc
/third_party/widevine/cdm/chromeos
/third_party/widevine/cdm/linux
/third_party/widevine/cdm/mac
/third_party/widevine/cdm/win
/third_party/widevine/test/license_server
/third_party/win_toolchain/.timestamps
/third_party/win_toolchain/files
/third_party/wix
/third_party/xdg-utils
/third_party/xulrunner-sdk
/third_party/yasm/binaries
/third_party/yasm/generate_files.xml
/third_party/yasm/source/patched-yasm
/third_party/yasm/yasm.xml
/tools/.bisect-builds-cache.json
/tools/distcc
/tools/gn/bin/linux
/tools/gn/bin/mac
/tools/gn/bin/win
/tools/gyp
/tools/histograms
/tools/json_schema_compiler/test/json_schema_compiler_tests.xml
/tools/metrics/actions/actions.old.xml
/tools/metrics/histograms/histograms.before.pretty-print.xml
/tools/page_cycler/acid3
/tools/perf/data
/tools/perf/internal
/tools/perf/results.html
/tools/swarming_client
/tools/tryserver
/tools/win/link_limiter/build
/ui/file_manager/internal
/ui/keyboard/keyboard_mojom_bindings.xml
/ui/surface/surface.xml
/ui/surface/surface_gpu_tests.xml
/v8
/webkit/data
/webpagereplay_logs/
/win8/delegate_execute/delegate_execute_version_resources.xml
/win8/metro_driver/metro_driver_version_resources.xml
/x86-generic_out/
/xcodebuild

@bpasero ag respects .gitignore and claims to be very performant. The only problem is it needs some effort to get it to work on Windows.

ag has broken gitignore support. It doesn't support directory excludes properly. And let's try to keep external dependencies to a minimum.

@bpasero What would happen if all rules from .gitignore were inputted to the exclude glob field found when searching? Apart from speed issues I mean.

I think it would work apart from an unusable slow search :). I think instead of trying to make the gitignore patterns work with our world we should shell out to git itself and ask it if a certain list of paths are valid paths for tracking changes.

/cc @chrmarti

@bpasero I think git has something like that. Mercurial has a command hg status -i which lists the ignored files present in the work tree and a similar command that shows all the tracked files and directories. Something similar can be achieved for git I think.

EDIT: Yup. git ls-files --ignored --exclude-standard lists all the files explicitly ignored due to the .gitignore file. And ( git status --short| grep '^?' | cut -d\ -f2- && git ls-files ) | sort -u gives all files that aren't ignored. Any git installation will provide grep, cut and sort so I think portability won't be an issue.

would it be possible to write an extension to do this?

Currently not.

@bpasero i personally think for search is fine to keep it as it is now, results returns from any file (even ignored).
But for files explorer (tree view) this is helpful, and won't affect performance, even, might increase it because will not be showing useless files (from dev perspective you dont want to see node_modules, bower files, js maps, transpiled js, some times etc) on that view, here is a library that seems doing that https://github.com/atom/git-utils#repositoryisignoredpath BUT built by the neighbors :(

Please make this a switch in the search UI itself, like "regex", "whole word" and "match case", not something hidden away in config!

I usually want it, but the times I don't want it are not rare, and I want to be able to just turn it off and search without changing configs or anything.

For example, I might have files that have been installed by bower that I want to include in a particular search because I'm trying to figure out how a library works, or maybe I want to include log / debug files that my code has written, but are gitignored.

I think that if I try and search inside a folder, which has itself been completely .gitignored, I am signalling my intent to search it anyway - it would be good if the "ignore .gitignored" button could be greyed out in this case.

Just tried out Visual Studio 2017 RC with the new “Open Folder” feature. They seem to respect .gitignore out of the box. I was kind of pleasantly surprised. No word on performance (performance is not really Studio's _thing_ anyway.)

It seems people are either rooting for having Code respect .gitignore for search results, or file explorer, or both.

I think the option should be set for both, but we should have to possibility to let the file explorer show .gitignored files while not displaying them in search results, or the other way around.

2017 and Still don't ignore repo ignore files? :stuck_out_tongue:

Everytime i want to use vscode for my projects, i face this issue: showing all dot files, cache files, build files, indexed, which are all declared to be ignored in the .gitignore, make the editor unusable:

  • it pollute the CMD+P search
  • it pollute the tree
  • it pollute the search in all files

:(

on every project i have to use the exclude files, via .vscode/settings.json and waste .gitignore functionality :(

I also would propose to not simply hide files but make them transculent in the sidebar so you can still open files and folders which are ignored BUT you can't search them and you see a visual indicator that it's not watched in your project.

Thats the only missing feature keeping me away from using VS Code on a daily base and keep to stick to Atom.

+1 for hiding .gitignore files from the file browser. If it's not the default behavior, at least having the option to hide these files would be ideal. The lack of this feature is keeping me in Atom (and Atom's freeze-ups are driving me nuts).

+1 to implement .gitignore functionality finally

@denieler where did they implement?

Any new update on this feature? For me it's still the main issue why I don't use vscode over atom.

For me this should handle

  • Tree view (blending out files which are gitignored, see #21247)
  • Quick Open Panel (Remove or move all gitignored files down in the list)
  • Search (Remove gitignored files from search)

I would like to check if I can find some way to implement it but it will take me a bit to get into the project.

@db2k yeah.. I even wanted to jump from Atom to VS code, but when I found this issue now I'm not sure..

At the moment you can still use files.exclude and search.exclude. Still hope to support gitignore in the future.

@roblourens yeah, but it is kind of lame.. it is 2017 already, not 2004

The problem is that I work on a lot of projects at the same time and setting up files.exclude and search.exclude in addition everytime for every project would be really a pain since I already have all that stuff in my .gitignore for each project.

Since VSCode is such a gitrelated editor with the Git sidebar etc. I guess that should just be an inbuild option to toggle if you need it or not... No way to fetch the project folders gitignore and merge the arrays into the file/search exclude arrays?

I'm not a pro with typescript which is why I can't really help for now since I would have to read me in first, but otherwise I would like to contribute somehow so we can get this feature in.

This bug is super frustrating and actually causes me to lose work on a regular basis. To repro:

npm install -g electron-forge
git clone https://github.com/paulcbetts/trickline && cd trickline
npm i

## This creates a folder called 'out', which is ignored in my gitignore. However,
## it will have a copy of every source file in my project, with the same names
electron-forge package

code . 

Now use Ctrl/Cmd-T to open a file. Whoops! You now have a 50% chance of editing the file in out, which is at best annoying, causes you to constantly wonder "WHY DIDNT MY CHANGE DO ANYTHING????", and at worst, loses data when out gets deleted by a git clean -xdf along with your accidental changes.

VS Code understands Git in lots of other ways, there's no reason it can't parse gitignore. libgit2 will even do this on your behalf and help you out to do so.

@paulcbetts wow. that's shitty. I never thought of that. Not sure if anyone reads this issue though. Lots of people asking for it, but no one answering..

@paulcbetts In your case, you probably want to exclude out via your tsconfig, since cmd+T is showing you files from the language service. That will also fix duplicates showing up in 'find all references', etc. Since files.exclude doesn't currently impact those features, .gitignore support as I'm imagining it wouldn't either. (And maybe I'm wrong, but I often want to use language service features on gitignored files like node_modules)

@paulcbetts @luisrudge @roblourens i'm using vscode exclusion, meanwhile this moves forward

screen shot 2017-03-01 at 2 01 42 pm

In your case, you probably want to exclude out via your tsconfig, since cmd+T is showing you files from the language service
(And maybe I'm wrong, but I often want to use language service features on gitignored files like node_modules)

@roblourens Cmd-T will really show you files in node_modules? I feel like there's got to be an extra layer of exclusion because that would be super noisy if it showed me every file in there

Hey after waiting for someone else to do it, I ended up putting together a small extension that copies your gitignore into your vscode workspace settings with one command: https://github.com/stubailo/vscode-ignore-gitignore

Let me know if this is useful, and looking forward to feedback and PRs! I've only tried it in a few projects but seems to work so far.

@paulcbetts regarding:

Cmd-T will really show you files in node_modules?

Cmd-T shows you all the symbols and not files in your workspace.

Regarding:

You now have a 50% chance of editing the file in out

The "out" folder includes the typescript source files in "out\trickline-win32-x64\resources\app\src" and the way the TypeScript language service is configured in the top-level "tsconfig.json" these files are part of the project context. They are therefore analyzed by TypeScript. To address this you should add an exclude of "out" to your "tsconfig.json" as shown below:

{
  "compilerOptions": {
    "removeComments": false,
    "preserveConstEnums": true,
    "declaration": true,
    "experimentalDecorators": true,
    "noImplicitAny": true,
    "noImplicitReturns": true,
    "suppressImplicitAnyIndexErrors": true,
    "strictNullChecks": true,
    "noUnusedLocals": true,
    "noImplicitThis": true,
    "noUnusedParameters": true,
    "module": "commonjs",
    "moduleResolution": "node",
    "pretty": true,
    "target": "es2015",
    "jsx": "react",
    "outDir": ".tmp/build"
  },
  "formatCodeOptions": {
    "indentSize": 2,
    "tabSize": 2
  },
  "types" : [
    "node",
    "electron"
  ],
  "exclude": [
    "out"
  ]
}

@egamma that's the whole point we're trying to get here... If we already have out in our .gitignore file, why would I have to add it to the tsconfig file again?

Exactly, there should actually be more like a hierarchy for that.

.gitignore should always be the first ignore configuration to be loaded and should be merged with other vscode specific ignore configs.

Thanks @stubailo, https://github.com/stubailo/vscode-ignore-gitignore is a decent workaround for now but this shouldl really be in core.

I think IntelliJ IDEA nailed this:

  • .gitignored files and folders are grayed out by default in File explorer
  • .gitignored files are automatically added to the projects "excluded" list

    • this means they do not participate in Search, Replace, Open File, Open Recent Files, Find symbols etc.

  • however, if you actually spell the file name (or if the file cannot be found in the current non-excluded project), it will switch to looking across all files in the project, including the ignored ones.

Searching for a file, there are matching files in non-ignored files/folders:

mobx.js does not exist in the non-ignored files, switch to full-project search (ignored files are still grayed out)

Are there actually any plans on ever solving this issue? Is this something way more complicated?
I tried to wrap my head around the src (never worked with ts before) and it seems that hooking into the right place would make it possible to fetch the .gitignore from the projects cwd and add all array elements to the files.exclude and search.exclude.

I couldn't find the right place where this happens, even though I found multiple files loading data from the settings.json.

Is there anyone from Microsoft clarifying the status of this issue and if it's actually wanted by Microsoft?

Anyway looking forward for further discussions here.

Hoping to get it in for search in this release, via moving search to ripgrep: https://github.com/Microsoft/vscode/issues/19983

Once we have that, it might be possible to use ripgrep's highly optimized gitignore code to support it in the file explorer as well. The problems with putting the patterns in files.exclude is that the syntax is not exactly the same, and that it doesn't support negative patterns, and performance for large gitignore files could also be an issue.

@roblourens sounds great and I understand the issues. I'm looking forward for the next release.

Ripgrep search landed in today's Insiders, with .gitignore support enabled by default! Set "search.useRipgrep": true to try it out. There will likely be bugs... .gitignore support will be configurable later but I'm not sure how yet.

@roblourens thats great. Going to check it out and see if I can spot bugs for now.

@roblourens this is awesome, thank you!

@roblourens should we close this one given ripgrep work landed (release notes)?

But not file explorer yet. Issues like #13535 have been dupped into this one.

I wasn't sure since it has a lot of discussion about gitignore for the file explorer too. I think it makes sense to close this and start a new issue for that though.

The Ripgrep support is great, thank you for that! Can it be used for Cmd-P searching also? (It _seems_ not, since I still get noise there if I don't configure the files.exclude setting to exclude them).

(Sorry to pollute this issue with a somewhat unrelated question, please point me in the right direction and I'll shut up. 😛)

Not yet, I've got an issue for it - https://github.com/Microsoft/vscode/issues/24074

@roblourens just curious: why was this closed? as far as I can tell it was never resolved.

It was implemented for 1.11 - https://github.com/Microsoft/vscode/issues/78#issuecomment-290939774

@roblourens Why is this closed? It is solved for searchs yes, but it's not solved for explorer and there is not an option to exclude files in the explorer tree from gitignore. Is there any other issue for the explorer topic?

Edit: yes, you can use the ignore-gitignore extension, but I think that this should be integrated in the editor.

Graying out gitignored files is implemented in 1.18, and hiding them can be tracked by https://github.com/Microsoft/vscode/issues/23804

Was this page helpful?
0 / 5 - 0 ratings