ruby-lsp 0.9.1 → 0.9.3

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: '08f4db46a392926873115c77175be859ecdfc4c5093e003f913eec7288f05fac'
4
- data.tar.gz: 2f34acc2fc69ab4dd6ad5fc9961a86c020d550284ed18aefd3221b0525af2628
3
+ metadata.gz: 0c2f16b0f0e93ade0e4465fcf71148ac156f6d65b1354f07af2df4007c600c15
4
+ data.tar.gz: 7c6f4668f461315039e37f04354dddadb1678dd89ff9c249a268897992dfa4c0
5
5
  SHA512:
6
- metadata.gz: 99a9e243c0dd2f763532a5a1c52241ac86c9a7ba2ccb0814932d8e08b17add78143566ac26ad609b59ff8d96e1d2844b53995b85b473cb736c5f87e2a30c5a26
7
- data.tar.gz: 2a1669be7a054a5d19b0b7eff113347571928cb601e1b432c6f49bc3f349a530b6d0df45c7ea5dfa46add7b69fd347713ec33f95fdca9baa896855f958814209
6
+ metadata.gz: 184683630988346ae617e3df3d6d04c66b822d6d9734f595a41caa3603b38046e5ee5a7a4361abede0f3b8d1584371730be9af905d006fa881d4b718f3381947
7
+ data.tar.gz: 7c10ef841c059110b1d5bc38cde57de243140c37d7095ab8c7ce16d28e4c520c402f2bfcf604f7002a7e06d7db031b8ab9e52ce28bf3c50be0dc2671d5728170
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.1
1
+ 0.9.3
data/exe/ruby-lsp CHANGED
@@ -3,6 +3,7 @@
3
3
 
4
4
  require "optparse"
5
5
 
6
+ original_args = ARGV.dup
6
7
  options = {}
7
8
  parser = OptionParser.new do |opts|
8
9
  opts.banner = "Usage: ruby-lsp [options]"
@@ -33,7 +34,7 @@ parser = OptionParser.new do |opts|
33
34
  end
34
35
 
35
36
  begin
36
- parser.parse
37
+ parser.parse!
37
38
  rescue OptionParser::InvalidOption => e
38
39
  warn(e)
39
40
  warn("")
@@ -56,7 +57,7 @@ if ENV["BUNDLE_GEMFILE"].nil?
56
57
 
57
58
  env = { "BUNDLE_GEMFILE" => bundle_gemfile }
58
59
  env["BUNDLE_PATH"] = bundle_path if bundle_path
59
- exit exec(env, "bundle exec ruby-lsp #{ARGV.join(" ")}")
60
+ exit exec(env, "bundle exec ruby-lsp #{original_args.join(" ")}")
60
61
  end
61
62
 
62
63
  require "sorbet-runtime"
@@ -134,7 +134,7 @@ module RubyIndexer
134
134
 
135
135
  sig { returns(Regexp) }
136
136
  def magic_comment_regex
137
- /^\s*#\s*#{@excluded_magic_comments.join("|")}/
137
+ @magic_comment_regex ||= T.let(/^\s*#\s*#{@excluded_magic_comments.join("|")}/, T.nilable(Regexp))
138
138
  end
139
139
 
140
140
  private
@@ -104,6 +104,7 @@ module RubyLsp
104
104
  emitter.visit(document.tree) if document.parsed?
105
105
 
106
106
  code_lens.merge_external_listeners_responses!
107
+ document_symbol.merge_external_listeners_responses!
107
108
 
108
109
  # Store all responses retrieve in this round of visits in the cache and then return the response for the request
109
110
  # we actually received
@@ -177,6 +178,8 @@ module RubyLsp
177
178
  workspace_symbol(request.dig(:params, :query))
178
179
  when "rubyLsp/textDocument/showSyntaxTree"
179
180
  show_syntax_tree(uri, request.dig(:params, :range))
181
+ else
182
+ VOID
180
183
  end
181
184
  end
182
185
 
@@ -204,8 +207,6 @@ module RubyLsp
204
207
 
205
208
  sig { void }
206
209
  def perform_initial_indexing
207
- return unless @store.experimental_features
208
-
209
210
  # The begin progress invocation happens during `initialize`, so that the notification is sent before we are
210
211
  # stuck indexing files
211
212
  RubyIndexer.configuration.load_config
@@ -581,7 +582,7 @@ module RubyLsp
581
582
  Interface::DocumentSymbolClientCapabilities.new(
582
583
  hierarchical_document_symbol_support: true,
583
584
  symbol_kind: {
584
- value_set: Requests::DocumentSymbol::SYMBOL_KIND.values,
585
+ value_set: (Constant::SymbolKind::FILE..Constant::SymbolKind::TYPE_PARAMETER).to_a,
585
586
  },
586
587
  )
587
588
  end
@@ -643,37 +644,35 @@ module RubyLsp
643
644
  )
