rucoa 0.5.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +12 -13
- data/data/definitions_ruby_3_1 +0 -0
- data/lib/rucoa/cli.rb +3 -2
- data/lib/rucoa/configuration.rb +69 -16
- data/lib/rucoa/handler_concerns/diagnostics_publishable.rb +14 -2
- data/lib/rucoa/handlers/initialize_handler.rb +7 -0
- data/lib/rucoa/handlers/initialized_handler.rb +1 -1
- data/lib/rucoa/handlers/text_document_completion_handler.rb +223 -0
- data/lib/rucoa/handlers/text_document_did_close_handler.rb +20 -0
- data/lib/rucoa/handlers/text_document_formatting_handler.rb +2 -2
- data/lib/rucoa/handlers/text_document_hover_handler.rb +76 -0
- data/lib/rucoa/handlers/text_document_range_formatting_handler.rb +2 -2
- data/lib/rucoa/handlers.rb +3 -0
- data/lib/rucoa/node_inspector.rb +13 -1
- data/lib/rucoa/position.rb +12 -1
- data/lib/rucoa/{definition_builders/rbs_constant_definition_builder.rb → rbs/constant_definition_mapper.rb} +4 -8
- data/lib/rucoa/{definition_builders/rbs_method_definition_builder.rb → rbs/method_definition_mapper.rb} +4 -7
- data/lib/rucoa/rbs/ruby_definitions_loader.rb +78 -0
- data/lib/rucoa/rbs.rb +9 -0
- data/lib/rucoa/rubocop/autocorrector.rb +40 -0
- data/lib/rucoa/rubocop/configuration_checker.rb +44 -0
- data/lib/rucoa/rubocop/investigator.rb +50 -0
- data/lib/rucoa/rubocop.rb +9 -0
- data/lib/rucoa/server.rb +45 -12
- data/lib/rucoa/source.rb +6 -1
- data/lib/rucoa/version.rb +1 -1
- data/lib/rucoa/{definition_builders/yard_method_definition_builder.rb → yard/definition_mapper.rb} +20 -21
- data/lib/rucoa/yard/definitions_loader.rb +62 -0
- data/lib/rucoa/yard.rb +8 -0
- data/lib/rucoa.rb +3 -7
- metadata +16 -12
- data/lib/rucoa/definition_builders.rb +0 -9
- data/lib/rucoa/rbs_document_loader.rb +0 -43
- data/lib/rucoa/rubocop_autocorrector.rb +0 -38
- data/lib/rucoa/rubocop_configuration_checker.rb +0 -42
- data/lib/rucoa/rubocop_investigator.rb +0 -48
- data/lib/rucoa/yard_glob_document_loader.rb +0 -47
- data/lib/rucoa/yard_string_document_loader.rb +0 -70
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.
|
4
|
+
version: 0.7.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-
|
11
|
+
date: 2022-09-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|
@@ -92,10 +92,6 @@ files:
|
|
92
92
|
- lib/rucoa/cli.rb
|
93
93
|
- lib/rucoa/configuration.rb
|
94
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
95
|
- lib/rucoa/definition_store.rb
|
100
96
|
- lib/rucoa/definitions.rb
|
101
97
|
- lib/rucoa/definitions/base.rb
|
@@ -113,10 +109,13 @@ files:
|
|
113
109
|
- lib/rucoa/handlers/initialized_handler.rb
|
114
110
|
- lib/rucoa/handlers/shutdown_handler.rb
|
115
111
|
- lib/rucoa/handlers/text_document_code_action_handler.rb
|
112
|
+
- lib/rucoa/handlers/text_document_completion_handler.rb
|
116
113
|
- lib/rucoa/handlers/text_document_did_change_handler.rb
|
114
|
+
- lib/rucoa/handlers/text_document_did_close_handler.rb
|
117
115
|
- lib/rucoa/handlers/text_document_did_open_handler.rb
|
118
116
|
- lib/rucoa/handlers/text_document_document_symbol_handler.rb
|
119
117
|
- lib/rucoa/handlers/text_document_formatting_handler.rb
|
118
|
+
- lib/rucoa/handlers/text_document_hover_handler.rb
|
120
119
|
- lib/rucoa/handlers/text_document_range_formatting_handler.rb
|
121
120
|
- lib/rucoa/handlers/text_document_selection_range_handler.rb
|
122
121
|
- lib/rucoa/handlers/text_document_signature_help_handler.rb
|
@@ -143,18 +142,23 @@ files:
|
|
143
142
|
- lib/rucoa/parser_builder.rb
|
144
143
|
- lib/rucoa/position.rb
|
145
144
|
- lib/rucoa/range.rb
|
146
|
-
- lib/rucoa/
|
147
|
-
- lib/rucoa/
|
148
|
-
- lib/rucoa/
|
149
|
-
- lib/rucoa/
|
145
|
+
- lib/rucoa/rbs.rb
|
146
|
+
- lib/rucoa/rbs/constant_definition_mapper.rb
|
147
|
+
- lib/rucoa/rbs/method_definition_mapper.rb
|
148
|
+
- lib/rucoa/rbs/ruby_definitions_loader.rb
|
149
|
+
- lib/rucoa/rubocop.rb
|
150
|
+
- lib/rucoa/rubocop/autocorrector.rb
|
151
|
+
- lib/rucoa/rubocop/configuration_checker.rb
|
152
|
+
- lib/rucoa/rubocop/investigator.rb
|
150
153
|
- lib/rucoa/server.rb
|
151
154
|
- lib/rucoa/source.rb
|
152
155
|
- lib/rucoa/source_store.rb
|
153
156
|
- lib/rucoa/types.rb
|
154
157
|
- lib/rucoa/types/method_type.rb
|
155
158
|
- lib/rucoa/version.rb
|
156
|
-
- lib/rucoa/
|
157
|
-
- lib/rucoa/
|
159
|
+
- lib/rucoa/yard.rb
|
160
|
+
- lib/rucoa/yard/definition_mapper.rb
|
161
|
+
- lib/rucoa/yard/definitions_loader.rb
|
158
162
|
- rucoa.gemspec
|
159
163
|
homepage: https://github.com/r7kamura/rucoa
|
160
164
|
licenses:
|
@@ -1,9 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Rucoa
|
4
|
-
module DefinitionBuilders
|
5
|
-
autoload :RbsConstantDefinitionBuilder, 'rucoa/definition_builders/rbs_constant_definition_builder'
|
6
|
-
autoload :RbsMethodDefinitionBuilder, 'rucoa/definition_builders/rbs_method_definition_builder'
|
7
|
-
autoload :YardMethodDefinitionBuilder, 'rucoa/definition_builders/yard_method_definition_builder'
|
8
|
-
end
|
9
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rbs'
|
4
|
-
|
5
|
-
module Rucoa
|
6
|
-
class RbsDocumentLoader
|
7
|
-
class << self
|
8
|
-
def call
|
9
|
-
new.call
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
# @return [Array<Rucoa::Definitions::Base>]
|
14
|
-
def call
|
15
|
-
declarations.flat_map do |declaration|
|
16
|
-
case declaration
|
17
|
-
when ::RBS::AST::Declarations::Constant
|
18
|
-
[
|
19
|
-
DefinitionBuilders::RbsConstantDefinitionBuilder.call(declaration: declaration)
|
20
|
-
]
|
21
|
-
when ::RBS::AST::Declarations::Class, ::RBS::AST::Declarations::Module
|
22
|
-
declaration.members.grep(::RBS::AST::Members::MethodDefinition).map do |method_definition|
|
23
|
-
DefinitionBuilders::RbsMethodDefinitionBuilder.call(
|
24
|
-
declaration: declaration,
|
25
|
-
method_definition: method_definition
|
26
|
-
)
|
27
|
-
end
|
28
|
-
else
|
29
|
-
[]
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
private
|
35
|
-
|
36
|
-
# @return [Array<RBS::AST::Declarations::Base>]
|
37
|
-
def declarations
|
38
|
-
::RBS::Environment.from_loader(
|
39
|
-
::RBS::EnvironmentLoader.new
|
40
|
-
).resolve_type_names.declarations
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rubocop'
|
4
|
-
|
5
|
-
module Rucoa
|
6
|
-
class RubocopAutocorrector < ::RuboCop::Runner
|
7
|
-
class << self
|
8
|
-
# @param source [Rucoa::Source]
|
9
|
-
# @return [String]
|
10
|
-
def call(source:)
|
11
|
-
new(source: source).call
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
# @param source [Rucoa::Source]
|
16
|
-
def initialize(source:)
|
17
|
-
@source = source
|
18
|
-
super(
|
19
|
-
::RuboCop::Options.new.parse(
|
20
|
-
%w[
|
21
|
-
--stderr
|
22
|
-
--force-exclusion
|
23
|
-
--format RuboCop::Formatter::BaseFormatter
|
24
|
-
-A
|
25
|
-
]
|
26
|
-
).first,
|
27
|
-
::RuboCop::ConfigStore.new
|
28
|
-
)
|
29
|
-
end
|
30
|
-
|
31
|
-
# @return [String]
|
32
|
-
def call
|
33
|
-
@options[:stdin] = @source.content
|
34
|
-
run([@source.path || 'untitled'])
|
35
|
-
@options[:stdin]
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'pathname'
|
4
|
-
|
5
|
-
module Rucoa
|
6
|
-
class RubocopConfigurationChecker
|
7
|
-
class << self
|
8
|
-
# @return [Boolean]
|
9
|
-
def call
|
10
|
-
new.call
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
# @return [Boolean]
|
15
|
-
def call
|
16
|
-
rubocop_configured_for_current_directory?
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
# @return [Boolean]
|
22
|
-
def rubocop_configured_for_current_directory?
|
23
|
-
each_current_and_ancestor_pathname.any? do |pathname|
|
24
|
-
pathname.join('.rubocop.yml').exist?
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
# @return [Enumerable<Pathname>]
|
29
|
-
def each_current_and_ancestor_pathname
|
30
|
-
return to_enum(__method__) unless block_given?
|
31
|
-
|
32
|
-
pathname = ::Pathname.pwd
|
33
|
-
loop do
|
34
|
-
yield pathname
|
35
|
-
break if pathname.root?
|
36
|
-
|
37
|
-
pathname = pathname.parent
|
38
|
-
end
|
39
|
-
self
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rubocop'
|
4
|
-
|
5
|
-
module Rucoa
|
6
|
-
class RubocopInvestigator < ::RuboCop::Runner
|
7
|
-
class << self
|
8
|
-
# @param source [Rucoa::Source]
|
9
|
-
# @return [Array<RuboCop::Cop::Offense>]
|
10
|
-
def call(source:)
|
11
|
-
new(source: source).call
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
# @param source [Rucoa::Source]
|
16
|
-
def initialize(source:)
|
17
|
-
@source = source
|
18
|
-
@offenses = []
|
19
|
-
super(
|
20
|
-
::RuboCop::Options.new.parse(
|
21
|
-
%w[
|
22
|
-
--stderr
|
23
|
-
--force-exclusion
|
24
|
-
--format RuboCop::Formatter::BaseFormatter
|
25
|
-
]
|
26
|
-
).first,
|
27
|
-
::RuboCop::ConfigStore.new
|
28
|
-
)
|
29
|
-
end
|
30
|
-
|
31
|
-
# @return [Array<RuboCop::Cop::Offense>]
|
32
|
-
def call
|
33
|
-
@options[:stdin] = @source.content
|
34
|
-
run([@source.path || 'untitled'])
|
35
|
-
@offenses
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
# @param file [String]
|
41
|
-
# @param offenses [Array<RuboCop::Cop::Offense>]
|
42
|
-
# @return [void]
|
43
|
-
def file_finished(file, offenses)
|
44
|
-
@offenses = offenses
|
45
|
-
super
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,47 +0,0 @@
|
|
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
|
@@ -1,70 +0,0 @@
|
|
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
|