ruby-lsp 0.4.1 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +44 -52
- data/VERSION +1 -1
- data/exe/ruby-lsp +12 -0
- data/lib/rubocop/cop/ruby_lsp/use_language_server_aliases.rb +62 -0
- data/lib/ruby_lsp/document.rb +13 -4
- data/lib/ruby_lsp/executor.rb +70 -26
- data/lib/ruby_lsp/internal.rb +1 -0
- data/lib/ruby_lsp/requests/base_request.rb +15 -6
- data/lib/ruby_lsp/requests/code_action_resolve.rb +40 -19
- data/lib/ruby_lsp/requests/code_actions.rb +5 -4
- data/lib/ruby_lsp/requests/diagnostics.rb +4 -4
- data/lib/ruby_lsp/requests/document_highlight.rb +3 -3
- data/lib/ruby_lsp/requests/document_link.rb +7 -7
- data/lib/ruby_lsp/requests/document_symbol.rb +14 -11
- data/lib/ruby_lsp/requests/folding_ranges.rb +38 -11
- data/lib/ruby_lsp/requests/formatting.rb +18 -5
- data/lib/ruby_lsp/requests/hover.rb +7 -6
- data/lib/ruby_lsp/requests/inlay_hints.rb +5 -4
- data/lib/ruby_lsp/requests/path_completion.rb +9 -3
- data/lib/ruby_lsp/requests/selection_ranges.rb +3 -3
- data/lib/ruby_lsp/requests/semantic_highlighting.rb +72 -8
- data/lib/ruby_lsp/requests/support/highlight_target.rb +5 -4
- data/lib/ruby_lsp/requests/support/rails_document_client.rb +7 -6
- data/lib/ruby_lsp/requests/support/selection_range.rb +1 -1
- data/lib/ruby_lsp/requests/support/semantic_token_encoder.rb +2 -2
- data/lib/ruby_lsp/requests/support/sorbet.rb +5 -15
- data/lib/ruby_lsp/requests/support/syntax_tree_formatting_runner.rb +39 -0
- data/lib/ruby_lsp/server.rb +4 -1
- data/lib/ruby_lsp/store.rb +11 -7
- data/lib/ruby_lsp/utils.rb +3 -0
- metadata +7 -5
@@ -67,12 +67,13 @@ module RubyLsp
|
|
67
67
|
return unless RAILTIES_VERSION
|
68
68
|
|
69
69
|
warn("Fetching Rails Documents...")
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
70
|
+
|
71
|
+
response = Net::HTTP.get_response(URI("#{RAILS_DOC_HOST}/v#{RAILTIES_VERSION}/js/search_index.js"))
|
72
|
+
|
73
|
+
if response.code == "302"
|
74
|
+
# If the version's doc is not found, e.g. Rails main, it'll be redirected
|
75
|
+
# In this case, we just fetch the latest doc
|
76
|
+
response = Net::HTTP.get_response(URI("#{RAILS_DOC_HOST}/js/search_index.js"))
|
76
77
|
end
|
77
78
|
|
78
79
|
if response.code == "200"
|
@@ -4,7 +4,7 @@
|
|
4
4
|
module RubyLsp
|
5
5
|
module Requests
|
6
6
|
module Support
|
7
|
-
class SelectionRange <
|
7
|
+
class SelectionRange < Interface::SelectionRange
|
8
8
|
extend T::Sig
|
9
9
|
|
10
10
|
sig { params(position: Document::PositionShape).returns(T::Boolean) }
|
@@ -16,7 +16,7 @@ module RubyLsp
|
|
16
16
|
sig do
|
17
17
|
params(
|
18
18
|
tokens: T::Array[SemanticHighlighting::SemanticToken],
|
19
|
-
).returns(
|
19
|
+
).returns(Interface::SemanticTokens)
|
20
20
|
end
|
21
21
|
def encode(tokens)
|
22
22
|
delta = tokens
|
@@ -27,7 +27,7 @@ module RubyLsp
|
|
27
27
|
compute_delta(token)
|
28
28
|
end
|
29
29
|
|
30
|
-
|
30
|
+
Interface::SemanticTokens.new(data: delta)
|
31
31
|
end
|
32
32
|
|
33
33
|
# The delta array is computed according to the LSP specification:
|
@@ -63,7 +63,8 @@ module RubyLsp
|
|
63
63
|
when SyntaxTree::VCall
|
64
64
|
ANNOTATIONS[node.value.value]
|
65
65
|
when SyntaxTree::CallNode
|
66
|
-
|
66
|
+
message = node.message
|
67
|
+
ANNOTATIONS[message.value] unless message.is_a?(Symbol)
|
67
68
|
else
|
68
69
|
T.absurd(node)
|
69
70
|
end
|
@@ -84,21 +85,10 @@ module RubyLsp
|
|
84
85
|
end
|
85
86
|
|
86
87
|
sig do
|
87
|
-
params(node: T.nilable(T.
|
88
|
-
SyntaxTree::VarRef,
|
89
|
-
SyntaxTree::CallNode,
|
90
|
-
SyntaxTree::VCall,
|
91
|
-
SyntaxTree::Ident,
|
92
|
-
SyntaxTree::Backtick,
|
93
|
-
SyntaxTree::Const,
|
94
|
-
SyntaxTree::Op,
|
95
|
-
Symbol,
|
96
|
-
))).returns(T.nilable(String))
|
88
|
+
params(node: T.nilable(SyntaxTree::Node)).returns(T.nilable(String))
|
97
89
|
end
|
98
90
|
def node_name(node)
|
99
91
|
case node
|
100
|
-
when NilClass
|
101
|
-
nil
|
102
92
|
when SyntaxTree::VarRef
|
103
93
|
node.value.value
|
104
94
|
when SyntaxTree::CallNode
|
@@ -107,8 +97,8 @@ module RubyLsp
|
|
107
97
|
node_name(node.value)
|
108
98
|
when SyntaxTree::Ident, SyntaxTree::Backtick, SyntaxTree::Const, SyntaxTree::Op
|
109
99
|
node.value
|
110
|
-
when
|
111
|
-
|
100
|
+
when NilClass, SyntaxTree::Node
|
101
|
+
nil
|
112
102
|
else
|
113
103
|
T.absurd(node)
|
114
104
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "syntax_tree/cli"
|
5
|
+
require "singleton"
|
6
|
+
|
7
|
+
module RubyLsp
|
8
|
+
module Requests
|
9
|
+
module Support
|
10
|
+
# :nodoc:
|
11
|
+
class SyntaxTreeFormattingRunner
|
12
|
+
extend T::Sig
|
13
|
+
include Singleton
|
14
|
+
|
15
|
+
sig { void }
|
16
|
+
def initialize
|
17
|
+
@options =
|
18
|
+
T.let(
|
19
|
+
begin
|
20
|
+
opts = SyntaxTree::CLI::Options.new
|
21
|
+
opts.parse(SyntaxTree::CLI::ConfigFile.new.arguments)
|
22
|
+
opts
|
23
|
+
end,
|
24
|
+
SyntaxTree::CLI::Options,
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
sig { params(_uri: String, document: Document).returns(T.nilable(String)) }
|
29
|
+
def run(_uri, document)
|
30
|
+
SyntaxTree.format(
|
31
|
+
document.source,
|
32
|
+
@options.print_width,
|
33
|
+
options: @options.formatter_options,
|
34
|
+
)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/ruby_lsp/server.rb
CHANGED
@@ -2,9 +2,11 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
module RubyLsp
|
5
|
+
# rubocop:disable RubyLsp/UseLanguageServerAliases
|
5
6
|
Interface = LanguageServer::Protocol::Interface
|
6
7
|
Constant = LanguageServer::Protocol::Constant
|
7
8
|
Transport = LanguageServer::Protocol::Transport
|
9
|
+
# rubocop:enable RubyLsp/UseLanguageServerAliases
|
8
10
|
|
9
11
|
class Server
|
10
12
|
extend T::Sig
|
@@ -33,7 +35,8 @@ module RubyLsp
|
|
33
35
|
# fall under the else branch which just pushes requests to the queue
|
34
36
|
@reader.read do |request|
|
35
37
|
case request[:method]
|
36
|
-
when "initialize", "initialized", "textDocument/didOpen", "textDocument/didClose", "textDocument/didChange"
|
38
|
+
when "initialize", "initialized", "textDocument/didOpen", "textDocument/didClose", "textDocument/didChange",
|
39
|
+
"textDocument/formatting", "textDocument/onTypeFormatting", "codeAction/resolve"
|
37
40
|
result = Executor.new(@store).execute(request)
|
38
41
|
finalize_request(result, request)
|
39
42
|
when "$/cancelRequest"
|
data/lib/ruby_lsp/store.rb
CHANGED
@@ -12,10 +12,14 @@ module RubyLsp
|
|
12
12
|
sig { params(encoding: String).void }
|
13
13
|
attr_writer :encoding
|
14
14
|
|
15
|
+
sig { returns(String) }
|
16
|
+
attr_accessor :formatter
|
17
|
+
|
15
18
|
sig { void }
|
16
19
|
def initialize
|
17
20
|
@state = T.let({}, T::Hash[String, Document])
|
18
21
|
@encoding = T.let("utf-8", String)
|
22
|
+
@formatter = T.let("auto", String)
|
19
23
|
end
|
20
24
|
|
21
25
|
sig { params(uri: String).returns(Document) }
|
@@ -23,19 +27,19 @@ module RubyLsp
|
|
23
27
|
document = @state[uri]
|
24
28
|
return document unless document.nil?
|
25
29
|
|
26
|
-
set(uri, File.binread(CGI.unescape(URI.parse(uri).path)))
|
30
|
+
set(uri: uri, source: File.binread(CGI.unescape(URI.parse(uri).path)), version: 0)
|
27
31
|
T.must(@state[uri])
|
28
32
|
end
|
29
33
|
|
30
|
-
sig { params(uri: String,
|
31
|
-
def set(uri
|
32
|
-
document = Document.new(
|
34
|
+
sig { params(uri: String, source: String, version: Integer).void }
|
35
|
+
def set(uri:, source:, version:)
|
36
|
+
document = Document.new(source: source, version: version, uri: uri, encoding: @encoding)
|
33
37
|
@state[uri] = document
|
34
38
|
end
|
35
39
|
|
36
|
-
sig { params(uri: String, edits: T::Array[Document::EditShape]).void }
|
37
|
-
def push_edits(uri
|
38
|
-
T.must(@state[uri]).push_edits(edits)
|
40
|
+
sig { params(uri: String, edits: T::Array[Document::EditShape], version: Integer).void }
|
41
|
+
def push_edits(uri:, edits:, version:)
|
42
|
+
T.must(@state[uri]).push_edits(edits, version: version)
|
39
43
|
end
|
40
44
|
|
41
45
|
sig { void }
|
data/lib/ruby_lsp/utils.rb
CHANGED
@@ -5,6 +5,9 @@ module RubyLsp
|
|
5
5
|
# Used to indicate that a request shouldn't return a response
|
6
6
|
VOID = T.let(Object.new.freeze, Object)
|
7
7
|
|
8
|
+
# This freeze is not redundant since the interpolated string is mutable
|
9
|
+
WORKSPACE_URI = T.let("file://#{Dir.pwd}".freeze, String) # rubocop:disable Style/RedundantFreeze
|
10
|
+
|
8
11
|
# A notification to be sent to the client
|
9
12
|
class Notification
|
10
13
|
extend T::Sig
|
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.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shopify
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: language_server-protocol
|
@@ -44,7 +44,7 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 6.1.1
|
48
48
|
- - "<"
|
49
49
|
- !ruby/object:Gem::Version
|
50
50
|
version: '7'
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
requirements:
|
55
55
|
- - ">="
|
56
56
|
- !ruby/object:Gem::Version
|
57
|
-
version:
|
57
|
+
version: 6.1.1
|
58
58
|
- - "<"
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '7'
|
@@ -70,6 +70,7 @@ files:
|
|
70
70
|
- README.md
|
71
71
|
- VERSION
|
72
72
|
- exe/ruby-lsp
|
73
|
+
- lib/rubocop/cop/ruby_lsp/use_language_server_aliases.rb
|
73
74
|
- lib/ruby-lsp.rb
|
74
75
|
- lib/ruby_lsp/document.rb
|
75
76
|
- lib/ruby_lsp/executor.rb
|
@@ -102,6 +103,7 @@ files:
|
|
102
103
|
- lib/ruby_lsp/requests/support/semantic_token_encoder.rb
|
103
104
|
- lib/ruby_lsp/requests/support/sorbet.rb
|
104
105
|
- lib/ruby_lsp/requests/support/source_uri.rb
|
106
|
+
- lib/ruby_lsp/requests/support/syntax_tree_formatting_runner.rb
|
105
107
|
- lib/ruby_lsp/server.rb
|
106
108
|
- lib/ruby_lsp/store.rb
|
107
109
|
- lib/ruby_lsp/utils.rb
|
@@ -125,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
127
|
- !ruby/object:Gem::Version
|
126
128
|
version: '0'
|
127
129
|
requirements: []
|
128
|
-
rubygems_version: 3.
|
130
|
+
rubygems_version: 3.4.9
|
129
131
|
signing_key:
|
130
132
|
specification_version: 4
|
131
133
|
summary: An opinionated language server for Ruby
|