rucoa 0.1.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.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +7 -0
  3. data/Gemfile +1 -0
  4. data/Gemfile.lock +4 -1
  5. data/README.md +7 -4
  6. data/lib/rucoa/cli.rb +2 -2
  7. data/lib/rucoa/configuration.rb +71 -0
  8. data/lib/rucoa/handler_concerns/configuration_requestable.rb +35 -0
  9. data/lib/rucoa/handler_concerns/diagnostics_publishable.rb +172 -0
  10. data/lib/rucoa/handler_concerns.rb +8 -0
  11. data/lib/rucoa/handlers/base.rb +61 -0
  12. data/lib/rucoa/handlers/initialize_handler.rb +23 -0
  13. data/lib/rucoa/handlers/initialized_handler.rb +13 -0
  14. data/lib/rucoa/handlers/text_document_code_action_handler.rb +104 -0
  15. data/lib/rucoa/handlers/text_document_did_change_handler.rb +31 -0
  16. data/lib/rucoa/handlers/text_document_did_open_handler.rb +31 -0
  17. data/lib/rucoa/handlers/text_document_document_symbol_handler.rb +241 -0
  18. data/lib/rucoa/handlers/text_document_formatting_handler.rb +64 -0
  19. data/lib/rucoa/handlers/text_document_range_formatting_handler.rb +76 -0
  20. data/lib/rucoa/handlers/text_document_selection_range_handler.rb +141 -0
  21. data/lib/rucoa/handlers/workspace_did_change_configuration_handler.rb +13 -0
  22. data/lib/rucoa/handlers.rb +17 -0
  23. data/lib/rucoa/message_reader.rb +3 -1
  24. data/lib/rucoa/message_writer.rb +3 -0
  25. data/lib/rucoa/node_concerns/name_full_qualifiable.rb +20 -0
  26. data/lib/rucoa/node_concerns.rb +7 -0
  27. data/lib/rucoa/nodes/base.rb +13 -0
  28. data/lib/rucoa/nodes/casgn_node.rb +14 -0
  29. data/lib/rucoa/nodes/class_node.rb +8 -0
  30. data/lib/rucoa/nodes/const_node.rb +12 -0
  31. data/lib/rucoa/nodes/def_node.rb +12 -0
  32. data/lib/rucoa/nodes/defs_node.rb +12 -0
  33. data/lib/rucoa/nodes/module_node.rb +21 -0
  34. data/lib/rucoa/nodes/sclass_node.rb +8 -0
  35. data/lib/rucoa/nodes/send_node.rb +17 -0
  36. data/lib/rucoa/nodes/str_node.rb +4 -0
  37. data/lib/rucoa/nodes/sym_node.rb +12 -0
  38. data/lib/rucoa/nodes.rb +9 -0
  39. data/lib/rucoa/parser_builder.rb +19 -10
  40. data/lib/rucoa/range.rb +32 -15
  41. data/lib/rucoa/rubocop_autocorrector.rb +38 -0
  42. data/lib/rucoa/rubocop_configuration_checker.rb +42 -0
  43. data/lib/rucoa/{rubocop_runner.rb → rubocop_investigator.rb} +9 -8
  44. data/lib/rucoa/server.rb +80 -97
  45. data/lib/rucoa/source.rb +2 -2
  46. data/lib/rucoa/source_store.rb +7 -1
  47. data/lib/rucoa/version.rb +1 -1
  48. data/lib/rucoa.rb +8 -4
  49. metadata +32 -5
  50. data/lib/rucoa/diagnostic_provider.rb +0 -112
  51. data/lib/rucoa/selection_range_provider.rb +0 -97
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rucoa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-03 00:00:00.000000000 Z
11
+ date: 2022-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -57,19 +57,46 @@ files:
57
57
  - exe/rucoa
58
58
  - lib/rucoa.rb
59
59
  - lib/rucoa/cli.rb
60
- - lib/rucoa/diagnostic_provider.rb
60
+ - lib/rucoa/configuration.rb
61
61
  - lib/rucoa/errors.rb
62
+ - lib/rucoa/handler_concerns.rb
63
+ - lib/rucoa/handler_concerns/configuration_requestable.rb
64
+ - lib/rucoa/handler_concerns/diagnostics_publishable.rb
65
+ - lib/rucoa/handlers.rb
66
+ - lib/rucoa/handlers/base.rb
67
+ - lib/rucoa/handlers/initialize_handler.rb
68
+ - lib/rucoa/handlers/initialized_handler.rb
69
+ - lib/rucoa/handlers/text_document_code_action_handler.rb
70
+ - lib/rucoa/handlers/text_document_did_change_handler.rb
71
+ - lib/rucoa/handlers/text_document_did_open_handler.rb
72
+ - lib/rucoa/handlers/text_document_document_symbol_handler.rb
73
+ - lib/rucoa/handlers/text_document_formatting_handler.rb
74
+ - lib/rucoa/handlers/text_document_range_formatting_handler.rb
75
+ - lib/rucoa/handlers/text_document_selection_range_handler.rb
76
+ - lib/rucoa/handlers/workspace_did_change_configuration_handler.rb
62
77
  - lib/rucoa/message_reader.rb
63
78
  - lib/rucoa/message_writer.rb
79
+ - lib/rucoa/node_concerns.rb
80
+ - lib/rucoa/node_concerns/name_full_qualifiable.rb
64
81
  - lib/rucoa/nodes.rb
