yoda-language-server 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/.rspec +3 -0
- data/.travis.yml +8 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +78 -0
- data/LICENSE.txt +21 -0
- data/README.md +85 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/client/atom/main.js +27 -0
- data/client/vscode/.gitignore +4 -0
- data/client/vscode/.vscode/launch.json +28 -0
- data/client/vscode/.vscode/settings.json +9 -0
- data/client/vscode/.vscode/tasks.json +20 -0
- data/client/vscode/.vscodeignore +8 -0
- data/client/vscode/CHANGELOG.md +7 -0
- data/client/vscode/README.md +65 -0
- data/client/vscode/package-lock.json +2688 -0
- data/client/vscode/package.json +39 -0
- data/client/vscode/src/extension.ts +42 -0
- data/client/vscode/src/test/extension.test.ts +22 -0
- data/client/vscode/src/test/index.ts +22 -0
- data/client/vscode/tsconfig.json +16 -0
- data/client/vscode/vsc-extension-quickstart.md +33 -0
- data/exe/yoda +27 -0
- data/lib/yoda.rb +11 -0
- data/lib/yoda/evaluation.rb +9 -0
- data/lib/yoda/evaluation/code_completion.rb +65 -0
- data/lib/yoda/evaluation/code_completion/base_provider.rb +57 -0
- data/lib/yoda/evaluation/code_completion/const_provider.rb +90 -0
- data/lib/yoda/evaluation/code_completion/method_provider.rb +82 -0
- data/lib/yoda/evaluation/code_completion/variable_provider.rb +18 -0
- data/lib/yoda/evaluation/comment_completion.rb +70 -0
- data/lib/yoda/evaluation/comment_completion/base_provider.rb +64 -0
- data/lib/yoda/evaluation/comment_completion/param_provider.rb +18 -0
- data/lib/yoda/evaluation/comment_completion/tag_provider.rb +41 -0
- data/lib/yoda/evaluation/comment_completion/type_provider.rb +58 -0
- data/lib/yoda/evaluation/current_node_explain.rb +70 -0
- data/lib/yoda/evaluation/evaluator.rb +103 -0
- data/lib/yoda/evaluation/signature_discovery.rb +83 -0
- data/lib/yoda/model.rb +12 -0
- data/lib/yoda/model/completion_item.rb +56 -0
- data/lib/yoda/model/descriptions.rb +10 -0
- data/lib/yoda/model/descriptions/base.rb +26 -0
- data/lib/yoda/model/descriptions/function_description.rb +40 -0
- data/lib/yoda/model/descriptions/value_description.rb +33 -0
- data/lib/yoda/model/descriptions/word_description.rb +32 -0
- data/lib/yoda/model/function_signatures.rb +13 -0
- data/lib/yoda/model/function_signatures/base.rb +68 -0
- data/lib/yoda/model/function_signatures/constructor.rb +70 -0
- data/lib/yoda/model/function_signatures/formatter.rb +82 -0
- data/lib/yoda/model/function_signatures/method.rb +67 -0
- data/lib/yoda/model/function_signatures/overload.rb +79 -0
- data/lib/yoda/model/function_signatures/parameter_list.rb +108 -0
- data/lib/yoda/model/function_signatures/type_builder.rb +101 -0
- data/lib/yoda/model/node_signature.rb +28 -0
- data/lib/yoda/model/path.rb +96 -0
- data/lib/yoda/model/scoped_path.rb +44 -0
- data/lib/yoda/model/types.rb +84 -0
- data/lib/yoda/model/types/any_type.rb +32 -0
- data/lib/yoda/model/types/base.rb +37 -0
- data/lib/yoda/model/types/duck_type.rb +41 -0
- data/lib/yoda/model/types/function_type.rb +174 -0
- data/lib/yoda/model/types/generic_type.rb +66 -0
- data/lib/yoda/model/types/instance_type.rb +42 -0
- data/lib/yoda/model/types/module_type.rb +42 -0
- data/lib/yoda/model/types/sequence_type.rb +53 -0
- data/lib/yoda/model/types/union_type.rb +56 -0
- data/lib/yoda/model/types/unknown_type.rb +40 -0
- data/lib/yoda/model/types/value_type.rb +58 -0
- data/lib/yoda/model/values.rb +9 -0
- data/lib/yoda/model/values/base.rb +32 -0
- data/lib/yoda/model/values/instance_value.rb +65 -0
- data/lib/yoda/model/values/module_value.rb +72 -0
- data/lib/yoda/parsing.rb +15 -0
- data/lib/yoda/parsing/ast_traversable.rb +18 -0
- data/lib/yoda/parsing/comment_tokenizer.rb +59 -0
- data/lib/yoda/parsing/location.rb +101 -0
- data/lib/yoda/parsing/node_objects.rb +10 -0
- data/lib/yoda/parsing/node_objects/const_node.rb +52 -0
- data/lib/yoda/parsing/node_objects/method_definition.rb +46 -0
- data/lib/yoda/parsing/node_objects/namespace.rb +104 -0
- data/lib/yoda/parsing/node_objects/send_node.rb +72 -0
- data/lib/yoda/parsing/parser.rb +27 -0
- data/lib/yoda/parsing/query.rb +11 -0
- data/lib/yoda/parsing/query/current_comment_query.rb +80 -0
- data/lib/yoda/parsing/query/current_comment_token_query.rb +153 -0
- data/lib/yoda/parsing/query/current_commenting_node_query.rb +68 -0
- data/lib/yoda/parsing/query/current_location_node_query.rb +51 -0
- data/lib/yoda/parsing/query/current_node_comment_query.rb +40 -0
- data/lib/yoda/parsing/range.rb +41 -0
- data/lib/yoda/parsing/scopes.rb +15 -0
- data/lib/yoda/parsing/scopes/base.rb +78 -0
- data/lib/yoda/parsing/scopes/builder.rb +60 -0
- data/lib/yoda/parsing/scopes/class_definition.rb +47 -0
- data/lib/yoda/parsing/scopes/meta_class_definition.rb +44 -0
- data/lib/yoda/parsing/scopes/meta_method_definition.rb +70 -0
- data/lib/yoda/parsing/scopes/method_definition.rb +69 -0
- data/lib/yoda/parsing/scopes/module_definition.rb +36 -0
- data/lib/yoda/parsing/scopes/root.rb +25 -0
- data/lib/yoda/parsing/source_analyzer.rb +59 -0
- data/lib/yoda/parsing/source_cutter.rb +231 -0
- data/lib/yoda/parsing/type_parser.rb +141 -0
- data/lib/yoda/runner.rb +6 -0
- data/lib/yoda/runner/infer.rb +50 -0
- data/lib/yoda/runner/setup.rb +26 -0
- data/lib/yoda/server.rb +191 -0
- data/lib/yoda/server/client_info.rb +98 -0
- data/lib/yoda/server/completion_provider.rb +78 -0
- data/lib/yoda/server/definition_provider.rb +36 -0
- data/lib/yoda/server/deserializer.rb +27 -0
- data/lib/yoda/server/hover_provider.rb +38 -0
- data/lib/yoda/server/signature_provider.rb +46 -0
- data/lib/yoda/store.rb +13 -0
- data/lib/yoda/store/actions.rb +10 -0
- data/lib/yoda/store/actions/import_core_library.rb +30 -0
- data/lib/yoda/store/actions/import_gems.rb +91 -0
- data/lib/yoda/store/actions/read_file.rb +36 -0
- data/lib/yoda/store/actions/read_project_files.rb +29 -0
- data/lib/yoda/store/adapters.rb +14 -0
- data/lib/yoda/store/adapters/base.rb +58 -0
- data/lib/yoda/store/adapters/leveldb_adapter.rb +80 -0
- data/lib/yoda/store/adapters/lmdb_adapter.rb +113 -0
- data/lib/yoda/store/objects.rb +46 -0
- data/lib/yoda/store/objects/addressable.rb +25 -0
- data/lib/yoda/store/objects/base.rb +116 -0
- data/lib/yoda/store/objects/class_object.rb +51 -0
- data/lib/yoda/store/objects/merger.rb +94 -0
- data/lib/yoda/store/objects/meta_class_object.rb +41 -0
- data/lib/yoda/store/objects/method_object.rb +94 -0
- data/lib/yoda/store/objects/module_object.rb +11 -0
- data/lib/yoda/store/objects/namespace_object.rb +67 -0
- data/lib/yoda/store/objects/overload.rb +51 -0
- data/lib/yoda/store/objects/patch.rb +46 -0
- data/lib/yoda/store/objects/patch_set.rb +80 -0
- data/lib/yoda/store/objects/tag.rb +62 -0
- data/lib/yoda/store/objects/value_object.rb +45 -0
- data/lib/yoda/store/project.rb +159 -0
- data/lib/yoda/store/query.rb +12 -0
- data/lib/yoda/store/query/associators.rb +10 -0
- data/lib/yoda/store/query/associators/associate_ancestors.rb +103 -0
- data/lib/yoda/store/query/associators/associate_methods.rb +38 -0
- data/lib/yoda/store/query/base.rb +16 -0
- data/lib/yoda/store/query/find_constant.rb +150 -0
- data/lib/yoda/store/query/find_meta_class.rb +18 -0
- data/lib/yoda/store/query/find_method.rb +74 -0
- data/lib/yoda/store/query/find_signature.rb +43 -0
- data/lib/yoda/store/registry.rb +67 -0
- data/lib/yoda/store/yard_importer.rb +260 -0
- data/lib/yoda/typing.rb +10 -0
- data/lib/yoda/typing/context.rb +96 -0
- data/lib/yoda/typing/environment.rb +35 -0
- data/lib/yoda/typing/evaluator.rb +256 -0
- data/lib/yoda/typing/lexical_scope.rb +26 -0
- data/lib/yoda/typing/relation.rb +15 -0
- data/lib/yoda/typing/traces.rb +9 -0
- data/lib/yoda/typing/traces/base.rb +26 -0
- data/lib/yoda/typing/traces/normal.rb +22 -0
- data/lib/yoda/typing/traces/send.rb +26 -0
- data/lib/yoda/version.rb +3 -0
- data/lib/yoda/yard_extensions.rb +11 -0
- data/lib/yoda/yard_extensions/sig_directive.rb +40 -0
- data/lib/yoda/yard_extensions/type_tag.rb +10 -0
- data/package.json +76 -0
- data/scripts/benchmark.rb +6 -0
- data/scripts/build_core_index.sh +16 -0
- data/yarn.lock +13 -0
- data/yoda-language-server.gemspec +40 -0
- metadata +424 -0
@@ -0,0 +1,66 @@
|
|
1
|
+
module Yoda
|
2
|
+
module Model
|
3
|
+
module Types
|
4
|
+
class GenericType < Base
|
5
|
+
# @return [Base]
|
6
|
+
attr_reader :base_type
|
7
|
+
|
8
|
+
# @return [Array<Base>]
|
9
|
+
attr_reader :type_arguments
|
10
|
+
|
11
|
+
# @param base_type [Base]
|
12
|
+
# @param key_type [Base]
|
13
|
+
# @param value_type [Base]
|
14
|
+
def self.from_key_value(base_type, key_type, value_type)
|
15
|
+
new(base_type, [key_type, value_type])
|
16
|
+
end
|
17
|
+
|
18
|
+
# @param paths [Array<Path>]
|
19
|
+
# @return [self]
|
20
|
+
def change_root(paths)
|
21
|
+
self.class.new(base_type.change_root(paths), type_arguments.map { |type| type.change_root(paths) })
|
22
|
+
end
|
23
|
+
|
24
|
+
# @param base_type [Types::Base]
|
25
|
+
# @param type_arguments [Array<Base>]
|
26
|
+
def initialize(base_type, type_arguments)
|
27
|
+
@base_type = base_type
|
28
|
+
@type_arguments = type_arguments
|
29
|
+
end
|
30
|
+
|
31
|
+
# @param another [Object]
|
32
|
+
def eql?(another)
|
33
|
+
another.is_a?(GenericType) &&
|
34
|
+
base_type == another.base_type &&
|
35
|
+
type_arguments == another.type_arguments
|
36
|
+
end
|
37
|
+
|
38
|
+
def hash
|
39
|
+
[self.class.name, base_type, type_arguments].hash
|
40
|
+
end
|
41
|
+
|
42
|
+
# @param namespace [YARD::CodeObjects::Base]
|
43
|
+
# @return [GenericType]
|
44
|
+
def change_root(namespace)
|
45
|
+
self.class.new(base_type.change_root(namespace), type_arguments.map { |type| type.change_root(namespace) })
|
46
|
+
end
|
47
|
+
|
48
|
+
# @param registry [Registry]
|
49
|
+
# @return [Array<YARD::CodeObjects::Base, YARD::CodeObjects::Proxy>]
|
50
|
+
def resolve(registry)
|
51
|
+
base_type.resolve(registry)
|
52
|
+
end
|
53
|
+
|
54
|
+
# @return [String]
|
55
|
+
def to_s
|
56
|
+
"#{base_type}<#{type_arguments.map(&:to_s).join(', ')}>"
|
57
|
+
end
|
58
|
+
|
59
|
+
# @return [self]
|
60
|
+
def map(&block)
|
61
|
+
self.class.new(base_type.map(&block), type_arguments.map(&block))
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Yoda
|
2
|
+
module Model
|
3
|
+
module Types
|
4
|
+
class InstanceType < Base
|
5
|
+
# @return [ScopedPath]
|
6
|
+
attr_reader :path
|
7
|
+
|
8
|
+
# @param value [String, Path, ScopedPath]
|
9
|
+
def initialize(path)
|
10
|
+
@path = ScopedPath.build(path)
|
11
|
+
end
|
12
|
+
|
13
|
+
# @param another [Object]
|
14
|
+
def eql?(another)
|
15
|
+
another.is_a?(InstanceType) &&
|
16
|
+
path == another.path
|
17
|
+
end
|
18
|
+
|
19
|
+
def hash
|
20
|
+
[self.class.name, path].hash
|
21
|
+
end
|
22
|
+
|
23
|
+
# @param paths [Array<Path>]
|
24
|
+
# @return [self]
|
25
|
+
def change_root(paths)
|
26
|
+
self.class.new(path.change_scope(paths))
|
27
|
+
end
|
28
|
+
|
29
|
+
# @param registry [Registry]
|
30
|
+
# @return [Array<Store::Objects::Base>]
|
31
|
+
def resolve(registry)
|
32
|
+
[Store::Query::FindConstant.new(registry).find(path)].compact
|
33
|
+
end
|
34
|
+
|
35
|
+
# @return [String]
|
36
|
+
def to_s
|
37
|
+
path.path.to_s
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Yoda
|
2
|
+
module Model
|
3
|
+
module Types
|
4
|
+
class ModuleType < Base
|
5
|
+
# @return [ScopedPath]
|
6
|
+
attr_reader :path
|
7
|
+
|
8
|
+
# @param value [String, Path, ScopedPath]
|
9
|
+
def initialize(path)
|
10
|
+
@path = ScopedPath.build(path)
|
11
|
+
end
|
12
|
+
|
13
|
+
# @param another [Object]
|
14
|
+
def eql?(another)
|
15
|
+
another.is_a?(ModuleType) &&
|
16
|
+
path == another.path
|
17
|
+
end
|
18
|
+
|
19
|
+
def hash
|
20
|
+
[self.class.name, path].hash
|
21
|
+
end
|
22
|
+
|
23
|
+
# @param paths [Array<Path>]
|
24
|
+
# @return [self]
|
25
|
+
def change_root(paths)
|
26
|
+
self.class.new(path.change_scope(paths))
|
27
|
+
end
|
28
|
+
|
29
|
+
# @param registry [Registry]
|
30
|
+
# @return [Array<YARD::CodeObjects::Base>]
|
31
|
+
def resolve(registry)
|
32
|
+
[Store::Query::FindMetaClass.new(registry).find(path)].compact
|
33
|
+
end
|
34
|
+
|
35
|
+
# @return [String]
|
36
|
+
def to_s
|
37
|
+
"#{path.path.to_s}.module"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Yoda
|
2
|
+
module Model
|
3
|
+
module Types
|
4
|
+
class SequenceType < Base
|
5
|
+
attr_reader :base_type, :types
|
6
|
+
|
7
|
+
# @param base_type [Base]
|
8
|
+
# @param types [Array<Base>]
|
9
|
+
def initialize(base_type, types)
|
10
|
+
@base_type = base_type
|
11
|
+
@types = types
|
12
|
+
end
|
13
|
+
|
14
|
+
def name
|
15
|
+
base_type.name
|
16
|
+
end
|
17
|
+
|
18
|
+
# @param another [Object]
|
19
|
+
def eql?(another)
|
20
|
+
another.is_a?(SequenceType) &&
|
21
|
+
base_type == another.base_type &&
|
22
|
+
types == another.types
|
23
|
+
end
|
24
|
+
|
25
|
+
def hash
|
26
|
+
[self.class.name, base_type, types].hash
|
27
|
+
end
|
28
|
+
|
29
|
+
# @param paths [Array<Path>]
|
30
|
+
# @return [self]
|
31
|
+
def change_root(paths)
|
32
|
+
self.class.new(base_type.change_root(paths), types.map { |type| type.change_root(paths) })
|
33
|
+
end
|
34
|
+
|
35
|
+
# @param registry [Registry]
|
36
|
+
# @return [Array<Store::Objects::Base>]
|
37
|
+
def resolve(registry)
|
38
|
+
base_type.resolve(registry)
|
39
|
+
end
|
40
|
+
|
41
|
+
# @return [String]
|
42
|
+
def to_s
|
43
|
+
"#{base_type}(#{types.map(&:to_s).join(', ')})"
|
44
|
+
end
|
45
|
+
|
46
|
+
# @return [self]
|
47
|
+
def map(&block)
|
48
|
+
self.class.new(base_type.map(&block), types.map(&block))
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'set'
|
2
|
+
|
3
|
+
module Yoda
|
4
|
+
module Model
|
5
|
+
module Types
|
6
|
+
class UnionType < Base
|
7
|
+
attr_reader :types
|
8
|
+
|
9
|
+
# @param types [Array<Base>]
|
10
|
+
# @return [Base]
|
11
|
+
def self.new(types)
|
12
|
+
reduced_types = types.reject { |type| type.is_a?(AnyType) || type.is_a?(UnknownType) }.uniq
|
13
|
+
return (types.first || AnyType.new) if reduced_types.length == 0
|
14
|
+
return reduced_types.first if reduced_types.length == 1
|
15
|
+
super(reduced_types)
|
16
|
+
end
|
17
|
+
|
18
|
+
# @param types [Array<Base>]
|
19
|
+
def initialize(types)
|
20
|
+
@types = types
|
21
|
+
end
|
22
|
+
|
23
|
+
def eql?(another)
|
24
|
+
another.is_a?(UnionType) &&
|
25
|
+
Set.new(types) == Set.new(another.types)
|
26
|
+
end
|
27
|
+
|
28
|
+
def hash
|
29
|
+
[self.class.name, Set.new(types)].hash
|
30
|
+
end
|
31
|
+
|
32
|
+
# @param paths [Array<Path>]
|
33
|
+
# @return [self]
|
34
|
+
def change_root(paths)
|
35
|
+
self.class.new(types.map { |type| type.change_root(paths) })
|
36
|
+
end
|
37
|
+
|
38
|
+
# @param registry [Registry]
|
39
|
+
# @return [Array<Store::Objects::Base>]
|
40
|
+
def resolve(registry)
|
41
|
+
types.map { |type| type.resolve(registry) }.flatten.compact
|
42
|
+
end
|
43
|
+
|
44
|
+
# @return [String]
|
45
|
+
def to_s
|
46
|
+
types.map(&:to_s).join(' | ')
|
47
|
+
end
|
48
|
+
|
49
|
+
# @return [self]
|
50
|
+
def map(&block)
|
51
|
+
self.class.new(types.map(&block))
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Yoda
|
2
|
+
module Model
|
3
|
+
module Types
|
4
|
+
class UnknownType < Base
|
5
|
+
attr_reader :name
|
6
|
+
|
7
|
+
# @param name [String]
|
8
|
+
def initialize(name = 'unknown')
|
9
|
+
@name = name
|
10
|
+
end
|
11
|
+
|
12
|
+
# @param another [Object]
|
13
|
+
def eql?(another)
|
14
|
+
another.is_a?(UnknownType)
|
15
|
+
end
|
16
|
+
|
17
|
+
def hash
|
18
|
+
[self.class.name, name].hash
|
19
|
+
end
|
20
|
+
|
21
|
+
# @param path [Path]
|
22
|
+
# @return [self]
|
23
|
+
def change_root(path)
|
24
|
+
self
|
25
|
+
end
|
26
|
+
|
27
|
+
# @param registry [Registry]
|
28
|
+
# @return [Array<YARD::CodeObjects::Base>]
|
29
|
+
def resolve(registry)
|
30
|
+
[]
|
31
|
+
end
|
32
|
+
|
33
|
+
# @return [String]
|
34
|
+
def to_s
|
35
|
+
'any'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Yoda
|
2
|
+
module Model
|
3
|
+
module Types
|
4
|
+
class ValueType < Base
|
5
|
+
attr_reader :value
|
6
|
+
|
7
|
+
VALUE_REGEXP = /\A[0-9a-z]/
|
8
|
+
|
9
|
+
# @param value [String]
|
10
|
+
def initialize(value)
|
11
|
+
@value = value
|
12
|
+
end
|
13
|
+
|
14
|
+
# @param another [Object]
|
15
|
+
def eql?(another)
|
16
|
+
another.is_a?(ValueType) &&
|
17
|
+
value == another.value
|
18
|
+
end
|
19
|
+
|
20
|
+
def hash
|
21
|
+
[self.class.name, value].hash
|
22
|
+
end
|
23
|
+
|
24
|
+
# @param paths [Array<Path>]
|
25
|
+
# @return [self]
|
26
|
+
def change_root(paths)
|
27
|
+
self
|
28
|
+
end
|
29
|
+
|
30
|
+
# @param registry [Registry]
|
31
|
+
# @return [Array<YARD::CodeObjects::Base>]
|
32
|
+
def resolve(registry)
|
33
|
+
[Store::Query::FindConstant.new(registry).find(value_class)].compact
|
34
|
+
end
|
35
|
+
|
36
|
+
def value_class
|
37
|
+
case value
|
38
|
+
when 'true'
|
39
|
+
'::TrueClass'
|
40
|
+
when 'false'
|
41
|
+
'::FalseClass'
|
42
|
+
when 'nil'
|
43
|
+
'::NilClass'
|
44
|
+
when /\A\d+\Z/
|
45
|
+
'::Numeric'
|
46
|
+
else
|
47
|
+
nil
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# @return [String]
|
52
|
+
def to_s
|
53
|
+
value
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Yoda
|
2
|
+
module Model
|
3
|
+
module Values
|
4
|
+
# @abstract
|
5
|
+
class Base
|
6
|
+
# @abstract
|
7
|
+
# @return [Array<Functions::Base>]
|
8
|
+
def methods
|
9
|
+
fail NotImplementedError
|
10
|
+
end
|
11
|
+
|
12
|
+
# @abstract
|
13
|
+
# @return [String]
|
14
|
+
def path
|
15
|
+
fail NotImplementedError
|
16
|
+
end
|
17
|
+
|
18
|
+
# @abstract
|
19
|
+
# @return [String]
|
20
|
+
def docstring
|
21
|
+
fail NotImplementedError
|
22
|
+
end
|
23
|
+
|
24
|
+
# @abstract
|
25
|
+
# @return [Array<[String, Integer]>]
|
26
|
+
def defined_files
|
27
|
+
fail NotImplementedError
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Yoda
|
2
|
+
module Model
|
3
|
+
module Values
|
4
|
+
class InstanceValue < Base
|
5
|
+
# @type Registry
|
6
|
+
attr_reader :registry
|
7
|
+
|
8
|
+
# @type ::YARD::CodeObjects::ClassObject | ::YARD::CodeObjects::Proxy
|
9
|
+
attr_reader :class_object
|
10
|
+
|
11
|
+
# @param registry [Registry]
|
12
|
+
# @param class_object [::YARD::CodeObjects::ClassObject, ::YARD::CodeObjects::Proxy]
|
13
|
+
def initialize(registry, class_object)
|
14
|
+
fail ArgumentError, registry unless registry.is_a?(Registry)
|
15
|
+
fail ArgumentError, class_object unless class_object.is_a?(::YARD::CodeObjects::NamespaceObject) || class_object.is_a?(::YARD::CodeObjects::Proxy)
|
16
|
+
@registry = registry
|
17
|
+
@class_object = class_object
|
18
|
+
end
|
19
|
+
|
20
|
+
# @return [Array<Functions::Base>]
|
21
|
+
def methods(visibility: nil)
|
22
|
+
return [] if class_object.type == :proxy
|
23
|
+
opts = { scope: :instance, visibility: visibility }.compact
|
24
|
+
class_object.meths(opts).map { |meth| Functions::Method.new(meth) } + object_methods(visibility: visibility)
|
25
|
+
end
|
26
|
+
|
27
|
+
# @return [String]
|
28
|
+
def path
|
29
|
+
namespace.path
|
30
|
+
end
|
31
|
+
|
32
|
+
def namespace
|
33
|
+
class_object
|
34
|
+
end
|
35
|
+
|
36
|
+
# @param [String]
|
37
|
+
def docstring
|
38
|
+
class_object.docstring
|
39
|
+
end
|
40
|
+
|
41
|
+
# @return [Array<[String, Integer]>]
|
42
|
+
def defined_files
|
43
|
+
namespace.files
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
# @return [Array<Functions::Base>]
|
49
|
+
def object_methods(visibility: nil)
|
50
|
+
return [] if class_object.type == :proxy
|
51
|
+
opts = { scope: :instance, visibility: visibility }.compact
|
52
|
+
method_names = Set.new(class_object.meths(opts).map(&:name))
|
53
|
+
if object = registry.find('::Object')
|
54
|
+
object.meths(opts)
|
55
|
+
.reject { |o| ![visibility].flatten.include?(:private) && o.namespace.name == :Kernel }
|
56
|
+
.reject { |o| method_names.include?(o.name) }
|
57
|
+
.map { |meth| Functions::Method.new(meth) }
|
58
|
+
else
|
59
|
+
[]
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|