ruby-lsp 0.17.17 → 0.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -110
- data/VERSION +1 -1
- data/exe/ruby-lsp +5 -4
- 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 +5 -4
- 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/method_test.rb +257 -2
- data/lib/ruby_indexer/test/rbs_indexer_test.rb +1 -1
- 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 +3 -1
- data/lib/ruby_lsp/listeners/code_lens.rb +34 -5
- 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 +0 -16
- 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 +3 -4
- data/lib/ruby_lsp/check_docs.rb +0 -130
@@ -14,18 +14,19 @@ module RubyLsp
|
|
14
14
|
super
|
15
15
|
end
|
16
16
|
|
17
|
-
sig { override.returns(
|
18
|
-
def parse
|
19
|
-
return
|
17
|
+
sig { override.returns(T::Boolean) }
|
18
|
+
def parse!
|
19
|
+
return false unless @needs_parsing
|
20
20
|
|
21
21
|
@needs_parsing = false
|
22
22
|
|
23
23
|
_, _, declarations = RBS::Parser.parse_signature(@source)
|
24
24
|
@syntax_error = false
|
25
25
|
@parse_result = declarations
|
26
|
+
true
|
26
27
|
rescue RBS::ParsingError
|
27
28
|
@syntax_error = true
|
28
|
-
|
29
|
+
true
|
29
30
|
end
|
30
31
|
|
31
32
|
sig { override.returns(T::Boolean) }
|
@@ -3,24 +3,9 @@
|
|
3
3
|
|
4
4
|
module RubyLsp
|
5
5
|
module Requests
|
6
|
-
# ![Code action resolve demo](../../code_action_resolve.gif)
|
7
|
-
#
|
8
6
|
# The [code action resolve](https://microsoft.github.io/language-server-protocol/specification#codeAction_resolve)
|
9
7
|
# request is used to to resolve the edit field for a given code action, if it is not already provided in the
|
10
8
|
# textDocument/codeAction response. We can use it for scenarios that require more computation such as refactoring.
|
11
|
-
#
|
12
|
-
# # Example: Extract to variable
|
13
|
-
#
|
14
|
-
# ```ruby
|
15
|
-
# # Before:
|
16
|
-
# 1 + 1 # Select the text and use Refactor: Extract Variable
|
17
|
-
#
|
18
|
-
# # After:
|
19
|
-
# new_variable = 1 + 1
|
20
|
-
# new_variable
|
21
|
-
#
|
22
|
-
# ```
|
23
|
-
#
|
24
9
|
class CodeActionResolve < Request
|
25
10
|
extend T::Sig
|
26
11
|
include Support::Common
|
@@ -3,19 +3,9 @@
|
|
3
3
|
|
4
4
|
module RubyLsp
|
5
5
|
module Requests
|
6
|
-
# ![Code actions demo](../../code_actions.gif)
|
7
|
-
#
|
8
6
|
# The [code actions](https://microsoft.github.io/language-server-protocol/specification#textDocument_codeAction)
|
9
7
|
# request informs the editor of RuboCop quick fixes that can be applied. These are accessible by hovering over a
|
10
8
|
# specific diagnostic.
|
11
|
-
#
|
12
|
-
# # Example
|
13
|
-
#
|
14
|
-
# ```ruby
|
15
|
-
# def say_hello
|
16
|
-
# puts "Hello" # --> code action: quick fix indentation
|
17
|
-
# end
|
18
|
-
# ```
|
19
9
|
class CodeActions < Request
|
20
10
|
extend T::Sig
|
21
11
|
|
@@ -7,19 +7,9 @@ require "ruby_lsp/listeners/code_lens"
|
|
7
7
|
|
8
8
|
module RubyLsp
|
9
9
|
module Requests
|
10
|
-
# ![Code lens demo](../../code_lens.gif)
|
11
|
-
#
|
12
10
|
# The
|
13
11
|
# [code lens](https://microsoft.github.io/language-server-protocol/specification#textDocument_codeLens)
|
14
|
-
# request informs the editor of runnable commands such as testing and debugging
|
15
|
-
#
|
16
|
-
# # Example
|
17
|
-
#
|
18
|
-
# ```ruby
|
19
|
-
# # Run | Run in Terminal | Debug
|
20
|
-
# class Test < Minitest::Test
|
21
|
-
# end
|
22
|
-
# ```
|
12
|
+
# request informs the editor of runnable commands such as testing and debugging.
|
23
13
|
class CodeLens < Request
|
24
14
|
extend T::Sig
|
25
15
|
|
@@ -5,27 +5,8 @@ require "ruby_lsp/listeners/completion"
|
|
5
5
|
|
6
6
|
module RubyLsp
|
7
7
|
module Requests
|
8
|
-
# ![Completion demo](../../completion.gif)
|
9
|
-
#
|
10
8
|
# The [completion](https://microsoft.github.io/language-server-protocol/specification#textDocument_completion)
|
11
9
|
# suggests possible completions according to what the developer is typing.
|
12
|
-
#
|
13
|
-
# Currently supported targets:
|
14
|
-
#
|
15
|
-
# - Classes
|
16
|
-
# - Modules
|
17
|
-
# - Constants
|
18
|
-
# - Require paths
|
19
|
-
# - Methods invoked on self only
|
20
|
-
# - Instance variables
|
21
|
-
#
|
22
|
-
# # Example
|
23
|
-
#
|
24
|
-
# ```ruby
|
25
|
-
# require "ruby_lsp/requests" # --> completion: suggests `base_request`, `code_actions`, ...
|
26
|
-
#
|
27
|
-
# RubyLsp::Requests:: # --> completion: suggests `Completion`, `Hover`, ...
|
28
|
-
# ```
|
29
10
|
class Completion < Request
|
30
11
|
extend T::Sig
|
31
12
|
|
@@ -36,7 +17,7 @@ module RubyLsp
|
|
36
17
|
def provider
|
37
18
|
Interface::CompletionOptions.new(
|
38
19
|
resolve_provider: true,
|
39
|
-
trigger_characters: ["/", "\"", "'", ":", "@", "."],
|
20
|
+
trigger_characters: ["/", "\"", "'", ":", "@", ".", "=", "<"],
|
40
21
|
completion_item: {
|
41
22
|
labelDetailsSupport: true,
|
42
23
|
},
|
@@ -60,6 +41,8 @@ module RubyLsp
|
|
60
41
|
# Completion always receives the position immediately after the character that was just typed. Here we adjust it
|
61
42
|
# back by 1, so that we find the right node
|
62
43
|
char_position = document.create_scanner.find_char_position(params[:position]) - 1
|
44
|
+
delegate_request_if_needed!(global_state, document, char_position)
|
45
|
+
|
63
46
|
node_context = RubyDocument.locate(
|
64
47
|
document.parse_result.value,
|
65
48
|
char_position,
|
@@ -3,8 +3,6 @@
|
|
3
3
|
|
4
4
|
module RubyLsp
|
5
5
|
module Requests
|
6
|
-
# ![Completion resolve demo](../../completion_resolve.gif)
|
7
|
-
#
|
8
6
|
# The [completionItem/resolve](https://microsoft.github.io/language-server-protocol/specification#completionItem_resolve)
|
9
7
|
# request provides additional information about the currently selected completion. Specifically, the `labelDetails`
|
10
8
|
# and `documentation` fields are provided, which are omitted from the completion items returned by
|
@@ -15,12 +13,6 @@ module RubyLsp
|
|
15
13
|
#
|
16
14
|
# At most 10 definitions are included, to ensure low latency during request processing and rendering the completion
|
17
15
|
# item.
|
18
|
-
#
|
19
|
-
# # Example
|
20
|
-
#
|
21
|
-
# ```ruby
|
22
|
-
# A # -> as the user cycles through completion items, the documentation will be resolved and displayed
|
23
|
-
# ```
|
24
16
|
class CompletionResolve < Request
|
25
17
|
extend T::Sig
|
26
18
|
include Requests::Support::Common
|
@@ -5,27 +5,9 @@ require "ruby_lsp/listeners/definition"
|
|
5
5
|
|
6
6
|
module RubyLsp
|
7
7
|
module Requests
|
8
|
-
# ![Definition demo](../../definition.gif)
|
9
|
-
#
|
10
8
|
# The [definition
|
11
9
|
# request](https://microsoft.github.io/language-server-protocol/specification#textDocument_definition) jumps to the
|
12
10
|
# definition of the symbol under the cursor.
|
13
|
-
#
|
14
|
-
# Currently supported targets:
|
15
|
-
#
|
16
|
-
# - Classes
|
17
|
-
# - Modules
|
18
|
-
# - Constants
|
19
|
-
# - Require paths
|
20
|
-
# - Methods invoked on self only and on receivers where the type is unknown
|
21
|
-
# - Instance variables
|
22
|
-
#
|
23
|
-
# # Example
|
24
|
-
#
|
25
|
-
# ```ruby
|
26
|
-
# require "some_gem/file" # <- Request go to definition on this string will take you to the file
|
27
|
-
# Product.new # <- Request go to definition on this class name will take you to its declaration.
|
28
|
-
# ```
|
29
11
|
class Definition < Request
|
30
12
|
extend T::Sig
|
31
13
|
extend T::Generic
|
@@ -53,8 +35,12 @@ module RubyLsp
|
|
53
35
|
)
|
54
36
|
@dispatcher = dispatcher
|
55
37
|
|
56
|
-
|
57
|
-
|
38
|
+
char_position = document.create_scanner.find_char_position(position)
|
39
|
+
delegate_request_if_needed!(global_state, document, char_position)
|
40
|
+
|
41
|
+
node_context = RubyDocument.locate(
|
42
|
+
document.parse_result.value,
|
43
|
+
char_position,
|
58
44
|
node_types: [
|
59
45
|
Prism::CallNode,
|
60
46
|
Prism::ConstantReadNode,
|
@@ -3,19 +3,9 @@
|
|
3
3
|
|
4
4
|
module RubyLsp
|
5
5
|
module Requests
|
6
|
-
# ![Diagnostics demo](../../diagnostics.gif)
|
7
|
-
#
|
8
6
|
# The
|
9
7
|
# [diagnostics](https://microsoft.github.io/language-server-protocol/specification#textDocument_publishDiagnostics)
|
10
8
|
# request informs the editor of RuboCop offenses for a given file.
|
11
|
-
#
|
12
|
-
# # Example
|
13
|
-
#
|
14
|
-
# ```ruby
|
15
|
-
# def say_hello
|
16
|
-
# puts "Hello" # --> diagnostics: incorrect indentation
|
17
|
-
# end
|
18
|
-
# ```
|
19
9
|
class Diagnostics < Request
|
20
10
|
extend T::Sig
|
21
11
|
|
@@ -5,8 +5,6 @@ require "ruby_lsp/listeners/document_highlight"
|
|
5
5
|
|
6
6
|
module RubyLsp
|
7
7
|
module Requests
|
8
|
-
# ![Document highlight demo](../../document_highlight.gif)
|
9
|
-
#
|
10
8
|
# The [document highlight](https://microsoft.github.io/language-server-protocol/specification#textDocument_documentHighlight)
|
11
9
|
# informs the editor all relevant elements of the currently pointed item for highlighting. For example, when
|
12
10
|
# the cursor is on the `F` of the constant `FOO`, the editor should identify other occurrences of `FOO`
|
@@ -14,29 +12,24 @@ module RubyLsp
|
|
14
12
|
#
|
15
13
|
# For writable elements like constants or variables, their read/write occurrences should be highlighted differently.
|
16
14
|
# This is achieved by sending different "kind" attributes to the editor (2 for read and 3 for write).
|
17
|
-
#
|
18
|
-
# # Example
|
19
|
-
#
|
20
|
-
# ```ruby
|
21
|
-
# FOO = 1 # should be highlighted as "write"
|
22
|
-
#
|
23
|
-
# def foo
|
24
|
-
# FOO # should be highlighted as "read"
|
25
|
-
# end
|
26
|
-
# ```
|
27
15
|
class DocumentHighlight < Request
|
28
16
|
extend T::Sig
|
29
17
|
|
30
18
|
sig do
|
31
19
|
params(
|
20
|
+
global_state: GlobalState,
|
32
21
|
document: T.any(RubyDocument, ERBDocument),
|
33
22
|
position: T::Hash[Symbol, T.untyped],
|
34
23
|
dispatcher: Prism::Dispatcher,
|
35
24
|
).void
|
36
25
|
end
|
37
|
-
def initialize(document, position, dispatcher)
|
26
|
+
def initialize(global_state, document, position, dispatcher)
|
38
27
|
super()
|
39
|
-
|
28
|
+
char_position = document.create_scanner.find_char_position(position)
|
29
|
+
delegate_request_if_needed!(global_state, document, char_position)
|
30
|
+
|
31
|
+
node_context = RubyDocument.locate(document.parse_result.value, char_position)
|
32
|
+
|
40
33
|
@response_builder = T.let(
|
41
34
|
ResponseBuilders::CollectionResponseBuilder[Interface::DocumentHighlight].new,
|
42
35
|
ResponseBuilders::CollectionResponseBuilder[Interface::DocumentHighlight],
|
@@ -5,19 +5,9 @@ require "ruby_lsp/listeners/document_link"
|
|
5
5
|
|
6
6
|
module RubyLsp
|
7
7
|
module Requests
|
8
|
-
# ![Document link demo](../../document_link.gif)
|
9
|
-
#
|
10
8
|
# The [document link](https://microsoft.github.io/language-server-protocol/specification#textDocument_documentLink)
|
11
9
|
# makes `# source://PATH_TO_FILE#line` comments in a Ruby/RBI file clickable if the file exists.
|
12
10
|
# When the user clicks the link, it'll open that location.
|
13
|
-
#
|
14
|
-
# # Example
|
15
|
-
#
|
16
|
-
# ```ruby
|
17
|
-
# # source://syntax_tree/3.2.1/lib/syntax_tree.rb#51 <- it will be clickable and will take the user to that location
|
18
|
-
# def format(source, maxwidth = T.unsafe(nil))
|
19
|
-
# end
|
20
|
-
# ```
|
21
11
|
class DocumentLink < Request
|
22
12
|
extend T::Sig
|
23
13
|
|
@@ -5,29 +5,12 @@ require "ruby_lsp/listeners/document_symbol"
|
|
5
5
|
|
6
6
|
module RubyLsp
|
7
7
|
module Requests
|
8
|
-
# ![Document symbol demo](../../document_symbol.gif)
|
9
|
-
#
|
10
8
|
# The [document
|
11
9
|
# symbol](https://microsoft.github.io/language-server-protocol/specification#textDocument_documentSymbol) request
|
12
10
|
# informs the editor of all the important symbols, such as classes, variables, and methods, defined in a file. With
|
13
11
|
# this information, the editor can populate breadcrumbs, file outline and allow for fuzzy symbol searches.
|
14
12
|
#
|
15
13
|
# In VS Code, fuzzy symbol search can be accessed by opening the command palette and inserting an `@` symbol.
|
16
|
-
#
|
17
|
-
# # Example
|
18
|
-
#
|
19
|
-
# ```ruby
|
20
|
-
# class Person # --> document symbol: class
|
21
|
-
# attr_reader :age # --> document symbol: field
|
22
|
-
#
|
23
|
-
# def initialize
|
24
|
-
# @age = 0 # --> document symbol: variable
|
25
|
-
# end
|
26
|
-
#
|
27
|
-
# def age # --> document symbol: method
|
28
|
-
# end
|
29
|
-
# end
|
30
|
-
# ```
|
31
14
|
class DocumentSymbol < Request
|
32
15
|
extend T::Sig
|
33
16
|
|
@@ -5,18 +5,8 @@ require "ruby_lsp/listeners/folding_ranges"
|
|
5
5
|
|
6
6
|
module RubyLsp
|
7
7
|
module Requests
|
8
|
-
# ![Folding ranges demo](../../folding_ranges.gif)
|
9
|
-
#
|
10
8
|
# The [folding ranges](https://microsoft.github.io/language-server-protocol/specification#textDocument_foldingRange)
|
11
9
|
# request informs the editor of the ranges where and how code can be folded.
|
12
|
-
#
|
13
|
-
# # Example
|
14
|
-
#
|
15
|
-
# ```ruby
|
16
|
-
# def say_hello # <-- folding range start
|
17
|
-
# puts "Hello"
|
18
|
-
# end # <-- folding range end
|
19
|
-
# ```
|
20
10
|
class FoldingRanges < Request
|
21
11
|
extend T::Sig
|
22
12
|
|
@@ -3,25 +3,9 @@
|
|
3
3
|
|
4
4
|
module RubyLsp
|
5
5
|
module Requests
|
6
|
-
# ![Formatting symbol demo](../../formatting.gif)
|
7
|
-
#
|
8
6
|
# The [formatting](https://microsoft.github.io/language-server-protocol/specification#textDocument_formatting)
|
9
7
|
# request uses RuboCop to fix auto-correctable offenses in the document. This requires enabling format on save and
|
10
8
|
# registering the ruby-lsp as the Ruby formatter.
|
11
|
-
#
|
12
|
-
# The `rubyLsp.formatter` setting specifies which formatter to use.
|
13
|
-
# If set to `auto` then it behaves as follows:
|
14
|
-
# * It will use RuboCop if it is part of the bundle.
|
15
|
-
# * If RuboCop is not available, and `syntax_tree` is a direct dependency, it will use that.
|
16
|
-
# * Otherwise, no formatting will be applied.
|
17
|
-
#
|
18
|
-
# # Example
|
19
|
-
#
|
20
|
-
# ```ruby
|
21
|
-
# def say_hello
|
22
|
-
# puts "Hello" # --> formatting: fixes the indentation on save
|
23
|
-
# end
|
24
|
-
# ```
|
25
9
|
class Formatting < Request
|
26
10
|
extend T::Sig
|
27
11
|
|
@@ -5,16 +5,8 @@ require "ruby_lsp/listeners/hover"
|
|
5
5
|
|
6
6
|
module RubyLsp
|
7
7
|
module Requests
|
8
|
-
# ![Hover demo](../../hover.gif)
|
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
|
-
# ![Inlay hint demo](../../inlay_hints.gif)
|
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
|
-
# ![On type formatting demo](../../on_type_formatting.gif)
|
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
|
-
# ![Prepare type hierarchy demo](../../prepare_type_hierarchy.gif)
|
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
|
-
# ![Selection ranges demo](../../selection_ranges.gif)
|
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
|
-
# ![Semantic highlighting demo](../../semantic_highlighting.gif)
|
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
|
-
# ![Show syntax tree demo](../../show_syntax_tree.gif)
|
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
|
-
# ![Signature help demo](../../signature_help.gif)
|
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)
|