65
82
  - lib/rucoa/nodes/base.rb
83
+ - lib/rucoa/nodes/casgn_node.rb
84
+ - lib/rucoa/nodes/class_node.rb
85
+ - lib/rucoa/nodes/const_node.rb
86
+ - lib/rucoa/nodes/def_node.rb
87
+ - lib/rucoa/nodes/defs_node.rb
88
+ - lib/rucoa/nodes/module_node.rb
89
+ - lib/rucoa/nodes/sclass_node.rb
90
+ - lib/rucoa/nodes/send_node.rb
66
91
  - lib/rucoa/nodes/str_node.rb
92
+ - lib/rucoa/nodes/sym_node.rb
67
93
  - lib/rucoa/parser.rb
68
94
  - lib/rucoa/parser_builder.rb
69
95
  - lib/rucoa/position.rb
70
96
  - lib/rucoa/range.rb
71
- - lib/rucoa/rubocop_runner.rb
72
- - lib/rucoa/selection_range_provider.rb
97
+ - lib/rucoa/rubocop_autocorrector.rb
98
+ - lib/rucoa/rubocop_configuration_checker.rb
99
+ - lib/rucoa/rubocop_investigator.rb
73
100
  - lib/rucoa/server.rb
74
101
  - lib/rucoa/source.rb
75
102
  - lib/rucoa/source_store.rb
@@ -1,112 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Rucoa
4
- class DiagnosticProvider
5
- # @param source [Rucoa::Source]
6
- # @return [Array<Hash>]
7
- def self.call(source:)
8
- new(source: source).call
9
- end
10
-
11
- # @param source [Rucoa::Source]
12
- def initialize(source:)
13
- @source = source
14
- end
15
-
16
- # @return [Array<Hash>]
17
- def call
18
- offenses.map do |offense|
19
- OffenseToDiagnosticMapper.call(offense: offense)
20
- end
21
- end
22
-
23
- private
24
-
25
- # @return [Array<RuboCop::Cop::Offense>]
26
- def offenses
27
- RubocopRunner.call(path: @source.path)
28
- end
29
-
30
- class OffenseToDiagnosticMapper
31
- LSP_SEVERITY_NAME_TO_VALUE_MAP = {
32
- error: 1,
33
- hint: 4,
34
- information: 3,
35
- warning: 2
36
- }.freeze
37
- private_constant :LSP_SEVERITY_NAME_TO_VALUE_MAP
38
-
39
- RUBOCOP_SEVERITY_NAME_TO_LSP_SEVERITY_MAP = {
40
- convention: LSP_SEVERITY_NAME_TO_VALUE_MAP[:information],
41
- error: LSP_SEVERITY_NAME_TO_VALUE_MAP[:error],
42
- fatal: LSP_SEVERITY_NAME_TO_VALUE_MAP[:error],
43
- info: LSP_SEVERITY_NAME_TO_VALUE_MAP[:information],
44
- refactor: LSP_SEVERITY_NAME_TO_VALUE_MAP[:hint],
45
- warning: LSP_SEVERITY_NAME_TO_VALUE_MAP[:warning]
46
- }.freeze
47
- private_constant :RUBOCOP_SEVERITY_NAME_TO_LSP_SEVERITY_MAP
48
-
49
- class << self
50
- # @param offense [RuboCop::Cop::Offense]
51
- # @return [Hash]
52
- def call(offense:)
53
- new(offense: offense).call
54
- end
55
- end
56
-
57
- # @param offense [RuboCop::Cop::Offense]
58
- def initialize(offense:)
59
- @offense = offense
60
- end
61
-
62
- # @return [Hash]
63
- def call
64
- {
65
- code: code,
66
- data: data,
67
- message: message,
68
- range: range,
69
- severity: severity,
70
- source: source
71
- }
72
- end
73
-
74
- private
75
-
76
- # @return [String]
77
- def code
78
- @offense.cop_name
79
- end
80
-
81
- # @return [Hash]
82
- def data
83
- {
84
- cop_name: @offense.cop_name,
85
- correctable: @offense.correctable?,
86
- path: @offense.location.source_buffer.name,
87
- range: range
88
- }
89
- end
90
-
91
- # @return [String]
92
- def message
93
- @offense.message.delete_prefix("#{@offense.cop_name}: ")
94
- end
95
-
96
- # @return [Hash]
97
- def range
98
- Range.from_rubocop_offense(@offense).to_vscode_range
99
- end
100
-
101
- # @return [Integer]
102
- def severity
103
- RUBOCOP_SEVERITY_NAME_TO_LSP_SEVERITY_MAP.fetch(@offense.severity.name, 1)
104
- end
105
-
106
- # @return [String]
107
- def source
108
- 'RuboCop'
109
- end
110
- end
111
- end
112
- end
@@ -1,97 +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
- end
79
- end
80
-
81
- private
82
-
83
- # @return [Rucoa::Range]
84
- def inner_range
85
- Range.new(
86
- Position.from_parser_range_ending(@node.location.begin),
87
- Position.from_parser_range_beginning(@node.location.end)
88
- )
89
- end
90
-
91
- # @return [Rucoa::Range]
92
- def expression_range
93
- Range.from_parser_range(@node.location.expression)
94
- end
95
- end
96
- end
97
- end