solargraph 0.32.1 → 0.32.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (177) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +9 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +6 -0
  5. data/.travis.yml +25 -0
  6. data/EXAMPLES.md +76 -0
  7. data/Gemfile +3 -0
  8. data/LANGUAGE_SERVER.md +51 -0
  9. data/LICENSE +21 -0
  10. data/OVERVIEW.md +37 -0
  11. data/README.md +106 -0
  12. data/Rakefile +14 -0
  13. data/SERVER.md +95 -0
  14. data/bin/solargraph +0 -0
  15. data/bin/solargraph-runtime +5 -5
  16. data/lib/solargraph.rb +54 -54
  17. data/lib/solargraph/api_map.rb +659 -659
  18. data/lib/solargraph/api_map/cache.rb +49 -49
  19. data/lib/solargraph/api_map/source_to_yard.rb +67 -67
  20. data/lib/solargraph/api_map/store.rb +201 -201
  21. data/lib/solargraph/bundle.rb +24 -24
  22. data/lib/solargraph/complex_type.rb +150 -150
  23. data/lib/solargraph/complex_type/type_methods.rb +124 -124
  24. data/lib/solargraph/complex_type/unique_type.rb +44 -44
  25. data/lib/solargraph/core_fills.rb +37 -37
  26. data/lib/solargraph/diagnostics.rb +52 -52
  27. data/lib/solargraph/diagnostics/base.rb +20 -20
  28. data/lib/solargraph/diagnostics/require_not_found.rb +28 -28
  29. data/lib/solargraph/diagnostics/rubocop.rb +98 -98
  30. data/lib/solargraph/diagnostics/rubocop_helpers.rb +46 -46
  31. data/lib/solargraph/diagnostics/type_not_defined.rb +108 -108
  32. data/lib/solargraph/diagnostics/update_errors.rb +38 -38
  33. data/lib/solargraph/language_server/completion_item_kinds.rb +33 -33
  34. data/lib/solargraph/language_server/error_codes.rb +18 -18
  35. data/lib/solargraph/language_server/host.rb +684 -681
  36. data/lib/solargraph/language_server/host/cataloger.rb +54 -79
  37. data/lib/solargraph/language_server/host/diagnoser.rb +80 -80
  38. data/lib/solargraph/language_server/host/dispatch.rb +112 -113
  39. data/lib/solargraph/language_server/host/sources.rb +138 -138
  40. data/lib/solargraph/language_server/message.rb +90 -90
  41. data/lib/solargraph/language_server/message/base.rb +83 -83
  42. data/lib/solargraph/language_server/message/completion_item/resolve.rb +40 -40
  43. data/lib/solargraph/language_server/message/exit_notification.rb +11 -11
  44. data/lib/solargraph/language_server/message/extended.rb +19 -19
  45. data/lib/solargraph/language_server/message/extended/check_gem_version.rb +86 -86
  46. data/lib/solargraph/language_server/message/extended/document.rb +18 -18
  47. data/lib/solargraph/language_server/message/extended/document_gems.rb +30 -30
  48. data/lib/solargraph/language_server/message/extended/environment.rb +20 -20
  49. data/lib/solargraph/language_server/message/extended/search.rb +18 -18
  50. data/lib/solargraph/language_server/message/initialize.rb +141 -141
  51. data/lib/solargraph/language_server/message/initialized.rb +23 -23
  52. data/lib/solargraph/language_server/message/shutdown.rb +11 -11
  53. data/lib/solargraph/language_server/message/text_document.rb +25 -25
  54. data/lib/solargraph/language_server/message/text_document/completion.rb +51 -51
  55. data/lib/solargraph/language_server/message/text_document/definition.rb +18 -18
  56. data/lib/solargraph/language_server/message/text_document/did_change.rb +13 -13
  57. data/lib/solargraph/language_server/message/text_document/document_symbol.rb +21 -21
  58. data/lib/solargraph/language_server/message/text_document/folding_range.rb +24 -24
  59. data/lib/solargraph/language_server/message/text_document/formatting.rb +50 -50
  60. data/lib/solargraph/language_server/message/text_document/hover.rb +31 -31
  61. data/lib/solargraph/language_server/message/text_document/on_type_formatting.rb +32 -32
  62. data/lib/solargraph/language_server/message/text_document/prepare_rename.rb +9 -9
  63. data/lib/solargraph/language_server/message/text_document/references.rb +14 -14
  64. data/lib/solargraph/language_server/message/text_document/rename.rb +17 -17
  65. data/lib/solargraph/language_server/message/text_document/signature_help.rb +19 -19
  66. data/lib/solargraph/language_server/message/workspace.rb +12 -12
  67. data/lib/solargraph/language_server/message/workspace/did_change_configuration.rb +29 -29
  68. data/lib/solargraph/language_server/message/workspace/did_change_watched_files.rb +29 -27
  69. data/lib/solargraph/language_server/message/workspace/did_change_workspace_folders.rb +24 -24
  70. data/lib/solargraph/language_server/message/workspace/workspace_symbol.rb +21 -21
  71. data/lib/solargraph/language_server/request.rb +22 -22
  72. data/lib/solargraph/language_server/symbol_kinds.rb +34 -34
  73. data/lib/solargraph/language_server/transport.rb +11 -11
  74. data/lib/solargraph/language_server/transport/adapter.rb +60 -60
  75. data/lib/solargraph/language_server/transport/data_reader.rb +66 -66
  76. data/lib/solargraph/language_server/uri_helpers.rb +25 -25
  77. data/lib/solargraph/library.rb +421 -419
  78. data/lib/solargraph/live_map.rb +126 -126
  79. data/lib/solargraph/live_map/cache.rb +38 -38
  80. data/lib/solargraph/location.rb +31 -31
  81. data/lib/solargraph/logging.rb +25 -25
  82. data/lib/solargraph/page.rb +68 -68
  83. data/lib/solargraph/pin.rb +50 -50
  84. data/lib/solargraph/pin/attribute.rb +41 -41
  85. data/lib/solargraph/pin/base.rb +280 -280
  86. data/lib/solargraph/pin/base_method.rb +76 -76
  87. data/lib/solargraph/pin/base_variable.rb +72 -72
  88. data/lib/solargraph/pin/block.rb +32 -32
  89. data/lib/solargraph/pin/block_parameter.rb +103 -103
  90. data/lib/solargraph/pin/class_variable.rb +9 -9
  91. data/lib/solargraph/pin/constant.rb +30 -30
  92. data/lib/solargraph/pin/conversions.rb +79 -79
  93. data/lib/solargraph/pin/documenting.rb +41 -41
  94. data/lib/solargraph/pin/duck_method.rb +14 -14
  95. data/lib/solargraph/pin/global_variable.rb +9 -9
  96. data/lib/solargraph/pin/instance_variable.rb +9 -9
  97. data/lib/solargraph/pin/keyword.rb +17 -17
  98. data/lib/solargraph/pin/local_variable.rb +23 -23
  99. data/lib/solargraph/pin/localized.rb +22 -22
  100. data/lib/solargraph/pin/method.rb +126 -126
  101. data/lib/solargraph/pin/method_alias.rb +30 -30
  102. data/lib/solargraph/pin/method_parameter.rb +40 -40
  103. data/lib/solargraph/pin/namespace.rb +54 -54
  104. data/lib/solargraph/pin/plugin/method.rb +25 -25
  105. data/lib/solargraph/pin/proxy_type.rb +35 -35
  106. data/lib/solargraph/pin/reference.rb +22 -22
  107. data/lib/solargraph/pin/reference/extend.rb +11 -11
  108. data/lib/solargraph/pin/reference/include.rb +11 -11
  109. data/lib/solargraph/pin/reference/require.rb +15 -15
  110. data/lib/solargraph/pin/reference/superclass.rb +11 -11
  111. data/lib/solargraph/pin/symbol.rb +44 -44
  112. data/lib/solargraph/pin/yard_pin.rb +10 -10
  113. data/lib/solargraph/pin/yard_pin/constant.rb +14 -14
  114. data/lib/solargraph/pin/yard_pin/method.rb +35 -35
  115. data/lib/solargraph/pin/yard_pin/namespace.rb +19 -19
  116. data/lib/solargraph/pin/yard_pin/yard_mixin.rb +14 -14
  117. data/lib/solargraph/plugin.rb +8 -8
  118. data/lib/solargraph/plugin/base.rb +41 -41
  119. data/lib/solargraph/plugin/canceler.rb +11 -11
  120. data/lib/solargraph/plugin/process.rb +172 -172
  121. data/lib/solargraph/plugin/runtime.rb +134 -134
  122. data/lib/solargraph/position.rb +110 -110
  123. data/lib/solargraph/range.rb +83 -83
  124. data/lib/solargraph/server_methods.rb +14 -14
  125. data/lib/solargraph/shell.rb +102 -102
  126. data/lib/solargraph/source.rb +521 -521
  127. data/lib/solargraph/source/chain.rb +120 -120
  128. data/lib/solargraph/source/chain/call.rb +107 -107
  129. data/lib/solargraph/source/chain/class_variable.rb +11 -11
  130. data/lib/solargraph/source/chain/constant.rb +30 -30
  131. data/lib/solargraph/source/chain/global_variable.rb +11 -11
  132. data/lib/solargraph/source/chain/head.rb +33 -33
  133. data/lib/solargraph/source/chain/instance_variable.rb +11 -11
  134. data/lib/solargraph/source/chain/link.rb +33 -33
  135. data/lib/solargraph/source/chain/literal.rb +21 -21
  136. data/lib/solargraph/source/chain/variable.rb +11 -11
  137. data/lib/solargraph/source/change.rb +77 -77
  138. data/lib/solargraph/source/cursor.rb +157 -157
  139. data/lib/solargraph/source/node_chainer.rb +96 -96
  140. data/lib/solargraph/source/node_methods.rb +225 -225
  141. data/lib/solargraph/source/source_chainer.rb +183 -183
  142. data/lib/solargraph/source_map.rb +169 -169
  143. data/lib/solargraph/source_map/clip.rb +145 -145
  144. data/lib/solargraph/source_map/completion.rb +21 -21
  145. data/lib/solargraph/source_map/mapper.rb +149 -149
  146. data/lib/solargraph/source_map/node_processor.rb +78 -78
  147. data/lib/solargraph/source_map/node_processor/alias_node.rb +19 -19
  148. data/lib/solargraph/source_map/node_processor/args_node.rb +28 -28
  149. data/lib/solargraph/source_map/node_processor/base.rb +68 -68
  150. data/lib/solargraph/source_map/node_processor/begin_node.rb +11 -11
  151. data/lib/solargraph/source_map/node_processor/block_node.rb +14 -14
  152. data/lib/solargraph/source_map/node_processor/casgn_node.rb +14 -14
  153. data/lib/solargraph/source_map/node_processor/cvasgn_node.rb +14 -14
  154. data/lib/solargraph/source_map/node_processor/def_node.rb +54 -54
  155. data/lib/solargraph/source_map/node_processor/defs_node.rb +21 -21
  156. data/lib/solargraph/source_map/node_processor/gvasgn_node.rb +12 -12
  157. data/lib/solargraph/source_map/node_processor/ivasgn_node.rb +18 -18
  158. data/lib/solargraph/source_map/node_processor/lvasgn_node.rb +16 -16
  159. data/lib/solargraph/source_map/node_processor/namespace_node.rb +26 -26
  160. data/lib/solargraph/source_map/node_processor/orasgn_node.rb +12 -12
  161. data/lib/solargraph/source_map/node_processor/sclass_node.rb +11 -11
  162. data/lib/solargraph/source_map/node_processor/send_node.rb +162 -162
  163. data/lib/solargraph/source_map/node_processor/sym_node.rb +11 -11
  164. data/lib/solargraph/source_map/region.rb +58 -58
  165. data/lib/solargraph/version.rb +3 -3
  166. data/lib/solargraph/views/environment.erb +53 -53
  167. data/lib/solargraph/workspace.rb +183 -183
  168. data/lib/solargraph/workspace/config.rb +170 -170
  169. data/lib/solargraph/yard_map.rb +298 -298
  170. data/lib/solargraph/yard_map/cache.rb +17 -17
  171. data/lib/solargraph/yard_map/core_docs.rb +163 -163
  172. data/lib/solargraph/yard_map/core_gen.rb +76 -76
  173. data/lib/yard-coregen.rb +16 -16
  174. data/lib/yard-solargraph.rb +18 -18
  175. data/solargraph.gemspec +37 -0
  176. data/travis-bundler.rb +10 -0
  177. metadata +19 -6
@@ -1,49 +1,49 @@
1
- module Solargraph
2
- class ApiMap
3
- class Cache
4
- def initialize
5
- @methods = {}
6
- @constants = {}
7
- @qualified_namespaces = {}
8
- end
9
-
10
- def get_methods fqns, scope, visibility, deep
11
- @methods[[fqns, scope, visibility.sort, deep]]
12
- end
13
-
14
- def set_methods fqns, scope, visibility, deep, value
15
- @methods[[fqns, scope, visibility.sort, deep]] = value
16
- end
17
-
18
- def get_constants namespace, context
19
- @constants[[namespace, context]]
20
- end
21
-
22
- def set_constants namespace, context, value
23
- @constants[[namespace, context]] = value
24
- end
25
-
26
- def get_qualified_namespace name, context
27
- @qualified_namespaces[[name, context]]
28
- end
29
-
30
- def set_qualified_namespace name, context, value
31
- @qualified_namespaces[[name, context]] = value
32
- end
33
-
34
- # @return [void]
35
- def clear
36
- @methods.clear
37
- @constants.clear
38
- @qualified_namespaces.clear
39
- end
40
-
41
- # @return [Boolean]
42
- def empty?
43
- @methods.empty? &&
44
- @constants.empty? &&
45
- @qualified_namespaces.empty?
46
- end
47
- end
48
- end
49
- end
1
+ module Solargraph
2
+ class ApiMap
3
+ class Cache
4
+ def initialize
5
+ @methods = {}
6
+ @constants = {}
7
+ @qualified_namespaces = {}
8
+ end
9
+
10
+ def get_methods fqns, scope, visibility, deep
11
+ @methods[[fqns, scope, visibility.sort, deep]]
12
+ end
13
+
14
+ def set_methods fqns, scope, visibility, deep, value
15
+ @methods[[fqns, scope, visibility.sort, deep]] = value
16
+ end
17
+
18
+ def get_constants namespace, context
19
+ @constants[[namespace, context]]
20
+ end
21
+
22
+ def set_constants namespace, context, value
23
+ @constants[[namespace, context]] = value
24
+ end
25
+
26
+ def get_qualified_namespace name, context
27
+ @qualified_namespaces[[name, context]]
28
+ end
29
+
30
+ def set_qualified_namespace name, context, value
31
+ @qualified_namespaces[[name, context]] = value
32
+ end
33
+
34
+ # @return [void]
35
+ def clear
36
+ @methods.clear
37
+ @constants.clear
38
+ @qualified_namespaces.clear
39
+ end
40
+
41
+ # @return [Boolean]
42
+ def empty?
43
+ @methods.empty? &&
44
+ @constants.empty? &&
45
+ @qualified_namespaces.empty?
46
+ end
47
+ end
48
+ end
49
+ end
@@ -1,67 +1,67 @@
1
- module Solargraph
2
- class ApiMap
3
- module SourceToYard
4
-
5
- # Get the YARD CodeObject at the specified path.
6
- #
7
- # @param path [String]
8
- # @return [YARD::CodeObjects::Base]
9
- def code_object_at path
10
- code_object_map[path]
11
- end
12
-
13
- # @return [Array<String>]
14
- def code_object_paths
15
- code_object_map.keys
16
- end
17
-
18
- # @param store [Array<Store>] ApiMap pin store
19
- # @return [void]
20
- def rake_yard store
21
- code_object_map.clear
22
- store.namespace_pins.each do |pin|
23
- next if pin.path.nil? or pin.path.empty?
24
- if pin.type == :class
25
- code_object_map[pin.path] ||= YARD::CodeObjects::ClassObject.new(root_code_object, pin.path)
26
- else
27
- code_object_map[pin.path] ||= YARD::CodeObjects::ModuleObject.new(root_code_object, pin.path)
28
- end
29
- code_object_map[pin.path].docstring = pin.docstring
30
- code_object_map[pin.path].files.push pin.location.filename unless pin.location.nil?
31
- end
32
- store.namespace_pins.each do |pin|
33
- # pin.include_references.each do |ref|
34
- store.get_includes(pin.path).each do |ref|
35
- code_object_map[pin.path].instance_mixins.push code_object_map[ref] unless code_object_map[ref].nil? or code_object_map[pin.path].nil?
36
- end
37
- end
38
- store.method_pins.each do |pin|
39
- code_object_map[pin.path] ||= YARD::CodeObjects::MethodObject.new(code_object_at(pin.namespace), pin.name, pin.scope)
40
- code_object_map[pin.path].docstring = pin.docstring
41
- code_object_map[pin.path].visibility = pin.visibility || :public
42
- code_object_map[pin.path].files.push pin.location.filename unless pin.location.nil?
43
- code_object_map[pin.path].parameters = pin.parameters.map do |p|
44
- n = p.match(/^[a-z0-9_]*:?/i)[0]
45
- v = nil
46
- if p.length > n.length
47
- v = p[n.length..-1].gsub(/^ = /, '')
48
- end
49
- [n, v]
50
- end
51
- end
52
- end
53
-
54
- private
55
-
56
- # @return [Hash]
57
- def code_object_map
58
- @code_object_map ||= {}
59
- end
60
-
61
- # @return [YARD::CodeObjects::RootObject]
62
- def root_code_object
63
- @root_code_object ||= YARD::CodeObjects::RootObject.new(nil, 'root')
64
- end
65
- end
66
- end
67
- end
1
+ module Solargraph
2
+ class ApiMap
3
+ module SourceToYard
4
+
5
+ # Get the YARD CodeObject at the specified path.
6
+ #
7
+ # @param path [String]
8
+ # @return [YARD::CodeObjects::Base]
9
+ def code_object_at path
10
+ code_object_map[path]
11
+ end
12
+
13
+ # @return [Array<String>]
14
+ def code_object_paths
15
+ code_object_map.keys
16
+ end
17
+
18
+ # @param store [Array<Store>] ApiMap pin store
19
+ # @return [void]
20
+ def rake_yard store
21
+ code_object_map.clear
22
+ store.namespace_pins.each do |pin|
23
+ next if pin.path.nil? or pin.path.empty?
24
+ if pin.type == :class
25
+ code_object_map[pin.path] ||= YARD::CodeObjects::ClassObject.new(root_code_object, pin.path)
26
+ else
27
+ code_object_map[pin.path] ||= YARD::CodeObjects::ModuleObject.new(root_code_object, pin.path)
28
+ end
29
+ code_object_map[pin.path].docstring = pin.docstring
30
+ code_object_map[pin.path].files.push pin.location.filename unless pin.location.nil?
31
+ end
32
+ store.namespace_pins.each do |pin|
33
+ # pin.include_references.each do |ref|
34
+ store.get_includes(pin.path).each do |ref|
35
+ code_object_map[pin.path].instance_mixins.push code_object_map[ref] unless code_object_map[ref].nil? or code_object_map[pin.path].nil?
36
+ end
37
+ end
38
+ store.method_pins.each do |pin|
39
+ code_object_map[pin.path] ||= YARD::CodeObjects::MethodObject.new(code_object_at(pin.namespace), pin.name, pin.scope)
40
+ code_object_map[pin.path].docstring = pin.docstring
41
+ code_object_map[pin.path].visibility = pin.visibility || :public
42
+ code_object_map[pin.path].files.push pin.location.filename unless pin.location.nil?
43
+ code_object_map[pin.path].parameters = pin.parameters.map do |p|
44
+ n = p.match(/^[a-z0-9_]*:?/i)[0]
45
+ v = nil
46
+ if p.length > n.length
47
+ v = p[n.length..-1].gsub(/^ = /, '')
48
+ end
49
+ [n, v]
50
+ end
51
+ end
52
+ end
53
+
54
+ private
55
+
56
+ # @return [Hash]
57
+ def code_object_map
58
+ @code_object_map ||= {}
59
+ end
60
+
61
+ # @return [YARD::CodeObjects::RootObject]
62
+ def root_code_object
63
+ @root_code_object ||= YARD::CodeObjects::RootObject.new(nil, 'root')
64
+ end
65
+ end
66
+ end
67
+ end
@@ -1,201 +1,201 @@
1
- require 'set'
2
-
3
- module Solargraph
4
- class ApiMap
5
- class Store
6
- # @return [Array<Solargraph::Pin::Base>]
7
- attr_reader :pins
8
-
9
- # @param pins [Array<Solargraph::Source>]
10
- def initialize pins = []
11
- @pins = pins
12
- index
13
- end
14
-
15
- # @param fqns [String]
16
- # @param visibility [Array<Symbol>]
17
- # @return [Array<Solargraph::Pin::Base>]
18
- def get_constants fqns, visibility = [:public]
19
- namespace_children(fqns).select { |pin|
20
- !pin.name.empty? and (pin.kind == Pin::NAMESPACE or pin.kind == Pin::CONSTANT) and visibility.include?(pin.visibility)
21
- }
22
- end
23
-
24
- # @param fqns [String]
25
- # @param scope [Symbol]
26
- # @param visibility [Array<Symbol>]
27
- # @return [Array<Solargraph::Pin::Base>]
28
- def get_methods fqns, scope: :instance, visibility: [:public]
29
- kinds = [Pin::METHOD, Pin::ATTRIBUTE]
30
- namespace_children(fqns).select{ |pin|
31
- kinds.include?(pin.kind) && pin.scope == scope && visibility.include?(pin.visibility)
32
- }
33
- end
34
-
35
- # @param fqns [String]
36
- # @return [String]
37
- def get_superclass fqns
38
- return superclass_references[fqns].first if superclass_references.has_key?(fqns)
39
- nil
40
- end
41
-
42
- # @param fqns [String]
43
- # @return [Array<String>]
44
- def get_includes fqns
45
- include_references[fqns] || []
46
- end
47
-
48
- # @param fqns [String]
49
- # @return [Array<String>]
50
- def get_extends fqns
51
- extend_references[fqns] || []
52
- end
53
-
54
- # @param path [String]
55
- # @return [Array<Solargraph::Pin::Base>]
56
- def get_path_pins path
57
- return [] if path.nil? # @todo Should be '' instead?
58
- pins.select { |pin| pin.path == path }
59
- end
60
-
61
- # @param fqns [String]
62
- # @param scope [Symbol] :class or :instance
63
- # @return [Array<Solargraph::Pin::Base>]
64
- def get_instance_variables(fqns, scope = :instance)
65
- namespace_children(fqns).select{|pin| pin.kind == Pin::INSTANCE_VARIABLE and pin.context.scope == scope}
66
- end
67
-
68
- # @param fqns [String]
69
- # @return [Array<Solargraph::Pin::Base>]
70
- def get_class_variables(fqns)
71
- namespace_children(fqns).select{|pin| pin.kind == Pin::CLASS_VARIABLE}
72
- end
73
-
74
- # @return [Array<Solargraph::Pin::Base>]
75
- def get_symbols
76
- symbols.uniq(&:name)
77
- end
78
-
79
- # @param fqns [String]
80
- # @return [Boolean]
81
- def namespace_exists?(fqns)
82
- fqns_pins(fqns).any?
83
- end
84
-
85
- # @return [Set<String>]
86
- def namespaces
87
- @namespaces ||= Set.new
88
- end
89
-
90
- # @return [Array<Solargraph::Pin::Base>]
91
- def namespace_pins
92
- @namespace_pins ||= pins.select{|p| p.kind == Pin::NAMESPACE}
93
- end
94
-
95
- # @return [Array<Solargraph::Pin::Base>]
96
- def method_pins
97
- @method_pins ||= pins.select{|p| p.kind == Pin::METHOD or p.kind == Pin::ATTRIBUTE}
98
- end
99
-
100
- # @param fqns [String]
101
- # @return [Array<String>]
102
- def domains(fqns)
103
- result = []
104
- fqns_pins(fqns).each do |nspin|
105
- result.concat nspin.domains
106
- end
107
- result
108
- end
109
-
110
- # @return [Hash]
111
- def named_macros
112
- @named_macros ||= begin
113
- result = {}
114
- pins.each do |pin|
115
- pin.macros.select{|m| m.tag.tag_name == 'macro'}.each do |macro|
116
- next if macro.tag.name.nil? || macro.tag.name.empty?
117
- result[macro.tag.name] = macro
118
- end
119
- end
120
- result
121
- end
122
- end
123
-
124
- def inspect
125
- # Avoid insane dumps in specs
126
- to_s
127
- end
128
-
129
- private
130
-
131
- # @param fqns [String]
132
- # @return [Array<Solargraph::Pin::Namespace>]
133
- def fqns_pins fqns
134
- return [] if fqns.nil?
135
- if fqns.include?('::')
136
- parts = fqns.split('::')
137
- name = parts.pop
138
- base = parts.join('::')
139
- else
140
- base = ''
141
- name = fqns
142
- end
143
- namespace_children(base).select{|pin| pin.name == name and pin.kind == Pin::NAMESPACE}
144
- end
145
-
146
- # @return [Array<Solargraph::Pin::Symbol>]
147
- def symbols
148
- @symbols ||= []
149
- end
150
-
151
- def superclass_references
152
- @superclass_references ||= {}
153
- end
154
-
155
- def include_references
156
- @include_references ||= {}
157
- end
158
-
159
- def extend_references
160
- @extend_references ||= {}
161
- end
162
-
163
- # @param name [String]
164
- # @return [Array<Solargraph::Pin::Base>]
165
- def namespace_children name
166
- namespace_map[name] || []
167
- end
168
-
169
- # @return [Hash]
170
- def namespace_map
171
- @namespace_map ||= {}
172
- end
173
-
174
- # @return [void]
175
- def index
176
- namespace_map.clear
177
- namespaces.clear
178
- symbols.clear
179
- namespace_map[''] = []
180
- pins.each do |pin|
181
- namespace_map[pin.namespace] ||= []
182
- namespace_map[pin.namespace].push pin
183
- namespaces.add pin.path if pin.kind == Pin::NAMESPACE and !pin.path.empty?
184
- symbols.push pin if pin.kind == Pin::SYMBOL
185
- if pin.kind == Pin::INCLUDE_REFERENCE
186
- include_references[pin.namespace] ||= []
187
- include_references[pin.namespace].push pin.name
188
- elsif pin.kind == Pin::EXTEND_REFERENCE
189
- extend_references[pin.namespace] ||= []
190
- extend_references[pin.namespace].push pin.name
191
- elsif pin.kind == Pin::SUPERCLASS_REFERENCE
192
- superclass_references[pin.namespace] ||= []
193
- superclass_references[pin.namespace].push pin.name
194
- end
195
- end
196
- @namespace_pins = nil
197
- @method_pins = nil
198
- end
199
- end
200
- end
201
- end
1
+ require 'set'
2
+
3
+ module Solargraph
4
+ class ApiMap
5
+ class Store
6
+ # @return [Array<Solargraph::Pin::Base>]
7
+ attr_reader :pins
8
+
9
+ # @param pins [Array<Solargraph::Source>]
10
+ def initialize pins = []
11
+ @pins = pins
12
+ index
13
+ end
14
+
15
+ # @param fqns [String]
16
+ # @param visibility [Array<Symbol>]
17
+ # @return [Array<Solargraph::Pin::Base>]
18
+ def get_constants fqns, visibility = [:public]
19
+ namespace_children(fqns).select { |pin|
20
+ !pin.name.empty? and (pin.kind == Pin::NAMESPACE or pin.kind == Pin::CONSTANT) and visibility.include?(pin.visibility)
21
+ }
22
+ end
23
+
24
+ # @param fqns [String]
25
+ # @param scope [Symbol]
26
+ # @param visibility [Array<Symbol>]
27
+ # @return [Array<Solargraph::Pin::Base>]
28
+ def get_methods fqns, scope: :instance, visibility: [:public]
29
+ kinds = [Pin::METHOD, Pin::ATTRIBUTE]
30
+ namespace_children(fqns).select{ |pin|
31
+ kinds.include?(pin.kind) && pin.scope == scope && visibility.include?(pin.visibility)
32
+ }
33
+ end
34
+
35
+ # @param fqns [String]
36
+ # @return [String]
37
+ def get_superclass fqns
38
+ return superclass_references[fqns].first if superclass_references.has_key?(fqns)
39
+ nil
40
+ end
41
+
42
+ # @param fqns [String]
43
+ # @return [Array<String>]
44
+ def get_includes fqns
45
+ include_references[fqns] || []
46
+ end
47
+
48
+ # @param fqns [String]
49
+ # @return [Array<String>]
50
+ def get_extends fqns
51
+ extend_references[fqns] || []
52
+ end
53
+
54
+ # @param path [String]
55
+ # @return [Array<Solargraph::Pin::Base>]
56
+ def get_path_pins path
57
+ return [] if path.nil? # @todo Should be '' instead?
58
+ pins.select { |pin| pin.path == path }
59
+ end
60
+
61
+ # @param fqns [String]
62
+ # @param scope [Symbol] :class or :instance
63
+ # @return [Array<Solargraph::Pin::Base>]
64
+ def get_instance_variables(fqns, scope = :instance)
65
+ namespace_children(fqns).select{|pin| pin.kind == Pin::INSTANCE_VARIABLE and pin.context.scope == scope}
66
+ end
67
+
68
+ # @param fqns [String]
69
+ # @return [Array<Solargraph::Pin::Base>]
70
+ def get_class_variables(fqns)
71
+ namespace_children(fqns).select{|pin| pin.kind == Pin::CLASS_VARIABLE}
72
+ end
73
+
74
+ # @return [Array<Solargraph::Pin::Base>]
75
+ def get_symbols
76
+ symbols.uniq(&:name)
77
+ end
78
+
79
+ # @param fqns [String]
80
+ # @return [Boolean]
81
+ def namespace_exists?(fqns)
82
+ fqns_pins(fqns).any?
83
+ end
84
+
85
+ # @return [Set<String>]
86
+ def namespaces
87
+ @namespaces ||= Set.new
88
+ end
89
+
90
+ # @return [Array<Solargraph::Pin::Base>]
91
+ def namespace_pins
92
+ @namespace_pins ||= pins.select{|p| p.kind == Pin::NAMESPACE}
93
+ end
94
+
95
+ # @return [Array<Solargraph::Pin::Base>]
96
+ def method_pins
97
+ @method_pins ||= pins.select{|p| p.kind == Pin::METHOD or p.kind == Pin::ATTRIBUTE}
98
+ end
99
+
100
+ # @param fqns [String]
101
+ # @return [Array<String>]
102
+ def domains(fqns)
103
+ result = []
104
+ fqns_pins(fqns).each do |nspin|
105
+ result.concat nspin.domains
106
+ end
107
+ result
108
+ end
109
+
110
+ # @return [Hash]
111
+ def named_macros
112
+ @named_macros ||= begin
113
+ result = {}
114
+ pins.each do |pin|
115
+ pin.macros.select{|m| m.tag.tag_name == 'macro'}.each do |macro|
116
+ next if macro.tag.name.nil? || macro.tag.name.empty?
117
+ result[macro.tag.name] = macro
118
+ end
119
+ end
120
+ result
121
+ end
122
+ end
123
+
124
+ def inspect
125
+ # Avoid insane dumps in specs
126
+ to_s
127
+ end
128
+
129
+ private
130
+
131
+ # @param fqns [String]
132
+ # @return [Array<Solargraph::Pin::Namespace>]
133
+ def fqns_pins fqns
134
+ return [] if fqns.nil?
135
+ if fqns.include?('::')
136
+ parts = fqns.split('::')
137
+ name = parts.pop
138
+ base = parts.join('::')
139
+ else
140
+ base = ''
141
+ name = fqns
142
+ end
143
+ namespace_children(base).select{|pin| pin.name == name and pin.kind == Pin::NAMESPACE}
144
+ end
145
+
146
+ # @return [Array<Solargraph::Pin::Symbol>]
147
+ def symbols
148
+ @symbols ||= []
149
+ end
150
+
151
+ def superclass_references
152
+ @superclass_references ||= {}
153
+ end
154
+
155
+ def include_references
156
+ @include_references ||= {}
157
+ end
158
+
159
+ def extend_references
160
+ @extend_references ||= {}
161
+ end
162
+
163
+ # @param name [String]
164
+ # @return [Array<Solargraph::Pin::Base>]
165
+ def namespace_children name
166
+ namespace_map[name] || []
167
+ end
168
+
169
+ # @return [Hash]
170
+ def namespace_map
171
+ @namespace_map ||= {}
172
+ end
173
+
174
+ # @return [void]
175
+ def index
176
+ namespace_map.clear
177
+ namespaces.clear
178
+ symbols.clear
179
+ namespace_map[''] = []
180
+ pins.each do |pin|
181
+ namespace_map[pin.namespace] ||= []
182
+ namespace_map[pin.namespace].push pin
183
+ namespaces.add pin.path if pin.kind == Pin::NAMESPACE and !pin.path.empty?
184
+ symbols.push pin if pin.kind == Pin::SYMBOL
185
+ if pin.kind == Pin::INCLUDE_REFERENCE
186
+ include_references[pin.namespace] ||= []
187
+ include_references[pin.namespace].push pin.name
188
+ elsif pin.kind == Pin::EXTEND_REFERENCE
189
+ extend_references[pin.namespace] ||= []
190
+ extend_references[pin.namespace].push pin.name
191
+ elsif pin.kind == Pin::SUPERCLASS_REFERENCE
192
+ superclass_references[pin.namespace] ||= []
193
+ superclass_references[pin.namespace].push pin.name
194
+ end
195
+ end
196
+ @namespace_pins = nil
197
+ @method_pins = nil
198
+ end
199
+ end
200
+ end
201
+ end