-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This request uses the gem source comments generated by Tapioca to let users quickly jump to the actual source of the definition.
- Loading branch information
Showing
6 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# typed: strict | ||
# frozen_string_literal: true | ||
|
||
module RubyLsp | ||
module Requests | ||
class DocumentLink < BaseRequest | ||
extend T::Sig | ||
|
||
sig { params(document: Document).void } | ||
def initialize(document) | ||
super | ||
|
||
@links = T.let([], T::Array[LanguageServer::Protocol::Interface::DocumentLink]) | ||
end | ||
|
||
sig { override.returns(T.all(T::Array[LanguageServer::Protocol::Interface::DocumentLink], Object)) } | ||
def run | ||
visit(@document.tree) | ||
@links | ||
end | ||
|
||
sig { params(node: SyntaxTree::Comment).void } | ||
def visit_comment(node) | ||
match = node.value.match(%r{source://(?<path>.*):(?<line>\d+)$}) | ||
return unless match | ||
|
||
file_path = File.join(Bundler.bundle_path, "gems", match[:path]) | ||
return unless File.exist?(file_path) | ||
|
||
target = "file://#{file_path}##{match[:line]}" | ||
|
||
@links << LanguageServer::Protocol::Interface::DocumentLink.new( | ||
range: range_from_syntax_tree_node(node), | ||
target: target, | ||
tooltip: "Jump to the source" | ||
) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"result": [ | ||
{ | ||
"range": {"start": {"line": 0, "character": 0}, "end": {"line": 0, "character": 50}}, | ||
"target": "file://BUNDLER_PATH/gems/syntax_tree-3.0.0/lib/syntax_tree.rb#39", | ||
"tooltip": "Jump to the source" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# source://syntax_tree-3.0.0/lib/syntax_tree.rb:39 | ||
def foo | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# typed: true | ||
# frozen_string_literal: true | ||
|
||
require "test_helper" | ||
require "expectations/expectations_test_runner" | ||
|
||
class DocumentLinkExpectationsTest < ExpectationsTestRunner | ||
expectations_tests RubyLsp::Requests::DocumentLink, "document_link" | ||
|
||
def assert_expectations(source, expected) | ||
actual = run_expectations(source) | ||
assert_equal(map_expectations(json_expectations(expected)), JSON.parse(actual.to_json)) | ||
end | ||
|
||
def map_expectations(expectations) | ||
expectations.each do |expectation| | ||
expectation["target"] = expectation["target"].sub("BUNDLER_PATH", Bundler.bundle_path.to_s) | ||
end | ||
end | ||
end |