rucoa 0.3.0 → 0.5.1

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 (75) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -0
  3. data/Gemfile +1 -0
  4. data/Gemfile.lock +12 -2
  5. data/README.md +37 -6
  6. data/data/definitions_ruby_3_1 +0 -0
  7. data/images/diagnostics.gif +0 -0
  8. data/images/document-formatting.gif +0 -0
  9. data/images/document-symbol.gif +0 -0
  10. data/images/selection-ranges.gif +0 -0
  11. data/lib/rucoa/configuration.rb +62 -28
  12. data/lib/rucoa/definition_archiver.rb +29 -0
  13. data/lib/rucoa/definition_builders/rbs_constant_definition_builder.rb +44 -0
  14. data/lib/rucoa/definition_builders/rbs_method_definition_builder.rb +106 -0
  15. data/lib/rucoa/definition_builders/yard_method_definition_builder.rb +218 -0
  16. data/lib/rucoa/definition_builders.rb +9 -0
  17. data/lib/rucoa/definition_store.rb +63 -0
  18. data/lib/rucoa/definitions/base.rb +12 -0
  19. data/lib/rucoa/definitions/constant_definition.rb +51 -0
  20. data/lib/rucoa/definitions/method_definition.rb +126 -0
  21. data/lib/rucoa/definitions/method_parameter_definition.rb +30 -0
  22. data/lib/rucoa/definitions.rb +9 -0
  23. data/lib/rucoa/handler_concerns/diagnostics_publishable.rb +140 -0
  24. data/lib/rucoa/handlers/base.rb +8 -0
  25. data/lib/rucoa/handlers/exit_handler.rb +11 -0
  26. data/lib/rucoa/handlers/initialize_handler.rb +7 -0
  27. data/lib/rucoa/handlers/initialized_handler.rb +10 -0
  28. data/lib/rucoa/handlers/shutdown_handler.rb +12 -0
  29. data/lib/rucoa/handlers/text_document_code_action_handler.rb +78 -3
  30. data/lib/rucoa/handlers/text_document_did_change_handler.rb +1 -20
  31. data/lib/rucoa/handlers/text_document_did_open_handler.rb +11 -4
  32. data/lib/rucoa/handlers/text_document_document_symbol_handler.rb +242 -0
  33. data/lib/rucoa/handlers/text_document_formatting_handler.rb +36 -5
  34. data/lib/rucoa/handlers/text_document_range_formatting_handler.rb +65 -13
  35. data/lib/rucoa/handlers/text_document_selection_range_handler.rb +124 -8
  36. data/lib/rucoa/handlers/text_document_signature_help_handler.rb +68 -0
  37. data/lib/rucoa/handlers.rb +4 -0
  38. data/lib/rucoa/node_concerns/name_full_qualifiable.rb +20 -0
  39. data/lib/rucoa/node_concerns.rb +7 -0
  40. data/lib/rucoa/node_inspector.rb +111 -0
  41. data/lib/rucoa/nodes/base.rb +43 -0
  42. data/lib/rucoa/nodes/casgn_node.rb +14 -0
  43. data/lib/rucoa/nodes/class_node.rb +8 -0
  44. data/lib/rucoa/nodes/const_node.rb +12 -0
  45. data/lib/rucoa/nodes/def_node.rb +71 -0
  46. data/lib/rucoa/nodes/defs_node.rb +12 -0
  47. data/lib/rucoa/nodes/lvar_node.rb +25 -0
  48. data/lib/rucoa/nodes/module_node.rb +21 -0
  49. data/lib/rucoa/nodes/sclass_node.rb +8 -0
  50. data/lib/rucoa/nodes/send_node.rb +60 -0
  51. data/lib/rucoa/nodes/str_node.rb +4 -0
  52. data/lib/rucoa/nodes/sym_node.rb +12 -0
  53. data/lib/rucoa/nodes.rb +10 -0
  54. data/lib/rucoa/parser_builder.rb +20 -10
  55. data/lib/rucoa/position.rb +2 -2
  56. data/lib/rucoa/range.rb +64 -14
  57. data/lib/rucoa/rbs_document_loader.rb +43 -0
  58. data/lib/rucoa/rubocop_autocorrector.rb +1 -1
  59. data/lib/rucoa/rubocop_investigator.rb +1 -1
  60. data/lib/rucoa/server.rb +20 -1
  61. data/lib/rucoa/source.rb +56 -6
  62. data/lib/rucoa/source_store.rb +6 -10
  63. data/lib/rucoa/types/method_type.rb +23 -0
  64. data/lib/rucoa/types.rb +7 -0
  65. data/lib/rucoa/version.rb +1 -1
  66. data/lib/rucoa/yard_glob_document_loader.rb +47 -0
  67. data/lib/rucoa/yard_string_document_loader.rb +70 -0
  68. data/lib/rucoa.rb +10 -5
  69. data/rucoa.gemspec +2 -0
  70. metadata +68 -7
  71. data/lib/rucoa/code_action_provider.rb +0 -102
  72. data/lib/rucoa/diagnostic_provider.rb +0 -143
  73. data/lib/rucoa/formatting_provider.rb +0 -54
  74. data/lib/rucoa/range_formatting_provider.rb +0 -67
  75. data/lib/rucoa/selection_range_provider.rb +0 -99
