solargraph 0.58.3 → 0.59.0.dev.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (201) hide show
  1. checksums.yaml +4 -4
  2. data/.envrc +3 -0
  3. data/.github/workflows/linting.yml +4 -5
  4. data/.github/workflows/plugins.yml +41 -38
  5. data/.github/workflows/rspec.yml +45 -13
  6. data/.github/workflows/typecheck.yml +2 -2
  7. data/.gitignore +0 -1
  8. data/.rubocop_todo.yml +27 -49
  9. data/CHANGELOG.md +1 -10
  10. data/README.md +3 -3
  11. data/Rakefile +1 -0
  12. data/lib/solargraph/api_map/cache.rb +3 -3
  13. data/lib/solargraph/api_map/constants.rb +13 -3
  14. data/lib/solargraph/api_map/index.rb +22 -11
  15. data/lib/solargraph/api_map/source_to_yard.rb +13 -1
  16. data/lib/solargraph/api_map/store.rb +11 -8
  17. data/lib/solargraph/api_map.rb +105 -50
  18. data/lib/solargraph/bench.rb +45 -45
  19. data/lib/solargraph/complex_type/conformance.rb +176 -0
  20. data/lib/solargraph/complex_type/type_methods.rb +16 -2
  21. data/lib/solargraph/complex_type/unique_type.rb +170 -20
  22. data/lib/solargraph/complex_type.rb +119 -14
  23. data/lib/solargraph/convention/data_definition/data_assignment_node.rb +61 -61
  24. data/lib/solargraph/convention/data_definition/data_definition_node.rb +3 -1
  25. data/lib/solargraph/convention/data_definition.rb +4 -1
  26. data/lib/solargraph/convention/gemfile.rb +15 -15
  27. data/lib/solargraph/convention/gemspec.rb +23 -23
  28. data/lib/solargraph/convention/rakefile.rb +17 -17
  29. data/lib/solargraph/convention/struct_definition/struct_assignment_node.rb +1 -0
  30. data/lib/solargraph/convention/struct_definition/struct_definition_node.rb +1 -0
  31. data/lib/solargraph/convention/struct_definition.rb +5 -1
  32. data/lib/solargraph/convention.rb +78 -78
  33. data/lib/solargraph/converters/dd.rb +17 -17
  34. data/lib/solargraph/converters/dl.rb +15 -15
  35. data/lib/solargraph/converters/dt.rb +15 -15
  36. data/lib/solargraph/converters/misc.rb +1 -1
  37. data/lib/solargraph/diagnostics/require_not_found.rb +1 -0
  38. data/lib/solargraph/diagnostics/rubocop.rb +1 -0
  39. data/lib/solargraph/diagnostics/rubocop_helpers.rb +2 -0
  40. data/lib/solargraph/diagnostics/type_check.rb +1 -0
  41. data/lib/solargraph/diagnostics/update_errors.rb +41 -41
  42. data/lib/solargraph/doc_map.rb +134 -373
  43. data/lib/solargraph/equality.rb +1 -1
  44. data/lib/solargraph/gem_pins.rb +14 -15
  45. data/lib/solargraph/language_server/error_codes.rb +20 -20
  46. data/lib/solargraph/language_server/host/diagnoser.rb +89 -89
  47. data/lib/solargraph/language_server/host/dispatch.rb +1 -0
  48. data/lib/solargraph/language_server/host/message_worker.rb +2 -1
  49. data/lib/solargraph/language_server/host/sources.rb +1 -0
  50. data/lib/solargraph/language_server/host.rb +6 -1
  51. data/lib/solargraph/language_server/message/base.rb +97 -97
  52. data/lib/solargraph/language_server/message/client/register_capability.rb +15 -15
  53. data/lib/solargraph/language_server/message/completion_item/resolve.rb +60 -60
  54. data/lib/solargraph/language_server/message/extended/check_gem_version.rb +2 -7
  55. data/lib/solargraph/language_server/message/extended/document.rb +1 -0
  56. data/lib/solargraph/language_server/message/extended/document_gems.rb +32 -32
  57. data/lib/solargraph/language_server/message/extended/download_core.rb +19 -19
  58. data/lib/solargraph/language_server/message/extended/search.rb +20 -20
  59. data/lib/solargraph/language_server/message/initialize.rb +191 -191
  60. data/lib/solargraph/language_server/message/text_document/completion.rb +2 -0
  61. data/lib/solargraph/language_server/message/text_document/definition.rb +2 -0
  62. data/lib/solargraph/language_server/message/text_document/document_highlight.rb +16 -16
  63. data/lib/solargraph/language_server/message/text_document/document_symbol.rb +2 -0
  64. data/lib/solargraph/language_server/message/text_document/formatting.rb +2 -0
  65. data/lib/solargraph/language_server/message/text_document/hover.rb +2 -0
  66. data/lib/solargraph/language_server/message/text_document/prepare_rename.rb +11 -11
  67. data/lib/solargraph/language_server/message/text_document/references.rb +16 -16
  68. data/lib/solargraph/language_server/message/text_document/rename.rb +19 -19
  69. data/lib/solargraph/language_server/message/text_document/signature_help.rb +1 -0
  70. data/lib/solargraph/language_server/message/text_document/type_definition.rb +2 -0
  71. data/lib/solargraph/language_server/message/workspace/did_change_configuration.rb +35 -35
  72. data/lib/solargraph/language_server/message/workspace/did_change_watched_files.rb +40 -40
  73. data/lib/solargraph/language_server/message/workspace/did_change_workspace_folders.rb +26 -26
  74. data/lib/solargraph/language_server/message/workspace/workspace_symbol.rb +2 -0
  75. data/lib/solargraph/language_server/message.rb +94 -94
  76. data/lib/solargraph/language_server/request.rb +27 -27
  77. data/lib/solargraph/language_server/transport/data_reader.rb +74 -74
  78. data/lib/solargraph/language_server/uri_helpers.rb +49 -49
  79. data/lib/solargraph/library.rb +59 -13
  80. data/lib/solargraph/location.rb +9 -4
  81. data/lib/solargraph/logging.rb +21 -1
  82. data/lib/solargraph/page.rb +92 -92
  83. data/lib/solargraph/parser/comment_ripper.rb +7 -0
  84. data/lib/solargraph/parser/flow_sensitive_typing.rb +330 -102
  85. data/lib/solargraph/parser/node_processor/base.rb +32 -2
  86. data/lib/solargraph/parser/node_processor.rb +7 -6
  87. data/lib/solargraph/parser/parser_gem/class_methods.rb +28 -10
  88. data/lib/solargraph/parser/parser_gem/flawed_builder.rb +19 -19
  89. data/lib/solargraph/parser/parser_gem/node_chainer.rb +31 -6
  90. data/lib/solargraph/parser/parser_gem/node_methods.rb +27 -7
  91. data/lib/solargraph/parser/parser_gem/node_processors/and_node.rb +4 -4
  92. data/lib/solargraph/parser/parser_gem/node_processors/args_node.rb +2 -0
  93. data/lib/solargraph/parser/parser_gem/node_processors/begin_node.rb +9 -0
  94. data/lib/solargraph/parser/parser_gem/node_processors/block_node.rb +11 -11
  95. data/lib/solargraph/parser/parser_gem/node_processors/def_node.rb +7 -0
  96. data/lib/solargraph/parser/parser_gem/node_processors/defs_node.rb +37 -37
  97. data/lib/solargraph/parser/parser_gem/node_processors/if_node.rb +36 -6
  98. data/lib/solargraph/parser/parser_gem/node_processors/ivasgn_node.rb +3 -2
  99. data/lib/solargraph/parser/parser_gem/node_processors/lvasgn_node.rb +1 -0
  100. data/lib/solargraph/parser/parser_gem/node_processors/masgn_node.rb +3 -1
  101. data/lib/solargraph/parser/parser_gem/node_processors/opasgn_node.rb +2 -2
  102. data/lib/solargraph/parser/parser_gem/node_processors/or_node.rb +22 -0
  103. data/lib/solargraph/parser/parser_gem/node_processors/orasgn_node.rb +1 -1
  104. data/lib/solargraph/parser/parser_gem/node_processors/resbody_node.rb +2 -1
  105. data/lib/solargraph/parser/parser_gem/node_processors/sclass_node.rb +1 -0
  106. data/lib/solargraph/parser/parser_gem/node_processors/send_node.rb +12 -7
  107. data/lib/solargraph/parser/parser_gem/node_processors/until_node.rb +29 -29
  108. data/lib/solargraph/parser/parser_gem/node_processors/when_node.rb +23 -0
  109. data/lib/solargraph/parser/parser_gem/node_processors/while_node.rb +5 -1
  110. data/lib/solargraph/parser/parser_gem/node_processors.rb +4 -0
  111. data/lib/solargraph/parser/parser_gem.rb +12 -12
  112. data/lib/solargraph/parser/region.rb +9 -3
  113. data/lib/solargraph/parser/snippet.rb +1 -1
  114. data/lib/solargraph/parser.rb +23 -23
  115. data/lib/solargraph/pin/base.rb +53 -21
  116. data/lib/solargraph/pin/base_variable.rb +312 -20
  117. data/lib/solargraph/pin/block.rb +26 -4
  118. data/lib/solargraph/pin/breakable.rb +5 -1
  119. data/lib/solargraph/pin/callable.rb +50 -3
  120. data/lib/solargraph/pin/closure.rb +2 -6
  121. data/lib/solargraph/pin/common.rb +20 -5
  122. data/lib/solargraph/pin/compound_statement.rb +55 -0
  123. data/lib/solargraph/pin/constant.rb +45 -45
  124. data/lib/solargraph/pin/conversions.rb +2 -1
  125. data/lib/solargraph/pin/delegated_method.rb +15 -4
  126. data/lib/solargraph/pin/documenting.rb +1 -0
  127. data/lib/solargraph/pin/instance_variable.rb +5 -1
  128. data/lib/solargraph/pin/keyword.rb +0 -4
  129. data/lib/solargraph/pin/local_variable.rb +13 -57
  130. data/lib/solargraph/pin/method.rb +90 -42
  131. data/lib/solargraph/pin/method_alias.rb +8 -0
  132. data/lib/solargraph/pin/namespace.rb +7 -1
  133. data/lib/solargraph/pin/parameter.rb +76 -13
  134. data/lib/solargraph/pin/proxy_type.rb +2 -1
  135. data/lib/solargraph/pin/reference/override.rb +1 -1
  136. data/lib/solargraph/pin/reference/superclass.rb +2 -0
  137. data/lib/solargraph/pin/reference.rb +2 -0
  138. data/lib/solargraph/pin/search.rb +1 -0
  139. data/lib/solargraph/pin/signature.rb +8 -0
  140. data/lib/solargraph/pin/symbol.rb +1 -1
  141. data/lib/solargraph/pin/until.rb +1 -1
  142. data/lib/solargraph/pin/while.rb +1 -1
  143. data/lib/solargraph/pin.rb +2 -0
  144. data/lib/solargraph/pin_cache.rb +477 -57
  145. data/lib/solargraph/position.rb +12 -26
  146. data/lib/solargraph/range.rb +6 -6
  147. data/lib/solargraph/rbs_map/conversions.rb +33 -10
  148. data/lib/solargraph/rbs_map/core_fills.rb +84 -84
  149. data/lib/solargraph/rbs_map/core_map.rb +24 -17
  150. data/lib/solargraph/rbs_map/stdlib_map.rb +34 -5
  151. data/lib/solargraph/rbs_map.rb +74 -20
  152. data/lib/solargraph/server_methods.rb +16 -16
  153. data/lib/solargraph/shell.rb +73 -39
  154. data/lib/solargraph/source/chain/array.rb +37 -37
  155. data/lib/solargraph/source/chain/call.rb +52 -17
  156. data/lib/solargraph/source/chain/class_variable.rb +13 -13
  157. data/lib/solargraph/source/chain/constant.rb +2 -0
  158. data/lib/solargraph/source/chain/global_variable.rb +13 -13
  159. data/lib/solargraph/source/chain/hash.rb +1 -0
  160. data/lib/solargraph/source/chain/if.rb +1 -0
  161. data/lib/solargraph/source/chain/instance_variable.rb +22 -1
  162. data/lib/solargraph/source/chain/link.rb +109 -109
  163. data/lib/solargraph/source/chain/literal.rb +5 -0
  164. data/lib/solargraph/source/chain/or.rb +9 -1
  165. data/lib/solargraph/source/chain/q_call.rb +11 -11
  166. data/lib/solargraph/source/chain/variable.rb +13 -13
  167. data/lib/solargraph/source/chain/z_super.rb +30 -30
  168. data/lib/solargraph/source/chain.rb +25 -22
  169. data/lib/solargraph/source/change.rb +9 -2
  170. data/lib/solargraph/source/cursor.rb +7 -1
  171. data/lib/solargraph/source/source_chainer.rb +13 -3
  172. data/lib/solargraph/source/updater.rb +4 -0
  173. data/lib/solargraph/source.rb +33 -7
  174. data/lib/solargraph/source_map/clip.rb +13 -2
  175. data/lib/solargraph/source_map/data.rb +4 -1
  176. data/lib/solargraph/source_map/mapper.rb +24 -1
  177. data/lib/solargraph/source_map.rb +14 -6
  178. data/lib/solargraph/type_checker/problem.rb +3 -1
  179. data/lib/solargraph/type_checker/rules.rb +75 -2
  180. data/lib/solargraph/type_checker.rb +111 -30
  181. data/lib/solargraph/version.rb +1 -1
  182. data/lib/solargraph/workspace/config.rb +3 -1
  183. data/lib/solargraph/workspace/gemspecs.rb +367 -0
  184. data/lib/solargraph/workspace/require_paths.rb +1 -0
  185. data/lib/solargraph/workspace.rb +158 -16
  186. data/lib/solargraph/yard_map/helpers.rb +2 -1
  187. data/lib/solargraph/yard_map/mapper/to_method.rb +5 -1
  188. data/lib/solargraph/yard_map/mapper/to_namespace.rb +1 -0
  189. data/lib/solargraph/yard_map/mapper.rb +5 -0
  190. data/lib/solargraph/yard_tags.rb +20 -20
  191. data/lib/solargraph/yardoc.rb +33 -23
  192. data/lib/solargraph.rb +24 -3
  193. data/rbs/fills/rubygems/0/dependency.rbs +193 -0
  194. data/rbs/fills/tuple/tuple.rbs +28 -0
  195. data/rbs/shims/ast/0/node.rbs +1 -1
  196. data/rbs/shims/diff-lcs/1.5/diff-lcs.rbs +11 -0
  197. data/solargraph.gemspec +2 -1
  198. metadata +12 -7
  199. data/lib/solargraph/type_checker/checks.rb +0 -124
  200. data/lib/solargraph/type_checker/param_def.rb +0 -37
  201. data/lib/solargraph/yard_map/to_method.rb +0 -89
