ruby-lsp 0.3.6 → 0.3.8

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.
@@ -34,12 +34,12 @@ module RubyLsp
34
34
  def matched_highlight(other)
35
35
  case @node
36
36
  # Method definitions and invocations
37
- when SyntaxTree::VCall, SyntaxTree::FCall, SyntaxTree::Call, SyntaxTree::Command,
38
- SyntaxTree::CommandCall, SyntaxTree::Def, SyntaxTree::Defs, SyntaxTree::DefEndless
37
+ when SyntaxTree::VCall, SyntaxTree::CallNode, SyntaxTree::Command,
38
+ SyntaxTree::CommandCall, SyntaxTree::DefNode
39
39
  case other
40
- when SyntaxTree::VCall, SyntaxTree::FCall, SyntaxTree::Call, SyntaxTree::Command, SyntaxTree::CommandCall
40
+ when SyntaxTree::VCall, SyntaxTree::CallNode, SyntaxTree::Command, SyntaxTree::CommandCall
41
41
  HighlightMatch.new(type: READ, node: other)
42
- when SyntaxTree::Def, SyntaxTree::Defs, SyntaxTree::Defs
42
+ when SyntaxTree::DefNode
43
43
  HighlightMatch.new(type: WRITE, node: other.name)
44
44
  end
45
45
  # Variables, parameters and constants
@@ -67,15 +67,14 @@ module RubyLsp
67
67
  case node
68
68
  when SyntaxTree::ConstPathRef, SyntaxTree::ConstPathField, SyntaxTree::TopConstField
69
69
  node.constant.value
70
- when SyntaxTree::GVar, SyntaxTree::IVar, SyntaxTree::Const, SyntaxTree::CVar, SyntaxTree::Ident,
71
- SyntaxTree::ArgsForward
70
+ when SyntaxTree::GVar, SyntaxTree::IVar, SyntaxTree::Const, SyntaxTree::CVar, SyntaxTree::Ident
72
71
  node.value
73
- when SyntaxTree::Field, SyntaxTree::Def, SyntaxTree::Defs, SyntaxTree::DefEndless, SyntaxTree::RestParam,
72
+ when SyntaxTree::Field, SyntaxTree::DefNode, SyntaxTree::RestParam,
74
73
  SyntaxTree::KwRestParam, SyntaxTree::BlockArg
75
74
  node.name&.value
76
- when SyntaxTree::VarField, SyntaxTree::VarRef, SyntaxTree::VCall, SyntaxTree::FCall
75
+ when SyntaxTree::VarField, SyntaxTree::VarRef, SyntaxTree::VCall
77
76
  node.value&.value
78
- when SyntaxTree::Call, SyntaxTree::Command, SyntaxTree::CommandCall
77
+ when SyntaxTree::CallNode, SyntaxTree::Command, SyntaxTree::CommandCall
79
78
  message = node.message
80
79
  message != :call ? message.value : nil
81
80
  when SyntaxTree::ClassDeclaration, SyntaxTree::ModuleDeclaration
@@ -10,8 +10,14 @@ module RubyLsp
10
10
  RAILS_DOC_HOST = "https://api.rubyonrails.org"
11
11
  SUPPORTED_RAILS_DOC_NAMESPACES = T.let(
12
12
  Regexp.union(
13
- /ActionDispatch/, /ActionController/, /AbstractController/, /ActiveRecord/, /ActiveModel/, /ActiveStorage/,
14
- /ActionText/, /ActiveJob/
13
+ /ActionDispatch/,
14
+ /ActionController/,
15
+ /AbstractController/,
16
+ /ActiveRecord/,
17
+ /ActiveModel/,
18
+ /ActiveStorage/,
19
+ /ActionText/,
20
+ /ActiveJob/,
15
21
  ).freeze,
16
22
  Regexp,
17
23
  )
@@ -19,7 +25,8 @@ module RubyLsp
19
25
  RAILTIES_VERSION = T.let(
20
26
  [*::Gem::Specification.default_stubs, *::Gem::Specification.stubs].find do |s|
21
27
  s.name == "railties"
22
- end&.version&.to_s, T.nilable(String)
28
+ end&.version&.to_s,
29
+ T.nilable(String),
23
30
  )
24
31
 
25
32
  class << self
@@ -59,7 +66,7 @@ module RubyLsp
59
66
  private def build_search_index
60
67
  return unless RAILTIES_VERSION
61
68
 
62
- $stderr.puts "Fetching Rails Documents..."
69
+ warn("Fetching Rails Documents...")
63
70
  # If the version's doc is not found, e.g. Rails main, it'll be redirected
64
71
  # In this case, we just fetch the latest doc
65
72
  response = if Gem::Version.new(RAILTIES_VERSION).prerelease?
@@ -71,11 +78,11 @@ module RubyLsp
71
78
  if response.code == "200"