data/lib/rucoa/server.rb CHANGED
@@ -4,21 +4,31 @@ module Rucoa
4
4
  class Server
5
5
  # @return [Hash{String => Class}]
6
6
  METHOD_TO_HANDLER_MAP = {
7
+ 'exit' => Handlers::ExitHandler,
7
8
  'initialize' => Handlers::InitializeHandler,
8
9
  'initialized' => Handlers::InitializedHandler,
10
+ 'shutdown' => Handlers::ShutdownHandler,
9
11
  'textDocument/codeAction' => Handlers::TextDocumentCodeActionHandler,
10
12
  'textDocument/didChange' => Handlers::TextDocumentDidChangeHandler,
11
13
  'textDocument/didOpen' => Handlers::TextDocumentDidOpenHandler,
14
+ 'textDocument/documentSymbol' => Handlers::TextDocumentDocumentSymbolHandler,
12
15
  'textDocument/formatting' => Handlers::TextDocumentFormattingHandler,
13
16
  'textDocument/rangeFormatting' => Handlers::TextDocumentRangeFormattingHandler,
14
17
  'textDocument/selectionRange' => Handlers::TextDocumentSelectionRangeHandler,
18
+ 'textDocument/signatureHelp' => Handlers::TextDocumentSignatureHelpHandler,
15
19
  'workspace/didChangeConfiguration' => Handlers::WorkspaceDidChangeConfigurationHandler
16
20
  }.freeze
17
21
  private_constant :METHOD_TO_HANDLER_MAP
18
22
 
23
+ # @return [Boolean]
24
+ attr_accessor :shutting_down
25
+
19
26
  # @return [Rucoa::Configuration]
20
27
  attr_reader :configuration
21
28
 
29
+ # @return [Rucoa::DefinitionStore]
30
+ attr_reader :definition_store
31
+
22
32
  # @return [Rucoa::SourceStore]
23
33
  attr_reader :source_store
24
34
 
@@ -28,10 +38,14 @@ module Rucoa
28
38
  @reader = MessageReader.new(input)
29
39
  @writer = MessageWriter.new(output)
30
40
 
41
+ @client_response_handlers = {}
31
42
  @configuration = Configuration.new
32
43
  @server_request_id = 0
33
- @client_response_handlers = {}
44
+ @shutting_down = false
34
45
  @source_store = SourceStore.new
46
+
47
+ @definition_store = DefinitionStore.new
48
+ @definition_store.definitions += DefinitionArchiver.load
35
49
  end
36
50
 
37
51
  # @return [void]
@@ -41,6 +55,11 @@ module Rucoa
41
55
  end
42
56
  end
43
57
 
58
+ # @return [void]
59
+ def finish
60
+ exit(0)
61
+ end
62
+
44
63
  # @yieldparam response [Hash]
45
64
  # @param message [Hash]
46
65
  # @return [void]
data/lib/rucoa/source.rb CHANGED
@@ -6,13 +6,59 @@ module Rucoa
6
6
  attr_reader :content
7
7
 
8
8
  # @return [String]
9
- attr_reader :path
9
+ attr_reader :uri
10
10
 
11
11
  # @param content [String]
12
- # @param path [String, nil]
13
- def initialize(content:, path: nil)
12
+ # @param uri [String, nil]
13
+ def initialize(content:, uri: nil)
14
14
  @content = content