@@ -1,74 +1,74 @@
1
- # frozen_string_literal: true
2
-
3
- require 'json'
4
-
5
- module Solargraph
6
- module LanguageServer
7
- module Transport
8
- class DataReader
9
- def initialize
10
- @in_header = true
11
- @content_length = 0
12
- @buffer = String.new
13
- end
14
-
15
- # Declare a block to be executed for each message received from the
16
- # client.
17
- #
18
- # @yieldparam [Hash] The message received from the client
19
- # @return [void]
20
- def set_message_handler &block
21
- @message_handler = block
22
- end
23
-
24
- # Process raw data received from the client. The data will be parsed
25
- # into messages based on the JSON-RPC protocol. Each message will be
26
- # passed to the block declared via set_message_handler. Incomplete data
27
- # will be buffered and subsequent data will be appended to the buffer.
28
- #
29
- # @param data [String]
30
- # @return [void]
31
- def receive data
32
- data.each_char do |char|
33
- @buffer.concat char
34
- if @in_header
35
- prepare_to_parse_message if @buffer.end_with?("\r\n\r\n")
36
- else
37
- parse_message_from_buffer if @buffer.bytesize == @content_length
38
- end
39
- end
40
- end
41
-
42
- private
43
-
44
- # @return [void]
45
- def prepare_to_parse_message
46
- @in_header = false
47
- @buffer.each_line do |line|
48
- parts = line.split(':').map(&:strip)
49
- if parts[0] == 'Content-Length'
50
- @content_length = parts[1].to_i
51
- break
52
- end
53
- end
54
- @buffer.clear
55
- end
56
-
57
- # @return [void]
58
- def parse_message_from_buffer
59
- begin
60
- msg = JSON.parse(@buffer)
61
- @message_handler.call msg unless @message_handler.nil?
62
- rescue JSON::ParserError => e
63
- Solargraph::Logging.logger.warn "Failed to parse request: #{e.message}"
64
- Solargraph::Logging.logger.debug "Buffer: #{@buffer}"
65
- ensure
66
- @buffer.clear
67
- @in_header = true
68
- @content_length = 0
69
- end
70
- end
71
- end
72
- end
73
- end
74
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+
5
+ module Solargraph
6
+ module LanguageServer
7
+ module Transport
8
+ class DataReader
9
+ def initialize
10
+ @in_header = true
11
+ @content_length = 0
12
+ @buffer = String.new
13
+ end
14
+
15
+ # Declare a block to be executed for each message received from the
16
+ # client.
17
+ #
18
+ # @yieldparam [Hash] The message received from the client
19
+ # @return [void]
20
+ def set_message_handler &block
21
+ @message_handler = block
22
+ end
23
+
24
+ # Process raw data received from the client. The data will be parsed
25
+ # into messages based on the JSON-RPC protocol. Each message will be
26
+ # passed to the block declared via set_message_handler. Incomplete data
27
+ # will be buffered and subsequent data will be appended to the buffer.
28
+ #
29
+ # @param data [String]
30
+ # @return [void]
31
+ def receive data
32
+ data.each_char do |char|
33
+ @buffer.concat char
34
+ if @in_header
35
+ prepare_to_parse_message if @buffer.end_with?("\r\n\r\n")
36
+ else
37
+ parse_message_from_buffer if @buffer.bytesize == @content_length
38
+ end
39
+ end
40
+ end
41
+
42
+ private
43
+
44
+ # @return [void]
45
+ def prepare_to_parse_message
46
+ @in_header = false
47
+ @buffer.each_line do |line|
48
+ parts = line.split(':').map(&:strip)
49
+ if parts[0] == 'Content-Length'
50
+ @content_length = parts[1].to_i
51
+ break
52
+ end
53
+ end
54
+ @buffer.clear
55
+ end
56
+
57
+ # @return [void]
58
+ def parse_message_from_buffer
59
+ begin
60
+ msg = JSON.parse(@buffer)
61
+ @message_handler.call msg unless @message_handler.nil?
62
+ rescue JSON::ParserError => e
63
+ Solargraph::Logging.logger.warn "Failed to parse request: #{e.message}"
64
+ Solargraph::Logging.logger.debug "Buffer: #{@buffer}"
65
+ ensure
66
+ @buffer.clear
67
+ @in_header = true
68
+ @content_length = 0
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -1,49 +1,49 @@
1
- # frozen_string_literal: true
2
-
3
- require 'cgi'
4
-
5
- module Solargraph
6
- module LanguageServer
7
- # Methods to handle conversions between file URIs and paths.
8
- #
9
- module UriHelpers
10
- module_function
11
-
12
- # Convert a file URI to a path.
13
- #
14
- # @param uri [String]
15
- # @return [String]
16
- def uri_to_file uri
17
- decode(uri).sub(/^file\:(?:\/\/)?/, '').sub(/^\/([a-z]\:)/i, '\1')
18
- end
19
-
20
- # Convert a file path to a URI.
21
- #
22
- # @param file [String]
23
- # @return [String]
24
- def file_to_uri file
25
- "file://#{encode(file.gsub(/^([a-z]\:)/i, '/\1'))}"
26
- end
27
-
28
- # Encode text to be used as a URI path component in LSP.
29
- #
30
- # @param text [String]
31
- # @return [String]
32
- def encode text
33
- CGI.escape(text)
34
- .gsub('%3A', ':')
35
- .gsub('%5C', '\\')
36
- .gsub('%2F', '/')
37
- .gsub('+', '%20')
38
- end
39
-
40
- # Decode text from a URI path component in LSP.
41
- #
42
- # @param text [String]
43
- # @return [String]
44
- def decode text
45
- CGI.unescape(text)
46
- end
47
- end
48
- end
49
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'cgi'
4
+
5
+ module Solargraph
6
+ module LanguageServer
7
+ # Methods to handle conversions between file URIs and paths.
8
+ #
9
+ module UriHelpers
10
+ module_function
11
+
12
+ # Convert a file URI to a path.
13
+ #
14
+ # @param uri [String]
15
+ # @return [String]
16
+ def uri_to_file uri
17
+ decode(uri).sub(/^file\:(?:\/\/)?/, '').sub(/^\/([a-z]\:)/i, '\1')
18
+ end
19
+
20
+ # Convert a file path to a URI.
21
+ #
22
+ # @param file [String]
23
+ # @return [String]
24
+ def file_to_uri file
25
+ "file://#{encode(file.gsub(/^([a-z]\:)/i, '/\1'))}"
26
+ end
27
+
28
+ # Encode text to be used as a URI path component in LSP.
29
+ #
30
+ # @param text [String]
31
+ # @return [String]
32
+ def encode text
33
+ CGI.escape(text)
34
+ .gsub('%3A', ':')
35
+ .gsub('%5C', '\\')
36
+ .gsub('%2F', '/')
37
+ .gsub('+', '%20')
38
+ end
39
+
40
+ # Decode text from a URI path component in LSP.
41
+ #
42
+ # @param text [String]
43
+ # @return [String]
44
+ def decode text
45
+ CGI.unescape(text)
46
+ end
47
+ end
48
+ end
49
+ end
@@ -1,9 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'rubygems'
3
4
  require 'pathname'
4
5
  require 'observer'
5
6
  require 'open3'
6
7
 
8
+ # @!parse
9
+ # class ::Gem::Specification
10
+ # # @return [String]
11
+ # def name; end
12
+ # end
13
+
7
14
  module Solargraph
8
15
  # A Library handles coordination between a Workspace and an ApiMap.
9
16
  #
@@ -33,6 +40,7 @@ module Solargraph
33
40
  # @type [Source, nil]
34
41
  @current = nil
35
42
  @sync_count = 0
43
+ @cache_progress = nil
36
44
  end
37
45
 
38
46
  def inspect
@@ -57,8 +65,11 @@ module Solargraph
57
65
  # @param source [Source, nil]
58
66
  # @return [void]
59
67
  def attach source
68
+ # @sg-ignore Need to add nil check here
60
69
  if @current && (!source || @current.filename != source.filename) && source_map_hash.key?(@current.filename) && !workspace.has_file?(@current.filename)
70
+ # @sg-ignore Need to add nil check here
61
71
  source_map_hash.delete @current.filename
72
+ # @sg-ignore Need to add nil check here
62
73
  source_map_external_require_hash.delete @current.filename
63
74
  @external_requires = nil
64
75
  end
@@ -182,9 +193,14 @@ module Solargraph
182
193
  if cursor.comment?
183
194
  source = read(filename)
184
195
  offset = Solargraph::Position.to_offset(source.code, Solargraph::Position.new(line, column))
196
+ # @sg-ignore Need to add nil check here
197
+ # @type [MatchData, nil]
185
198
  lft = source.code[0..offset-1].match(/\[[a-z0-9_:<, ]*?([a-z0-9_:]*)\z/i)
199
+ # @sg-ignore Need to add nil check here
200
+ # @type [MatchData, nil]
186
201
  rgt = source.code[offset..-1].match(/^([a-z0-9_]*)(:[a-z0-9_:]*)?[\]>, ]/i)
187
202
  if lft && rgt
203
+ # @sg-ignore Need to add nil check here
188
204
  tag = (lft[1] + rgt[1]).sub(/:+$/, '')
189
205
  clip = mutex.synchronize { api_map.clip(cursor) }
190
206
  clip.translate tag
@@ -255,15 +271,19 @@ module Solargraph
255
271
  files.uniq(&:filename).each do |source|
256
272
  found = source.references(pin.name)
257
273
  found.select! do |loc|
274
+ # @sg-ignore Need to add nil check here
275
+ # @type [Solargraph::Pin::Base, nil]
258
276
  referenced = definitions_at(loc.filename, loc.range.ending.line, loc.range.ending.character).first
259
277
  referenced&.path == pin.path
260
278
  end
261
279
  if pin.path == 'Class#new'
280
+ # @todo flow sensitive typing should allow shadowing of Kernel#caller
262
281
  caller = cursor.chain.base.infer(api_map, clip.send(:closure), clip.locals).first
263
282
  if caller.defined?
264
283
  found.select! do |loc|
265
284
  clip = api_map.clip_at(loc.filename, loc.range.start)
266
285
  other = clip.send(:cursor).chain.base.infer(api_map, clip.send(:closure), clip.locals).first
286
+ # @todo flow sensitive typing should allow shadowing of Kernel#caller
267
287
  caller == other
268
288
  end
269
289
  else
@@ -273,12 +293,13 @@ module Solargraph
273
293
  # HACK: for language clients that exclude special characters from the start of variable names
274
294
  if strip && match = cursor.word.match(/^[^a-z0-9_]+/i)
275
295
  found.map! do |loc|
276
- Solargraph::Location.new(loc.filename, Solargraph::Range.from_to(loc.range.start.line, loc.range.start.column + match[0].length, loc.range.ending.line, loc.range.ending.column))
296
+ Solargraph::Location.new(loc.filename,
297
+ # @sg-ignore flow sensitive typing needs to handle if foo = bar
298
+ Solargraph::Range.from_to(loc.range.start.line, loc.range.start.column + match[0].length, loc.range.ending.line,
299
+ loc.range.ending.column))
277
300
  end
278
301
  end
279
- result.concat(found.sort do |a, b|
280
- a.range.start.line <=> b.range.start.line
281
- end)
302
+ result.concat(found.sort { |a, b| a.range.start.line <=> b.range.start.line })
282
303
  end
283
304
  result.uniq
284
305
  end
@@ -299,13 +320,12 @@ module Solargraph
299
320
  def locate_ref location
300
321
  map = source_map_hash[location.filename]
301
322
  return if map.nil?
323
+ # @sg-ignore Need to add nil check here
302
324
  pin = map.requires.select { |p| p.location.range.contain?(location.range.start) }.first
303
325
  return nil if pin.nil?
304
326
  # @param full [String]
305
327
  return_if_match = proc do |full|
306
- if source_map_hash.key?(full)
307
- return Location.new(full, Solargraph::Range.from_to(0, 0, 0, 0))
308
- end
328
+ return Location.new(full, Solargraph::Range.from_to(0, 0, 0, 0)) if source_map_hash.key?(full)
309
329
  end
310
330
  workspace.require_paths.each do |path|
311
331
  full = File.join path, pin.name
@@ -403,6 +423,7 @@ module Solargraph
403
423
  workspace.config.reporters.each do |line|
404
424
  if line == 'all!'
405
425
  Diagnostics.reporters.each do |reporter_name|
426
+ # @sg-ignore Need to add nil check here
406
427
  repargs[Diagnostics.reporter(reporter_name)] ||= []
407
428
  end
408
429
  else
@@ -410,7 +431,9 @@ module Solargraph
410
431
  name = args.shift
411
432
  reporter = Diagnostics.reporter(name)
412
433
  raise DiagnosticsError, "Diagnostics reporter #{name} does not exist" if reporter.nil?
434
+ # @sg-ignore flow sensitive typing needs to handle 'raise if'
413
435
  repargs[reporter] ||= []
436
+ # @sg-ignore flow sensitive typing needs to handle 'raise if'
414
437
  repargs[reporter].concat args
415
438
  end
416
439
  end
@@ -433,6 +456,7 @@ module Solargraph
433
456
  source_maps: source_map_hash.values,
434
457
  workspace: workspace,
435
458
  external_requires: external_requires,
