ruby-lsp 0.16.5 → 0.16.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/exe/ruby-lsp +6 -2
- data/lib/ruby_indexer/lib/ruby_indexer/configuration.rb +1 -0
- data/lib/ruby_indexer/lib/ruby_indexer/entry.rb +5 -20
- data/lib/ruby_indexer/test/configuration_test.rb +8 -0
- data/lib/ruby_lsp/requests/definition.rb +21 -12
- data/lib/ruby_lsp/requests/hover.rb +11 -7
- data/lib/ruby_lsp/requests/request.rb +14 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d725a0a2fbd58820e2a87efae85564498221feb8410292055b0caafd889284e6
|
4
|
+
data.tar.gz: 5376ca8a9d08ca0883fca3aa19a1a178102eb60f49ab3fe5f07bb1a58ba63ddf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81fbb2e5018ad55d8888c98e277e7ac6ed8b45314627b1a3e3dabde2cb8aac0284dc70487a694226e5a08817feb82b64daadfcb955e9642b288e575189a56015
|
7
|
+
data.tar.gz: f32ef084e4412752cc32df55da0dd7b985d3826db110bf91ba3473773043c50345ceb597432483a0a75f1790cabfca796fa9581d3ba86edff96a8642fb2312f2
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.16.
|
1
|
+
0.16.6
|
data/exe/ruby-lsp
CHANGED
@@ -75,14 +75,18 @@ require "ruby_lsp/internal"
|
|
75
75
|
|
76
76
|
if options[:debug]
|
77
77
|
if ["x64-mingw-ucrt", "x64-mingw32"].include?(RUBY_PLATFORM)
|
78
|
-
puts "Debugging is not supported on Windows"
|
78
|
+
$stderr.puts "Debugging is not supported on Windows"
|
79
79
|
exit 1
|
80
80
|
end
|
81
81
|
|
82
82
|
begin
|
83
|
+
original_stdout = $stdout
|
84
|
+
$stdout = $stderr
|
83
85
|
require "debug/open_nonstop"
|
84
86
|
rescue LoadError
|
85
|
-
|
87
|
+
$stderr.puts("You need to install the debug gem to use the --debug flag")
|
88
|
+
ensure
|
89
|
+
$stdout = original_stdout
|
86
90
|
end
|
87
91
|
end
|
88
92
|
|
@@ -56,6 +56,7 @@ module RubyIndexer
|
|
56
56
|
load_path_entry = T.let(nil, T.nilable(String))
|
57
57
|
|
58
58
|
Dir.glob(pattern, File::FNM_PATHNAME | File::FNM_EXTGLOB).map! do |path|
|
59
|
+
path = File.expand_path(path)
|
59
60
|
# All entries for the same pattern match the same $LOAD_PATH entry. Since searching the $LOAD_PATH for every
|
60
61
|
# entry is expensive, we memoize it until we find a path that doesn't belong to that $LOAD_PATH. This happens
|
61
62
|
# on repositories that define multiple gems, like Rails. All frameworks are defined inside the Dir.pwd, but
|
@@ -61,28 +61,13 @@ module RubyIndexer
|
|
61
61
|
abstract!
|
62
62
|
|
63
63
|
sig { returns(T::Array[String]) }
|
64
|
-
|
65
|
-
|
66
|
-
sig { returns(T::Array[String]) }
|
67
|
-
attr_accessor :prepended_modules
|
68
|
-
|
69
|
-
sig do
|
70
|
-
params(
|
71
|
-
name: String,
|
72
|
-
file_path: String,
|
73
|
-
location: T.any(Prism::Location, RubyIndexer::Location),
|
74
|
-
comments: T::Array[String],
|
75
|
-
).void
|
76
|
-
end
|
77
|
-
def initialize(name, file_path, location, comments)
|
78
|
-
super(name, file_path, location, comments)
|
79
|
-
@included_modules = T.let([], T::Array[String])
|
80
|
-
@prepended_modules = T.let([], T::Array[String])
|
64
|
+
def included_modules
|
65
|
+
@included_modules ||= T.let([], T.nilable(T::Array[String]))
|
81
66
|
end
|
82
67
|
|
83
|
-
sig { returns(String) }
|
84
|
-
def
|
85
|
-
T.
|
68
|
+
sig { returns(T::Array[String]) }
|
69
|
+
def prepended_modules
|
70
|
+
@prepended_modules ||= T.let([], T.nilable(T::Array[String]))
|
86
71
|
end
|
87
72
|
end
|
88
73
|
|
@@ -20,6 +20,14 @@ module RubyIndexer
|
|
20
20
|
assert(indexables.none? { |indexable| indexable.full_path == __FILE__ })
|
21
21
|
end
|
22
22
|
|
23
|
+
def test_indexables_have_expanded_full_paths
|
24
|
+
@config.apply_config({ "included_patterns" => ["**/*.rb"] })
|
25
|
+
indexables = @config.indexables
|
26
|
+
|
27
|
+
# All paths should be expanded
|
28
|
+
assert(indexables.none? { |indexable| indexable.full_path.start_with?("lib/") })
|
29
|
+
end
|
30
|
+
|
23
31
|
def test_indexables_only_includes_gem_require_paths
|
24
32
|
indexables = @config.indexables
|
25
33
|
|
@@ -43,6 +43,7 @@ module RubyLsp
|
|
43
43
|
ResponseBuilders::CollectionResponseBuilder[Interface::Location].new,
|
44
44
|
ResponseBuilders::CollectionResponseBuilder[Interface::Location],
|
45
45
|
)
|
46
|
+
@dispatcher = dispatcher
|
46
47
|
|
47
48
|
target, parent, nesting = document.locate_node(
|
48
49
|
position,
|
@@ -50,33 +51,41 @@ module RubyLsp
|
|
50
51
|
)
|
51
52
|
|
52
53
|
if target.is_a?(Prism::ConstantReadNode) && parent.is_a?(Prism::ConstantPathNode)
|
54
|
+
# If the target is part of a constant path node, we need to find the exact portion of the constant that the
|
55
|
+
# user is requesting to go to definition for
|
53
56
|
target = determine_target(
|
54
57
|
target,
|
55
58
|
parent,
|
56
59
|
position,
|
57
60
|
)
|
61
|
+
elsif target.is_a?(Prism::CallNode) && target.name != :require && target.name != :require_relative &&
|
62
|
+
!covers_position?(target.message_loc, position)
|
63
|
+
# If the target is a method call, we need to ensure that the requested position is exactly on top of the
|
64
|
+
# method identifier. Otherwise, we risk showing definitions for unrelated things
|
65
|
+
target = nil
|
58
66
|
end
|
59
67
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
+
if target
|
69
|
+
Listeners::Definition.new(
|
70
|
+
@response_builder,
|
71
|
+
global_state,
|
72
|
+
document.uri,
|
73
|
+
nesting,
|
74
|
+
dispatcher,
|
75
|
+
typechecker_enabled,
|
76
|
+
)
|
68
77
|
|
69
|
-
|
70
|
-
|
78
|
+
Addon.addons.each do |addon|
|
79
|
+
addon.create_definition_listener(@response_builder, document.uri, nesting, dispatcher)
|
80
|
+
end
|
71
81
|
end
|
72
82
|
|
73
83
|
@target = T.let(target, T.nilable(Prism::Node))
|
74
|
-
@dispatcher = dispatcher
|
75
84
|
end
|
76
85
|
|
77
86
|
sig { override.returns(T::Array[Interface::Location]) }
|
78
87
|
def perform
|
79
|
-
@dispatcher.dispatch_once(@target)
|
88
|
+
@dispatcher.dispatch_once(@target) if @target
|
80
89
|
@response_builder.response
|
81
90
|
end
|
82
91
|
end
|
@@ -41,25 +41,29 @@ module RubyLsp
|
|
41
41
|
end
|
42
42
|
def initialize(document, global_state, position, dispatcher, typechecker_enabled)
|
43
43
|
super()
|
44
|
-
|
45
|
-
@target, parent, nesting = document.locate_node(
|
44
|
+
target, parent, nesting = document.locate_node(
|
46
45
|
position,
|
47
46
|
node_types: Listeners::Hover::ALLOWED_TARGETS,
|
48
47
|
)
|
49
48
|
|
50
49
|
if (Listeners::Hover::ALLOWED_TARGETS.include?(parent.class) &&
|
51
|
-
!Listeners::Hover::ALLOWED_TARGETS.include?(
|
52
|
-
(parent.is_a?(Prism::ConstantPathNode) &&
|
53
|
-
|
54
|
-
T.must(
|
50
|
+
!Listeners::Hover::ALLOWED_TARGETS.include?(target.class)) ||
|
51
|
+
(parent.is_a?(Prism::ConstantPathNode) && target.is_a?(Prism::ConstantReadNode))
|
52
|
+
target = determine_target(
|
53
|
+
T.must(target),
|
55
54
|
T.must(parent),
|
56
55
|
position,
|
57
56
|
)
|
57
|
+
elsif target.is_a?(Prism::CallNode) && target.name != :require && target.name != :require_relative &&
|
58
|
+
!covers_position?(target.message_loc, position)
|
59
|
+
|
60
|
+
target = nil
|
58
61
|
end
|
59
62
|
|
60
63
|
# Don't need to instantiate any listeners if there's no target
|
61
|
-
return unless
|
64
|
+
return unless target
|
62
65
|
|
66
|
+
@target = T.let(target, T.nilable(Prism::Node))
|
63
67
|
uri = document.uri
|
64
68
|
@response_builder = T.let(ResponseBuilders::Hover.new, ResponseBuilders::Hover)
|
65
69
|
Listeners::Hover.new(@response_builder, global_state, uri, nesting, dispatcher, typechecker_enabled)
|
@@ -65,6 +65,20 @@ module RubyLsp
|
|
65
65
|
|
66
66
|
target
|
67
67
|
end
|
68
|
+
|
69
|
+
# Checks if a given location covers the position requested
|
70
|
+
sig { params(location: T.nilable(Prism::Location), position: T::Hash[Symbol, T.untyped]).returns(T::Boolean) }
|
71
|
+
def covers_position?(location, position)
|
72
|
+
return false unless location
|
73
|
+
|
74
|
+
start_line = location.start_line - 1
|
75
|
+
end_line = location.end_line - 1
|
76
|
+
line = position[:line]
|
77
|
+
character = position[:character]
|
78
|
+
|
79
|
+
(start_line < line || (start_line == line && location.start_column <= character)) &&
|
80
|
+
(end_line > line || (end_line == line && location.end_column >= character))
|
81
|
+
end
|
68
82
|
end
|
69
83
|
end
|
70
84
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-lsp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.16.
|
4
|
+
version: 0.16.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shopify
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-04-
|
11
|
+
date: 2024-04-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: language_server-protocol
|