15
- @path = path
15
+ @uri = uri
16
+ end
17
+
18
+ # @return [Array<Rucoa::Definition::Base>]
19
+ # @example returns definitions from given source
20
+ # content = <<~RUBY
21
+ # class Foo
22
+ # def bar
23
+ # end
24
+ # end
25
+ # RUBY
26
+ # source = Rucoa::Source.new(
27
+ # content: content,
28
+ # uri: 'file:///path/to/foo.rb'
29
+ # )
30
+ # expect(source.definitions).to match(
31
+ # [
32
+ # a_kind_of(Rucoa::Definitions::MethodDefinition)
33
+ # ]
34
+ # )
35
+ def definitions
36
+ @definitions ||= YardStringDocumentLoader.call(
37
+ content: @content,
38
+ path: path
39
+ )
40
+ end
41
+
42
+ # @return [String, nil]
43
+ # @example returns path from given VSCode URI
44
+ # source = Rucoa::Source.new(
45
+ # content: '',
46
+ # uri: 'file:///path/to/foo.rb'
47
+ # )
48
+ # expect(source.path).to eq('/path/to/foo.rb')
49
+ # @example returns nil for untitled URI
50
+ # source = Rucoa::Source.new(
51
+ # content: '',
52
+ # uri: 'untitled:Untitled-1'
53
+ # )
54
+ # expect(source.path).to be_nil
55
+ def path
56
+ return unless @uri
57
+
58
+ path = ::URI.parse(@uri).path
59
+ return unless path
60
+
61
+ ::CGI.unescape(path)
16
62
  end
17
63
 
18
64
  # @param position [Rucoa::Position]
@@ -21,15 +67,19 @@ module Rucoa
21
67
  root_and_descendant_nodes.reverse.find do |node|
22
68
  node.include_position?(position)
23
69
  end
70
+ rescue ::Parser::SyntaxError
71
+ nil
24
72
  end
25
73
 
26
- private
27
-
28
74
  # @return [Rucoa::Nodes::Base, nil]
29
75
  def root_node
30
76
  @root_node ||= Parser.call(@content)
77
+ rescue ::Parser::SyntaxError
78
+ nil
31
79
  end
32
80
 
81
+ private
82
+
33
83
  # @return [Array<Rucoa::Nodes::Base>]
34
84
  def root_and_descendant_nodes
35
85
  return [] unless root_node
@@ -9,22 +9,18 @@ module Rucoa
9
9
  @data = {}
10
10
  end
11
11
 
12
+ # @param source [Rucoa::Source]
13
+ # @return [void]
14
+ def update(source)
15
+ @data[source.uri] = source
16
+ end
17
+
12
18
  # @param uri [String]
13
19
  # @return [String, nil]
14
20
  def get(uri)
15
21
  @data[uri]
16
22
  end
17
23
 
18
- # @param uri [String]
19
- # @param content [String]
20
- # @return [void]
21
- def set(uri, content)
22
- @data[uri] = Source.new(
23
- content: content,
24
- path: path_from_uri(uri)
25
- )
26
- end
27
-
28
24
  # @yieldparam uri [String]
29
25
  # @return [Enumerable<String>]
30
26
  def each_uri(&block)
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rucoa
4
+ module Types
5
+ class MethodType
6
+ # @return [String]
7
+ attr_reader :parameters_string
8
+
9
+ # @return [String]
10
+ attr_reader :return_type
11
+
12
+ # @param parameters_string [String]
13
+ # @param return_type [String]
14
+ def initialize(
15
+ parameters_string:,
16
+ return_type:
17
+ )
18
+ @parameters_string = parameters_string
19
+ @return_type = return_type
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rucoa
4
+ module Types
5
+ autoload :MethodType, 'rucoa/types/method_type'
6
+ end
7
+ end
data/lib/rucoa/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rucoa
4
- VERSION = '0.3.0'
4
+ VERSION = '0.5.1'
5
5
  end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'logger'