72
79
  process_search_index(response.body)
73
80
  else
74
- $stderr.puts("Response failed: #{response.inspect}")
81
+ warn("Response failed: #{response.inspect}")
75
82
  nil
76
83
  end
77
84
  rescue StandardError => e
78
- $stderr.puts("Exception occurred when fetching Rails document index: #{e.inspect}")
85
+ warn("Exception occurred when fetching Rails document index: #{e.inspect}")
79
86
  end
80
87
 
81
88
  sig { params(js: String).returns(T::Hash[String, T::Array[T::Hash[Symbol, String]]]) }
@@ -7,14 +7,17 @@ module RubyLsp
7
7
  class RuboCopDiagnostic
8
8
  extend T::Sig
9
9
 
10
- RUBOCOP_TO_LSP_SEVERITY = T.let({
11
- convention: LanguageServer::Protocol::Constant::DiagnosticSeverity::INFORMATION,
12
- info: LanguageServer::Protocol::Constant::DiagnosticSeverity::INFORMATION,
13
- refactor: LanguageServer::Protocol::Constant::DiagnosticSeverity::INFORMATION,
14
- warning: LanguageServer::Protocol::Constant::DiagnosticSeverity::WARNING,
15
- error: LanguageServer::Protocol::Constant::DiagnosticSeverity::ERROR,
16
- fatal: LanguageServer::Protocol::Constant::DiagnosticSeverity::ERROR,
17
- }.freeze, T::Hash[Symbol, Integer])
10
+ RUBOCOP_TO_LSP_SEVERITY = T.let(
11
+ {
12
+ convention: LanguageServer::Protocol::Constant::DiagnosticSeverity::INFORMATION,
13
+ info: LanguageServer::Protocol::Constant::DiagnosticSeverity::INFORMATION,
14
+ refactor: LanguageServer::Protocol::Constant::DiagnosticSeverity::INFORMATION,
15
+ warning: LanguageServer::Protocol::Constant::DiagnosticSeverity::WARNING,
16
+ error: LanguageServer::Protocol::Constant::DiagnosticSeverity::ERROR,
17
+ fatal: LanguageServer::Protocol::Constant::DiagnosticSeverity::ERROR,
18
+ }.freeze,
19
+ T::Hash[Symbol, Integer],
20
+ )
18
21
 
19
22
  sig { returns(T::Array[LanguageServer::Protocol::Interface::TextEdit]) }
20
23
  attr_reader :replacements
@@ -94,8 +97,10 @@ module RubyLsp
94
97
  LanguageServer::Protocol::Interface::TextEdit.new(
95
98
  range: LanguageServer::Protocol::Interface::Range.new(
96
99
  start: LanguageServer::Protocol::Interface::Position.new(line: range.line - 1, character: range.column),
97
- end: LanguageServer::Protocol::Interface::Position.new(line: range.last_line - 1,
98
- character: range.last_column),
100
+ end: LanguageServer::Protocol::Interface::Position.new(
101
+ line: range.last_line - 1,
102
+ character: range.last_column,
103
+ ),
99
104
  ),
100
105
  new_text: replacement,
101
106
  )
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require "ruby_lsp/requests/support/rubocop_runner"
5
- return unless defined?(::RubyLsp::Requests::Support::RuboCopRunner)
5
+ return unless defined?(RubyLsp::Requests::Support::RuboCopRunner)
6
6
 
7
7
  require "cgi"
8
8
  require "singleton"
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require "ruby_lsp/requests/support/rubocop_runner"
5
- return unless defined?(::RubyLsp::Requests::Support::RuboCopRunner)
5
+ return unless defined?(RubyLsp::Requests::Support::RuboCopRunner)
6
6
 
7
7
  require "cgi"
8
8
  require "singleton"
@@ -25,12 +25,15 @@ module RubyLsp
25
25
  sig { returns(T::Array[RuboCop::Cop::Offense]) }
26
26
  attr_reader :offenses
27
27
 
28
- DEFAULT_ARGS = T.let([
29
- "--stderr", # Print any output to stderr so that our stdout does not get polluted
30
- "--force-exclusion",
31
- "--format",
32
- "RuboCop::Formatter::BaseFormatter", # Suppress any output by using the base formatter
33
- ].freeze, T::Array[String])
28
+ DEFAULT_ARGS = T.let(
29
+ [
30
+ "--stderr", # Print any output to stderr so that our stdout does not get polluted
31
+ "--force-exclusion",
32
+ "--format",
33
+ "RuboCop::Formatter::BaseFormatter", # Suppress any output by using the base formatter
34
+ ].freeze,
35
+ T::Array[String],
36
+ )
34
37
 
35
38
  sig { params(args: String).void }
36
39
  def initialize(*args)
@@ -8,13 +8,16 @@ module URI
8
8
  class Source < URI::File