459
+ # @sg-ignore Need to add nil check here
436
460
  live_map: @current ? source_map_hash[@current.filename] : nil
437
461
  )
438
462
  end
@@ -469,10 +493,13 @@ module Solargraph
469
493
  # @return [SourceMap, Boolean]
470
494
  def next_map
471
495
  return false if mapped?
496
+ # @sg-ignore Need to add nil check here
472
497
  src = workspace.sources.find { |s| !source_map_hash.key?(s.filename) }
473
498
  if src
474
499
  Logging.logger.debug "Mapping #{src.filename}"
500
+ # @sg-ignore Need to add nil check here
475
501
  source_map_hash[src.filename] = Solargraph::SourceMap.map(src)
502
+ # @sg-ignore Need to add nil check here
476
503
  source_map_hash[src.filename]
477
504
  else
478
505
  false
@@ -482,7 +509,9 @@ module Solargraph
482
509
  # @return [self]
483
510
  def map!
484
511
  workspace.sources.each do |src|
512
+ # @sg-ignore Need to add nil check here
485
513
  source_map_hash[src.filename] = Solargraph::SourceMap.map(src)
514
+ # @sg-ignore Need to add nil check here
486
515
  find_external_requires source_map_hash[src.filename]
487
516
  end
488
517
  self
@@ -500,6 +529,11 @@ module Solargraph
500
529
 
501
530
  private
502
531
 
532
+ # @return [PinCache]
533
+ def pin_cache
534
+ workspace.pin_cache
535
+ end
536
+
503
537
  # @return [Hash{String => Array<String>}]
504
538
  def source_map_external_require_hash
505
539
  @source_map_external_require_hash ||= {}
@@ -513,6 +547,7 @@ module Solargraph
513
547
  # return if new_set == source_map_external_require_hash[source_map.filename]
514
548
  _filenames = nil
515
549
  filenames = ->{ _filenames ||= workspace.filenames.to_set }
550
+ # @sg-ignore Need to add nil check here
516
551
  source_map_external_require_hash[source_map.filename] = new_set.reject do |path|
517
552
  workspace.require_paths.any? do |base|
518
553
  full = File.join(base, path)
@@ -562,11 +597,15 @@ module Solargraph
562
597
  # @return [void]
563
598
  def maybe_map source
564
599
  return unless source
600
+ # @sg-ignore Need to add nil check here
565
601
  return unless @current == source || workspace.has_file?(source.filename)
602
+ # @sg-ignore Need to add nil check here
566
603
  if source_map_hash.key?(source.filename)
567
604
  new_map = Solargraph::SourceMap.map(source)
605
+ # @sg-ignore Need to add nil check here
568
606
  source_map_hash[source.filename] = new_map
569
607
  else
608
+ # @sg-ignore Need to add nil check here
570
609
  source_map_hash[source.filename] = Solargraph::SourceMap.map(source)
571
610
  end
572
611
  end
@@ -585,7 +624,7 @@ module Solargraph
585
624
 
586
625
  pending = api_map.uncached_gemspecs.length - cache_errors.length - 1
587
626
 
588
- if Yardoc.processing?(spec)
627
+ if pin_cache.yardoc_processing?(spec)
589
628
  logger.info "Enqueuing cache of #{spec.name} #{spec.version} (already being processed)"
590
629
  queued_gemspec_cache.push(spec)
591
630
  return if pending - queued_gemspec_cache.length < 1
@@ -596,7 +635,10 @@ module Solargraph
596
635
  logger.info "Caching #{spec.name} #{spec.version}"
597
636
  Thread.new do
598
637
  report_cache_progress spec.name, pending
599
- _o, e, s = Open3.capture3(workspace.command_path, 'cache', spec.name, spec.version.to_s)
638
+ kwargs = {}
639
+ kwargs[:chdir] = workspace.directory.to_s if workspace.directory && !workspace.directory.empty?
640
+ _o, e, s = Open3.capture3(workspace.command_path, 'cache', spec.name, spec.version.to_s,
641
+ **kwargs)
600
642
  if s.success?
601
643
  logger.info "Cached #{spec.name} #{spec.version}"
602
644
  else
@@ -613,8 +655,7 @@ module Solargraph
613
655
 
614
656
  # @return [Array<Gem::Specification>]
615
657
  def cacheable_specs
616
- cacheable = api_map.uncached_yard_gemspecs +
617
- api_map.uncached_rbs_collection_gemspecs -
658
+ cacheable = api_map.uncached_gemspecs +
618
659
  queued_gemspec_cache -
619
660
  cache_errors.to_a
620
661
  return cacheable unless cacheable.empty?
@@ -632,11 +673,15 @@ module Solargraph
632
673
  # @return [void]
633
674
  def report_cache_progress gem_name, pending
634
675
  @total ||= pending