4
+ require 'yard'
5
+
6
+ module Rucoa
7
+ class YardGlobDocumentLoader
8
+ class << self
9
+ # @param globs [Array<String>]
10
+ # @return [Array<Rucoa::Definitions::Base>]
11
+ def call(globs:)
12
+ new(
13
+ globs: globs
14
+ ).call
15
+ end
16
+ end
17
+
18
+ # @param globs [String]
19
+ def initialize(globs:)
20
+ @globs = globs
21
+ end
22
+
23
+ # @return [Array<Rucoa::Definitions::Base>]
24
+ def call
25
+ code_objects.filter_map do |code_object|
26
+ case code_object
27
+ when ::YARD::CodeObjects::MethodObject
28
+ DefinitionBuilders::YardMethodDefinitionBuilder.call(
29
+ code_object: code_object,
30
+ path: code_object.file
31
+ )
32
+ end
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ # @return [Array<YARD::CodeObjects::Base>]
39
+ def code_objects
40
+ ::YARD::Logger.instance.enter_level(::Logger::FATAL) do
41
+ ::YARD::Registry.clear
42
+ ::YARD.parse(@globs)
43
+ ::YARD::Registry.all
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'logger'
4
+ require 'yard'
5
+
6
+ module Rucoa
7
+ class YardStringDocumentLoader
8
+ class << self
9
+ # @param content [String]
10
+ # @return [Array<Rucoa::Definitions::Base>]
11
+ # @example returns method definitions from Ruby source code
12
+ # content = <<~RUBY
13
+ # class Foo
14
+ # # Return given argument as an Integer.
15
+ # # @param bar [String]
16
+ # # @return [Integer]
17
+ # def foo(bar)
18
+ # bar.to_i
19
+ # end
20
+ # end
21
+ # RUBY
22
+ # definitions = Rucoa::YardStringDocumentLoader.call(
23
+ # content: content,
24
+ # path: '/path/to/foo.rb'
25
+ # )
26
+ # expect(definitions.size).to eq(1)
27
+ # expect(definitions.first.full_qualified_name).to eq('Foo#foo')
28
+ # expect(definitions.first.source_path).to eq('/path/to/foo.rb')
29
+ # expect(definitions.first.description).to eq('Return given argument as an Integer.')
30
+ # expect(definitions.first.return_types).to eq(%w[Integer])
31
+ def call(content:, path:)
32
+ new(
33
+ content: content,
34
+ path: path
35
+ ).call
36
+ end
37
+ end
38
+
39
+ # @param content [String]
40
+ # @param path [String]
41
+ def initialize(content:, path:)
42
+ @content = content
43
+ @path = path
44
+ end
45
+
46
+ # @return [Array<Rucoa::Definitions::Base>]
47
+ def call
48
+ code_objects.filter_map do |code_object|
49
+ case code_object
50
+ when ::YARD::CodeObjects::MethodObject
51
+ DefinitionBuilders::YardMethodDefinitionBuilder.call(
52
+ code_object: code_object,
53
+ path: @path
54
+ )
55
+ end
56
+ end
57
+ end
58
+
59
+ private
60
+
61
+ # @return [Array<YARD::CodeObjects::Base>]
62
+ def code_objects
63
+ ::YARD::Logger.instance.enter_level(::Logger::FATAL) do
64
+ ::YARD::Registry.clear
65
+ ::YARD.parse_string(@content)
66
+ ::YARD::Registry.all
67
+ end
68
+ end
69
+ end
70
+ end
data/lib/rucoa.rb CHANGED
@@ -4,26 +4,31 @@ require_relative 'rucoa/version'
4
4
 
5
5
  module Rucoa
6
6
  autoload :Cli, 'rucoa/cli'
7
- autoload :CodeActionProvider, 'rucoa/code_action_provider'
8
7
  autoload :Configuration, 'rucoa/configuration'
9
- autoload :DiagnosticProvider, 'rucoa/diagnostic_provider'
8
+ autoload :DefinitionArchiver, 'rucoa/definition_archiver'
9
+ autoload :DefinitionBuilders, 'rucoa/definition_builders'
10
+ autoload :Definitions, 'rucoa/definitions'
11
+ autoload :DefinitionStore, 'rucoa/definition_store'
10
12
  autoload :Errors, 'rucoa/errors'
11
- autoload :FormattingProvider, 'rucoa/formatting_provider'
12
13
  autoload :HandlerConcerns, 'rucoa/handler_concerns'
13
14
  autoload :Handlers, 'rucoa/handlers'
14
15
  autoload :MessageReader, 'rucoa/message_reader'
15
16
  autoload :MessageWriter, 'rucoa/message_writer'
17
+ autoload :NodeConcerns, 'rucoa/node_concerns'
18
+ autoload :NodeInspector, 'rucoa/node_inspector'
16
19
  autoload :Nodes, 'rucoa/nodes'
17
20
  autoload :Parser, 'rucoa/parser'
18
21
  autoload :ParserBuilder, 'rucoa/parser_builder'
19
22
  autoload :Position, 'rucoa/position'
20
23
  autoload :Range, 'rucoa/range'
21
- autoload :RangeFormattingProvider, 'rucoa/range_formatting_provider'
24
+ autoload :RbsDocumentLoader, 'rucoa/rbs_document_loader'
22
25
  autoload :RubocopAutocorrector, 'rucoa/rubocop_autocorrector'
