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

Crash during initialization on Windows due to invalid absolute path (lowercase drive letter) #892

Closed
W4RH4WK opened this issue Aug 15, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@W4RH4WK
Copy link

W4RH4WK commented Aug 15, 2023

Ruby version

3.2.2

Code snippet

No response

Description

I just encountered a somewhat strange issue. I am trying to use Ruby LSP, but it crashes during initialization:

Ruby LSP> Skipping lockfile copies because there's no top level bundle
Ruby LSP> Running bundle install for the custom bundle. This may take a while...
Could not find gem 'debug'.
C:/Ruby32-x64/lib/ruby/3.2.0/uri/generic.rb:770:in `check_path': bad component(expected absolute path component): c:/Users/w4rh4wk/git/ank (URI::InvalidComponentError)
	from C:/Ruby32-x64/lib/ruby/3.2.0/uri/generic.rb:816:in `path='
	from C:/Ruby32-x64/lib/ruby/3.2.0/uri/generic.rb:192:in `initialize'
	from C:/Ruby32-x64/lib/ruby/3.2.0/uri/generic.rb:136:in `new'
	from C:/Ruby32-x64/lib/ruby/3.2.0/uri/generic.rb:136:in `build'
	from C:/Users/w4rh4wk/.gem/ruby/3.2.0/gems/ruby-lsp-0.8.0/lib/core_ext/uri.rb:18:in `from_path'
	from C:/Users/w4rh4wk/.gem/ruby/3.2.0/gems/sorbet-runtime-0.5.10965/lib/types/private/methods/_methods.rb:277:in `bind_call'
	from C:/Users/w4rh4wk/.gem/ruby/3.2.0/gems/sorbet-runtime-0.5.10965/lib/types/private/methods/_methods.rb:277:in `block in _on_method_added'
	from C:/Users/w4rh4wk/.gem/ruby/3.2.0/gems/ruby-lsp-0.8.0/lib/ruby_lsp/utils.rb:9:in `<module:RubyLsp>'
	from C:/Users/w4rh4wk/.gem/ruby/3.2.0/gems/ruby-lsp-0.8.0/lib/ruby_lsp/utils.rb:4:in `<top (required)>'
	from <internal:C:/Ruby32-x64/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
	from <internal:C:/Ruby32-x64/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
	from C:/Users/w4rh4wk/.gem/ruby/3.2.0/gems/ruby-lsp-0.8.0/lib/ruby_lsp/internal.rb:14:in `<top (required)>'
	from C:/Users/w4rh4wk/.gem/ruby/3.2.0/gems/ruby-lsp-0.8.0/exe/ruby-lsp:39:in `require_relative'
	from C:/Users/w4rh4wk/.gem/ruby/3.2.0/gems/ruby-lsp-0.8.0/exe/ruby-lsp:39:in `<top (required)>'
	from C:/Users/w4rh4wk/AppData/Local/Microsoft/WindowsApps/ruby-lsp:32:in `load'
	from C:/Users/w4rh4wk/AppData/Local/Microsoft/WindowsApps/ruby-lsp:32:in `<main>'
[Error - 10:41:05 PM] Server initialization failed.
  Message: Pending response rejected since connection got disposed
  Code: -32097 

It appears that the path c:/Users/w4rh4wk/git/ank is not considered a valid absolute path. Inspecting the code around this invocation shows this:

      def from_path(path:, scheme: "file")
        # On Windows, if the path begins with the disk name, we need to add a leading slash to make it a valid URI
        escaped_path = if /^[A-Z]:/.match?(path)
          DEFAULT_PARSER.escape("/#{path}")
        else
          DEFAULT_PARSER.escape(path)
        end

        build(scheme: scheme, path: escaped_path)
      end

Since the regex matches only on uppercase drive letters, no leading slash is added.

I have no idea why the drive letter in this path is lowercase. My suggestion would be to also add support for lowercase drive letters to the regex.

Expected output

Ruby LSP should not crash during initialization.

@W4RH4WK W4RH4WK added the bug Something isn't working label Aug 15, 2023
@vinistock
Copy link
Member

vinistock commented Aug 16, 2023

Already fixed by #885. Just waiting on a release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants