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,50 +1,50 @@
1
- module Solargraph
2
- # The namespace for pins used in maps.
3
- #
4
- module Pin
5
- autoload :Conversions, 'solargraph/pin/conversions'
6
- autoload :Base, 'solargraph/pin/base'
7
- autoload :BaseMethod, 'solargraph/pin/base_method'
8
- autoload :Method, 'solargraph/pin/method'
9
- autoload :MethodAlias, 'solargraph/pin/method_alias'
10
- autoload :Attribute, 'solargraph/pin/attribute'
11
- autoload :BaseVariable, 'solargraph/pin/base_variable'
12
- autoload :InstanceVariable, 'solargraph/pin/instance_variable'
13
- autoload :ClassVariable, 'solargraph/pin/class_variable'
14
- autoload :LocalVariable, 'solargraph/pin/local_variable'
15
- autoload :GlobalVariable, 'solargraph/pin/global_variable'
16
- autoload :Constant, 'solargraph/pin/constant'
17
- autoload :Symbol, 'solargraph/pin/symbol'
18
- autoload :Namespace, 'solargraph/pin/namespace'
19
- autoload :Keyword, 'solargraph/pin/keyword'
20
- autoload :MethodParameter, 'solargraph/pin/method_parameter'
21
- autoload :BlockParameter, 'solargraph/pin/block_parameter'
22
- autoload :Reference, 'solargraph/pin/reference'
23
- autoload :Documenting, 'solargraph/pin/documenting'
24
- autoload :Block, 'solargraph/pin/block'
25
- autoload :Localized, 'solargraph/pin/localized'
26
- autoload :ProxyType, 'solargraph/pin/proxy_type'
27
- autoload :DuckMethod, 'solargraph/pin/duck_method'
28
- autoload :YardPin, 'solargraph/pin/yard_pin'
29
-
30
- ATTRIBUTE = 1
31
- CLASS_VARIABLE = 2
32
- CONSTANT = 3
33
- GLOBAL_VARIABLE = 4
34
- INSTANCE_VARIABLE = 5
35
- KEYWORD = 6
36
- LOCAL_VARIABLE = 7
37
- METHOD = 8
38
- NAMESPACE = 9
39
- SYMBOL = 10
40
- BLOCK = 11
41
- BLOCK_PARAMETER = 12
42
- REQUIRE_REFERENCE = 13
43
- SUPERCLASS_REFERENCE = 14
44
- INCLUDE_REFERENCE = 15
45
- EXTEND_REFERENCE = 16
46
- METHOD_ALIAS = 17
47
-
48
- ROOT_PIN = Pin::Namespace.new(nil, '', '', '', :class, :public)
49
- end
50
- end
1
+ module Solargraph
2
+ # The namespace for pins used in maps.
3
+ #
4
+ module Pin
5
+ autoload :Conversions, 'solargraph/pin/conversions'
6
+ autoload :Base, 'solargraph/pin/base'
7
+ autoload :BaseMethod, 'solargraph/pin/base_method'
8
+ autoload :Method, 'solargraph/pin/method'
9
+ autoload :MethodAlias, 'solargraph/pin/method_alias'
10
+ autoload :Attribute, 'solargraph/pin/attribute'
11
+ autoload :BaseVariable, 'solargraph/pin/base_variable'
12
+ autoload :InstanceVariable, 'solargraph/pin/instance_variable'
13
+ autoload :ClassVariable, 'solargraph/pin/class_variable'
14
+ autoload :LocalVariable, 'solargraph/pin/local_variable'
15
+ autoload :GlobalVariable, 'solargraph/pin/global_variable'
16
+ autoload :Constant, 'solargraph/pin/constant'
17
+ autoload :Symbol, 'solargraph/pin/symbol'
18
+ autoload :Namespace, 'solargraph/pin/namespace'
19
+ autoload :Keyword, 'solargraph/pin/keyword'
20
+ autoload :MethodParameter, 'solargraph/pin/method_parameter'
21
+ autoload :BlockParameter, 'solargraph/pin/block_parameter'
22
+ autoload :Reference, 'solargraph/pin/reference'
23
+ autoload :Documenting, 'solargraph/pin/documenting'
24
+ autoload :Block, 'solargraph/pin/block'
25
+ autoload :Localized, 'solargraph/pin/localized'
26
+ autoload :ProxyType, 'solargraph/pin/proxy_type'
27
+ autoload :DuckMethod, 'solargraph/pin/duck_method'
28
+ autoload :YardPin, 'solargraph/pin/yard_pin'
29
+
30
+ ATTRIBUTE = 1
31
+ CLASS_VARIABLE = 2
32
+ CONSTANT = 3
33
+ GLOBAL_VARIABLE = 4
34
+ INSTANCE_VARIABLE = 5
35
+ KEYWORD = 6
36
+ LOCAL_VARIABLE = 7
37
+ METHOD = 8
38
+ NAMESPACE = 9
39
+ SYMBOL = 10
40
+ BLOCK = 11
41
+ BLOCK_PARAMETER = 12
42
+ REQUIRE_REFERENCE = 13
43
+ SUPERCLASS_REFERENCE = 14
44
+ INCLUDE_REFERENCE = 15
45
+ EXTEND_REFERENCE = 16
46
+ METHOD_ALIAS = 17
47
+
48
+ ROOT_PIN = Pin::Namespace.new(nil, '', '', '', :class, :public)
49
+ end
50
+ end
@@ -1,41 +1,41 @@
1
- module Solargraph
2
- module Pin
3
- class Attribute < BaseMethod
4
- # @return [Symbol] :reader or :writer
5
- attr_reader :access
6
-
7
- def initialize location, namespace, name, comments, access, scope, visibility
8
- super(location, namespace, name, comments)
9
- @access = access
10
- @scope = scope
11
- @visibility = visibility
12
- end
13
-
14
- def kind
15
- Solargraph::Pin::ATTRIBUTE
16
- end
17
-
18
- def completion_item_kind
19
- Solargraph::LanguageServer::CompletionItemKinds::PROPERTY
20
- end
21
-
22
- def symbol_kind
23
- Solargraph::LanguageServer::SymbolKinds::PROPERTY
24
- end
25
-
26
- def path
27
- @path ||= namespace + (scope == :instance ? '#' : '.') + name
28
- end
29
-
30
- def parameters
31
- # Since attributes are generally equivalent to methods, treat
32
- # them as methods without parameters
33
- []
34
- end
35
-
36
- def parameter_names
37
- []
38
- end
39
- end
40
- end
41
- end
1
+ module Solargraph
2
+ module Pin
3
+ class Attribute < BaseMethod
4
+ # @return [Symbol] :reader or :writer
5
+ attr_reader :access
6
+
7
+ def initialize location, namespace, name, comments, access, scope, visibility
8
+ super(location, namespace, name, comments)
9
+ @access = access
10
+ @scope = scope
11
+ @visibility = visibility
12
+ end
13
+
14
+ def kind
15
+ Solargraph::Pin::ATTRIBUTE
16
+ end
17
+
18
+ def completion_item_kind
19
+ Solargraph::LanguageServer::CompletionItemKinds::PROPERTY
20
+ end
21
+
22
+ def symbol_kind
23
+ Solargraph::LanguageServer::SymbolKinds::PROPERTY
24
+ end
25
+
26
+ def path
27
+ @path ||= namespace + (scope == :instance ? '#' : '.') + name
28
+ end
29
+
30
+ def parameters
31
+ # Since attributes are generally equivalent to methods, treat
32
+ # them as methods without parameters
33
+ []
34
+ end
35
+
36
+ def parameter_names
37
+ []
38
+ end
39
+ end
40
+ end
41
+ end
@@ -1,280 +1,280 @@
1
- module Solargraph
2
- module Pin
3
- # The base class for map pins.
4
- #
5
- class Base
6
- include Conversions
7
- include Documenting
8
-
9
- # @return [Solargraph::Location]
10
- attr_reader :location
11
-
12
- # The namespace in which this pin is defined.
13
- # The root namespace is an empty string.
14
- #
15
- # @return [String]
16
- attr_reader :namespace
17
-
18
- # @return [String]
19
- attr_reader :name
20
-
21
- # @return [Integer]
22
- attr_reader :kind
23
-
24
- # @return [String]
25
- attr_reader :path
26
-
27
- # @param location [Solargraph::Location]
28
- # @param namespace [String]
29
- # @param name [String]
30
- # @param comments [String]
31
- def initialize location, namespace, name, comments
32
- @location = location
33
- @namespace = namespace
34
- @name = name
35
- @comments = comments
36
- end
37
-
38
- # @return [String]
39
- def comments
40
- @comments ||= ''
41
- end
42
-
43
- # @return [String]
44
- def filename
45
- return nil if location.nil?
46
- location.filename
47
- end
48
-
49
- # @return [Integer]
50
- def completion_item_kind
51
- LanguageServer::CompletionItemKinds::KEYWORD
52
- end
53
-
54
- # @return [Integer]
55
- def symbol_kind
56
- nil
57
- end
58
-
59
- def to_s
60
- name.to_s
61
- end
62
-
63
- # @return [Boolean]
64
- def variable?
65
- false
66
- end
67
-
68
- # @return [ComplexType]
69
- def context
70
- @context ||= ComplexType.try_parse(namespace || '')
71
- end
72
-
73
- # Pin equality is determined using the #nearly? method and also
74
- # requiring both pins to have the same location.
75
- #
76
- def == other
77
- return false unless nearly? other
78
- comments == other.comments and location == other.location
79
- end
80
-
81
- # True if the specified pin is a near match to this one. A near match
82
- # indicates that the pins contain mostly the same data. Any differences
83
- # between them should not have an impact on the API surface.
84
- #
85
- # @param other [Solargraph::Pin::Base, Object]
86
- # @return [Boolean]
87
- def nearly? other
88
- self.class == other.class &&
89
- namespace == other.namespace &&
90
- name == other.name &&
91
- (comments == other.comments ||
92
- (((maybe_directives? == false && other.maybe_directives? == false) || compare_directives(directives, other.directives)) &&
93
- compare_docstring_tags(docstring, other.docstring))
94
- )
95
- end
96
-
97
- # An alias for return_complex_type.
98
- #
99
- # @return [ComplexType]
100
- def return_type
101
- return_complex_type
102
- end
103
-
104
- # All of the pin's return types as an array of ComplexTypes.
105
- #
106
- # @return [ComplexType]
107
- def return_complex_type
108
- @return_complex_type ||= ComplexType::UNDEFINED
109
- end
110
-
111
- # @return [YARD::Docstring]
112
- def docstring
113
- parse_comments unless defined?(@docstring)
114
- @docstring ||= Solargraph::Source.parse_docstring('').to_docstring
115
- end
116
-
117
- # @return [Array<YARD::Tags::Directive>]
118
- def directives
119
- parse_comments unless defined?(@directives)
120
- @directives
121
- end
122
-
123
- # @return [Array<YARD::Tags::MacroDirective>]
124
- def macros
125
- @macros ||= collect_macros
126
- end
127
-
128
- # Perform a quick check to see if this pin possibly includes YARD
129
- # directives. This method does not require parsing the comments.
130
- #
131
- # After the comments have been parsed, this method will return false if
132
- # no directives were found, regardless of whether it previously appeared
133
- # possible.
134
- #
135
- # @return [Boolean]
136
- def maybe_directives?
137
- return !@directives.empty? if defined?(@directives)
138
- @maybe_directives ||= comments.include?('@!')
139
- end
140
-
141
- # @return [Boolean]
142
- def deprecated?
143
- @deprecated ||= docstring.has_tag?('deprecated')
144
- end
145
-
146
- # Get a fully qualified type from the pin's return type.
147
- #
148
- # The relative type is determined from YARD documentation (@return,
149
- # @param, @type, etc.) and its namespaces are fully qualified using the
150
- # provided ApiMap.
151
- #
152
- # @param api_map [ApiMap]
153
- # @return [ComplexType]
154
- def typify api_map
155
- return_complex_type.qualify(api_map, namespace)
156
- end
157
-
158
- # Infer the pin's return type via static code analysis.
159
- #
160
- # @param api_map [ApiMap]
161
- # @return [ComplexType]
162
- def probe api_map
163
- typify api_map
164
- end
165
-
166
- # @deprecated Use #typify and/or #probe instead
167
- # @param api_map [ApiMap]
168
- # @return [ComplexType]
169
- def infer api_map
170
- Solargraph::Logging.logger.warn "WARNING: Pin #infer methods are deprecated. Use #typify or #probe instead."
171
- type = typify(api_map)
172
- return type unless type.undefined?
173
- probe api_map
174
- end
175
-
176
- # Try to merge data from another pin. Merges are only possible if the
177
- # pins are near matches (see the #nearly? method). The changes should
178
- # not have any side effects on the API surface.
179
- #
180
- # @param pin [Pin::Base] The pin to merge into this one
181
- # @return [Boolean] True if the pins were merged
182
- def try_merge! pin
183
- return false unless nearly?(pin)
184
- @location = pin.location
185
- return true if comments == pin.comments
186
- @comments = pin.comments
187
- @docstring = pin.docstring
188
- @return_complex_type = pin.return_complex_type
189
- @documentation = nil
190
- @deprecated = nil
191
- reset_conversions
192
- true
193
- end
194
-
195
- def proxied?
196
- @proxied ||= false
197
- end
198
-
199
- # Return a proxy for this pin with the specified return type. Other than
200
- # the return type and the #proxied? setting, the proxy should be a clone
201
- # of the original.
202
- #
203
- # @param return_type [ComplexType]
204
- # @return [self]
205
- def proxy return_type
206
- result = dup
207
- result.return_complex_type = return_type
208
- result.proxied = true
209
- result
210
- end
211
-
212
- protected
213
-
214
- # @return [Boolean]
215
- attr_writer :proxied
216
-
217
- # @return [ComplexType]
218
- attr_writer :return_complex_type
219
-
220
- private
221
-
222
- # @return [void]
223
- def parse_comments
224
- if comments.empty?
225
- @docstring = nil
226
- @directives = []
227
- else
228
- # HACK: Pass a dummy code object to the parser for plugins that
229
- # expect it not to be nil
230
- parse = Solargraph::Source.parse_docstring(comments)
231
- @docstring = parse.to_docstring
232
- @directives = parse.directives
233
- end
234
- end
235
-
236
- # True if two docstrings have the same tags, regardless of any other
237
- # differences.
238
- #
239
- # @param d1 [YARD::Docstring]
240
- # @param d2 [YARD::Docstring]
241
- # @return [boolean]
242
- def compare_docstring_tags d1, d2
243
- return false if d1.tags.length != d2.tags.length
244
- d1.tags.each_index do |i|
245
- return false unless compare_tags(d1.tags[i], d2.tags[i])
246
- end
247
- true
248
- end
249
-
250
- # @param d1 [Array<YARD::Tags::Directive>]
251
- # @param d2 [Array<YARD::Tags::Directive>]
252
- # @return [Boolean]
253
- def compare_directives d1, d2
254
- return false if d1.length != d2.length
255
- d1.each_index do |i|
256
- return false unless compare_tags(d1[i].tag, d2[i].tag)
257
- end
258
- true
259
- end
260
-
261
- # @param t1 [YARD::Tags::Tag]
262
- # @param t2 [YARD::Tags::Tag]
263
- # @return [Boolean]
264
- def compare_tags t1, t2
265
- t1.class == t2.class &&
266
- t1.tag_name == t2.tag_name &&
267
- t1.text == t2.text &&
268
- t1.name == t2.name &&
269
- t1.types == t2.types
270
- end
271
-
272
- # @return [Array<YARD::Tags::Handlers::Directive>]
273
- def collect_macros
274
- return [] unless maybe_directives?
275
- parse = Solargraph::Source.parse_docstring(comments)
276
- parse.directives.select{ |d| d.tag.tag_name == 'macro' }
277
- end
278
- end
279
- end
280
- end
1
+ module Solargraph
2
+ module Pin
3
+ # The base class for map pins.
4
+ #
5
+ class Base
6
+ include Conversions
7
+ include Documenting
8
+
9
+ # @return [Solargraph::Location]
10
+ attr_reader :location
11
+
12
+ # The namespace in which this pin is defined.
13
+ # The root namespace is an empty string.
14
+ #
15
+ # @return [String]
16
+ attr_reader :namespace
17
+
18
+ # @return [String]
19
+ attr_reader :name
20
+
21
+ # @return [Integer]
22
+ attr_reader :kind
23
+
24
+ # @return [String]
25
+ attr_reader :path
26
+
27
+ # @param location [Solargraph::Location]
28
+ # @param namespace [String]
29
+ # @param name [String]
30
+ # @param comments [String]
31
+ def initialize location, namespace, name, comments
32
+ @location = location
33
+ @namespace = namespace
34
+ @name = name
35
+ @comments = comments
36
+ end
37
+
38
+ # @return [String]
39
+ def comments
40
+ @comments ||= ''
41
+ end
42
+
43
+ # @return [String]
44
+ def filename
45
+ return nil if location.nil?
46
+ location.filename
47
+ end
48
+
49
+ # @return [Integer]
50
+ def completion_item_kind
51
+ LanguageServer::CompletionItemKinds::KEYWORD
52
+ end
53
+
54
+ # @return [Integer]
55
+ def symbol_kind
56
+ nil
57
+ end
58
+
59
+ def to_s
60
+ name.to_s
61
+ end
62
+
63
+ # @return [Boolean]
64
+ def variable?
65
+ false
66
+ end
67
+
68
+ # @return [ComplexType]
69
+ def context
70
+ @context ||= ComplexType.try_parse(namespace || '')
71
+ end
72
+
73
+ # Pin equality is determined using the #nearly? method and also
74
+ # requiring both pins to have the same location.
75
+ #
76
+ def == other
77
+ return false unless nearly? other
78
+ comments == other.comments and location == other.location
79
+ end
80
+
81
+ # True if the specified pin is a near match to this one. A near match
82
+ # indicates that the pins contain mostly the same data. Any differences
83
+ # between them should not have an impact on the API surface.
84
+ #
85
+ # @param other [Solargraph::Pin::Base, Object]
86
+ # @return [Boolean]
87
+ def nearly? other
88
+ self.class == other.class &&
89
+ namespace == other.namespace &&
90
+ name == other.name &&
91
+ (comments == other.comments ||
92
+ (((maybe_directives? == false && other.maybe_directives? == false) || compare_directives(directives, other.directives)) &&
93
+ compare_docstring_tags(docstring, other.docstring))
94
+ )
95
+ end
96
+
97
+ # An alias for return_complex_type.
98
+ #
99
+ # @return [ComplexType]
100
+ def return_type
101
+ return_complex_type
102
+ end
103
+
104
+ # All of the pin's return types as an array of ComplexTypes.
105
+ #
106
+ # @return [ComplexType]
107
+ def return_complex_type
108
+ @return_complex_type ||= ComplexType::UNDEFINED
109
+ end
110
+
111
+ # @return [YARD::Docstring]
112
+ def docstring
113
+ parse_comments unless defined?(@docstring)
114
+ @docstring ||= Solargraph::Source.parse_docstring('').to_docstring
115
+ end
116
+
117
+ # @return [Array<YARD::Tags::Directive>]
118
+ def directives
119
+ parse_comments unless defined?(@directives)
120
+ @directives
121
+ end
122
+
123
+ # @return [Array<YARD::Tags::MacroDirective>]
124
+ def macros
125
+ @macros ||= collect_macros
126
+ end
127
+
128
+ # Perform a quick check to see if this pin possibly includes YARD
129
+ # directives. This method does not require parsing the comments.
130
+ #
131
+ # After the comments have been parsed, this method will return false if
132
+ # no directives were found, regardless of whether it previously appeared
133
+ # possible.
134
+ #
135
+ # @return [Boolean]
136
+ def maybe_directives?
137
+ return !@directives.empty? if defined?(@directives)
138
+ @maybe_directives ||= comments.include?('@!')
139
+ end
140
+
141
+ # @return [Boolean]
142
+ def deprecated?
143
+ @deprecated ||= docstring.has_tag?('deprecated')
144
+ end
145
+
146
+ # Get a fully qualified type from the pin's return type.
147
+ #
148
+ # The relative type is determined from YARD documentation (@return,
149
+ # @param, @type, etc.) and its namespaces are fully qualified using the
150
+ # provided ApiMap.
151
+ #
152
+ # @param api_map [ApiMap]
153
+ # @return [ComplexType]
154
+ def typify api_map
155
+ return_complex_type.qualify(api_map, namespace)
156
+ end
157
+
158
+ # Infer the pin's return type via static code analysis.
159
+ #
160
+ # @param api_map [ApiMap]
161
+ # @return [ComplexType]
162
+ def probe api_map
163
+ typify api_map
164
+ end
165
+
166
+ # @deprecated Use #typify and/or #probe instead
167
+ # @param api_map [ApiMap]
168
+ # @return [ComplexType]
169
+ def infer api_map
170
+ Solargraph::Logging.logger.warn "WARNING: Pin #infer methods are deprecated. Use #typify or #probe instead."
171
+ type = typify(api_map)
172
+ return type unless type.undefined?
173
+ probe api_map
174
+ end
175
+
176
+ # Try to merge data from another pin. Merges are only possible if the
177
+ # pins are near matches (see the #nearly? method). The changes should
178
+ # not have any side effects on the API surface.
179
+ #
180
+ # @param pin [Pin::Base] The pin to merge into this one
181
+ # @return [Boolean] True if the pins were merged
182
+ def try_merge! pin
183
+ return false unless nearly?(pin)
184
+ @location = pin.location
185
+ return true if comments == pin.comments
186
+ @comments = pin.comments
187
+ @docstring = pin.docstring
188
+ @return_complex_type = pin.return_complex_type
189
+ @documentation = nil
190
+ @deprecated = nil
191
+ reset_conversions
192
+ true
193
+ end
194
+
195
+ def proxied?
196
+ @proxied ||= false
197
+ end
198
+
199
+ # Return a proxy for this pin with the specified return type. Other than
200
+ # the return type and the #proxied? setting, the proxy should be a clone
201
+ # of the original.
202
+ #
203
+ # @param return_type [ComplexType]
204
+ # @return [self]
205
+ def proxy return_type
206
+ result = dup
207
+ result.return_complex_type = return_type
208
+ result.proxied = true
209
+ result
210
+ end
211
+
212
+ protected
213
+
214
+ # @return [Boolean]
215
+ attr_writer :proxied
216
+
217
+ # @return [ComplexType]
218
+ attr_writer :return_complex_type
219
+
220
+ private
221
+
222
+ # @return [void]
223
+ def parse_comments
224
+ if comments.empty?
225
+ @docstring = nil
226
+ @directives = []
227
+ else
228
+ # HACK: Pass a dummy code object to the parser for plugins that
229
+ # expect it not to be nil
230
+ parse = Solargraph::Source.parse_docstring(comments)
231
+ @docstring = parse.to_docstring
232
+ @directives = parse.directives
233
+ end
234
+ end
235
+
236
+ # True if two docstrings have the same tags, regardless of any other
237
+ # differences.
238
+ #
239
+ # @param d1 [YARD::Docstring]
240
+ # @param d2 [YARD::Docstring]
241
+ # @return [boolean]
242
+ def compare_docstring_tags d1, d2
243
+ return false if d1.tags.length != d2.tags.length
244
+ d1.tags.each_index do |i|
245
+ return false unless compare_tags(d1.tags[i], d2.tags[i])
246
+ end
247
+ true
248
+ end
249
+
250
+ # @param d1 [Array<YARD::Tags::Directive>]
251
+ # @param d2 [Array<YARD::Tags::Directive>]
252
+ # @return [Boolean]
253
+ def compare_directives d1, d2
254
+ return false if d1.length != d2.length
255
+ d1.each_index do |i|
256
+ return false unless compare_tags(d1[i].tag, d2[i].tag)
257
+ end
258
+ true
259
+ end
260
+
261
+ # @param t1 [YARD::Tags::Tag]
262
+ # @param t2 [YARD::Tags::Tag]
263
+ # @return [Boolean]
264
+ def compare_tags t1, t2
265
+ t1.class == t2.class &&
266
+ t1.tag_name == t2.tag_name &&
267
+ t1.text == t2.text &&
268
+ t1.name == t2.name &&
269
+ t1.types == t2.types
270
+ end
271
+
272
+ # @return [Array<YARD::Tags::Handlers::Directive>]
273
+ def collect_macros
274
+ return [] unless maybe_directives?
275
+ parse = Solargraph::Source.parse_docstring(comments)
276
+ parse.directives.select{ |d| d.tag.tag_name == 'macro' }
277
+ end
278
+ end
279
+ end
280
+ end