ruby-lsp 0.26.8 → 0.26.10
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 +0 -8
- data/exe/ruby-lsp-launcher +1 -4
- data/lib/ruby_lsp/addon.rb +19 -19
- data/lib/ruby_lsp/base_server.rb +2 -0
- data/lib/ruby_lsp/listeners/document_link.rb +17 -1
- data/lib/ruby_lsp/listeners/semantic_highlighting.rb +1 -1
- data/lib/ruby_lsp/requests/on_type_formatting.rb +4 -0
- data/lib/ruby_lsp/response_builders/semantic_highlighting.rb +3 -3
- data/lib/ruby_lsp/scripts/compose_bundle_windows.rb +0 -2
- data/lib/ruby_lsp/server.rb +18 -2
- data/lib/ruby_lsp/setup_bundler.rb +2 -5
- 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: 8c98cbc9dfd7d9b5bd299f9dc258841c7b3e3cc69fb58b537a9df8f4332332b3
|
|
4
|
+
data.tar.gz: b627dd5f43911a8b11b469998f1b7ed539a8651e87f80d13d3fe65ac0614ff0e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bbc993bf3cdfc2371d29b47812dbee2b39bab7b25bd8214be7fd289abff9c92f5eaa4b43d1da0f64c4e2f8170d616c260942e5e5adfa44a728a8573d059cd9fc
|
|
7
|
+
data.tar.gz: 2e3bb291df191f0ae3c71ccca73305852b93258468942e9cc5e1de29de36161bba4d0640941bb76a3bfdf2d7c8e80c99d599bf4dd930ce9342277e4731600398
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.26.
|
|
1
|
+
0.26.10
|
data/exe/ruby-lsp
CHANGED
|
@@ -21,13 +21,6 @@ parser = OptionParser.new do |opts|
|
|
|
21
21
|
options[:time_index] = true
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
-
opts.on(
|
|
25
|
-
"--branch [BRANCH]",
|
|
26
|
-
"Launch the Ruby LSP using the specified branch rather than the release version",
|
|
27
|
-
) do |branch|
|
|
28
|
-
options[:branch] = branch
|
|
29
|
-
end
|
|
30
|
-
|
|
31
24
|
opts.on("--doctor", "Run troubleshooting steps") do
|
|
32
25
|
options[:doctor] = true
|
|
33
26
|
end
|
|
@@ -70,7 +63,6 @@ if ENV["BUNDLE_GEMFILE"].nil?
|
|
|
70
63
|
flags = []
|
|
71
64
|
flags << "--debug" if options[:debug]
|
|
72
65
|
flags << "--beta" if options[:beta]
|
|
73
|
-
flags.push("--branch", options[:branch]) if options[:branch]
|
|
74
66
|
exit exec(Gem.ruby, File.expand_path("ruby-lsp-launcher", __dir__), *flags)
|
|
75
67
|
end
|
|
76
68
|
|
data/exe/ruby-lsp-launcher
CHANGED
|
@@ -20,10 +20,8 @@ reboot = false
|
|
|
20
20
|
workspace_uri = ARGV.first
|
|
21
21
|
raw_initialize_path = File.join(".ruby-lsp", "raw_initialize")
|
|
22
22
|
|
|
23
|
-
# Extract CLI options that affect bundle composition (e.g. --
|
|
23
|
+
# Extract CLI options that affect bundle composition (e.g. --beta) from the arguments passed by the server
|
|
24
24
|
cli_options = {}
|
|
25
|
-
branch_index = ARGV.index("--branch")
|
|
26
|
-
cli_options[:branch] = ARGV[branch_index + 1] if branch_index
|
|
27
25
|
cli_options[:beta] = true if ARGV.include?("--beta")
|
|
28
26
|
|
|
29
27
|
raw_initialize = if workspace_uri && !workspace_uri.start_with?("--")
|
|
@@ -57,7 +55,6 @@ pid = if Gem.win_platform?
|
|
|
57
55
|
|
|
58
56
|
cli_flags = []
|
|
59
57
|
cli_flags << "--beta" if cli_options[:beta]
|
|
60
|
-
cli_flags.push("--branch", cli_options[:branch]) if cli_options[:branch]
|
|
61
58
|
|
|
62
59
|
Process.spawn(
|
|
63
60
|
Gem.ruby,
|
data/lib/ruby_lsp/addon.rb
CHANGED
|
@@ -56,26 +56,9 @@ module RubyLsp
|
|
|
56
56
|
addon_files = Gem.find_files("ruby_lsp/**/addon.rb")
|
|
57
57
|
|
|
58
58
|
if include_project_addons
|
|
59
|
-
project_addons = Dir.glob("#{global_state.workspace_path}/**/ruby_lsp/**/addon.rb")
|
|
60
59
|
bundle_path = Bundler.bundle_path.to_s
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
# Create an array of rejection glob patterns to ignore add-ons already discovered through Gem.find_files if
|
|
64
|
-
# they are also copied inside the workspace for whatever reason. We received reports of projects having gems
|
|
65
|
-
# installed in vendor/bundle despite BUNDLE_PATH pointing elsewhere. Without this mechanism, we will
|
|
66
|
-
# double-require the same add-on, potentially for different versions of the same gem, which leads to incorrect
|
|
67
|
-
# behavior
|
|
68
|
-
reject_glob_patterns = addon_files.map do |path|
|
|
69
|
-
relative_gem_path = Pathname.new(path).relative_path_from(gems_dir)
|
|
70
|
-
first_part, *parts = relative_gem_path.to_s.split(File::SEPARATOR)
|
|
71
|
-
first_part&.gsub!(/-([0-9.]+)$/, "*")
|
|
72
|
-
"**/#{first_part}/#{parts.join("/")}"
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
project_addons.reject! do |path|
|
|
76
|
-
path.start_with?(bundle_path) ||
|
|
77
|
-
reject_glob_patterns.any? { |pattern| File.fnmatch?(pattern, path, File::Constants::FNM_PATHNAME) }
|
|
78
|
-
end
|
|
60
|
+
project_addons = Dir.glob("#{global_state.workspace_path}/**/ruby_lsp/**/addon.rb")
|
|
61
|
+
project_addons.reject! { |path| path.start_with?(bundle_path) || gem_installation_path?(path) }
|
|
79
62
|
|
|
80
63
|
addon_files.concat(project_addons)
|
|
81
64
|
end
|
|
@@ -162,6 +145,23 @@ module RubyLsp
|
|
|
162
145
|
"Add-on is not compatible with this version of the Ruby LSP. Skipping its activation"
|
|
163
146
|
end
|
|
164
147
|
end
|
|
148
|
+
|
|
149
|
+
private
|
|
150
|
+
|
|
151
|
+
# Checks if a path appears to be inside a versioned gem installation directory (e.g., `rubocop-1.73.0/lib/...`) by
|
|
152
|
+
# looking for a directory segment matching `name-version` before the `lib` component
|
|
153
|
+
#
|
|
154
|
+
#: (String path) -> bool
|
|
155
|
+
def gem_installation_path?(path)
|
|
156
|
+
parts = path.split(%r{[/\\]})
|
|
157
|
+
lib_index = parts.rindex("lib")
|
|
158
|
+
return false unless lib_index
|
|
159
|
+
|
|
160
|
+
prefix = parts[0...lib_index] #: Array[String]?
|
|
161
|
+
return false unless prefix
|
|
162
|
+
|
|
163
|
+
prefix.any? { |part| part.match?(/-\d+(\.\d+)+$/) }
|
|
164
|
+
end
|
|
165
165
|
end
|
|
166
166
|
|
|
167
167
|
#: -> void
|
data/lib/ruby_lsp/base_server.rb
CHANGED
|
@@ -74,6 +74,8 @@ module RubyLsp
|
|
|
74
74
|
)
|
|
75
75
|
end
|
|
76
76
|
end
|
|
77
|
+
rescue URI::Error
|
|
78
|
+
# A client can send a document URI with a scheme Ruby's URI parser rejects, so we don't want to fail
|
|
77
79
|
rescue Store::NonExistingDocumentError
|
|
78
80
|
# If we receive a request for a file that no longer exists, we don't want to fail
|
|
79
81
|
end
|
|
@@ -21,6 +21,8 @@ module RubyLsp
|
|
|
21
21
|
|
|
22
22
|
Gem::Specification.stubs.each do |stub|
|
|
23
23
|
spec = stub.to_spec
|
|
24
|
+
next unless spec
|
|
25
|
+
|
|
24
26
|
lookup[spec.name] = {}
|
|
25
27
|
lookup[spec.name][spec.version.to_s] = {}
|
|
26
28
|
|
|
@@ -31,6 +33,8 @@ module RubyLsp
|
|
|
31
33
|
|
|
32
34
|
Gem::Specification.default_stubs.each do |stub|
|
|
33
35
|
spec = stub.to_spec
|
|
36
|
+
next unless spec
|
|
37
|
+
|
|
34
38
|
lookup[spec.name] = {}
|
|
35
39
|
lookup[spec.name][spec.version.to_s] = {}
|
|
36
40
|
prefix_matchers = Regexp.union(spec.require_paths.map do |rp|
|
|
@@ -60,6 +64,7 @@ module RubyLsp
|
|
|
60
64
|
@lines_to_comments = comments.to_h do |comment|
|
|
61
65
|
[comment.location.end_line, comment]
|
|
62
66
|
end #: Hash[Integer, Prism::Comment]
|
|
67
|
+
@sig_comments = {} #: Hash[Integer, Prism::Comment]
|
|
63
68
|
|
|
64
69
|
dispatcher.register(
|
|
65
70
|
self,
|
|
@@ -68,9 +73,20 @@ module RubyLsp
|
|
|
68
73
|
:on_module_node_enter,
|
|
69
74
|
:on_constant_write_node_enter,
|
|
70
75
|
:on_constant_path_write_node_enter,
|
|
76
|
+
:on_call_node_enter,
|
|
71
77
|
)
|
|
72
78
|
end
|
|
73
79
|
|
|
80
|
+
#: (Prism::CallNode node) -> void
|
|
81
|
+
def on_call_node_enter(node)
|
|
82
|
+
return unless node.name == :sig
|
|
83
|
+
|
|
84
|
+
comment = @lines_to_comments[node.location.start_line - 1]
|
|
85
|
+
return unless comment
|
|
86
|
+
|
|
87
|
+
@sig_comments[node.location.end_line] = comment
|
|
88
|
+
end
|
|
89
|
+
|
|
74
90
|
#: (Prism::DefNode node) -> void
|
|
75
91
|
def on_def_node_enter(node)
|
|
76
92
|
extract_document_link(node)
|
|
@@ -100,7 +116,7 @@ module RubyLsp
|
|
|
100
116
|
|
|
101
117
|
#: (Prism::Node node) -> void
|
|
102
118
|
def extract_document_link(node)
|
|
103
|
-
comment = @lines_to_comments[node.location.start_line - 1]
|
|
119
|
+
comment = @lines_to_comments[node.location.start_line - 1] || @sig_comments[node.location.start_line - 1]
|
|
104
120
|
return unless comment
|
|
105
121
|
|
|
106
122
|
match = comment.location.slice.match(%r{(source://.*#\d+|pkg:gem/.*#.*)$})
|
|
@@ -162,7 +162,7 @@ module RubyLsp
|
|
|
162
162
|
|
|
163
163
|
#: (Prism::SelfNode node) -> void
|
|
164
164
|
def on_self_node_enter(node)
|
|
165
|
-
@response_builder.add_token(node.location, :variable, [:
|
|
165
|
+
@response_builder.add_token(node.location, :variable, [:defaultLibrary])
|
|
166
166
|
end
|
|
167
167
|
|
|
168
168
|
#: (Prism::LocalVariableWriteNode node) -> void
|
|
@@ -120,6 +120,10 @@ module RubyLsp
|
|
|
120
120
|
|
|
121
121
|
return unless END_REGEXES.any? { |regex| regex.match?(@previous_line) }
|
|
122
122
|
|
|
123
|
+
# Endless method definitions (e.g., `def foo = 42`) are complete statements
|
|
124
|
+
# and should not have `end` added
|
|
125
|
+
return if @previous_line.match?(/\bdef\s+[\w.]+[!?=]?(\([^)]*\))?\s*=[^=~>]/)
|
|
126
|
+
|
|
123
127
|
indents = " " * @indentation
|
|
124
128
|
current_line = @lines[@position[:line]]
|
|
125
129
|
next_line = @lines[@position[:line] + 1]
|
|
@@ -43,7 +43,7 @@ module RubyLsp
|
|
|
43
43
|
async: 6,
|
|
44
44
|
modification: 7,
|
|
45
45
|
documentation: 8,
|
|
46
|
-
|
|
46
|
+
defaultLibrary: 9,
|
|
47
47
|
}.freeze #: Hash[Symbol, Integer]
|
|
48
48
|
|
|
49
49
|
#: ((^(Integer arg0) -> Integer | Prism::CodeUnitsCache) code_units_cache) -> void
|
|
@@ -184,8 +184,8 @@ module RubyLsp
|
|
|
184
184
|
end
|
|
185
185
|
|
|
186
186
|
# Encode an array of modifiers to positions onto a bit flag
|
|
187
|
-
# For example, [:
|
|
188
|
-
# 0b1000000000, as :
|
|
187
|
+
# For example, [:defaultLibrary] will be encoded as
|
|
188
|
+
# 0b1000000000, as :defaultLibrary is the 10th bit according
|
|
189
189
|
# to the token modifiers index map.
|
|
190
190
|
#: (Array[Integer] modifiers) -> Integer
|
|
191
191
|
def encode_modifiers(modifiers)
|
|
@@ -7,6 +7,4 @@ require_relative "compose_bundle"
|
|
|
7
7
|
# invoke the compose method from inside a forked process
|
|
8
8
|
options = {}
|
|
9
9
|
options[:beta] = true if ARGV.include?("--beta")
|
|
10
|
-
branch_index = ARGV.index("--branch")
|
|
11
|
-
options[:branch] = ARGV[branch_index + 1] if branch_index
|
|
12
10
|
compose(ARGV.first, **options)
|
data/lib/ruby_lsp/server.rb
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
|
|
4
4
|
module RubyLsp
|
|
5
5
|
class Server < BaseServer
|
|
6
|
+
NON_REPORTABLE_SETUP_ERRORS = [
|
|
7
|
+
Bundler::GemNotFound,
|
|
8
|
+
Bundler::GitError,
|
|
9
|
+
Bundler::Dsl::DSLError,
|
|
10
|
+
].freeze #: Array[singleton(StandardError)]
|
|
11
|
+
|
|
6
12
|
# Only for testing
|
|
7
13
|
#: GlobalState
|
|
8
14
|
attr_reader :global_state
|
|
@@ -118,6 +124,16 @@ module RubyLsp
|
|
|
118
124
|
@global_state.synchronize { @cancelled_requests << message[:params][:id] }
|
|
119
125
|
when nil
|
|
120
126
|
process_response(message) if message[:result]
|
|
127
|
+
else
|
|
128
|
+
id = message[:id]
|
|
129
|
+
|
|
130
|
+
if id
|
|
131
|
+
send_message(Error.new(
|
|
132
|
+
id: id,
|
|
133
|
+
code: Constant::ErrorCodes::METHOD_NOT_FOUND,
|
|
134
|
+
message: "Method not found: #{message[:method]}",
|
|
135
|
+
))
|
|
136
|
+
end
|
|
121
137
|
end
|
|
122
138
|
rescue DelegateRequestError
|
|
123
139
|
send_message(Error.new(id: message[:id], code: DelegateRequestError::CODE, message: "DELEGATE_REQUEST"))
|
|
@@ -315,7 +331,7 @@ module RubyLsp
|
|
|
315
331
|
|
|
316
332
|
global_state_notifications.each { |notification| send_message(notification) }
|
|
317
333
|
|
|
318
|
-
if @setup_error
|
|
334
|
+
if @setup_error && NON_REPORTABLE_SETUP_ERRORS.none? { |error_class| @setup_error.is_a?(error_class) }
|
|
319
335
|
send_message(Notification.telemetry(
|
|
320
336
|
type: "error",
|
|
321
337
|
errorMessage: @setup_error.message,
|
|
@@ -1211,7 +1227,7 @@ module RubyLsp
|
|
|
1211
1227
|
}
|
|
1212
1228
|
end
|
|
1213
1229
|
end
|
|
1214
|
-
rescue Bundler::GemNotFound, Bundler::GemfileNotFound
|
|
1230
|
+
rescue Bundler::GemNotFound, Bundler::GemfileNotFound, Errno::ENOENT
|
|
1215
1231
|
[]
|
|
1216
1232
|
end
|
|
1217
1233
|
|
|
@@ -39,7 +39,6 @@ module RubyLsp
|
|
|
39
39
|
#: (String project_path, **untyped options) -> void
|
|
40
40
|
def initialize(project_path, **options)
|
|
41
41
|
@project_path = project_path
|
|
42
|
-
@branch = options[:branch] #: String?
|
|
43
42
|
@launcher = options[:launcher] #: bool?
|
|
44
43
|
@beta = options[:beta] #: bool?
|
|
45
44
|
force_output_to_stderr! if @launcher
|
|
@@ -178,9 +177,7 @@ module RubyLsp
|
|
|
178
177
|
|
|
179
178
|
unless @dependencies["ruby-lsp"]
|
|
180
179
|
version = @beta ? "0.a" : RUBY_LSP_MIN_VERSION
|
|
181
|
-
|
|
182
|
-
ruby_lsp_entry << ", github: \"Shopify/ruby-lsp\", branch: \"#{@branch}\"" if @branch
|
|
183
|
-
parts << ruby_lsp_entry
|
|
180
|
+
parts << "gem \"ruby-lsp\", \">= #{version}\", require: false, group: :development"
|
|
184
181
|
end
|
|
185
182
|
|
|
186
183
|
unless @dependencies["debug"]
|
|
@@ -448,7 +445,7 @@ module RubyLsp
|
|
|
448
445
|
requirement = Gem::Requirement.new(@bundler_version.to_s)
|
|
449
446
|
return if Gem::Specification.any? { |s| s.name == "bundler" && requirement =~ s.version }
|
|
450
447
|
|
|
451
|
-
Gem.install("bundler", @bundler_version.to_s)
|
|
448
|
+
Gem.install("bundler", @bundler_version.to_s, env_shebang: true)
|
|
452
449
|
end
|
|
453
450
|
|
|
454
451
|
#: -> bool
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ruby-lsp
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.26.
|
|
4
|
+
version: 0.26.10
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Shopify
|
|
@@ -203,7 +203,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
203
203
|
- !ruby/object:Gem::Version
|
|
204
204
|
version: '0'
|
|
205
205
|
requirements: []
|
|
206
|
-
rubygems_version: 4.0.
|
|
206
|
+
rubygems_version: 4.0.10
|
|
207
207
|
specification_version: 4
|
|
208
208
|
summary: An opinionated language server for Ruby
|
|
209
209
|
test_files: []
|