676
+ # @sg-ignore flow sensitive typing needs better handling of ||= on lvars
635
677
  @total = pending if pending > @total
678
+ # @sg-ignore flow sensitive typing needs better handling of ||= on lvars
636
679
  finished = @total - pending
680
+ # @sg-ignore flow sensitive typing needs better handling of ||= on lvars
637
681
  pct = if @total.zero?
638
682
  0
639
683
  else
684
+ # @sg-ignore flow sensitive typing needs better handling of ||= on lvars
640
685
  ((finished.to_f / @total.to_f) * 100).to_i
641
686
  end
642
687
  message = "#{gem_name}#{pending > 0 ? " (+#{pending})" : ''}"
@@ -647,9 +692,11 @@ module Solargraph
647
692
  @cache_progress = LanguageServer::Progress.new('Caching gem')
648
693
  # If we don't send both a begin and a report, the progress notification
649
694
  # might get stuck in the status bar forever
695
+ # @sg-ignore flow sensitive typing should be able to handle redefinition
650
696
  @cache_progress.begin(message, pct)
651
697
  changed
652
698
  notify_observers @cache_progress
699
+ # @sg-ignore flow sensitive typing should be able to handle redefinition
653
700
  @cache_progress.report(message, pct)
654
701
  end
655
702
  changed
@@ -673,8 +720,7 @@ module Solargraph
673
720
  source_map_hash.values.each { |map| find_external_requires(map) }
674
721
  api_map.catalog bench
675
722
  logger.info "Catalog complete (#{api_map.source_maps.length} files, #{api_map.pins.length} pins)"
676
- logger.info "#{api_map.uncached_yard_gemspecs.length} uncached YARD gemspecs"
677
- logger.info "#{api_map.uncached_rbs_collection_gemspecs.length} uncached RBS collection gemspecs"
723
+ logger.info "#{api_map.uncached_gemspecs.length} uncached gemspecs"
678
724
  cache_next_gemspec
679
725
  @sync_count = 0
680
726
  end
@@ -6,6 +6,7 @@ module Solargraph
6
6
  #
7
7
  class Location
8
8
  include Equality
9
+ include Comparable
9
10
 
10
11
  # @return [String]
11
12
  attr_reader :filename
@@ -13,14 +14,15 @@ module Solargraph
13
14
  # @return [Solargraph::Range]
14
15
  attr_reader :range
15
16
 
16
- # @param filename [String]
17
+ # @param filename [String, nil]
17
18
  # @param range [Solargraph::Range]
18
19
  def initialize filename, range
20
+ raise "Use nil to represent no-file" if filename&.empty?
21
+
19
22
  @filename = filename
20
23
  @range = range
21
24
  end
22
25
 
23
- # @sg-ignore Fix "Not enough arguments to Module#protected"
24
26
  protected def equality_fields
25
27
  [filename, range]
26
28
  end
@@ -64,14 +66,17 @@ module Solargraph
64
66
  # @return [Location, nil]
65
67
  def self.from_node(node)
66
68
  return nil if node.nil? || node.loc.nil?
69
+ filename = node.loc.expression.source_buffer.name
70
+ # @sg-ignore flow sensitive typing needs to create separate ranges for postfix if
71
+ filename = nil if filename.empty?
67
72
  range = Range.from_node(node)
68
- self.new(node.loc.expression.source_buffer.name, range)
73
+ # @sg-ignore Need to add nil check here
74
+ self.new(filename, range)
69
75
  end
70
76
 
71
77
  # @param other [BasicObject]
72
78
  def == other
73
79
  return false unless other.is_a?(Location)
74
- # @sg-ignore https://github.com/castwide/solargraph/pull/1114
75
80
  filename == other.filename and range == other.range
76
81
  end
77
82
 
@@ -29,9 +29,29 @@ module Solargraph
29
29
 
30
30
  module_function
31
31
 
32
+ # override this in your class to temporarily set a custom
33
+ # filtering log level for the class (e.g., suppress any debug
34
+ # message by setting it to :info even if it is set elsewhere, or
35
+ # show existing debug messages by setting to :debug).
36
+ #
37
+ # @return [Symbol]
38
+ def log_level
39
+ :warn
40
+ end
41
+
32
42
  # @return [Logger]
33
43
  def logger
34
- @@logger
44
+ if LOG_LEVELS[log_level.to_s] == DEFAULT_LOG_LEVEL
45
+ @@logger
46
+ else
47
+ new_log_level = LOG_LEVELS[log_level.to_s]
48
+ logger = Logger.new(STDERR, level: new_log_level)
49
+
50
+ # @sg-ignore Wrong argument type for Logger#formatter=: arg_0
51
+ # expected nil, received Logger::_Formatter, nil
52
+ logger.formatter = @@logger.formatter
53
+ logger
54
+ end
35
55
  end
36
56
  end
37
57
  end