ruby-lsp 0.17.16 → 0.18.0
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/README.md +4 -110
- data/VERSION +1 -1
- data/exe/ruby-lsp +10 -8
- data/lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb +14 -6
- data/lib/ruby_indexer/lib/ruby_indexer/entry.rb +157 -27
- data/lib/ruby_indexer/lib/ruby_indexer/index.rb +31 -12
- data/lib/ruby_indexer/lib/ruby_indexer/rbs_indexer.rb +2 -2
- data/lib/ruby_indexer/test/classes_and_modules_test.rb +10 -10
- data/lib/ruby_indexer/test/constant_test.rb +4 -4
- data/lib/ruby_indexer/test/enhancements_test.rb +2 -2
- data/lib/ruby_indexer/test/index_test.rb +41 -0
- data/lib/ruby_indexer/test/method_test.rb +257 -2
- data/lib/ruby_indexer/test/rbs_indexer_test.rb +1 -1
- data/lib/ruby_lsp/addon.rb +3 -2
- data/lib/ruby_lsp/base_server.rb +21 -1
- data/lib/ruby_lsp/document.rb +5 -3
- data/lib/ruby_lsp/erb_document.rb +29 -10
- data/lib/ruby_lsp/global_state.rb +15 -1
- data/lib/ruby_lsp/listeners/code_lens.rb +34 -5
- data/lib/ruby_lsp/listeners/folding_ranges.rb +1 -1
- data/lib/ruby_lsp/listeners/semantic_highlighting.rb +28 -0
- data/lib/ruby_lsp/listeners/signature_help.rb +55 -24
- data/lib/ruby_lsp/rbs_document.rb +5 -4
- data/lib/ruby_lsp/requests/code_action_resolve.rb +0 -15
- data/lib/ruby_lsp/requests/code_actions.rb +0 -10
- data/lib/ruby_lsp/requests/code_lens.rb +1 -11
- data/lib/ruby_lsp/requests/completion.rb +3 -20
- data/lib/ruby_lsp/requests/completion_resolve.rb +0 -8
- data/lib/ruby_lsp/requests/definition.rb +6 -20
- data/lib/ruby_lsp/requests/diagnostics.rb +0 -10
- data/lib/ruby_lsp/requests/document_highlight.rb +7 -14
- data/lib/ruby_lsp/requests/document_link.rb +0 -10
- data/lib/ruby_lsp/requests/document_symbol.rb +0 -17
- data/lib/ruby_lsp/requests/folding_ranges.rb +0 -10
- data/lib/ruby_lsp/requests/formatting.rb +3 -17
- data/lib/ruby_lsp/requests/hover.rb +9 -9
- data/lib/ruby_lsp/requests/inlay_hints.rb +0 -30
- data/lib/ruby_lsp/requests/on_type_formatting.rb +0 -10
- data/lib/ruby_lsp/requests/prepare_type_hierarchy.rb +0 -11
- data/lib/ruby_lsp/requests/request.rb +17 -1
- data/lib/ruby_lsp/requests/selection_ranges.rb +0 -10
- data/lib/ruby_lsp/requests/semantic_highlighting.rb +1 -23
- data/lib/ruby_lsp/requests/show_syntax_tree.rb +0 -11
- data/lib/ruby_lsp/requests/signature_help.rb +5 -20
- data/lib/ruby_lsp/requests/support/common.rb +1 -1
- data/lib/ruby_lsp/requests/support/rubocop_runner.rb +2 -0
- data/lib/ruby_lsp/requests/type_hierarchy_supertypes.rb +0 -11
- data/lib/ruby_lsp/requests/workspace_symbol.rb +0 -12
- data/lib/ruby_lsp/ruby_document.rb +4 -3
- data/lib/ruby_lsp/server.rb +23 -8
- data/lib/ruby_lsp/setup_bundler.rb +31 -13
- data/lib/ruby_lsp/type_inferrer.rb +6 -2
- data/lib/ruby_lsp/utils.rb +11 -1
- metadata +7 -14
- data/lib/ruby_lsp/check_docs.rb +0 -130
@@ -5,16 +5,8 @@ require "ruby_lsp/listeners/hover"
|
|
5
5
|
|
6
6
|
module RubyLsp
|
7
7
|
module Requests
|
8
|
-
# 
|
9
|
-
#
|
10
8
|
# The [hover request](https://microsoft.github.io/language-server-protocol/specification#textDocument_hover)
|
11
9
|
# displays the documentation for the symbol currently under the cursor.
|
12
|
-
#
|
13
|
-
# # Example
|
14
|
-
#
|
15
|
-
# ```ruby
|
16
|
-
# String # -> Hovering over the class reference will show all declaration locations and the documentation
|
17
|
-
# ```
|
18
10
|
class Hover < Request
|
19
11
|
extend T::Sig
|
20
12
|
extend T::Generic
|
@@ -41,7 +33,15 @@ module RubyLsp
|
|
41
33
|
end
|
42
34
|
def initialize(document, global_state, position, dispatcher, sorbet_level)
|
43
35
|
super()
|
44
|
-
|
36
|
+
|
37
|
+
char_position = document.create_scanner.find_char_position(position)
|
38
|
+
delegate_request_if_needed!(global_state, document, char_position)
|
39
|
+
|
40
|
+
node_context = RubyDocument.locate(
|
41
|
+
document.parse_result.value,
|
42
|
+
char_position,
|
43
|
+
node_types: Listeners::Hover::ALLOWED_TARGETS,
|
44
|
+
)
|
45
45
|
target = node_context.node
|
46
46
|
parent = node_context.parent
|
47
47
|
|
@@ -5,39 +5,9 @@ require "ruby_lsp/listeners/inlay_hints"
|
|
5
5
|
|
6
6
|
module RubyLsp
|
7
7
|
module Requests
|
8
|
-
# 
|
9
|
-
#
|
10
8
|
# [Inlay hints](https://microsoft.github.io/language-server-protocol/specification#textDocument_inlayHint)
|
11
9
|
# are labels added directly in the code that explicitly show the user something that might
|
12
10
|
# otherwise just be implied.
|
13
|
-
#
|
14
|
-
# # Configuration
|
15
|
-
#
|
16
|
-
# To enable rescue hints, set `rubyLsp.featuresConfiguration.inlayHint.implicitRescue` to `true`.
|
17
|
-
#
|
18
|
-
# To enable hash value hints, set `rubyLsp.featuresConfiguration.inlayHint.implicitHashValue` to `true`.
|
19
|
-
#
|
20
|
-
# To enable all hints, set `rubyLsp.featuresConfiguration.inlayHint.enableAll` to `true`.
|
21
|
-
#
|
22
|
-
# # Example
|
23
|
-
#
|
24
|
-
# ```ruby
|
25
|
-
# begin
|
26
|
-
# puts "do something that might raise"
|
27
|
-
# rescue # Label "StandardError" goes here as a bare rescue implies rescuing StandardError
|
28
|
-
# puts "handle some rescue"
|
29
|
-
# end
|
30
|
-
# ```
|
31
|
-
#
|
32
|
-
# # Example
|
33
|
-
#
|
34
|
-
# ```ruby
|
35
|
-
# var = "foo"
|
36
|
-
# {
|
37
|
-
# var: var, # Label "var" goes here in cases where the value is omitted
|
38
|
-
# a: "hello",
|
39
|
-
# }
|
40
|
-
# ```
|
41
11
|
class InlayHints < Request
|
42
12
|
extend T::Sig
|
43
13
|
|
@@ -3,18 +3,8 @@
|
|
3
3
|
|
4
4
|
module RubyLsp
|
5
5
|
module Requests
|
6
|
-
# 
|
7
|
-
#
|
8
6
|
# The [on type formatting](https://microsoft.github.io/language-server-protocol/specification#textDocument_onTypeFormatting)
|
9
7
|
# request formats code as the user is typing. For example, automatically adding `end` to class definitions.
|
10
|
-
#
|
11
|
-
# # Example
|
12
|
-
#
|
13
|
-
# ```ruby
|
14
|
-
# class Foo # <-- upon adding a line break, on type formatting is triggered
|
15
|
-
# # <-- cursor ends up here
|
16
|
-
# end # <-- end is automatically added
|
17
|
-
# ```
|
18
8
|
class OnTypeFormatting < Request
|
19
9
|
extend T::Sig
|
20
10
|
|
@@ -3,22 +3,11 @@
|
|
3
3
|
|
4
4
|
module RubyLsp
|
5
5
|
module Requests
|
6
|
-
# 
|
7
|
-
#
|
8
6
|
# The [prepare type hierarchy
|
9
7
|
# request](https://microsoft.github.io/language-server-protocol/specification#textDocument_prepareTypeHierarchy)
|
10
8
|
# displays the list of ancestors (supertypes) and descendants (subtypes) for the selected type.
|
11
9
|
#
|
12
10
|
# Currently only supports supertypes due to a limitation of the index.
|
13
|
-
#
|
14
|
-
# # Example
|
15
|
-
#
|
16
|
-
# ```ruby
|
17
|
-
# class Foo; end
|
18
|
-
# class Bar < Foo; end
|
19
|
-
#
|
20
|
-
# puts Bar # <-- right click on `Bar` and select "Show Type Hierarchy"
|
21
|
-
# ```
|
22
11
|
class PrepareTypeHierarchy < Request
|
23
12
|
extend T::Sig
|
24
13
|
|
@@ -3,7 +3,6 @@
|
|
3
3
|
|
4
4
|
module RubyLsp
|
5
5
|
module Requests
|
6
|
-
# :nodoc:
|
7
6
|
class Request
|
8
7
|
extend T::Sig
|
9
8
|
extend T::Generic
|
@@ -17,6 +16,23 @@ module RubyLsp
|
|
17
16
|
|
18
17
|
private
|
19
18
|
|
19
|
+
# Signals to the client that the request should be delegated to the language server server for the host language
|
20
|
+
# in ERB files
|
21
|
+
sig do
|
22
|
+
params(
|
23
|
+
global_state: GlobalState,
|
24
|
+
document: Document[T.untyped],
|
25
|
+
char_position: Integer,
|
26
|
+
).void
|
27
|
+
end
|
28
|
+
def delegate_request_if_needed!(global_state, document, char_position)
|
29
|
+
if global_state.supports_request_delegation &&
|
30
|
+
document.is_a?(ERBDocument) &&
|
31
|
+
document.inside_host_language?(char_position)
|
32
|
+
raise DelegateRequestError
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
20
36
|
# Checks if a location covers a position
|
21
37
|
sig { params(location: Prism::Location, position: T.untyped).returns(T::Boolean) }
|
22
38
|
def cover?(location, position)
|
@@ -3,8 +3,6 @@
|
|
3
3
|
|
4
4
|
module RubyLsp
|
5
5
|
module Requests
|
6
|
-
# 
|
7
|
-
#
|
8
6
|
# The [selection ranges](https://microsoft.github.io/language-server-protocol/specification#textDocument_selectionRange)
|
9
7
|
# request informs the editor of ranges that the user may want to select based on the location(s)
|
10
8
|
# of their cursor(s).
|
@@ -12,14 +10,6 @@ module RubyLsp
|
|
12
10
|
# Trigger this request with: Ctrl + Shift + -> or Ctrl + Shift + <-
|
13
11
|
#
|
14
12
|
# Note that if using VSCode Neovim, you will need to be in Insert mode for this to work correctly.
|
15
|
-
#
|
16
|
-
# # Example
|
17
|
-
#
|
18
|
-
# ```ruby
|
19
|
-
# def foo # --> The next selection range encompasses the entire method definition.
|
20
|
-
# puts "Hello, world!" # --> Cursor is on this line
|
21
|
-
# end
|
22
|
-
# ```
|
23
13
|
class SelectionRanges < Request
|
24
14
|
extend T::Sig
|
25
15
|
include Support::Common
|
@@ -5,31 +5,9 @@ require "ruby_lsp/listeners/semantic_highlighting"
|
|
5
5
|
|
6
6
|
module RubyLsp
|
7
7
|
module Requests
|
8
|
-
# 
|
9
|
-
#
|
10
8
|
# The [semantic
|
11
9
|
# highlighting](https://microsoft.github.io/language-server-protocol/specification#textDocument_semanticTokens)
|
12
10
|
# request informs the editor of the correct token types to provide consistent and accurate highlighting for themes.
|
13
|
-
#
|
14
|
-
# # Example
|
15
|
-
#
|
16
|
-
# ```ruby
|
17
|
-
# def foo
|
18
|
-
# var = 1 # --> semantic highlighting: local variable
|
19
|
-
# some_invocation # --> semantic highlighting: method invocation
|
20
|
-
# var # --> semantic highlighting: local variable
|
21
|
-
# end
|
22
|
-
#
|
23
|
-
# # Strategy
|
24
|
-
#
|
25
|
-
# To maximize editor performance, the Ruby LSP will return the minimum number of semantic tokens, since applying
|
26
|
-
# them is an expensive operation for the client. This means that the server only returns tokens for ambiguous pieces
|
27
|
-
# of syntax, such as method invocations with no receivers or parenthesis (which can be confused with local
|
28
|
-
# variables).
|
29
|
-
#
|
30
|
-
# Offloading as much handling as possible to Text Mate grammars or equivalent will guarantee responsiveness in the
|
31
|
-
# editor and allow for a much smoother experience.
|
32
|
-
# ```
|
33
11
|
class SemanticHighlighting < Request
|
34
12
|
extend T::Sig
|
35
13
|
|
@@ -39,7 +17,7 @@ module RubyLsp
|
|
39
17
|
sig { returns(Interface::SemanticTokensRegistrationOptions) }
|
40
18
|
def provider
|
41
19
|
Interface::SemanticTokensRegistrationOptions.new(
|
42
|
-
document_selector: [{ language: "ruby" }],
|
20
|
+
document_selector: [{ language: "ruby" }, { language: "erb" }],
|
43
21
|
legend: Interface::SemanticTokensLegend.new(
|
44
22
|
token_types: ResponseBuilders::SemanticHighlighting::TOKEN_TYPES.keys,
|
45
23
|
token_modifiers: ResponseBuilders::SemanticHighlighting::TOKEN_MODIFIERS.keys,
|
@@ -3,20 +3,9 @@
|
|
3
3
|
|
4
4
|
module RubyLsp
|
5
5
|
module Requests
|
6
|
-
# 
|
7
|
-
#
|
8
6
|
# Show syntax tree is a custom [LSP
|
9
7
|
# request](https://microsoft.github.io/language-server-protocol/specification#requestMessage) that displays the AST
|
10
8
|
# for the current document or for the current selection in a new tab.
|
11
|
-
#
|
12
|
-
# # Example
|
13
|
-
#
|
14
|
-
# ```ruby
|
15
|
-
# # Executing the Ruby LSP: Show syntax tree command will display the AST for the document
|
16
|
-
# 1 + 1
|
17
|
-
# # (program (statements ((binary (int "1") + (int "1")))))
|
18
|
-
# ```
|
19
|
-
#
|
20
9
|
class ShowSyntaxTree < Request
|
21
10
|
extend T::Sig
|
22
11
|
|
@@ -5,25 +5,9 @@ require "ruby_lsp/listeners/signature_help"
|
|
5
5
|
|
6
6
|
module RubyLsp
|
7
7
|
module Requests
|
8
|
-
# 
|
9
|
-
#
|
10
8
|
# The [signature help
|
11
9
|
# request](https://microsoft.github.io/language-server-protocol/specification#textDocument_signatureHelp) displays
|
12
10
|
# information about the parameters of a method as you type an invocation.
|
13
|
-
#
|
14
|
-
# Currently only supports methods invoked directly on `self` without taking inheritance into account.
|
15
|
-
#
|
16
|
-
# # Example
|
17
|
-
#
|
18
|
-
# ```ruby
|
19
|
-
# class Foo
|
20
|
-
# def bar(a, b, c)
|
21
|
-
# end
|
22
|
-
#
|
23
|
-
# def baz
|
24
|
-
# bar( # -> Signature help will show the parameters of `bar`
|
25
|
-
# end
|
26
|
-
# ```
|
27
11
|
class SignatureHelp < Request
|
28
12
|
extend T::Sig
|
29
13
|
|
@@ -51,10 +35,11 @@ module RubyLsp
|
|
51
35
|
end
|
52
36
|
def initialize(document, global_state, position, context, dispatcher, sorbet_level) # rubocop:disable Metrics/ParameterLists
|
53
37
|
super()
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
38
|
+
|
39
|
+
char_position = document.create_scanner.find_char_position(position)
|
40
|
+
delegate_request_if_needed!(global_state, document, char_position)
|
41
|
+
|
42
|
+
node_context = RubyDocument.locate(document.parse_result.value, char_position, node_types: [Prism::CallNode])
|
58
43
|
|
59
44
|
target = adjust_for_nested_target(node_context.node, node_context.parent, position)
|
60
45
|
|
@@ -99,7 +99,7 @@ module RubyLsp
|
|
99
99
|
)
|
100
100
|
|
101
101
|
definitions << "[#{entry.file_name}](#{uri})"
|
102
|
-
content << "\n\n#{entry.comments
|
102
|
+
content << "\n\n#{entry.comments}" unless entry.comments.empty?
|
103
103
|
end
|
104
104
|
|
105
105
|
additional_entries_text = if max_entries && entries.length > max_entries
|
@@ -80,7 +80,9 @@ module RubyLsp
|
|
80
80
|
|
81
81
|
args += DEFAULT_ARGS
|
82
82
|
rubocop_options = ::RuboCop::Options.new.parse(args).first
|
83
|
+
|
83
84
|
config_store = ::RuboCop::ConfigStore.new
|
85
|
+
config_store.options_config = rubocop_options[:config] if rubocop_options[:config]
|
84
86
|
@config_for_working_directory = T.let(config_store.for_pwd, ::RuboCop::Config)
|
85
87
|
|
86
88
|
super(rubocop_options, config_store)
|
@@ -3,20 +3,9 @@
|
|
3
3
|
|
4
4
|
module RubyLsp
|
5
5
|
module Requests
|
6
|
-
# 
|
7
|
-
#
|
8
6
|
# The [type hierarchy supertypes
|
9
7
|
# request](https://microsoft.github.io/language-server-protocol/specification#typeHierarchy_supertypes)
|
10
8
|
# displays the list of ancestors (supertypes) for the selected type.
|
11
|
-
#
|
12
|
-
# # Example
|
13
|
-
#
|
14
|
-
# ```ruby
|
15
|
-
# class Foo; end
|
16
|
-
# class Bar < Foo; end
|
17
|
-
#
|
18
|
-
# puts Bar # <-- right click on `Bar` and select "Show Type Hierarchy"
|
19
|
-
# ```
|
20
9
|
class TypeHierarchySupertypes < Request
|
21
10
|
extend T::Sig
|
22
11
|
|
@@ -3,21 +3,9 @@
|
|
3
3
|
|
4
4
|
module RubyLsp
|
5
5
|
module Requests
|
6
|
-
# 
|
7
|
-
#
|
8
6
|
# The [workspace symbol](https://microsoft.github.io/language-server-protocol/specification#workspace_symbol)
|
9
7
|
# request allows fuzzy searching declarations in the entire project. On VS Code, use CTRL/CMD + T to search for
|
10
8
|
# symbols.
|
11
|
-
#
|
12
|
-
# # Example
|
13
|
-
#
|
14
|
-
# ```ruby
|
15
|
-
# # Searching for `Floo` will fuzzy match and return all declarations according to the query, including this `Foo`
|
16
|
-
# class
|
17
|
-
# class Foo
|
18
|
-
# end
|
19
|
-
# ```
|
20
|
-
#
|
21
9
|
class WorkspaceSymbol < Request
|
22
10
|
extend T::Sig
|
23
11
|
include Support::Common
|
@@ -121,12 +121,13 @@ module RubyLsp
|
|
121
121
|
end
|
122
122
|
end
|
123
123
|
|
124
|
-
sig { override.returns(
|
125
|
-
def parse
|
126
|
-
return
|
124
|
+
sig { override.returns(T::Boolean) }
|
125
|
+
def parse!
|
126
|
+
return false unless @needs_parsing
|
127
127
|
|
128
128
|
@needs_parsing = false
|
129
129
|
@parse_result = Prism.parse(@source)
|
130
|
+
true
|
130
131
|
end
|
131
132
|
|
132
133
|
sig { override.returns(T::Boolean) }
|
data/lib/ruby_lsp/server.rb
CHANGED
@@ -9,12 +9,6 @@ module RubyLsp
|
|
9
9
|
sig { returns(GlobalState) }
|
10
10
|
attr_reader :global_state
|
11
11
|
|
12
|
-
sig { params(test_mode: T::Boolean).void }
|
13
|
-
def initialize(test_mode: false)
|
14
|
-
super
|
15
|
-
@global_state = T.let(GlobalState.new, GlobalState)
|
16
|
-
end
|
17
|
-
|
18
12
|
sig { override.params(message: T::Hash[Symbol, T.untyped]).void }
|
19
13
|
def process_message(message)
|
20
14
|
case message[:method]
|
@@ -98,6 +92,8 @@ module RubyLsp
|
|
98
92
|
when "$/cancelRequest"
|
99
93
|
@mutex.synchronize { @cancelled_requests << message[:params][:id] }
|
100
94
|
end
|
95
|
+
rescue DelegateRequestError
|
96
|
+
send_message(Error.new(id: message[:id], code: DelegateRequestError::CODE, message: "DELEGATE_REQUEST"))
|
101
97
|
rescue StandardError, LoadError => e
|
102
98
|
# If an error occurred in a request, we have to return an error response or else the editor will hang
|
103
99
|
if message[:id]
|
@@ -284,7 +280,15 @@ module RubyLsp
|
|
284
280
|
RubyVM::YJIT.enable if defined?(RubyVM::YJIT.enable)
|
285
281
|
|
286
282
|
if defined?(Requests::Support::RuboCopFormatter)
|
287
|
-
|
283
|
+
begin
|
284
|
+
@global_state.register_formatter("rubocop", Requests::Support::RuboCopFormatter.new)
|
285
|
+
rescue RuboCop::Error => e
|
286
|
+
# The user may have provided unknown config switches in .rubocop or
|
287
|
+
# is trying to load a non-existant config file.
|
288
|
+
send_message(Notification.window_show_error(
|
289
|
+
"RuboCop configuration error: #{e.message}. Formatting will not be available.",
|
290
|
+
))
|
291
|
+
end
|
288
292
|
end
|
289
293
|
if defined?(Requests::Support::SyntaxTreeFormatter)
|
290
294
|
@global_state.register_formatter("syntax_tree", Requests::Support::SyntaxTreeFormatter.new)
|
@@ -543,7 +547,7 @@ module RubyLsp
|
|
543
547
|
return
|
544
548
|
end
|
545
549
|
|
546
|
-
request = Requests::DocumentHighlight.new(document, params[:position], dispatcher)
|
550
|
+
request = Requests::DocumentHighlight.new(@global_state, document, params[:position], dispatcher)
|
547
551
|
dispatcher.dispatch(document.parse_result.value)
|
548
552
|
send_message(Result.new(id: message[:id], response: request.perform))
|
549
553
|
end
|
@@ -740,6 +744,17 @@ module RubyLsp
|
|
740
744
|
|
741
745
|
sig { params(message: T::Hash[Symbol, T.untyped]).void }
|
742
746
|
def text_document_completion_item_resolve(message)
|
747
|
+
# When responding to a delegated completion request, it means we're handling a completion item that isn't related
|
748
|
+
# to Ruby (probably related to an ERB host language like HTML). We need to return the original completion item
|
749
|
+
# back to the editor so that it's displayed correctly
|
750
|
+
if message.dig(:params, :data, :delegateCompletion)
|
751
|
+
send_message(Result.new(
|
752
|
+
id: message[:id],
|
753
|
+
response: message[:params],
|
754
|
+
))
|
755
|
+
return
|
756
|
+
end
|
757
|
+
|
743
758
|
send_message(Result.new(
|
744
759
|
id: message[:id],
|
745
760
|
response: Requests::CompletionResolve.new(@global_state, message[:params]).perform,
|
@@ -56,7 +56,7 @@ module RubyLsp
|
|
56
56
|
|
57
57
|
# Sets up the custom bundle and returns the `BUNDLE_GEMFILE`, `BUNDLE_PATH` and `BUNDLE_APP_CONFIG` that should be
|
58
58
|
# used for running the server
|
59
|
-
sig { returns([String,
|
59
|
+
sig { returns(T::Hash[String, String]) }
|
60
60
|
def setup!
|
61
61
|
raise BundleNotLocked if @gemfile&.exist? && !@lockfile&.exist?
|
62
62
|
|
@@ -176,22 +176,18 @@ module RubyLsp
|
|
176
176
|
dependencies
|
177
177
|
end
|
178
178
|
|
179
|
-
sig { params(bundle_gemfile: T.nilable(Pathname)).returns([String,
|
179
|
+
sig { params(bundle_gemfile: T.nilable(Pathname)).returns(T::Hash[String, String]) }
|
180
180
|
def run_bundle_install(bundle_gemfile = @gemfile)
|
181
|
+
env = bundler_settings_as_env
|
182
|
+
env["BUNDLE_GEMFILE"] = bundle_gemfile.to_s
|
183
|
+
|
181
184
|
# If the user has a custom bundle path configured, we need to ensure that we will use the absolute and not
|
182
185
|
# relative version of it when running `bundle install`. This is necessary to avoid installing the gems under the
|
183
186
|
# `.ruby-lsp` folder, which is not the user's intention. For example, if the path is configured as `vendor`, we
|
184
187
|
# want to install it in the top level `vendor` and not `.ruby-lsp/vendor`
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
# Use the absolute `BUNDLE_PATH` to prevent accidentally creating unwanted folders under `.ruby-lsp`
|
189
|
-
env = {}
|
190
|
-
env["BUNDLE_GEMFILE"] = bundle_gemfile.to_s
|
191
|
-
env["BUNDLE_PATH"] = expanded_path if expanded_path
|
192
|
-
|
193
|
-
local_config_path = File.join(@project_path, ".bundle")
|
194
|
-
env["BUNDLE_APP_CONFIG"] = local_config_path if Dir.exist?(local_config_path)
|
188
|
+
if env["BUNDLE_PATH"]
|
189
|
+
env["BUNDLE_PATH"] = File.expand_path(env["BUNDLE_PATH"], @project_path)
|
190
|
+
end
|
195
191
|
|
196
192
|
# If `ruby-lsp` and `debug` (and potentially `ruby-lsp-rails`) are already in the Gemfile, then we shouldn't try
|
197
193
|
# to upgrade them or else we'll produce undesired source control changes. If the custom bundle was just created
|
@@ -238,7 +234,29 @@ module RubyLsp
|
|
238
234
|
return setup!
|
239
235
|
end
|
240
236
|
|
241
|
-
|
237
|
+
env
|
238
|
+
end
|
239
|
+
|
240
|
+
# Gather all Bundler settings (global and local) and return them as a hash that can be used as the environment
|
241
|
+
sig { returns(T::Hash[String, String]) }
|
242
|
+
def bundler_settings_as_env
|
243
|
+
local_config_path = File.join(@project_path, ".bundle")
|
244
|
+
|
245
|
+
# If there's no Gemfile or if the local config path does not exist, we return an empty setting set (which has the
|
246
|
+
# global settings included). Otherwise, we also load the local settings
|
247
|
+
settings = begin
|
248
|
+
Dir.exist?(local_config_path) ? Bundler::Settings.new(local_config_path) : Bundler::Settings.new
|
249
|
+
rescue Bundler::GemfileNotFound
|
250
|
+
Bundler::Settings.new
|
251
|
+
end
|
252
|
+
|
253
|
+
# Map all settings to their environment variable names with `key_for` and their values. For example, the if the
|
254
|
+
# setting name `e` is `path` with a value of `vendor/bundle`, then it will return `"BUNDLE_PATH" =>
|
255
|
+
# "vendor/bundle"`
|
256
|
+
settings.all.to_h do |e|
|
257
|
+
key = Bundler::Settings.key_for(e)
|
258
|
+
[key, settings[e].to_s]
|
259
|
+
end
|
242
260
|
end
|
243
261
|
|
244
262
|
sig { returns(T::Boolean) }
|
@@ -121,8 +121,12 @@ module RubyLsp
|
|
121
121
|
return Type.new(node_context.fully_qualified_name) if node_context.surrounding_method
|
122
122
|
|
123
123
|
# If we're not inside a method, then we're inside the body of a class or module, which is a singleton
|
124
|
-
# context
|
125
|
-
|
124
|
+
# context.
|
125
|
+
#
|
126
|
+
# If the class/module definition is using compact style (e.g.: `class Foo::Bar`), then we need to split the name
|
127
|
+
# into its individual parts to build the correct singleton name
|
128
|
+
parts = nesting.flat_map { |part| part.split("::") }
|
129
|
+
Type.new("#{parts.join("::")}::<Class:#{parts.last}>")
|
126
130
|
end
|
127
131
|
|
128
132
|
sig do
|
data/lib/ruby_lsp/utils.rb
CHANGED
@@ -25,7 +25,17 @@ module RubyLsp
|
|
25
25
|
end,
|
26
26
|
String,
|
27
27
|
)
|
28
|
-
GUESSED_TYPES_URL = "https://github.
|
28
|
+
GUESSED_TYPES_URL = "https://shopify.github.io/ruby-lsp/design-and-roadmap.html#guessed-types"
|
29
|
+
|
30
|
+
# Request delegation for embedded languages is not yet standardized into the language server specification. Here we
|
31
|
+
# use this custom error class as a way to return a signal to the client that the request should be delegated to the
|
32
|
+
# language server for the host language. The support for delegation is custom built on the client side, so each editor
|
33
|
+
# needs to implement their own until this becomes a part of the spec
|
34
|
+
class DelegateRequestError < StandardError
|
35
|
+
# A custom error code that clients can use to handle delegate requests. This is past the range of error codes listed
|
36
|
+
# by the specification to avoid conflicting with other error types
|
37
|
+
CODE = -32900
|
38
|
+
end
|
29
39
|
|
30
40
|
# A notification to be sent to the client
|
31
41
|
class Message
|
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.
|
4
|
+
version: 0.18.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shopify
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-09-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: language_server-protocol
|
@@ -28,22 +28,16 @@ dependencies:
|
|
28
28
|
name: prism
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 0.29.0
|
34
|
-
- - "<"
|
31
|
+
- - "~>"
|
35
32
|
- !ruby/object:Gem::Version
|
36
|
-
version: '0
|
33
|
+
version: '1.0'
|
37
34
|
type: :runtime
|
38
35
|
prerelease: false
|
39
36
|
version_requirements: !ruby/object:Gem::Requirement
|
40
37
|
requirements:
|
41
|
-
- - "
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version: 0.29.0
|
44
|
-
- - "<"
|
38
|
+
- - "~>"
|
45
39
|
- !ruby/object:Gem::Version
|
46
|
-
version: '0
|
40
|
+
version: '1.0'
|
47
41
|
- !ruby/object:Gem::Dependency
|
48
42
|
name: rbs
|
49
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -118,7 +112,6 @@ files:
|
|
118
112
|
- lib/ruby_indexer/test/test_case.rb
|
119
113
|
- lib/ruby_lsp/addon.rb
|
120
114
|
- lib/ruby_lsp/base_server.rb
|
121
|
-
- lib/ruby_lsp/check_docs.rb
|
122
115
|
- lib/ruby_lsp/document.rb
|
123
116
|
- lib/ruby_lsp/erb_document.rb
|
124
117
|
- lib/ruby_lsp/global_state.rb
|
@@ -207,7 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
207
200
|
- !ruby/object:Gem::Version
|
208
201
|
version: '0'
|
209
202
|
requirements: []
|
210
|
-
rubygems_version: 3.5.
|
203
|
+
rubygems_version: 3.5.18
|
211
204
|
signing_key:
|
212
205
|
specification_version: 4
|
213
206
|
summary: An opinionated language server for Ruby
|