ruby-lsp 0.2.0 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +27 -0
- data/VERSION +1 -1
- data/exe/ruby-lsp +1 -3
- data/lib/ruby-lsp.rb +2 -2
- data/lib/ruby_lsp/document.rb +10 -3
- data/lib/ruby_lsp/handler.rb +17 -138
- data/lib/ruby_lsp/internal.rb +3 -1
- data/lib/ruby_lsp/requests/document_highlight.rb +25 -42
- data/lib/ruby_lsp/requests/document_link.rb +119 -0
- data/lib/ruby_lsp/requests/folding_ranges.rb +5 -1
- data/lib/ruby_lsp/requests/formatting.rb +1 -0
- data/lib/ruby_lsp/requests/semantic_highlighting.rb +17 -7
- data/lib/ruby_lsp/requests/support/highlight_target.rb +88 -0
- data/lib/ruby_lsp/requests/support/rubocop_diagnostic.rb +9 -2
- data/lib/ruby_lsp/requests/support/source_uri.rb +82 -0
- data/lib/ruby_lsp/requests.rb +3 -0
- data/lib/ruby_lsp/server.rb +193 -0
- data/lib/ruby_lsp/store.rb +12 -5
- metadata +6 -70
- data/.github/dependabot.yml +0 -11
- data/.github/probots.yml +0 -2
- data/.github/pull_request_template.md +0 -15
- data/.github/workflows/ci.yml +0 -31
- data/.github/workflows/publish_docs.yml +0 -32
- data/.gitignore +0 -9
- data/.rubocop.yml +0 -39
- data/.vscode/extensions.json +0 -5
- data/.vscode/settings.json +0 -5
- data/.vscode/tasks.json +0 -25
- data/CODE_OF_CONDUCT.md +0 -78
- data/Gemfile +0 -18
- data/Gemfile.lock +0 -126
- data/Rakefile +0 -28
- data/bin/console +0 -19
- data/bin/rubocop +0 -29
- data/bin/tapioca +0 -29
- data/bin/test +0 -9
- data/dev.yml +0 -20
- data/lib/ruby_lsp/cli.rb +0 -89
- data/rakelib/check_docs.rake +0 -81
- data/ruby-lsp.gemspec +0 -27
- data/service.yml +0 -2
- data/sorbet/config +0 -4
- data/sorbet/rbi/.rubocop.yml +0 -8
- data/sorbet/rbi/gems/ansi@1.5.0.rbi +0 -338
- data/sorbet/rbi/gems/ast@2.4.2.rbi +0 -522
- data/sorbet/rbi/gems/builder@3.2.4.rbi +0 -418
- data/sorbet/rbi/gems/coderay@1.1.3.rbi +0 -8
- data/sorbet/rbi/gems/debug@1.5.0.rbi +0 -1273
- data/sorbet/rbi/gems/diff-lcs@1.5.0.rbi +0 -867
- data/sorbet/rbi/gems/io-console@0.5.11.rbi +0 -8
- data/sorbet/rbi/gems/irb@1.4.1.rbi +0 -376
- data/sorbet/rbi/gems/language_server-protocol@3.16.0.3.rbi +0 -7325
- data/sorbet/rbi/gems/method_source@1.0.0.rbi +0 -8
- data/sorbet/rbi/gems/minitest-reporters@1.5.0.rbi +0 -612
- data/sorbet/rbi/gems/minitest@5.15.0.rbi +0 -994
- data/sorbet/rbi/gems/parallel@1.22.1.rbi +0 -163
- data/sorbet/rbi/gems/parser@3.1.2.0.rbi +0 -3968
- data/sorbet/rbi/gems/prettier_print@0.1.0.rbi +0 -734
- data/sorbet/rbi/gems/pry@0.14.1.rbi +0 -8
- data/sorbet/rbi/gems/rainbow@3.1.1.rbi +0 -227
- data/sorbet/rbi/gems/rake@13.0.6.rbi +0 -1853
- data/sorbet/rbi/gems/rbi@0.0.14.rbi +0 -2337
- data/sorbet/rbi/gems/regexp_parser@2.5.0.rbi +0 -1854
- data/sorbet/rbi/gems/reline@0.3.1.rbi +0 -1274
- data/sorbet/rbi/gems/rexml@3.2.5.rbi +0 -3852
- data/sorbet/rbi/gems/rubocop-ast@1.18.0.rbi +0 -4180
- data/sorbet/rbi/gems/rubocop-minitest@0.20.0.rbi +0 -1369
- data/sorbet/rbi/gems/rubocop-rake@0.6.0.rbi +0 -246
- data/sorbet/rbi/gems/rubocop-shopify@2.6.0.rbi +0 -8
- data/sorbet/rbi/gems/rubocop-sorbet@0.6.8.rbi +0 -652
- data/sorbet/rbi/gems/rubocop@1.30.0.rbi +0 -36729
- data/sorbet/rbi/gems/ruby-progressbar@1.11.0.rbi +0 -732
- data/sorbet/rbi/gems/spoom@1.1.11.rbi +0 -1600
- data/sorbet/rbi/gems/syntax_tree@2.7.1.rbi +0 -6777
- data/sorbet/rbi/gems/tapioca@0.8.1.rbi +0 -1972
- data/sorbet/rbi/gems/thor@1.2.1.rbi +0 -2921
- data/sorbet/rbi/gems/unicode-display_width@2.1.0.rbi +0 -27
- data/sorbet/rbi/gems/unparser@0.6.5.rbi +0 -2789
- data/sorbet/rbi/gems/webrick@1.7.0.rbi +0 -1779
- data/sorbet/rbi/gems/yard-sorbet@0.6.1.rbi +0 -289
- data/sorbet/rbi/gems/yard@0.9.27.rbi +0 -13048
- data/sorbet/rbi/shims/fiddle.rbi +0 -4
- data/sorbet/rbi/shims/hash.rbi +0 -6
- data/sorbet/rbi/shims/rdoc.rbi +0 -4
- data/sorbet/tapioca/config.yml +0 -13
- data/sorbet/tapioca/require.rb +0 -7
@@ -0,0 +1,88 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module RubyLsp
|
5
|
+
module Requests
|
6
|
+
module Support
|
7
|
+
class HighlightTarget
|
8
|
+
extend T::Sig
|
9
|
+
|
10
|
+
READ = LanguageServer::Protocol::Constant::DocumentHighlightKind::READ
|
11
|
+
WRITE = LanguageServer::Protocol::Constant::DocumentHighlightKind::WRITE
|
12
|
+
|
13
|
+
class HighlightMatch < T::Struct
|
14
|
+
const :type, Integer
|
15
|
+
const :node, SyntaxTree::Node
|
16
|
+
end
|
17
|
+
|
18
|
+
sig { params(node: SyntaxTree::Node).void }
|
19
|
+
def initialize(node)
|
20
|
+
@node = node
|
21
|
+
@value = T.let(value(node), T.nilable(String))
|
22
|
+
end
|
23
|
+
|
24
|
+
sig { params(other: SyntaxTree::Node).returns(T.nilable(HighlightMatch)) }
|
25
|
+
def highlight_type(other)
|
26
|
+
matched_highlight(other) if other.is_a?(SyntaxTree::Params) || (@value && @value == value(other))
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
# Match the target type (where the cursor is positioned) with the `other` type (the node we're currently
|
32
|
+
# visiting)
|
33
|
+
sig { params(other: SyntaxTree::Node).returns(T.nilable(HighlightMatch)) }
|
34
|
+
def matched_highlight(other)
|
35
|
+
case @node
|
36
|
+
# Method definitions and invocations
|
37
|
+
when SyntaxTree::VCall, SyntaxTree::FCall, SyntaxTree::Call, SyntaxTree::Command,
|
38
|
+
SyntaxTree::CommandCall, SyntaxTree::Def, SyntaxTree::Defs, SyntaxTree::DefEndless
|
39
|
+
case other
|
40
|
+
when SyntaxTree::VCall, SyntaxTree::FCall, SyntaxTree::Call, SyntaxTree::Command, SyntaxTree::CommandCall
|
41
|
+
HighlightMatch.new(type: READ, node: other)
|
42
|
+
when SyntaxTree::Def, SyntaxTree::Defs, SyntaxTree::Defs
|
43
|
+
HighlightMatch.new(type: WRITE, node: other.name)
|
44
|
+
end
|
45
|
+
# Variables, parameters and constants
|
46
|
+
when SyntaxTree::GVar, SyntaxTree::IVar, SyntaxTree::Const, SyntaxTree::CVar, SyntaxTree::VarField,
|
47
|
+
SyntaxTree::VarRef, SyntaxTree::Ident
|
48
|
+
case other
|
49
|
+
when SyntaxTree::VarField
|
50
|
+
HighlightMatch.new(type: WRITE, node: other)
|
51
|
+
when SyntaxTree::VarRef
|
52
|
+
HighlightMatch.new(type: READ, node: other)
|
53
|
+
when SyntaxTree::ClassDeclaration, SyntaxTree::ModuleDeclaration
|
54
|
+
HighlightMatch.new(type: WRITE, node: other.constant)
|
55
|
+
when SyntaxTree::ConstPathRef
|
56
|
+
HighlightMatch.new(type: READ, node: other.constant)
|
57
|
+
when SyntaxTree::Params
|
58
|
+
params = other.child_nodes.compact
|
59
|
+
match = params.find { |param| value(param) == @value }
|
60
|
+
HighlightMatch.new(type: WRITE, node: match) if match
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
sig { params(node: SyntaxTree::Node).returns(T.nilable(String)) }
|
66
|
+
def value(node)
|
67
|
+
case node
|
68
|
+
when SyntaxTree::ConstPathRef, SyntaxTree::ConstPathField, SyntaxTree::TopConstField
|
69
|
+
node.constant.value
|
70
|
+
when SyntaxTree::GVar, SyntaxTree::IVar, SyntaxTree::Const, SyntaxTree::CVar, SyntaxTree::Ident,
|
71
|
+
SyntaxTree::ArgsForward
|
72
|
+
node.value
|
73
|
+
when SyntaxTree::Field, SyntaxTree::Def, SyntaxTree::Defs, SyntaxTree::DefEndless, SyntaxTree::RestParam,
|
74
|
+
SyntaxTree::KwRestParam, SyntaxTree::BlockArg
|
75
|
+
node.name&.value
|
76
|
+
when SyntaxTree::VarField, SyntaxTree::VarRef, SyntaxTree::VCall, SyntaxTree::FCall
|
77
|
+
node.value&.value
|
78
|
+
when SyntaxTree::Call, SyntaxTree::Command, SyntaxTree::CommandCall
|
79
|
+
message = node.message
|
80
|
+
message != :call ? message.value : nil
|
81
|
+
when SyntaxTree::ClassDeclaration, SyntaxTree::ModuleDeclaration
|
82
|
+
node.constant.constant.value
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -61,11 +61,18 @@ module RubyLsp
|
|
61
61
|
|
62
62
|
sig { returns(LanguageServer::Protocol::Interface::Diagnostic) }
|
63
63
|
def to_lsp_diagnostic
|
64
|
+
if @offense.correctable?
|
65
|
+
severity = RUBOCOP_TO_LSP_SEVERITY[@offense.severity.name]
|
66
|
+
message = @offense.message
|
67
|
+
else
|
68
|
+
severity = LanguageServer::Protocol::Constant::DiagnosticSeverity::WARNING
|
69
|
+
message = "#{@offense.message}\n\nThis offense is not auto-correctable.\n"
|
70
|
+
end
|
64
71
|
LanguageServer::Protocol::Interface::Diagnostic.new(
|
65
|
-
message:
|
72
|
+
message: message,
|
66
73
|
source: "RuboCop",
|
67
74
|
code: @offense.cop_name,
|
68
|
-
severity:
|
75
|
+
severity: severity,
|
69
76
|
range: LanguageServer::Protocol::Interface::Range.new(
|
70
77
|
start: LanguageServer::Protocol::Interface::Position.new(
|
71
78
|
line: @offense.line - 1,
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "uri/file"
|
5
|
+
|
6
|
+
module URI
|
7
|
+
# Must be kept in sync with the one in Tapioca
|
8
|
+
class Source < URI::File
|
9
|
+
extend T::Sig
|
10
|
+
|
11
|
+
COMPONENT = T.let([
|
12
|
+
:scheme,
|
13
|
+
:gem_name,
|
14
|
+
:gem_version,
|
15
|
+
:path,
|
16
|
+
:line_number,
|
17
|
+
].freeze, T::Array[Symbol])
|
18
|
+
|
19
|
+
T.unsafe(self).alias_method(:gem_name, :host)
|
20
|
+
T.unsafe(self).alias_method(:line_number, :fragment)
|
21
|
+
|
22
|
+
sig { returns(T.nilable(String)) }
|
23
|
+
attr_reader :gem_version
|
24
|
+
|
25
|
+
class << self
|
26
|
+
extend T::Sig
|
27
|
+
|
28
|
+
sig do
|
29
|
+
params(
|
30
|
+
gem_name: String,
|
31
|
+
gem_version: T.nilable(String),
|
32
|
+
path: String,
|
33
|
+
line_number: T.nilable(String)
|
34
|
+
).returns(URI::Source)
|
35
|
+
end
|
36
|
+
def build(gem_name:, gem_version:, path:, line_number:)
|
37
|
+
super(
|
38
|
+
{
|
39
|
+
scheme: "source",
|
40
|
+
host: gem_name,
|
41
|
+
path: DEFAULT_PARSER.escape("/#{gem_version}/#{path}"),
|
42
|
+
fragment: line_number,
|
43
|
+
}
|
44
|
+
)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
sig { params(v: T.nilable(String)).void }
|
49
|
+
def set_path(v) # rubocop:disable Naming/AccessorMethodName
|
50
|
+
return if v.nil?
|
51
|
+
|
52
|
+
gem_version, path = v.delete_prefix("/").split("/", 2)
|
53
|
+
|
54
|
+
@gem_version = T.let(gem_version, T.nilable(String))
|
55
|
+
@path = T.let(path, T.nilable(String))
|
56
|
+
end
|
57
|
+
|
58
|
+
sig { params(v: T.nilable(String)).returns(T::Boolean) }
|
59
|
+
def check_host(v)
|
60
|
+
return true unless v
|
61
|
+
|
62
|
+
if /[A-Za-z][A-Za-z0-9\-_]*/ !~ v
|
63
|
+
raise InvalidComponentError,
|
64
|
+
"bad component(expected gem name): #{v}"
|
65
|
+
end
|
66
|
+
|
67
|
+
true
|
68
|
+
end
|
69
|
+
|
70
|
+
sig { returns(String) }
|
71
|
+
def to_s
|
72
|
+
"source://#{gem_name}/#{gem_version}#{path}##{line_number}"
|
73
|
+
end
|
74
|
+
|
75
|
+
if URI.respond_to?(:register_scheme)
|
76
|
+
URI.register_scheme("SOURCE", self)
|
77
|
+
else
|
78
|
+
@@schemes = T.let(@@schemes, T::Hash[String, Class]) # rubocop:disable Style/ClassVars
|
79
|
+
@@schemes["SOURCE"] = self
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
data/lib/ruby_lsp/requests.rb
CHANGED
@@ -5,6 +5,7 @@ module RubyLsp
|
|
5
5
|
# Supported features
|
6
6
|
#
|
7
7
|
# - {RubyLsp::Requests::DocumentSymbol}
|
8
|
+
# - {RubyLsp::Requests::DocumentLink}
|
8
9
|
# - {RubyLsp::Requests::FoldingRanges}
|
9
10
|
# - {RubyLsp::Requests::SelectionRanges}
|
10
11
|
# - {RubyLsp::Requests::SemanticHighlighting}
|
@@ -15,6 +16,7 @@ module RubyLsp
|
|
15
16
|
module Requests
|
16
17
|
autoload :BaseRequest, "ruby_lsp/requests/base_request"
|
17
18
|
autoload :DocumentSymbol, "ruby_lsp/requests/document_symbol"
|
19
|
+
autoload :DocumentLink, "ruby_lsp/requests/document_link"
|
18
20
|
autoload :FoldingRanges, "ruby_lsp/requests/folding_ranges"
|
19
21
|
autoload :SelectionRanges, "ruby_lsp/requests/selection_ranges"
|
20
22
|
autoload :SemanticHighlighting, "ruby_lsp/requests/semantic_highlighting"
|
@@ -29,6 +31,7 @@ module RubyLsp
|
|
29
31
|
autoload :SelectionRange, "ruby_lsp/requests/support/selection_range"
|
30
32
|
autoload :SemanticTokenEncoder, "ruby_lsp/requests/support/semantic_token_encoder"
|
31
33
|
autoload :SyntaxErrorDiagnostic, "ruby_lsp/requests/support/syntax_error_diagnostic"
|
34
|
+
autoload :HighlightTarget, "ruby_lsp/requests/support/highlight_target"
|
32
35
|
end
|
33
36
|
end
|
34
37
|
end
|
@@ -0,0 +1,193 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "ruby_lsp/internal"
|
5
|
+
|
6
|
+
module RubyLsp
|
7
|
+
Handler.start do
|
8
|
+
on("initialize") do |request|
|
9
|
+
store.clear
|
10
|
+
initialization_options = request.dig(:params, :initializationOptions)
|
11
|
+
enabled_features = initialization_options.fetch(:enabledFeatures, [])
|
12
|
+
|
13
|
+
document_symbol_provider = if enabled_features.include?("documentSymbols")
|
14
|
+
Interface::DocumentSymbolClientCapabilities.new(
|
15
|
+
hierarchical_document_symbol_support: true,
|
16
|
+
symbol_kind: {
|
17
|
+
value_set: Requests::DocumentSymbol::SYMBOL_KIND.values,
|
18
|
+
}
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
document_link_provider = if enabled_features.include?("documentLink")
|
23
|
+
Interface::DocumentLinkOptions.new(resolve_provider: false)
|
24
|
+
end
|
25
|
+
|
26
|
+
folding_ranges_provider = if enabled_features.include?("foldingRanges")
|
27
|
+
Interface::FoldingRangeClientCapabilities.new(line_folding_only: true)
|
28
|
+
end
|
29
|
+
|
30
|
+
semantic_tokens_provider = if enabled_features.include?("semanticHighlighting")
|
31
|
+
Interface::SemanticTokensRegistrationOptions.new(
|
32
|
+
document_selector: { scheme: "file", language: "ruby" },
|
33
|
+
legend: Interface::SemanticTokensLegend.new(
|
34
|
+
token_types: Requests::SemanticHighlighting::TOKEN_TYPES.keys,
|
35
|
+
token_modifiers: Requests::SemanticHighlighting::TOKEN_MODIFIERS.keys
|
36
|
+
),
|
37
|
+
range: false,
|
38
|
+
full: {
|
39
|
+
delta: true,
|
40
|
+
}
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
diagnostics_provider = if enabled_features.include?("diagnostics")
|
45
|
+
{
|
46
|
+
interFileDependencies: false,
|
47
|
+
workspaceDiagnostics: false,
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
# TODO: switch back to using Interface::ServerCapabilities once the gem is updated for spec 3.17
|
52
|
+
Interface::InitializeResult.new(
|
53
|
+
capabilities: {
|
54
|
+
textDocumentSync: Interface::TextDocumentSyncOptions.new(
|
55
|
+
change: Constant::TextDocumentSyncKind::INCREMENTAL,
|
56
|
+
open_close: true,
|
57
|
+
),
|
58
|
+
selectionRangeProvider: enabled_features.include?("selectionRanges"),
|
59
|
+
documentSymbolProvider: document_symbol_provider,
|
60
|
+
documentLinkProvider: document_link_provider,
|
61
|
+
foldingRangeProvider: folding_ranges_provider,
|
62
|
+
semanticTokensProvider: semantic_tokens_provider,
|
63
|
+
documentFormattingProvider: enabled_features.include?("formatting"),
|
64
|
+
documentHighlightProvider: enabled_features.include?("documentHighlights"),
|
65
|
+
codeActionProvider: enabled_features.include?("codeActions"),
|
66
|
+
diagnosticProvider: diagnostics_provider,
|
67
|
+
}.reject { |_, v| !v }
|
68
|
+
)
|
69
|
+
end
|
70
|
+
|
71
|
+
on("textDocument/didChange") do |request|
|
72
|
+
uri = request.dig(:params, :textDocument, :uri)
|
73
|
+
store.push_edits(uri, request.dig(:params, :contentChanges))
|
74
|
+
|
75
|
+
Handler::VOID
|
76
|
+
end
|
77
|
+
|
78
|
+
on("textDocument/didOpen") do |request|
|
79
|
+
uri = request.dig(:params, :textDocument, :uri)
|
80
|
+
text = request.dig(:params, :textDocument, :text)
|
81
|
+
store.set(uri, text)
|
82
|
+
|
83
|
+
Handler::VOID
|
84
|
+
end
|
85
|
+
|
86
|
+
on("textDocument/didClose") do |request|
|
87
|
+
uri = request.dig(:params, :textDocument, :uri)
|
88
|
+
store.delete(uri)
|
89
|
+
clear_diagnostics(uri)
|
90
|
+
|
91
|
+
Handler::VOID
|
92
|
+
end
|
93
|
+
|
94
|
+
on("textDocument/documentSymbol") do |request|
|
95
|
+
store.cache_fetch(request.dig(:params, :textDocument, :uri), :document_symbol) do |document|
|
96
|
+
Requests::DocumentSymbol.new(document).run
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
on("textDocument/documentLink") do |request|
|
101
|
+
uri = request.dig(:params, :textDocument, :uri)
|
102
|
+
store.cache_fetch(uri, :document_link) do |document|
|
103
|
+
RubyLsp::Requests::DocumentLink.new(uri, document).run
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
on("textDocument/foldingRange") do |request|
|
108
|
+
store.cache_fetch(request.dig(:params, :textDocument, :uri), :folding_ranges) do |document|
|
109
|
+
Requests::FoldingRanges.new(document).run
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
on("textDocument/selectionRange") do |request|
|
114
|
+
uri = request.dig(:params, :textDocument, :uri)
|
115
|
+
positions = request.dig(:params, :positions)
|
116
|
+
|
117
|
+
ranges = store.cache_fetch(uri, :selection_ranges) do |document|
|
118
|
+
Requests::SelectionRanges.new(document).run
|
119
|
+
end
|
120
|
+
|
121
|
+
# Per the selection range request spec (https://microsoft.github.io/language-server-protocol/specification#textDocument_selectionRange),
|
122
|
+
# every position in the positions array should have an element at the same index in the response
|
123
|
+
# array. For positions without a valid selection range, the corresponding element in the response
|
124
|
+
# array will be nil.
|
125
|
+
|
126
|
+
unless ranges.nil?
|
127
|
+
positions.map do |position|
|
128
|
+
ranges.find do |range|
|
129
|
+
range.cover?(position)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
on("textDocument/semanticTokens/full") do |request|
|
136
|
+
store.cache_fetch(request.dig(:params, :textDocument, :uri), :semantic_highlighting) do |document|
|
137
|
+
T.cast(
|
138
|
+
Requests::SemanticHighlighting.new(
|
139
|
+
document,
|
140
|
+
encoder: Requests::Support::SemanticTokenEncoder.new
|
141
|
+
).run,
|
142
|
+
LanguageServer::Protocol::Interface::SemanticTokens
|
143
|
+
)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
on("textDocument/formatting") do |request|
|
148
|
+
uri = request.dig(:params, :textDocument, :uri)
|
149
|
+
|
150
|
+
Requests::Formatting.new(uri, store.get(uri)).run
|
151
|
+
end
|
152
|
+
|
153
|
+
on("textDocument/documentHighlight") do |request|
|
154
|
+
document = store.get(request.dig(:params, :textDocument, :uri))
|
155
|
+
|
156
|
+
if document.parsed?
|
157
|
+
Requests::DocumentHighlight.new(document, request.dig(:params, :position)).run
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
on("textDocument/codeAction") do |request|
|
162
|
+
uri = request.dig(:params, :textDocument, :uri)
|
163
|
+
range = request.dig(:params, :range)
|
164
|
+
start_line = range.dig(:start, :line)
|
165
|
+
end_line = range.dig(:end, :line)
|
166
|
+
|
167
|
+
store.cache_fetch(uri, :code_actions) do |document|
|
168
|
+
Requests::CodeActions.new(uri, document, start_line..end_line).run
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
on("textDocument/diagnostic") do |request|
|
173
|
+
uri = request.dig(:params, :textDocument, :uri)
|
174
|
+
response = store.cache_fetch(uri, :diagnostics) do |document|
|
175
|
+
Requests::Diagnostics.new(uri, document).run
|
176
|
+
end
|
177
|
+
|
178
|
+
{ kind: "full", items: response.map(&:to_lsp_diagnostic) } if response
|
179
|
+
rescue RuboCop::ValidationError => e
|
180
|
+
show_message(Constant::MessageType::ERROR, "Error in RuboCop configuration file: #{e.message}")
|
181
|
+
nil
|
182
|
+
end
|
183
|
+
|
184
|
+
on("shutdown") { shutdown }
|
185
|
+
|
186
|
+
on("exit") do
|
187
|
+
# We return zero if shutdown has already been received or one otherwise as per the recommendation in the spec
|
188
|
+
# https://microsoft.github.io/language-server-protocol/specification/#exit
|
189
|
+
status = store.empty? ? 0 : 1
|
190
|
+
exit(status)
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
data/lib/ruby_lsp/store.rb
CHANGED
@@ -25,9 +25,8 @@ module RubyLsp
|
|
25
25
|
|
26
26
|
sig { params(uri: String, content: String).void }
|
27
27
|
def set(uri, content)
|
28
|
-
|
29
|
-
|
30
|
-
# Do not update the store if there are syntax errors
|
28
|
+
document = Document.new(content)
|
29
|
+
@state[uri] = document
|
31
30
|
end
|
32
31
|
|
33
32
|
sig { params(uri: String, edits: T::Array[Document::EditShape]).void }
|
@@ -40,6 +39,11 @@ module RubyLsp
|
|
40
39
|
@state.clear
|
41
40
|
end
|
42
41
|
|
42
|
+
sig { returns(T::Boolean) }
|
43
|
+
def empty?
|
44
|
+
@state.empty?
|
45
|
+
end
|
46
|
+
|
43
47
|
sig { params(uri: String).void }
|
44
48
|
def delete(uri)
|
45
49
|
@state.delete(uri)
|
@@ -51,10 +55,13 @@ module RubyLsp
|
|
51
55
|
uri: String,
|
52
56
|
request_name: Symbol,
|
53
57
|
block: T.proc.params(document: Document).returns(T.type_parameter(:T))
|
54
|
-
).returns(T.type_parameter(:T))
|
58
|
+
).returns(T.nilable(T.type_parameter(:T)))
|
55
59
|
end
|
56
60
|
def cache_fetch(uri, request_name, &block)
|
57
|
-
get(uri)
|
61
|
+
document = get(uri)
|
62
|
+
return unless document.parsed?
|
63
|
+
|
64
|
+
document.cache_fetch(request_name, &block)
|
58
65
|
end
|
59
66
|
end
|
60
67
|
end
|
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.2.
|
4
|
+
version: 0.2.3
|
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
|
+
date: 2022-08-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: language_server-protocol
|
@@ -60,32 +60,12 @@ executables:
|
|
60
60
|
extensions: []
|
61
61
|
extra_rdoc_files: []
|
62
62
|
files:
|
63
|
-
- ".github/dependabot.yml"
|
64
|
-
- ".github/probots.yml"
|
65
|
-
- ".github/pull_request_template.md"
|
66
|
-
- ".github/workflows/ci.yml"
|
67
|
-
- ".github/workflows/publish_docs.yml"
|
68
|
-
- ".gitignore"
|
69
|
-
- ".rubocop.yml"
|
70
|
-
- ".vscode/extensions.json"
|
71
|
-
- ".vscode/settings.json"
|
72
|
-
- ".vscode/tasks.json"
|
73
63
|
- CHANGELOG.md
|
74
|
-
- CODE_OF_CONDUCT.md
|
75
|
-
- Gemfile
|
76
|
-
- Gemfile.lock
|
77
64
|
- LICENSE.txt
|
78
65
|
- README.md
|
79
|
-
- Rakefile
|
80
66
|
- VERSION
|
81
|
-
- bin/console
|
82
|
-
- bin/rubocop
|
83
|
-
- bin/tapioca
|
84
|
-
- bin/test
|
85
|
-
- dev.yml
|
86
67
|
- exe/ruby-lsp
|
87
68
|
- lib/ruby-lsp.rb
|
88
|
-
- lib/ruby_lsp/cli.rb
|
89
69
|
- lib/ruby_lsp/document.rb
|
90
70
|
- lib/ruby_lsp/handler.rb
|
91
71
|
- lib/ruby_lsp/internal.rb
|
@@ -94,66 +74,22 @@ files:
|
|
94
74
|
- lib/ruby_lsp/requests/code_actions.rb
|
95
75
|
- lib/ruby_lsp/requests/diagnostics.rb
|
96
76
|
- lib/ruby_lsp/requests/document_highlight.rb
|
77
|
+
- lib/ruby_lsp/requests/document_link.rb
|
97
78
|
- lib/ruby_lsp/requests/document_symbol.rb
|
98
79
|
- lib/ruby_lsp/requests/folding_ranges.rb
|
99
80
|
- lib/ruby_lsp/requests/formatting.rb
|
100
81
|
- lib/ruby_lsp/requests/selection_ranges.rb
|
101
82
|
- lib/ruby_lsp/requests/semantic_highlighting.rb
|
83
|
+
- lib/ruby_lsp/requests/support/highlight_target.rb
|
102
84
|
- lib/ruby_lsp/requests/support/rubocop_diagnostic.rb
|
103
85
|
- lib/ruby_lsp/requests/support/rubocop_diagnostics_runner.rb
|
104
86
|
- lib/ruby_lsp/requests/support/rubocop_formatting_runner.rb
|
105
87
|
- lib/ruby_lsp/requests/support/selection_range.rb
|
106
88
|
- lib/ruby_lsp/requests/support/semantic_token_encoder.rb
|
89
|
+
- lib/ruby_lsp/requests/support/source_uri.rb
|
107
90
|
- lib/ruby_lsp/requests/support/syntax_error_diagnostic.rb
|
91
|
+
- lib/ruby_lsp/server.rb
|
108
92
|
- lib/ruby_lsp/store.rb
|
109
|
-
- rakelib/check_docs.rake
|
110
|
-
- ruby-lsp.gemspec
|
111
|
-
- service.yml
|
112
|
-
- sorbet/config
|
113
|
-
- sorbet/rbi/.rubocop.yml
|
114
|
-
- sorbet/rbi/gems/ansi@1.5.0.rbi
|
115
|
-
- sorbet/rbi/gems/ast@2.4.2.rbi
|
116
|
-
- sorbet/rbi/gems/builder@3.2.4.rbi
|
117
|
-
- sorbet/rbi/gems/coderay@1.1.3.rbi
|
118
|
-
- sorbet/rbi/gems/debug@1.5.0.rbi
|
119
|
-
- sorbet/rbi/gems/diff-lcs@1.5.0.rbi
|
120
|
-
- sorbet/rbi/gems/io-console@0.5.11.rbi
|
121
|
-
- sorbet/rbi/gems/irb@1.4.1.rbi
|
122
|
-
- sorbet/rbi/gems/language_server-protocol@3.16.0.3.rbi
|
123
|
-
- sorbet/rbi/gems/method_source@1.0.0.rbi
|
124
|
-
- sorbet/rbi/gems/minitest-reporters@1.5.0.rbi
|
125
|
-
- sorbet/rbi/gems/minitest@5.15.0.rbi
|
126
|
-
- sorbet/rbi/gems/parallel@1.22.1.rbi
|
127
|
-
- sorbet/rbi/gems/parser@3.1.2.0.rbi
|
128
|
-
- sorbet/rbi/gems/prettier_print@0.1.0.rbi
|
129
|
-
- sorbet/rbi/gems/pry@0.14.1.rbi
|
130
|
-
- sorbet/rbi/gems/rainbow@3.1.1.rbi
|
131
|
-
- sorbet/rbi/gems/rake@13.0.6.rbi
|
132
|
-
- sorbet/rbi/gems/rbi@0.0.14.rbi
|
133
|
-
- sorbet/rbi/gems/regexp_parser@2.5.0.rbi
|
134
|
-
- sorbet/rbi/gems/reline@0.3.1.rbi
|
135
|
-
- sorbet/rbi/gems/rexml@3.2.5.rbi
|
136
|
-
- sorbet/rbi/gems/rubocop-ast@1.18.0.rbi
|
137
|
-
- sorbet/rbi/gems/rubocop-minitest@0.20.0.rbi
|
138
|
-
- sorbet/rbi/gems/rubocop-rake@0.6.0.rbi
|
139
|
-
- sorbet/rbi/gems/rubocop-shopify@2.6.0.rbi
|
140
|
-
- sorbet/rbi/gems/rubocop-sorbet@0.6.8.rbi
|
141
|
-
- sorbet/rbi/gems/rubocop@1.30.0.rbi
|
142
|
-
- sorbet/rbi/gems/ruby-progressbar@1.11.0.rbi
|
143
|
-
- sorbet/rbi/gems/spoom@1.1.11.rbi
|
144
|
-
- sorbet/rbi/gems/syntax_tree@2.7.1.rbi
|
145
|
-
- sorbet/rbi/gems/tapioca@0.8.1.rbi
|
146
|
-
- sorbet/rbi/gems/thor@1.2.1.rbi
|
147
|
-
- sorbet/rbi/gems/unicode-display_width@2.1.0.rbi
|
148
|
-
- sorbet/rbi/gems/unparser@0.6.5.rbi
|
149
|
-
- sorbet/rbi/gems/webrick@1.7.0.rbi
|
150
|
-
- sorbet/rbi/gems/yard-sorbet@0.6.1.rbi
|
151
|
-
- sorbet/rbi/gems/yard@0.9.27.rbi
|
152
|
-
- sorbet/rbi/shims/fiddle.rbi
|
153
|
-
- sorbet/rbi/shims/hash.rbi
|
154
|
-
- sorbet/rbi/shims/rdoc.rbi
|
155
|
-
- sorbet/tapioca/config.yml
|
156
|
-
- sorbet/tapioca/require.rb
|
157
93
|
homepage: https://github.com/Shopify/ruby-lsp
|
158
94
|
licenses:
|
159
95
|
- MIT
|
data/.github/dependabot.yml
DELETED
data/.github/probots.yml
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
### Motivation
|
2
|
-
|
3
|
-
<!-- Explain why you are making this change. Include links to issues or describe the problem being solved, not the solution. -->
|
4
|
-
|
5
|
-
### Implementation
|
6
|
-
|
7
|
-
<!-- How did you implement your changes? Explain your solution, design decisions, things reviewers should watch out for. -->
|
8
|
-
|
9
|
-
### Automated Tests
|
10
|
-
|
11
|
-
<!-- We hope you added unit tests as part of your changes, just state that you have. If you haven't, state why. -->
|
12
|
-
|
13
|
-
### Manual Tests
|
14
|
-
|
15
|
-
<!-- Explain how we can test these changes in our own instance of VS Code. Provide the step by step instructions. -->
|
data/.github/workflows/ci.yml
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
name: CI
|
2
|
-
|
3
|
-
on: [push, pull_request]
|
4
|
-
|
5
|
-
jobs:
|
6
|
-
build:
|
7
|
-
runs-on: ubuntu-latest
|
8
|
-
strategy:
|
9
|
-
fail-fast: false
|
10
|
-
matrix:
|
11
|
-
ruby: [ "2.7", "3.0", "3.1" ]
|
12
|
-
name: Ruby ${{ matrix.ruby }}
|
13
|
-
steps:
|
14
|
-
- uses: actions/checkout@v2
|
15
|
-
- name: Set up Ruby
|
16
|
-
uses: ruby/setup-ruby@v1
|
17
|
-
with:
|
18
|
-
ruby-version: ${{ matrix.ruby }}
|
19
|
-
bundler-cache: true
|
20
|
-
|
21
|
-
- name: Check if documentation is up to date
|
22
|
-
run: bundle exec rake check_docs
|
23
|
-
|
24
|
-
- name: Typecheck
|
25
|
-
run: bundle exec srb tc
|
26
|
-
|
27
|
-
- name: Lint Ruby files
|
28
|
-
run: bin/rubocop
|
29
|
-
|
30
|
-
- name: Run tests
|
31
|
-
run: bin/test
|
@@ -1,32 +0,0 @@
|
|
1
|
-
name: Publish docs
|
2
|
-
|
3
|
-
on:
|
4
|
-
push:
|
5
|
-
branches: [main]
|
6
|
-
|
7
|
-
jobs:
|
8
|
-
build:
|
9
|
-
runs-on: ubuntu-latest
|
10
|
-
name: Publish documentation website
|
11
|
-
steps:
|
12
|
-
- uses: actions/checkout@v3
|
13
|
-
|
14
|
-
- name: Set up Ruby
|
15
|
-
uses: ruby/setup-ruby@v1
|
16
|
-
with:
|
17
|
-
ruby-version: 3.1.1
|
18
|
-
bundler-cache: true
|
19
|
-
|
20
|
-
- name: Configure git
|
21
|
-
run: |
|
22
|
-
git config user.name github-actions
|
23
|
-
git config user.email github-actions@github.com
|
24
|
-
|
25
|
-
- name: Generate documentation
|
26
|
-
run: bundle exec rake yard
|
27
|
-
|
28
|
-
- name: Commit to gh-pages
|
29
|
-
run: |
|
30
|
-
git add docs
|
31
|
-
git commit -m "Publish website $(git log --format=format:%h -1)"
|
32
|
-
git push --force origin main:gh-pages
|