644
645
  end
645
646
 
646
- if @store.experimental_features
647
- # Dynamically registered capabilities
648
- file_watching_caps = options.dig(:capabilities, :workspace, :didChangeWatchedFiles)
649
-
650
- # Not every client supports dynamic registration or file watching
651
- if file_watching_caps&.dig(:dynamicRegistration) && file_watching_caps&.dig(:relativePatternSupport)
652
- @message_queue << Request.new(
653
- message: "client/registerCapability",
654
- params: Interface::RegistrationParams.new(
655
- registrations: [
656
- # Register watching Ruby files
657
- Interface::Registration.new(
658
- id: "workspace/didChangeWatchedFiles",
659
- method: "workspace/didChangeWatchedFiles",
660
- register_options: Interface::DidChangeWatchedFilesRegistrationOptions.new(
661
- watchers: [
662
- Interface::FileSystemWatcher.new(
663
- glob_pattern: "**/*.rb",
664
- kind: Constant::WatchKind::CREATE | Constant::WatchKind::CHANGE | Constant::WatchKind::DELETE,
665
- ),
666
- ],
667
- ),
647
+ # Dynamically registered capabilities
648
+ file_watching_caps = options.dig(:capabilities, :workspace, :didChangeWatchedFiles)
649
+
650
+ # Not every client supports dynamic registration or file watching
651
+ if file_watching_caps&.dig(:dynamicRegistration) && file_watching_caps&.dig(:relativePatternSupport)
652
+ @message_queue << Request.new(
653
+ message: "client/registerCapability",
654
+ params: Interface::RegistrationParams.new(
655
+ registrations: [
656
+ # Register watching Ruby files
657
+ Interface::Registration.new(
658
+ id: "workspace/didChangeWatchedFiles",
659
+ method: "workspace/didChangeWatchedFiles",
660
+ register_options: Interface::DidChangeWatchedFilesRegistrationOptions.new(
661
+ watchers: [
662
+ Interface::FileSystemWatcher.new(
663
+ glob_pattern: "**/*.rb",
664
+ kind: Constant::WatchKind::CREATE | Constant::WatchKind::CHANGE | Constant::WatchKind::DELETE,
665
+ ),
666
+ ],
668
667
  ),
669
- ],
670
- ),
671
- )
672
- end
673
-
674
- begin_progress("indexing-progress", "Ruby LSP: indexing files")
668
+ ),
669
+ ],
670
+ ),
671
+ )
675
672
  end
676
673
 
674
+ begin_progress("indexing-progress", "Ruby LSP: indexing files")
675
+
677
676
  Interface::InitializeResult.new(
678
677
  capabilities: Interface::ServerCapabilities.new(
679
678
  text_document_sync: Interface::TextDocumentSyncOptions.new(
@@ -124,5 +124,14 @@ module RubyLsp
124
124
  ).returns(T.nilable(Listener[T.nilable(Interface::Hover)]))
125
125
  end
126
126
  def create_hover_listener(emitter, message_queue); end
127
+
128
+ # Creates a new DocumentSymbol listener. This method is invoked on every DocumentSymbol request
129
+ sig do
130
+ overridable.params(
131
+ emitter: EventEmitter,
132
+ message_queue: Thread::Queue,
133
+ ).returns(T.nilable(Listener[T.nilable(Interface::DocumentSymbol)]))
134
+ end
135
+ def create_document_symbol_listener(emitter, message_queue); end
127
136
  end
128
137
  end
@@ -65,7 +65,7 @@ module RubyLsp
65
65
  class_name = node.constant.constant.value
66
66
  @class_stack.push(class_name)
67
67
 
68
- if class_name.end_with?("Test")
68
+ if @path && class_name.end_with?("Test")
69
69
  add_test_code_lens(
70
70
  node,
71
71
  name: class_name,
@@ -89,7 +89,7 @@ module RubyLsp
89
89
  visibility, _ = @visibility_stack.last
90
90
  if visibility == "public"
91
91
  method_name = node.name.value
92
- if method_name.start_with?("test_")
92
+ if @path && method_name.start_with?("test_")
93
93
  add_test_code_lens(
94
94
  node,
95
95
  name: method_name,
@@ -32,38 +32,6 @@ module RubyLsp
32
32
 
33
33
  ResponseType = type_member { { fixed: T::Array[Interface::DocumentSymbol] } }
34
34
 
35
- SYMBOL_KIND = T.let(
36
- {
37
- file: 1,
38
- module: 2,
39
- namespace: 3,
40
- package: 4,
41
- class: 5,
42
- method: 6,
43
- property: 7,
44
- field: 8,
45
- constructor: 9,
46
- enum: 10,
47
- interface: 11,
48
- function: 12,
49
- variable: 13,
50
- constant: 14,
51
- string: 15,
52
- number: 16,
53
- boolean: 17,
54
- array: 18,
55
- object: 19,
56
- key: 20,
57
- null: 21,
58
- enummember: 22,
59
- struct: 23,
60
- event: 24,
61
- operator: 25,
62
- typeparameter: 26,
63
- }.freeze,
64
- T::Hash[Symbol, Integer],
65
- )
66
-
67
35
  ATTR_ACCESSORS = T.let(["attr_reader", "attr_writer", "attr_accessor"].freeze, T::Array[String])
68
36
 
69
37
  class SymbolHierarchyRoot
@@ -92,6 +60,10 @@ module RubyLsp
92
60
  T::Array[T.any(SymbolHierarchyRoot, Interface::DocumentSymbol)],
93
61
  )
94
62
 
63
+ @external_listeners.concat(
64
+ Extension.extensions.filter_map { |ext| ext.create_document_symbol_listener(emitter, message_queue) },
65
+ )
66
+
95
67
  emitter.register(
96
68
  self,
97
69
  :on_class,
@@ -107,11 +79,18 @@ module RubyLsp
107
79
  )
108
80
  end
109
81
 
82
+ # Merges responses from other listeners
83
+ sig { override.params(other: Listener[ResponseType]).returns(T.self_type) }
84
+ def merge_response!(other)
85
+ @response.concat(other.response)
86
+ self
87
+ end
88
+
110
89
  sig { params(node: SyntaxTree::ClassDeclaration).void }
111
90
  def on_class(node)
112
91
  @stack << create_document_symbol(
113
92
  name: full_constant_name(node.constant),
114
- kind: :class,
93
+ kind: Constant::SymbolKind::CLASS,
115
94
  range_node: node,
116
95
  selection_range_node: node.constant,
117
96
  )
@@ -131,7 +110,7 @@ module RubyLsp
131
110
 
132
111
  create_document_symbol(
133
112
  name: argument.value.value,
134
- kind: :field,
113
+ kind: Constant::SymbolKind::FIELD,
135
114
  range_node: argument,
136
115
  selection_range_node: argument.value,
137
116
  )
@@ -142,7 +121,7 @@ module RubyLsp
142
121
  def on_const_path_field(node)
143
122
  create_document_symbol(
144
123
  name: node.constant.value,
145
- kind: :constant,
124
+ kind: Constant::SymbolKind::CONSTANT,
146
125
  range_node: node,
147
126
  selection_range_node: node.constant,
148
127
  )
@@ -154,10 +133,10 @@ module RubyLsp
154
133
 
155
134
  if target.is_a?(SyntaxTree::VarRef) && target.value.is_a?(SyntaxTree::Kw) && target.value.value == "self"
156
135
  name = "self.#{node.name.value}"
157
- kind = :method
136
+ kind = Constant::SymbolKind::METHOD
158
137
  else
159
138
  name = node.name.value
160
- kind = name == "initialize" ? :constructor : :method
139
+ kind = name == "initialize" ? Constant::SymbolKind::CONSTRUCTOR : Constant::SymbolKind::METHOD
161
140
  end
162
141
 
163
142
  symbol = create_document_symbol(
@@ -179,7 +158,7 @@ module RubyLsp
179
158
  def on_module(node)
180
159
  @stack << create_document_symbol(
181
160
  name: full_constant_name(node.constant),
182
- kind: :module,
161
+ kind: Constant::SymbolKind::MODULE,
183
162
  range_node: node,
184
163
  selection_range_node: node.constant,
185
164
  )
@@ -194,7 +173,7 @@ module RubyLsp
194
173
  def on_top_const_field(node)
195
174
  create_document_symbol(
196
175
  name: node.constant.value,
197
- kind: :constant,
176
+ kind: Constant::SymbolKind::CONSTANT,
198
177
  range_node: node,
199
178
  selection_range_node: node.constant,
200
179
  )
@@ -205,9 +184,9 @@ module RubyLsp
205
184
  value = node.value
206
185
  kind = case value
207
186
  when SyntaxTree::Const
208
- :constant
187
+ Constant::SymbolKind::CONSTANT
209
188
  when SyntaxTree::CVar, SyntaxTree::IVar
210
- :variable
189
+ Constant::SymbolKind::VARIABLE
211
190
  else
212
191
  return
213
192
  end
@@ -225,7 +204,7 @@ module RubyLsp
225
204
  sig do
226
205
  params(
227
206
  name: String,
228
- kind: Symbol,
207
+ kind: Integer,
229
208
  range_node: SyntaxTree::Node,
230
209
  selection_range_node: SyntaxTree::Node,
231
210
  ).returns(Interface::DocumentSymbol)
@@ -233,7 +212,7 @@ module RubyLsp
233
212
  def create_document_symbol(name:, kind:, range_node:, selection_range_node:)
234
213
  symbol = Interface::DocumentSymbol.new(
235
214
  name: name,
236
- kind: SYMBOL_KIND[kind],
215
+ kind: kind,
237
216
  range: range_from_syntax_tree_node(range_node),
238
217
  selection_range: range_from_syntax_tree_node(selection_range_node),
239
218
  children: [],
@@ -112,11 +112,12 @@ module RubyLsp
112
112
  next_line = @lines[@position[:line] + 1]
113
113
 
114
114
  if current_line.nil? || current_line.strip.empty?
115
- add_edit_with_text(" \n#{indents}end")
115
+ add_edit_with_text("\n")
116
+ add_edit_with_text("#{indents}end")
116
117
  move_cursor_to(@position[:line], @indentation + 2)
117
118
  elsif next_line.nil? || next_line.strip.empty?
118
- add_edit_with_text("#{indents}end", { line: @position[:line] + 1, character: @position[:character] })
119
- move_cursor_to(@position[:line], @indentation + 3)
119
+ add_edit_with_text("#{indents}end\n", { line: @position[:line] + 1, character: @position[:character] })
120
+ move_cursor_to(@position[:line] - 1, @indentation + @previous_line.size + 1)
120
121
  end
121
122
  end
122
123
 
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.9.1
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-08-28 00:00:00.000000000 Z
11
+ date: 2023-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: language_server-protocol