23
26
  autoload :RubocopConfigurationChecker, 'rucoa/rubocop_configuration_checker'
24
27
  autoload :RubocopInvestigator, 'rucoa/rubocop_investigator'
25
- autoload :SelectionRangeProvider, 'rucoa/selection_range_provider'
26
28
  autoload :Server, 'rucoa/server'
27
29
  autoload :Source, 'rucoa/source'
28
30
  autoload :SourceStore, 'rucoa/source_store'
31
+ autoload :Types, 'rucoa/types'
32
+ autoload :YardGlobDocumentLoader, 'rucoa/yard_glob_document_loader'
33
+ autoload :YardStringDocumentLoader, 'rucoa/yard_string_document_loader'
29
34
  end
data/rucoa.gemspec CHANGED
@@ -28,5 +28,7 @@ Gem::Specification.new do |spec|
28
28
  spec.require_paths = ['lib']
29
29
 
30
30
  spec.add_dependency 'parser'
31
+ spec.add_dependency 'rbs'
31
32
  spec.add_dependency 'rubocop'
33
+ spec.add_dependency 'yard'
32
34
  end
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.3.0
4
+ version: 0.5.1
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-07 00:00:00.000000000 Z
11
+ date: 2022-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rbs
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rubocop
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +52,20 @@ dependencies:
38
52
  - - ">="
39
53
  - !ruby/object:Gem::Version
40
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: yard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
41
69
  description:
42
70
  email:
43
71
  - r7kamura@gmail.com
@@ -54,46 +82,79 @@ files:
54
82
  - LICENSE.txt
55
83
  - README.md
56
84
  - Rakefile
85
+ - data/definitions_ruby_3_1
57
86
  - exe/rucoa
87
+ - images/diagnostics.gif
88
+ - images/document-formatting.gif
89
+ - images/document-symbol.gif
90
+ - images/selection-ranges.gif
58
91
  - lib/rucoa.rb
59
92
  - lib/rucoa/cli.rb
60
- - lib/rucoa/code_action_provider.rb
61
93
  - lib/rucoa/configuration.rb
62
- - lib/rucoa/diagnostic_provider.rb
94
+ - lib/rucoa/definition_archiver.rb
95
+ - lib/rucoa/definition_builders.rb
96
+ - lib/rucoa/definition_builders/rbs_constant_definition_builder.rb
97
+ - lib/rucoa/definition_builders/rbs_method_definition_builder.rb
98
+ - lib/rucoa/definition_builders/yard_method_definition_builder.rb
99
+ - lib/rucoa/definition_store.rb
100
+ - lib/rucoa/definitions.rb
101
+ - lib/rucoa/definitions/base.rb
102
+ - lib/rucoa/definitions/constant_definition.rb
103
+ - lib/rucoa/definitions/method_definition.rb
104
+ - lib/rucoa/definitions/method_parameter_definition.rb
63
105
  - lib/rucoa/errors.rb
64
- - lib/rucoa/formatting_provider.rb
65
106
  - lib/rucoa/handler_concerns.rb
66
107
  - lib/rucoa/handler_concerns/configuration_requestable.rb
67
108
  - lib/rucoa/handler_concerns/diagnostics_publishable.rb
68
109
  - lib/rucoa/handlers.rb
69
110
  - lib/rucoa/handlers/base.rb
111
+ - lib/rucoa/handlers/exit_handler.rb
70
112
  - lib/rucoa/handlers/initialize_handler.rb
71
113
  - lib/rucoa/handlers/initialized_handler.rb
114
+ - lib/rucoa/handlers/shutdown_handler.rb
72
115
  - lib/rucoa/handlers/text_document_code_action_handler.rb
73
116
  - lib/rucoa/handlers/text_document_did_change_handler.rb
74
117
  - lib/rucoa/handlers/text_document_did_open_handler.rb
118
+ - lib/rucoa/handlers/text_document_document_symbol_handler.rb
75
119
  - lib/rucoa/handlers/text_document_formatting_handler.rb
76
120
  - lib/rucoa/handlers/text_document_range_formatting_handler.rb
77
121
  - lib/rucoa/handlers/text_document_selection_range_handler.rb
122
+ - lib/rucoa/handlers/text_document_signature_help_handler.rb
78
123
  - lib/rucoa/handlers/workspace_did_change_configuration_handler.rb
79
124
  - lib/rucoa/message_reader.rb
80
125
  - lib/rucoa/message_writer.rb
