rucoa 0.3.0 → 0.4.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/Gemfile.lock +1 -1
- data/README.md +2 -2
- data/lib/rucoa/configuration.rb +8 -0
- data/lib/rucoa/handler_concerns/diagnostics_publishable.rb +140 -0
- data/lib/rucoa/handlers/initialize_handler.rb +1 -0
- data/lib/rucoa/handlers/text_document_code_action_handler.rb +78 -3
- data/lib/rucoa/handlers/text_document_document_symbol_handler.rb +241 -0
- data/lib/rucoa/handlers/text_document_formatting_handler.rb +36 -5
- data/lib/rucoa/handlers/text_document_range_formatting_handler.rb +65 -13
- data/lib/rucoa/handlers/text_document_selection_range_handler.rb +124 -8
- data/lib/rucoa/handlers.rb +1 -0
- data/lib/rucoa/node_concerns/name_full_qualifiable.rb +20 -0
- data/lib/rucoa/node_concerns.rb +7 -0
- data/lib/rucoa/nodes/base.rb +13 -0
- data/lib/rucoa/nodes/casgn_node.rb +14 -0
- data/lib/rucoa/nodes/class_node.rb +8 -0
- data/lib/rucoa/nodes/const_node.rb +12 -0
- data/lib/rucoa/nodes/def_node.rb +12 -0
- data/lib/rucoa/nodes/defs_node.rb +12 -0
- data/lib/rucoa/nodes/module_node.rb +21 -0
- data/lib/rucoa/nodes/sclass_node.rb +8 -0
- data/lib/rucoa/nodes/send_node.rb +17 -0
- data/lib/rucoa/nodes/str_node.rb +4 -0
- data/lib/rucoa/nodes/sym_node.rb +12 -0
- data/lib/rucoa/nodes.rb +9 -0
- data/lib/rucoa/parser_builder.rb +19 -10
- data/lib/rucoa/server.rb +1 -0
- data/lib/rucoa/source.rb +2 -2
- data/lib/rucoa/version.rb +1 -1
- data/lib/rucoa.rb +1 -5
- metadata +14 -7
- data/lib/rucoa/code_action_provider.rb +0 -102
- data/lib/rucoa/diagnostic_provider.rb +0 -143
- data/lib/rucoa/formatting_provider.rb +0 -54
- data/lib/rucoa/range_formatting_provider.rb +0 -67
- data/lib/rucoa/selection_range_provider.rb +0 -99
@@ -1,143 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Rucoa
|
4
|
-
class DiagnosticProvider
|
5
|
-
# @param source [Rucoa::Source]
|
6
|
-
# @param uri [String]
|
7
|
-
# @return [Array<Hash>]
|
8
|
-
def self.call(source:, uri:)
|
9
|
-
new(
|
10
|
-
source: source,
|
11
|
-
uri: uri
|
12
|
-
).call
|
13
|
-
end
|
14
|
-
|
15
|
-
# @param source [Rucoa::Source]
|
16
|
-
# @param uri [String]
|
17
|
-
def initialize(source:, uri:)
|
18
|
-
@source = source
|
19
|
-
@uri = uri
|
20
|
-
end
|
21
|
-
|
22
|
-
# @return [Array<Hash>]
|
23
|
-
def call
|
24
|
-
return [] unless RubocopConfigurationChecker.call
|
25
|
-
|
26
|
-
offenses.map do |offense|
|
27
|
-
OffenseToDiagnosticMapper.call(
|
28
|
-
offense,
|
29
|
-
source: @source,
|
30
|
-
uri: @uri
|
31
|
-
)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
private
|
36
|
-
|
37
|
-
# @return [Array<RuboCop::Cop::Offense>]
|
38
|
-
def offenses
|
39
|
-
RubocopInvestigator.call(source: @source)
|
40
|
-
end
|
41
|
-
|
42
|
-
class OffenseToDiagnosticMapper
|
43
|
-
LSP_SEVERITY_NAME_TO_VALUE_MAP = {
|
44
|
-
error: 1,
|
45
|
-
hint: 4,
|
46
|
-
information: 3,
|
47
|
-
warning: 2
|
48
|
-
}.freeze
|
49
|
-
private_constant :LSP_SEVERITY_NAME_TO_VALUE_MAP
|
50
|
-
|
51
|
-
RUBOCOP_SEVERITY_NAME_TO_LSP_SEVERITY_MAP = {
|
52
|
-
convention: LSP_SEVERITY_NAME_TO_VALUE_MAP[:information],
|
53
|
-
error: LSP_SEVERITY_NAME_TO_VALUE_MAP[:error],
|
54
|
-
fatal: LSP_SEVERITY_NAME_TO_VALUE_MAP[:error],
|
55
|
-
info: LSP_SEVERITY_NAME_TO_VALUE_MAP[:information],
|
56
|
-
refactor: LSP_SEVERITY_NAME_TO_VALUE_MAP[:hint],
|
57
|
-
warning: LSP_SEVERITY_NAME_TO_VALUE_MAP[:warning]
|
58
|
-
}.freeze
|
59
|
-
private_constant :RUBOCOP_SEVERITY_NAME_TO_LSP_SEVERITY_MAP
|
60
|
-
|
61
|
-
class << self
|
62
|
-
# @param offense [RuboCop::Cop::Offense]
|
63
|
-
# @param source [Rucoa::Source]
|
64
|
-
# @param uri [String]
|
65
|
-
# @return [Hash]
|
66
|
-
def call(offense, source:, uri:)
|
67
|
-
new(
|
68
|
-
offense,
|
69
|
-
source: source,
|
70
|
-
uri: uri
|
71
|
-
).call
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
# @param offense [RuboCop::Cop::Offense]
|
76
|
-
# @param source [Rucoa::Source]
|
77
|
-
# @param uri [String]
|
78
|
-
def initialize(offense, source:, uri:)
|
79
|
-
@offense = offense
|
80
|
-
@source = source
|
81
|
-
@uri = uri
|
82
|
-
end
|
83
|
-
|
84
|
-
# @return [Hash]
|
85
|
-
def call
|
86
|
-
{
|
87
|
-
code: code,
|
88
|
-
data: data,
|
89
|
-
message: message,
|
90
|
-
range: range,
|
91
|
-
severity: severity,
|
92
|
-
source: source
|
93
|
-
}
|
94
|
-
end
|
95
|
-
|
96
|
-
private
|
97
|
-
|
98
|
-
# @return [String]
|
99
|
-
def code
|
100
|
-
@offense.cop_name
|
101
|
-
end
|
102
|
-
|
103
|
-
# @return [Hash]
|
104
|
-
def data
|
105
|
-
{
|
106
|
-
cop_name: @offense.cop_name,
|
107
|
-
edits: edits,
|
108
|
-
uri: @uri
|
109
|
-
}
|
110
|
-
end
|
111
|
-
|
112
|
-
# @return [Array<Hash>, nil]
|
113
|
-
def edits
|
114
|
-
@offense.corrector&.as_replacements&.map do |range, replacement|
|
115
|
-
{
|
116
|
-
newText: replacement,
|
117
|
-
range: Range.from_parser_range(range).to_vscode_range
|
118
|
-
}
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
# @return [String]
|
123
|
-
def message
|
124
|
-
@offense.message.delete_prefix("#{@offense.cop_name}: ")
|
125
|
-
end
|
126
|
-
|
127
|
-
# @return [Hash]
|
128
|
-
def range
|
129
|
-
Range.from_parser_range(@offense.location).to_vscode_range
|
130
|
-
end
|
131
|
-
|
132
|
-
# @return [Integer]
|
133
|
-
def severity
|
134
|
-
RUBOCOP_SEVERITY_NAME_TO_LSP_SEVERITY_MAP.fetch(@offense.severity.name, 1)
|
135
|
-
end
|
136
|
-
|
137
|
-
# @return [String]
|
138
|
-
def source
|
139
|
-
'RuboCop'
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Rucoa
|
4
|
-
class FormattingProvider
|
5
|
-
class << self
|
6
|
-
# @param source [Rucoa::Source]
|
7
|
-
# @return [Array<Hash>]
|
8
|
-
def call(source:)
|
9
|
-
new(source: source).call
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
# @param source [Rucoa::Source]
|
14
|
-
def initialize(source:)
|
15
|
-
@source = source
|
16
|
-
end
|
17
|
-
|
18
|
-
# @return [Array<Hash>]
|
19
|
-
def call
|
20
|
-
return [] unless RubocopConfigurationChecker.call
|
21
|
-
|
22
|
-
[text_edit]
|
23
|
-
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
# @return [Hash]
|
28
|
-
def text_edit
|
29
|
-
{
|
30
|
-
newText: new_text,
|
31
|
-
range: range
|
32
|
-
}
|
33
|
-
end
|
34
|
-
|
35
|
-
# @return [String]
|
36
|
-
def new_text
|
37
|
-
RubocopAutocorrector.call(source: @source)
|
38
|
-
end
|
39
|
-
|
40
|
-
# @return [Hash]
|
41
|
-
def range
|
42
|
-
Range.new(
|
43
|
-
Position.new(
|
44
|
-
column: 0,
|
45
|
-
line: 1
|
46
|
-
),
|
47
|
-
Position.new(
|
48
|
-
column: @source.content.lines.last.length,
|
49
|
-
line: @source.content.lines.count + 1
|
50
|
-
)
|
51
|
-
).to_vscode_range
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
@@ -1,67 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Rucoa
|
4
|
-
class RangeFormattingProvider
|
5
|
-
class << self
|
6
|
-
# @param range [Rucoa::Range]
|
7
|
-
# @param source [Rucoa::Source]
|
8
|
-
# @return [Array<Hash>]
|
9
|
-
def call(range:, source:)
|
10
|
-
new(range: range, source: source).call
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
# @param range [Rucoa::Range]
|
15
|
-
# @param source [Rucoa::Source]
|
16
|
-
def initialize(range:, source:)
|
17
|
-
@range = range
|
18
|
-
@source = source
|
19
|
-
end
|
20
|
-
|
21
|
-
# @return [Array<Hash>]
|
22
|
-
def call
|
23
|
-
return [] unless RubocopConfigurationChecker.call
|
24
|
-
|
25
|
-
edits
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
# @return [Array<RuboCop::Cop::Corrector>]
|
31
|
-
def correctable_offenses
|
32
|
-
offenses.select(&:corrector)
|
33
|
-
end
|
34
|
-
|
35
|
-
# @return [Array(Rucoa::Range, String)]
|
36
|
-
def correctable_replacements
|
37
|
-
replacements.select do |range, _|
|
38
|
-
@range.contains?(range)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
# @return [Array<Hash>]
|
43
|
-
def edits
|
44
|
-
correctable_replacements.map do |range, replacement|
|
45
|
-
{
|
46
|
-
newText: replacement,
|
47
|
-
range: range.to_vscode_range
|
48
|
-
}
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
# @return [Array<RuboCop::Cop::Offense>]
|
53
|
-
def offenses
|
54
|
-
RubocopInvestigator.call(source: @source)
|
55
|
-
end
|
56
|
-
|
57
|
-
# @return [Array(Rucoa::Range, String)]
|
58
|
-
def replacements
|
59
|
-
correctable_offenses.map(&:corrector).flat_map(&:as_replacements).map do |range, replacement|
|
60
|
-
[
|
61
|
-
Range.from_parser_range(range),
|
62
|
-
replacement
|
63
|
-
]
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
@@ -1,99 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Rucoa
|
4
|
-
class SelectionRangeProvider
|
5
|
-
class << self
|
6
|
-
# @param source [Rucoa::Source]
|
7
|
-
# @param position [Rucoa::Position]
|
8
|
-
# @return [Hash, nil]
|
9
|
-
def call(position:, source:)
|
10
|
-
new(
|
11
|
-
position: position,
|
12
|
-
source: source
|
13
|
-
).call
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
# @param position [Rucoa::Position]
|
18
|
-
# @param source [Rucoa::Source]
|
19
|
-
def initialize(position:, source:)
|
20
|
-
@position = position
|
21
|
-
@source = source
|
22
|
-
end
|
23
|
-
|
24
|
-
# @return [Hash, nil]
|
25
|
-
def call
|
26
|
-
ranges.reverse.reduce(nil) do |result, range|
|
27
|
-
{
|
28
|
-
parent: result,
|
29
|
-
range: range.to_vscode_range
|
30
|
-
}
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
private
|
35
|
-
|
36
|
-
# @return [Rucoa::Nodes::Base, nil]
|
37
|
-
def node_at_position
|
38
|
-
if instance_variable_defined?(:@node_at_position)
|
39
|
-
@node_at_position
|
40
|
-
else
|
41
|
-
@node_at_position = @source.node_at(@position)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
# @return [Array<Rucoa::Range>]
|
46
|
-
def ranges
|
47
|
-
return [] unless node_at_position
|
48
|
-
|
49
|
-
[node_at_position, *node_at_position.ancestors].flat_map do |node|
|
50
|
-
NodeToRangesMapper.call(node)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
class NodeToRangesMapper
|
55
|
-
class << self
|
56
|
-
# @param node [Rucoa::Nodes::Base]
|
57
|
-
# @return [Array<Rucoa::Range>]
|
58
|
-
def call(node)
|
59
|
-
new(node).call
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
# @param node [Rucoa::Nodes::Base]
|
64
|
-
def initialize(node)
|
65
|
-
@node = node
|
66
|
-
end
|
67
|
-
|
68
|
-
# @return [Array<Rucoa::Range>]
|
69
|
-
def call
|
70
|
-
case @node
|
71
|
-
when Nodes::StrNode
|
72
|
-
[
|
73
|
-
inner_range,
|
74
|
-
expression_range
|
75
|
-
]
|
76
|
-
else
|
77
|
-
[
|
78
|
-
expression_range
|
79
|
-
]
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
private
|
84
|
-
|
85
|
-
# @return [Rucoa::Range]
|
86
|
-
def inner_range
|
87
|
-
Range.new(
|
88
|
-
Position.from_parser_range_ending(@node.location.begin),
|
89
|
-
Position.from_parser_range_beginning(@node.location.end)
|
90
|
-
)
|
91
|
-
end
|
92
|
-
|
93
|
-
# @return [Rucoa::Range]
|
94
|
-
def expression_range
|
95
|
-
Range.from_parser_range(@node.location.expression)
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|