9
9
  extend T::Sig
10
10
 
11
- COMPONENT = T.let([
12
- :scheme,
13
- :gem_name,
14
- :gem_version,
15
- :path,
16
- :line_number,
17
- ].freeze, T::Array[Symbol])
11
+ COMPONENT = T.let(
12
+ [
13
+ :scheme,
14
+ :gem_name,
15
+ :gem_version,
16
+ :path,
17
+ :line_number,
18
+ ].freeze,
19
+ T::Array[Symbol],
20
+ )
18
21
 
19
22
  T.unsafe(self).alias_method(:gem_name, :host)
20
23
  T.unsafe(self).alias_method(:line_number, :fragment)
@@ -7,6 +7,8 @@ module RubyLsp
7
7
  Handler.start do
8
8
  on("initialize") do |request|
9
9
  store.clear
10
+ store.encoding = request.dig(:params, :capabilities, :general, :positionEncodings)
11
+
10
12
  initialization_options = request.dig(:params, :initializationOptions)
11
13
  enabled_features = initialization_options.fetch(:enabledFeatures, [])
12
14
 
@@ -38,10 +40,8 @@ module RubyLsp
38
40
  token_types: Requests::SemanticHighlighting::TOKEN_TYPES.keys,
39
41
  token_modifiers: Requests::SemanticHighlighting::TOKEN_MODIFIERS.keys,
40
42
  ),
41
- range: false,
42
- full: {
43
- delta: true,
44
- },
43
+ range: true,
44
+ full: { delta: false },
45
45
  )
46
46
  end
47
47
 
@@ -168,6 +168,19 @@ module RubyLsp
168
168
  end
169
169
  end
170
170
 
171
+ on("textDocument/semanticTokens/range", parallel: true) do |request|
172
+ document = store.get(request.dig(:params, :textDocument, :uri))
173
+ range = request.dig(:params, :range)
174
+ start_line = range.dig(:start, :line)
175
+ end_line = range.dig(:end, :line)
176
+
177
+ Requests::SemanticHighlighting.new(
178
+ document,
179
+ range: start_line..end_line,
180
+ encoder: Requests::Support::SemanticTokenEncoder.new,
181
+ ).run
182
+ end
183
+
171
184
  on("textDocument/formatting", parallel: true) do |request|
172
185
  uri = request.dig(:params, :textDocument, :uri)
173
186
 
@@ -192,13 +205,12 @@ module RubyLsp
192
205
 
193
206
  on("textDocument/codeAction", parallel: true) do |request|
194
207
  uri = request.dig(:params, :textDocument, :uri)
208
+ document = store.get(uri)
195
209
  range = request.dig(:params, :range)
196
210
  start_line = range.dig(:start, :line)
197
211
  end_line = range.dig(:end, :line)
198
212
 
199
- store.cache_fetch(uri, :code_actions) do |document|
200
- Requests::CodeActions.new(uri, document, start_line..end_line).run
201
- end
213
+ Requests::CodeActions.new(uri, document, start_line..end_line).run
202
214
  end
203
215
 
204
216
  on("textDocument/inlayHint", parallel: true) do |request|
@@ -9,9 +9,13 @@ module RubyLsp
9
9
  class Store
10
10
  extend T::Sig
11
11
 
12
+ sig { params(encoding: String).void }
13
+ attr_writer :encoding
14
+
12
15
  sig { void }
13
16
  def initialize
14
17
  @state = T.let({}, T::Hash[String, Document])
18
+ @encoding = T.let("utf-8", String)
15
19
  end
16
20
 
17
21
  sig { params(uri: String).returns(Document) }
@@ -25,7 +29,7 @@ module RubyLsp
25
29
 
26
30
  sig { params(uri: String, content: String).void }
27
31
  def set(uri, content)
28
- document = Document.new(content)
32
+ document = Document.new(content, @encoding)
29
33
  @state[uri] = document
30
34
  end
31
35
 
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.3.6
4
+ version: 0.3.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-11-11 00:00:00.000000000 Z
11
+ date: 2023-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: language_server-protocol
@@ -44,20 +44,20 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 4.0.2
47
+ version: 5.0.0
48
48
  - - "<"
49
49
  - !ruby/object:Gem::Version
50
- version: 5.0.0
50
+ version: '6'
51
51
  type: :runtime
52
52
  prerelease: false
53
53
  version_requirements: !ruby/object:Gem::Requirement
54
54
  requirements:
55
55
  - - ">="
56
56
  - !ruby/object:Gem::Version
57
- version: 4.0.2
57
+ version: 5.0.0
58
58
  - - "<"
59
59
  - !ruby/object:Gem::Version
60
- version: 5.0.0
60
+ version: '6'
61
61
  description: An opinionated language server for Ruby
62
62
  email:
63
63
  - ruby@shopify.com