ruby-lsp icon indicating copy to clipboard operation
ruby-lsp copied to clipboard

Error running ruby-lsp in path with spaces

Open tonklon opened this issue 3 years ago • 6 comments

When running ruby-lsp in a project with a space somewhere in the absolute path it crashes with:

bundler: failed to load command: ruby-lsp (/Users/tono/.asdf/installs/ruby/3.1.3/bin/ruby-lsp)
/Users/tono/.asdf/installs/ruby/3.1.3/lib/ruby/gems/3.1.0/gems/uri-0.12.1/lib/uri/rfc3986_parser.rb:66:in `split': bad URI(is not URI?): "file:///Users/tono/some/path with spaces/code" (URI::InvalidURIError)
	from /Users/tono/.asdf/installs/ruby/3.1.3/lib/ruby/gems/3.1.0/gems/uri-0.12.1/lib/uri/rfc3986_parser.rb:71:in `parse'
	from /Users/tono/.asdf/installs/ruby/3.1.3/lib/ruby/gems/3.1.0/gems/uri-0.12.1/lib/uri/common.rb:193:in `parse'
	from /Users/tono/.asdf/installs/ruby/3.1.3/lib/ruby/gems/3.1.0/gems/uri-0.12.1/lib/uri/common.rb:722:in `URI'
	from /Users/tono/.asdf/installs/ruby/3.1.3/lib/ruby/gems/3.1.0/gems/ruby-lsp-0.5.1/lib/ruby_lsp/utils.rb:9:in `<module:RubyLsp>'
	from /Users/tono/.asdf/installs/ruby/3.1.3/lib/ruby/gems/3.1.0/gems/ruby-lsp-0.5.1/lib/ruby_lsp/utils.rb:4:in `<top (required)>'
	from /Users/tono/.asdf/installs/ruby/3.1.3/lib/ruby/gems/3.1.0/gems/ruby-lsp-0.5.1/lib/ruby_lsp/internal.rb:12:in `require'
	from /Users/tono/.asdf/installs/ruby/3.1.3/lib/ruby/gems/3.1.0/gems/ruby-lsp-0.5.1/lib/ruby_lsp/internal.rb:12:in `<top (required)>'
	from /Users/tono/.asdf/installs/ruby/3.1.3/lib/ruby/gems/3.1.0/gems/ruby-lsp-0.5.1/exe/ruby-lsp:21:in `require_relative'
	from /Users/tono/.asdf/installs/ruby/3.1.3/lib/ruby/gems/3.1.0/gems/ruby-lsp-0.5.1/exe/ruby-lsp:21:in `<top (required)>'
	from /Users/tono/.asdf/installs/ruby/3.1.3/bin/ruby-lsp:25:in `load'
	from /Users/tono/.asdf/installs/ruby/3.1.3/bin/ruby-lsp:25:in `<top (required)>'
	from /Users/tono/.asdf/installs/ruby/3.1.3/lib/ruby/gems/3.1.0/gems/bundler-2.4.4/lib/bundler/cli/exec.rb:58:in `load'
	from /Users/tono/.asdf/installs/ruby/3.1.3/lib/ruby/gems/3.1.0/gems/bundler-2.4.4/lib/bundler/cli/exec.rb:58:in `kernel_load'
	from /Users/tono/.asdf/installs/ruby/3.1.3/lib/ruby/gems/3.1.0/gems/bundler-2.4.4/lib/bundler/cli/exec.rb:23:in `run'
	from /Users/tono/.asdf/installs/ruby/3.1.3/lib/ruby/gems/3.1.0/gems/bundler-2.4.4/lib/bundler/cli.rb:491:in `exec'
	from /Users/tono/.asdf/installs/ruby/3.1.3/lib/ruby/gems/3.1.0/gems/bundler-2.4.4/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
	from /Users/tono/.asdf/installs/ruby/3.1.3/lib/ruby/gems/3.1.0/gems/bundler-2.4.4/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
	from /Users/tono/.asdf/installs/ruby/3.1.3/lib/ruby/gems/3.1.0/gems/bundler-2.4.4/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
	from /Users/tono/.asdf/installs/ruby/3.1.3/lib/ruby/gems/3.1.0/gems/bundler-2.4.4/lib/bundler/cli.rb:34:in `dispatch'
	from /Users/tono/.asdf/installs/ruby/3.1.3/lib/ruby/gems/3.1.0/gems/bundler-2.4.4/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
	from /Users/tono/.asdf/installs/ruby/3.1.3/lib/ruby/gems/3.1.0/gems/bundler-2.4.4/lib/bundler/cli.rb:28:in `start'
	from /Users/tono/.asdf/installs/ruby/3.1.3/lib/ruby/gems/3.1.0/gems/bundler-2.4.4/exe/bundle:45:in `block in <top (required)>'
	from /Users/tono/.asdf/installs/ruby/3.1.3/lib/ruby/gems/3.1.0/gems/bundler-2.4.4/lib/bundler/friendly_errors.rb:117:in `with_friendly_errors'
	from /Users/tono/.asdf/installs/ruby/3.1.3/lib/ruby/gems/3.1.0/gems/bundler-2.4.4/exe/bundle:33:in `<top (required)>'
	from /Users/tono/.asdf/installs/ruby/3.1.3/bin/bundle:25:in `load'
	from /Users/tono/.asdf/installs/ruby/3.1.3/bin/bundle:25:in `<main>'

I am running ruby-lsp using the vscode extension.

The line from the stack trace is: https://github.com/Shopify/ruby-lsp/blob/52193042a44f6798ad6ac35cc4dd992094d59db7/lib/ruby_lsp/utils.rb#L9

I guess the path should be url encodes here. Shall I try to submit a PR fixing this?

tonklon avatar May 09 '23 20:05 tonklon

This might not be the best option, but at least it works in my case:

WORKSPACE_URI = T.let(URI("file://#{Dir.pwd.split('/').map{|p| URI.encode_uri_component p}.join('/')}".freeze), URI::Generic) # rubocop:disable Style/RedundantFreeze

tonklon avatar May 09 '23 21:05 tonklon

@tonklon yes, a PR would be good, thank you.

andyw8 avatar May 09 '23 21:05 andyw8

Yeah, we're indeed not handling URIs properly in a few places. This issue #633 should address it as well.

Basically, we need to properly decode and parse URIs everywhere.

vinistock avatar May 25 '23 15:05 vinistock

This might not be the best option, but at least it works in my case:

WORKSPACE_URI = T.let(URI("file://#{Dir.pwd.split('/').map{|p| URI.encode_uri_component p}.join('/')}".freeze), URI::Generic) # rubocop:disable Style/RedundantFreeze

Where did you put this? Cheers!

iRonin avatar May 31 '23 15:05 iRonin

@iRonin I hacked it inside the installed gem in file ruby-lsp/lib/ruby_lsp/utils.rb. It's line 9.

tonklon avatar Jun 07 '23 06:06 tonklon

Today ruby-lsp stopped working for me, even with my suggested workaround above in place.

This time I do not get an error message, it just does not work when there's a space in the path.

It immediately starts working when I start the same project from a path without spaces.

This might or might not be related to ruby-lsp. It can be problem of vscode or other parts. I just wanted to note it here for reference.

tonklon avatar Jun 07 '23 07:06 tonklon