Skip to content

Unexpected Errno::ENAMETOOLONG on Windows#4020

Open
rellampec wants to merge 18 commits intoShopify:mainfrom
rellampec:oss
Open

Unexpected Errno::ENAMETOOLONG on Windows#4020
rellampec wants to merge 18 commits intoShopify:mainfrom
rellampec:oss

Conversation

@rellampec
Copy link

Motivation

The ruby built (ruby executable path: C:\ruby\Ruby32-x64\bin\ruby.exe) of RubyInstaller (for Windows machines) triggers an error on Dir.glob for wide inclusive patterns.

Dir.glob("*/**/*")

# => <internal:dir>:ln:in `glob': Filename too long - frontends/webapp-frontend/src/features/featureMangement/features/featureTypes/components/FeatureTypeDraggableField/components/AreaConfiguration/components/AreaFilters/components/AreaFiltersDrawer/components/AreaByLocationPreview/hooks (Errno::ENAMETOOLONG)
  • Apparently, their x64 version hasn't been compiled by taking into account what follows further down.

In ruby-lsp this translates into:

  1. Failed index_all (ln: Dir.glob(File.join(@workspace_path, pattern), flags)).
  2. Failed load_addons (ln: Dir.glob("#{global_state.workspace_path}/**/ruby_lsp/**/addon.rb")).

Windows has a registry entry, under the path Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem, called LongPathsEnabled to enabling support for file paths over 260 characters, that defaults to 0 , but that can be changed to 1.

There have been a couple of bugs reported in ruby-core:

And one fix has been merged: [Win32] long path name support [Bug #12551]#4505 (article of the author of the fix).

However, the fix can only make its way to the executable if the Windows application manifest that is embedded to it during the built has this entry:

<ws2:longPathAware>true</ws2:longPathAware>

None of the ruby installer repos (old or new) has any reported issue on this matter.

On the other hand, although ruby-lsp allows to declare an indexation configuration parameter with this settings key rubyLsp.indexing: {excludedPatterns: []}, excluding the root folder of the deepest part of the working directory does not prevent the error to popup. Although such an error shouldn't be reason for ruby-lsp to stop indexing, it does stop indexing.

Vs Code extension Settings:

{
  "rubyLsp.indexing": {
    "excludedPatterns": [
      "**/test/**/*.rb",
      "frontends/**/*.rb",
      "vendor/**/*",
      ".bundle/**/*",
      "gitlab-ci/**/*",
      "deb/**/*",
      "graphql-docs/**/",
      "deployment/**/*"
    ]
}
  • Observe that "frontends/**/*.rb" is excluded, and nevertheless the indexer ended up failing.

Implementation

My changes involve all the below in order of priority:

  1. More error logging (Ruby LSP output) on indexation and addons loading.
  2. Let load_addons and index_all continue by logging any error when it occurs (instead of completely failing). This is implemented with error handling and logging.
  3. Decouple/granulate glob on load_addons provided that it globs on per main space/root-folder basis (same approach as used in the indexer with top_level_directories (line)
  4. Ensure that patterns excluded from indexation aren't included during the scoping of included urls. This has been implemented decoupling top level directories in the included_patterns variable, and subtracting from the Array the excluded_patterns, before the Dir.glob is run.

Automated Tests

I haven't, because I do not know how to do it, and I do not know if the changes I implemented are really part of the test suit.

Manual Tests

  1. From a local repo with the fork as origin, I implemented changes and pushed them to the remote.
  2. With an aside folder (not in the working directory) for the ruby-lsp Gemfile, I pointed the ruby-lsp gem to the feature branch of this PR.
  3. The VS Code is configured to use that Gemfile to bundle ruby-lsp.
  4. I have also re-installed multiple times the gem that I built locally.
  5. On each change, I used reload window on VS Code, and checked the view > output terminal.

@rellampec rellampec requested a review from a team as a code owner March 19, 2026 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant