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

Return early if magic source link URI has no path #3056

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/ruby_lsp/listeners/document_link.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ def extract_document_link(node)
gem_version = resolve_version(uri)
return if gem_version.nil?

file_path = self.class.gem_paths.dig(uri.gem_name, gem_version, CGI.unescape(uri.path))
path = uri.path
return unless path

file_path = self.class.gem_paths.dig(uri.gem_name, gem_version, CGI.unescape(path))
return if file_path.nil?

@response_builder << Interface::DocumentLink.new(
Expand Down
19 changes: 19 additions & 0 deletions test/requests/document_link_expectations_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,25 @@ def run_expectations(source)
listener.perform
end

def test_magic_source_links_on_unsaved_files
source = <<~RUBY
# source://erb/#1
def bar
end
RUBY

with_server(source) do |server, uri|
server.process_message(
id: 1,
method: "textDocument/documentLink",
params: { textDocument: { uri: uri } },
)

server.pop_response
assert_empty(server.pop_response.response)
end
end

private

def substitute(original)
Expand Down
Loading