ruby-lsp 0.16.5 → 0.16.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bcd4426f17d6d429be733a9adcdf799e23c29689ad5fb69f9b9f7b3cd334bf9b
4
- data.tar.gz: 071d5c37e1acf83c07a5b48e85a3bc4a18fb63a20b54ff191158799cf4320803
3
+ metadata.gz: d725a0a2fbd58820e2a87efae85564498221feb8410292055b0caafd889284e6
4
+ data.tar.gz: 5376ca8a9d08ca0883fca3aa19a1a178102eb60f49ab3fe5f07bb1a58ba63ddf
5
5
  SHA512:
6
- metadata.gz: 9edc44ec74f5f5d9b5f15fb7d22501126eb8f6bec3d9a69b3061946b369ecb0e453e45e9a0dc9df1482117dc738f7bd66005e2dcd0cd46e3aaad6f6658283766
7
- data.tar.gz: c4f9ddb4da9373544b2456632a0fb76bdbca5e5ddf5e874b0e6ab4f6aae13ad8b17ef9482873b37ae33bc7ec797faebde76bf5a6e9d86e6a4ddf798b4eb9f0df
6
+ metadata.gz: 81fbb2e5018ad55d8888c98e277e7ac6ed8b45314627b1a3e3dabde2cb8aac0284dc70487a694226e5a08817feb82b64daadfcb955e9642b288e575189a56015
7
+ data.tar.gz: f32ef084e4412752cc32df55da0dd7b985d3826db110bf91ba3473773043c50345ceb597432483a0a75f1790cabfca796fa9581d3ba86edff96a8642fb2312f2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.16.5
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
- warn("You need to install the debug gem to use the --debug flag")
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
- attr_accessor :included_modules
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 short_name
85
- T.must(@name.split("::").last)
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
- Listeners::Definition.new(
61
- @response_builder,
62
- global_state,
63
- document.uri,
64
- nesting,
65
- dispatcher,
66
- typechecker_enabled,
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
- Addon.addons.each do |addon|
70
- addon.create_definition_listener(@response_builder, document.uri, nesting, dispatcher)
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
- @target = T.let(nil, T.nilable(Prism::Node))
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?(@target.class)) ||
52
- (parent.is_a?(Prism::ConstantPathNode) && @target.is_a?(Prism::ConstantReadNode))
53
- @target = determine_target(
54
- T.must(@target),
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 @target
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.5
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-24 00:00:00.000000000 Z
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