126
+ - lib/rucoa/node_concerns.rb
127
+ - lib/rucoa/node_concerns/name_full_qualifiable.rb
128
+ - lib/rucoa/node_inspector.rb
81
129
  - lib/rucoa/nodes.rb
82
130
  - lib/rucoa/nodes/base.rb
131
+ - lib/rucoa/nodes/casgn_node.rb
132
+ - lib/rucoa/nodes/class_node.rb
133
+ - lib/rucoa/nodes/const_node.rb
134
+ - lib/rucoa/nodes/def_node.rb
135
+ - lib/rucoa/nodes/defs_node.rb
136
+ - lib/rucoa/nodes/lvar_node.rb
137
+ - lib/rucoa/nodes/module_node.rb
138
+ - lib/rucoa/nodes/sclass_node.rb
139
+ - lib/rucoa/nodes/send_node.rb
83
140
  - lib/rucoa/nodes/str_node.rb
141
+ - lib/rucoa/nodes/sym_node.rb
84
142
  - lib/rucoa/parser.rb
85
143
  - lib/rucoa/parser_builder.rb
86
144
  - lib/rucoa/position.rb
87
145
  - lib/rucoa/range.rb
88
- - lib/rucoa/range_formatting_provider.rb
146
+ - lib/rucoa/rbs_document_loader.rb
89
147
  - lib/rucoa/rubocop_autocorrector.rb
90
148
  - lib/rucoa/rubocop_configuration_checker.rb
91
149
  - lib/rucoa/rubocop_investigator.rb
92
- - lib/rucoa/selection_range_provider.rb
93
150
  - lib/rucoa/server.rb
94
151
  - lib/rucoa/source.rb
95
152
  - lib/rucoa/source_store.rb
153
+ - lib/rucoa/types.rb
154
+ - lib/rucoa/types/method_type.rb
96
155
  - lib/rucoa/version.rb
156
+ - lib/rucoa/yard_glob_document_loader.rb
157
+ - lib/rucoa/yard_string_document_loader.rb
97
158
  - rucoa.gemspec
98
159
  homepage: https://github.com/r7kamura/rucoa
99
160
  licenses:
@@ -1,102 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Rucoa
4
- class CodeActionProvider
5
- class << self
6
- # @param diagnostics [Array<Hash>]
7
- # @return [Array<Hash>]
8
- def call(diagnostics:)
9
- new(diagnostics: diagnostics).call
10
- end
11
- end
12
-
13
- # @param diagnostics [Array<Hash>]
14
- def initialize(diagnostics:)
15
- @diagnostics = diagnostics
16
- end
17
-
18
- # @return [Array<Hash>]
19
- def call
20
- correctable_diagnostics.map do |diagnostic|
21
- DiagnosticToCodeActionMapper.call(diagnostic)
22
- end
23
- end
24
-
25
- private
26
-
27
- # @return [Array<Hash>]
28
- def correctable_diagnostics
29
- @diagnostics.select do |diagnostic|
30
- diagnostic.dig('data', 'edits')
31
- end
32
- end
33
-
34
- class DiagnosticToCodeActionMapper
35
- class << self
36
- # @param diagnostic [Hash]
37
- # @return [Hash]
38
- def call(diagnostic)
39
- new(diagnostic).call
40
- end
41
- end
42
-
43
- # @param diagnostic [Hash]
44
- def initialize(diagnostic)
45
- @diagnostic = diagnostic
46
- end
47
-
48
- # @return [Hash]
49
- def call
50
- {
51
- diagnostics: diagnostics,
52
- edit: edit,
53
- isPreferred: preferred?,
54
- kind: kind,
55
- title: title
56
- }
57
- end
58
-
59
- private
60
-
61
- # @return [Hash]
62
- def edit
63
- {
64
- documentChanges: [
65
- {
66
- edits: @diagnostic.dig('data', 'edits'),
67
- textDocument: {
68
- uri: @diagnostic.dig('data', 'uri'),
69
- version: nil
70
- }
71
- }
72
- ]
73
- }
74
- end
75
-
76
- # @return [String]
77
- def cop_name
78
- @diagnostic.dig('data', 'cop_name')
79
- end
80
-
81
- # @return [Array]
82
- def diagnostics
83
- [@diagnostic]
84
- end
85
-
86
- # @return [Boolean]
87
- def preferred?
88
- true
89
- end
90
-
91
- # @return [String]
92
- def kind
93
- 'quickfix'
94
- end
95
-
96
- # @return [String]
97
- def title
98
- "Autocorrect #{cop_name}"
99
- end
100
- end
101
- end
102
- end