solargraph 0.59.0.dev.1 → 0.59.0.dev.2

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 (169) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/plugins.yml +4 -1
  3. data/.github/workflows/rspec.yml +3 -14
  4. data/.gitignore +1 -0
  5. data/.rubocop.yml +32 -5
  6. data/.rubocop_todo.yml +37 -931
  7. data/CHANGELOG.md +7 -1
  8. data/Gemfile +3 -1
  9. data/Rakefile +25 -23
  10. data/bin/solargraph +2 -1
  11. data/lib/solargraph/api_map/index.rb +5 -11
  12. data/lib/solargraph/api_map/source_to_yard.rb +9 -8
  13. data/lib/solargraph/api_map/store.rb +22 -20
  14. data/lib/solargraph/api_map.rb +50 -37
  15. data/lib/solargraph/bench.rb +44 -45
  16. data/lib/solargraph/complex_type/type_methods.rb +12 -15
  17. data/lib/solargraph/complex_type/unique_type.rb +54 -43
  18. data/lib/solargraph/complex_type.rb +69 -61
  19. data/lib/solargraph/convention/data_definition/data_assignment_node.rb +61 -61
  20. data/lib/solargraph/convention/data_definition/data_definition_node.rb +4 -4
  21. data/lib/solargraph/convention/data_definition.rb +1 -1
  22. data/lib/solargraph/convention/gemfile.rb +15 -15
  23. data/lib/solargraph/convention/gemspec.rb +23 -23
  24. data/lib/solargraph/convention/rakefile.rb +17 -17
  25. data/lib/solargraph/convention/struct_definition/struct_assignment_node.rb +1 -1
  26. data/lib/solargraph/convention/struct_definition/struct_definition_node.rb +3 -3
  27. data/lib/solargraph/convention/struct_definition.rb +3 -3
  28. data/lib/solargraph/convention.rb +78 -78
  29. data/lib/solargraph/converters/dd.rb +19 -17
  30. data/lib/solargraph/converters/dl.rb +17 -15
  31. data/lib/solargraph/converters/dt.rb +17 -15
  32. data/lib/solargraph/converters/misc.rb +3 -1
  33. data/lib/solargraph/diagnostics/rubocop.rb +10 -10
  34. data/lib/solargraph/diagnostics/rubocop_helpers.rb +3 -3
  35. data/lib/solargraph/diagnostics/type_check.rb +10 -10
  36. data/lib/solargraph/diagnostics/update_errors.rb +37 -41
  37. data/lib/solargraph/doc_map.rb +9 -10
  38. data/lib/solargraph/equality.rb +3 -3
  39. data/lib/solargraph/gem_pins.rb +7 -5
  40. data/lib/solargraph/language_server/error_codes.rb +20 -20
  41. data/lib/solargraph/language_server/host/diagnoser.rb +89 -89
  42. data/lib/solargraph/language_server/host/dispatch.rb +2 -3
  43. data/lib/solargraph/language_server/host/message_worker.rb +2 -2
  44. data/lib/solargraph/language_server/host/sources.rb +1 -1
  45. data/lib/solargraph/language_server/host.rb +24 -21
  46. data/lib/solargraph/language_server/message/base.rb +97 -97
  47. data/lib/solargraph/language_server/message/client/register_capability.rb +13 -15
  48. data/lib/solargraph/language_server/message/completion_item/resolve.rb +58 -60
  49. data/lib/solargraph/language_server/message/extended/check_gem_version.rb +10 -11
  50. data/lib/solargraph/language_server/message/extended/document_gems.rb +32 -32
  51. data/lib/solargraph/language_server/message/extended/download_core.rb +20 -19
  52. data/lib/solargraph/language_server/message/extended/search.rb +20 -20
  53. data/lib/solargraph/language_server/message/initialize.rb +197 -191
  54. data/lib/solargraph/language_server/message/text_document/completion.rb +8 -8
  55. data/lib/solargraph/language_server/message/text_document/definition.rb +41 -34
  56. data/lib/solargraph/language_server/message/text_document/document_highlight.rb +23 -16
  57. data/lib/solargraph/language_server/message/text_document/document_symbol.rb +29 -21
  58. data/lib/solargraph/language_server/message/text_document/formatting.rb +6 -6
  59. data/lib/solargraph/language_server/message/text_document/hover.rb +3 -5
  60. data/lib/solargraph/language_server/message/text_document/prepare_rename.rb +18 -11
  61. data/lib/solargraph/language_server/message/text_document/references.rb +23 -16
  62. data/lib/solargraph/language_server/message/text_document/rename.rb +26 -19
  63. data/lib/solargraph/language_server/message/text_document/signature_help.rb +2 -2
  64. data/lib/solargraph/language_server/message/text_document/type_definition.rb +25 -19
  65. data/lib/solargraph/language_server/message/workspace/did_change_configuration.rb +41 -35
  66. data/lib/solargraph/language_server/message/workspace/did_change_watched_files.rb +48 -40
  67. data/lib/solargraph/language_server/message/workspace/did_change_workspace_folders.rb +32 -26
  68. data/lib/solargraph/language_server/message/workspace/workspace_symbol.rb +27 -19
  69. data/lib/solargraph/language_server/message.rb +94 -94
  70. data/lib/solargraph/language_server/request.rb +29 -27
  71. data/lib/solargraph/language_server/transport/data_reader.rb +72 -74
  72. data/lib/solargraph/language_server/uri_helpers.rb +49 -49
  73. data/lib/solargraph/library.rb +28 -33
  74. data/lib/solargraph/location.rb +10 -12
  75. data/lib/solargraph/logging.rb +4 -4
  76. data/lib/solargraph/page.rb +92 -92
  77. data/lib/solargraph/parser/comment_ripper.rb +12 -4
  78. data/lib/solargraph/parser/flow_sensitive_typing.rb +32 -42
  79. data/lib/solargraph/parser/node_processor/base.rb +4 -4
  80. data/lib/solargraph/parser/node_processor.rb +1 -1
  81. data/lib/solargraph/parser/parser_gem/class_methods.rb +4 -4
  82. data/lib/solargraph/parser/parser_gem/flawed_builder.rb +19 -19
  83. data/lib/solargraph/parser/parser_gem/node_chainer.rb +20 -20
  84. data/lib/solargraph/parser/parser_gem/node_methods.rb +66 -65
  85. data/lib/solargraph/parser/parser_gem/node_processors/args_node.rb +12 -12
  86. data/lib/solargraph/parser/parser_gem/node_processors/block_node.rb +1 -1
  87. data/lib/solargraph/parser/parser_gem/node_processors/def_node.rb +3 -3
  88. data/lib/solargraph/parser/parser_gem/node_processors/defs_node.rb +38 -37
  89. data/lib/solargraph/parser/parser_gem/node_processors/if_node.rb +3 -3
  90. data/lib/solargraph/parser/parser_gem/node_processors/ivasgn_node.rb +2 -1
  91. data/lib/solargraph/parser/parser_gem/node_processors/opasgn_node.rb +1 -1
  92. data/lib/solargraph/parser/parser_gem/node_processors/sclass_node.rb +3 -5
  93. data/lib/solargraph/parser/parser_gem/node_processors/send_node.rb +118 -112
  94. data/lib/solargraph/parser/parser_gem/node_processors/until_node.rb +29 -29
  95. data/lib/solargraph/parser/parser_gem/node_processors/when_node.rb +1 -1
  96. data/lib/solargraph/parser/parser_gem/node_processors/while_node.rb +1 -1
  97. data/lib/solargraph/parser/parser_gem.rb +14 -12
  98. data/lib/solargraph/parser/snippet.rb +2 -0
  99. data/lib/solargraph/parser.rb +25 -23
  100. data/lib/solargraph/pin/base.rb +78 -64
  101. data/lib/solargraph/pin/base_variable.rb +28 -71
  102. data/lib/solargraph/pin/block.rb +3 -2
  103. data/lib/solargraph/pin/breakable.rb +2 -0
  104. data/lib/solargraph/pin/callable.rb +23 -26
  105. data/lib/solargraph/pin/closure.rb +5 -4
  106. data/lib/solargraph/pin/common.rb +5 -2
  107. data/lib/solargraph/pin/compound_statement.rb +3 -3
  108. data/lib/solargraph/pin/constant.rb +43 -45
  109. data/lib/solargraph/pin/conversions.rb +9 -4
  110. data/lib/solargraph/pin/delegated_method.rb +4 -4
  111. data/lib/solargraph/pin/documenting.rb +3 -2
  112. data/lib/solargraph/pin/local_variable.rb +4 -4
  113. data/lib/solargraph/pin/method.rb +71 -70
  114. data/lib/solargraph/pin/namespace.rb +13 -12
  115. data/lib/solargraph/pin/parameter.rb +28 -27
  116. data/lib/solargraph/pin/proxy_type.rb +2 -0
  117. data/lib/solargraph/pin/reference.rb +17 -0
  118. data/lib/solargraph/pin/search.rb +2 -2
  119. data/lib/solargraph/pin/signature.rb +9 -14
  120. data/lib/solargraph/pin/symbol.rb +1 -0
  121. data/lib/solargraph/pin/until.rb +1 -3
  122. data/lib/solargraph/pin/while.rb +1 -3
  123. data/lib/solargraph/pin_cache.rb +16 -19
  124. data/lib/solargraph/position.rb +35 -17
  125. data/lib/solargraph/range.rb +10 -9
  126. data/lib/solargraph/rbs_map/conversions.rb +312 -206
  127. data/lib/solargraph/rbs_map/core_fills.rb +91 -84
  128. data/lib/solargraph/rbs_map/stdlib_map.rb +0 -1
  129. data/lib/solargraph/rbs_map.rb +3 -12
  130. data/lib/solargraph/server_methods.rb +16 -16
  131. data/lib/solargraph/shell.rb +63 -53
  132. data/lib/solargraph/source/chain/array.rb +39 -37
  133. data/lib/solargraph/source/chain/call.rb +49 -44
  134. data/lib/solargraph/source/chain/class_variable.rb +13 -13
  135. data/lib/solargraph/source/chain/constant.rb +3 -1
  136. data/lib/solargraph/source/chain/global_variable.rb +13 -13
  137. data/lib/solargraph/source/chain/hash.rb +8 -6
  138. data/lib/solargraph/source/chain/if.rb +11 -10
  139. data/lib/solargraph/source/chain/instance_variable.rb +3 -1
  140. data/lib/solargraph/source/chain/link.rb +99 -109
  141. data/lib/solargraph/source/chain/literal.rb +4 -6
  142. data/lib/solargraph/source/chain/or.rb +2 -4
  143. data/lib/solargraph/source/chain/q_call.rb +13 -11
  144. data/lib/solargraph/source/chain/variable.rb +15 -13
  145. data/lib/solargraph/source/chain/z_super.rb +28 -30
  146. data/lib/solargraph/source/chain.rb +24 -16
  147. data/lib/solargraph/source/change.rb +3 -3
  148. data/lib/solargraph/source/cursor.rb +18 -18
  149. data/lib/solargraph/source/encoding_fixes.rb +6 -7
  150. data/lib/solargraph/source/source_chainer.rb +46 -32
  151. data/lib/solargraph/source/updater.rb +1 -1
  152. data/lib/solargraph/source.rb +27 -29
  153. data/lib/solargraph/source_map/clip.rb +38 -30
  154. data/lib/solargraph/source_map/mapper.rb +52 -46
  155. data/lib/solargraph/source_map.rb +8 -4
  156. data/lib/solargraph/type_checker/rules.rb +8 -8
  157. data/lib/solargraph/type_checker.rb +95 -101
  158. data/lib/solargraph/version.rb +1 -1
  159. data/lib/solargraph/workspace/config.rb +10 -9
  160. data/lib/solargraph/workspace/gemspecs.rb +1 -1
  161. data/lib/solargraph/workspace.rb +21 -44
  162. data/lib/solargraph/yard_map/helpers.rb +6 -2
  163. data/lib/solargraph/yard_map/mapper/to_method.rb +8 -6
  164. data/lib/solargraph/yard_map/mapper/to_namespace.rb +1 -1
  165. data/lib/solargraph/yard_map/mapper.rb +12 -12
  166. data/lib/solargraph/yard_tags.rb +20 -20
  167. data/lib/solargraph.rb +5 -5
  168. data/solargraph.gemspec +35 -34
  169. metadata +28 -28
@@ -1,84 +1,91 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- class RbsMap
5
- # Override pins to fill gaps in RbsMap::CoreMap coverage
6
- #
7
- module CoreFills
8
- Override = Pin::Reference::Override
9
-
10
- KEYWORDS = [
11
- '__ENCODING__', '__LINE__', '__FILE__', 'BEGIN', 'END', 'alias', 'and',
12
- 'begin', 'break', 'case', 'class', 'def', 'defined?', 'do', 'else',
13
- 'elsif', 'end', 'ensure', 'false', 'for', 'if', 'in', 'module', 'next',
14
- 'nil', 'not', 'or', 'redo', 'rescue', 'retry', 'return', 'self', 'super',
15
- 'then', 'true', 'undef', 'unless', 'until', 'when', 'while', 'yield'
16
- ].map { |k| Pin::Keyword.new(k, source: :core_fill) }
17
-
18
- MISSING = [
19
- Solargraph::Pin::Method.new(name: 'class', scope: :instance,
20
- closure: Solargraph::Pin::Namespace.new(name: 'Object', source: :core_fill), comments: '@return [::Class<self>]',
21
- source: :core_fill)
22
- ]
23
-
24
- OVERRIDES = [
25
- Override.from_comment('BasicObject#instance_eval', '@yieldreceiver [self]',
26
- source: :core_fill),
27
- Override.from_comment('BasicObject#instance_exec', '@yieldreceiver [self]',
28
- source: :core_fill),
29
- Override.from_comment('Module#define_method', '@yieldreceiver [::Object<self>]',
30
- source: :core_fill),
31
- Override.from_comment('Module#class_eval', '@yieldreceiver [::Class<self>]',
32
- source: :core_fill),
33
- Override.from_comment('Module#class_exec', '@yieldreceiver [::Class<self>]',
34
- source: :core_fill),
35
- Override.from_comment('Module#module_eval', '@yieldreceiver [::Module<self>]',
36
- source: :core_fill),
37
- Override.from_comment('Module#module_exec', '@yieldreceiver [::Module<self>]',
38
- source: :core_fill),
39
- # RBS does not define Class with a generic, so all calls to
40
- # generic() return an 'untyped'. We can do better:
41
- Override.method_return('Class#allocate', 'self', source: :core_fill),
42
- ]
43
-
44
- # @todo I don't see any direct link in RBS to build this from -
45
- # presumably RBS is using duck typing to match interfaces
46
- # against concrete classes
47
- INCLUDES = [
48
- Solargraph::Pin::Reference::Include.new(name: '_ToAry',
49
- closure: Solargraph::Pin::Namespace.new(name: 'Array', source: :core_fill),
50
- generic_values: ['generic<Elem>'],
51
- source: :core_fill),
52
- Solargraph::Pin::Reference::Include.new(name: '_ToAry',
53
- closure: Solargraph::Pin::Namespace.new(name: 'Set', source: :core_fill),
54
- generic_values: ['generic<Elem>'],
55
- source: :core_fill),
56
- Solargraph::Pin::Reference::Include.new(name: '_Each',
57
- closure: Solargraph::Pin::Namespace.new(name: 'Array', source: :core_fill),
58
- generic_values: ['generic<Elem>'],
59
- source: :core_fill),
60
- Solargraph::Pin::Reference::Include.new(name: '_Each',
61
- closure: Solargraph::Pin::Namespace.new(name: 'Set', source: :core_fill),
62
- generic_values: ['generic<Elem>'],
63
- source: :core_fill),
64
- Solargraph::Pin::Reference::Include.new(name: '_ToS',
65
- closure: Solargraph::Pin::Namespace.new(name: 'Object', source: :core_fill),
66
- source: :core_fill),
67
- Solargraph::Pin::Reference::Include.new(name: '_ToS',
68
- closure: Solargraph::Pin::Namespace.new(name: 'String', source: :core_fill),
69
- source: :core_fill)
70
- ]
71
-
72
- # HACK: Add Errno exception classes
73
- errno = Solargraph::Pin::Namespace.new(name: 'Errno', source: :core_fill)
74
- errnos = []
75
- Errno.constants.each do |const|
76
- errnos.push Solargraph::Pin::Namespace.new(type: :class, name: const.to_s, closure: errno, source: :core_fill)
77
- errnos.push Solargraph::Pin::Reference::Superclass.new(closure: errnos.last, name: 'SystemCallError', source: :core_fill)
78
- end
79
- ERRNOS = errnos
80
-
81
- ALL = KEYWORDS + MISSING + OVERRIDES + ERRNOS + INCLUDES
82
- end
83
- end
84
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Solargraph
4
+ class RbsMap
5
+ # Override pins to fill gaps in RbsMap::CoreMap coverage
6
+ #
7
+ module CoreFills
8
+ Override = Pin::Reference::Override
9
+
10
+ KEYWORDS = [
11
+ '__ENCODING__', '__LINE__', '__FILE__', 'BEGIN', 'END', 'alias', 'and',
12
+ 'begin', 'break', 'case', 'class', 'def', 'defined?', 'do', 'else',
13
+ 'elsif', 'end', 'ensure', 'false', 'for', 'if', 'in', 'module', 'next',
14
+ 'nil', 'not', 'or', 'redo', 'rescue', 'retry', 'return', 'self', 'super',
15
+ 'then', 'true', 'undef', 'unless', 'until', 'when', 'while', 'yield'
16
+ ].map { |k| Pin::Keyword.new(k, source: :core_fill) }
17
+
18
+ MISSING = [
19
+ Solargraph::Pin::Method.new(name: 'class', scope: :instance,
20
+ closure: Solargraph::Pin::Namespace.new(name: 'Object', source: :core_fill), comments: '@return [::Class<self>]',
21
+ source: :core_fill)
22
+ ].freeze
23
+
24
+ OVERRIDES = [
25
+ Override.from_comment('BasicObject#instance_eval', '@yieldreceiver [self]',
26
+ source: :core_fill),
27
+ Override.from_comment('BasicObject#instance_exec', '@yieldreceiver [self]',
28
+ source: :core_fill),
29
+ Override.from_comment('Module#define_method', '@yieldreceiver [::Object<self>]',
30
+ source: :core_fill),
31
+ Override.from_comment('Module#class_eval', '@yieldreceiver [::Class<self>]',
32
+ source: :core_fill),
33
+ Override.from_comment('Module#class_exec', '@yieldreceiver [::Class<self>]',
34
+ source: :core_fill),
35
+ Override.from_comment('Module#module_eval', '@yieldreceiver [::Module<self>]',
36
+ source: :core_fill),
37
+ Override.from_comment('Module#module_exec', '@yieldreceiver [::Module<self>]',
38
+ source: :core_fill),
39
+ # RBS does not define Class with a generic, so all calls to
40
+ # generic() return an 'untyped'. We can do better:
41
+ Override.method_return('Class#allocate', 'self', source: :core_fill)
42
+ ].freeze
43
+
44
+ # @todo I don't see any direct link in RBS to build this from -
45
+ # presumably RBS is using duck typing to match interfaces
46
+ # against concrete classes
47
+ INCLUDES = [
48
+ Solargraph::Pin::Reference::Include.new(name: '_ToAry',
49
+ closure: Solargraph::Pin::Namespace.new(name: 'Array',
50
+ source: :core_fill),
51
+ generic_values: ['generic<Elem>'],
52
+ source: :core_fill),
53
+ Solargraph::Pin::Reference::Include.new(name: '_ToAry',
54
+ closure: Solargraph::Pin::Namespace.new(name: 'Set',
55
+ source: :core_fill),
56
+ generic_values: ['generic<Elem>'],
57
+ source: :core_fill),
58
+ Solargraph::Pin::Reference::Include.new(name: '_Each',
59
+ closure: Solargraph::Pin::Namespace.new(name: 'Array',
60
+ source: :core_fill),
61
+ generic_values: ['generic<Elem>'],
62
+ source: :core_fill),
63
+ Solargraph::Pin::Reference::Include.new(name: '_Each',
64
+ closure: Solargraph::Pin::Namespace.new(name: 'Set',
65
+ source: :core_fill),
66
+ generic_values: ['generic<Elem>'],
67
+ source: :core_fill),
68
+ Solargraph::Pin::Reference::Include.new(name: '_ToS',
69
+ closure: Solargraph::Pin::Namespace.new(name: 'Object',
70
+ source: :core_fill),
71
+ source: :core_fill),
72
+ Solargraph::Pin::Reference::Include.new(name: '_ToS',
73
+ closure: Solargraph::Pin::Namespace.new(name: 'String',
74
+ source: :core_fill),
75
+ source: :core_fill)
76
+ ].freeze
77
+
78
+ # HACK: Add Errno exception classes
79
+ errno = Solargraph::Pin::Namespace.new(name: 'Errno', source: :core_fill)
80
+ errnos = []
81
+ Errno.constants.each do |const|
82
+ errnos.push Solargraph::Pin::Namespace.new(type: :class, name: const.to_s, closure: errno, source: :core_fill)
83
+ errnos.push Solargraph::Pin::Reference::Superclass.new(closure: errnos.last, name: 'SystemCallError',
84
+ source: :core_fill)
85
+ end
86
+ ERRNOS = errnos
87
+
88
+ ALL = KEYWORDS + MISSING + OVERRIDES + ERRNOS + INCLUDES
89
+ end
90
+ end
91
+ end
@@ -12,7 +12,6 @@ module Solargraph
12
12
  # @type [Hash{String => RbsMap}]
13
13
  @stdlib_maps_hash = {}
14
14
 
15
-
16
15
  # @param rebuild [Boolean] build pins regardless of whether we
17
16
  # have cached them already
18
17
  # @param library [String]
@@ -16,11 +16,7 @@ module Solargraph
16
16
  # @type [Hash{String => RbsMap}]
17
17
  @@rbs_maps_hash = {}
18
18
 
19
- attr_reader :library
20
-
21
- attr_reader :rbs_collection_paths
22
-
23
- attr_reader :rbs_collection_config_path
19
+ attr_reader :library, :rbs_collection_paths, :rbs_collection_config_path
24
20
 
25
21
  # @param library [String]
26
22
  # @param version [String, nil]
@@ -72,7 +68,7 @@ module Solargraph
72
68
  def cache_key
73
69
  return CACHE_KEY_UNRESOLVED unless resolved?
74
70
 
75
- @hextdigest ||= begin
71
+ @cache_key ||= begin
76
72
  # @type [String, nil]
77
73
  data = nil
78
74
  # @type gem_config [nil, Hash{String => Hash{String => String}}]
@@ -145,7 +141,7 @@ module Solargraph
145
141
  # @return [generic<T>, nil]
146
142
  def path_pin path, klass = Pin::Base
147
143
  pin = pins.find { |p| p.path == path }
148
- pin if pin&.is_a?(klass)
144
+ pin if pin.is_a?(klass)
149
145
  end
150
146
 
151
147
  # @param path [String]
@@ -176,11 +172,6 @@ module Solargraph
176
172
 
177
173
  private
178
174
 
179
- # @return [RBS::EnvironmentLoader]
180
- def loader
181
- @loader ||= RBS::EnvironmentLoader.new(core_root: nil, repository: repository)
182
- end
183
-
184
175
  # @return [Conversions]
185
176
  def conversions
186
177
  @conversions ||= Conversions.new(loader: loader)
@@ -1,16 +1,16 @@
1
- # frozen_string_literal: true
2
-
3
- require 'socket'
4
-
5
- module Solargraph
6
- module ServerMethods
7
- # @return [Integer]
8
- def available_port
9
- socket = Socket.new(:INET, :STREAM, 0)
10
- socket.bind(Addrinfo.tcp("127.0.0.1", 0))
11
- port = socket.local_address.ip_port
12
- socket.close
13
- port
14
- end
15
- end
16
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'socket'
4
+
5
+ module Solargraph
6
+ module ServerMethods
7
+ # @return [Integer]
8
+ def available_port
9
+ socket = Socket.new(:INET, :STREAM, 0)
10
+ socket.bind(Addrinfo.tcp('127.0.0.1', 0))
11
+ port = socket.local_address.ip_port
12
+ socket.close
13
+ port
14
+ end
15
+ end
16
+ end
@@ -16,7 +16,7 @@ module Solargraph
16
16
 
17
17
  map %w[--version -v] => :version
18
18
 
19
- desc "--version, -v", "Print the version"
19
+ desc '--version, -v', 'Print the version'
20
20
  # @return [void]
21
21
  def version
22
22
  puts Solargraph::VERSION
@@ -31,15 +31,15 @@ module Solargraph
31
31
  port = options[:port]
32
32
  port = available_port if port.zero?
33
33
  Backport.run do
34
- Signal.trap("INT") do
34
+ Signal.trap('INT') do
35
35
  Backport.stop
36
36
  end
37
- Signal.trap("TERM") do
37
+ Signal.trap('TERM') do
38
38
  Backport.stop
39
39
  end
40
40
  # @sg-ignore Wrong argument type for Backport.prepare_tcp_server: adapter expected Backport::Adapter, received Module<Solargraph::LanguageServer::Transport::Adapter>
41
41
  Backport.prepare_tcp_server host: options[:host], port: port, adapter: Solargraph::LanguageServer::Transport::Adapter
42
- STDERR.puts "Solargraph is listening PORT=#{port} PID=#{Process.pid}"
42
+ warn "Solargraph is listening PORT=#{port} PID=#{Process.pid}"
43
43
  end
44
44
  end
45
45
 
@@ -48,15 +48,15 @@ module Solargraph
48
48
  def stdio
49
49
  require 'backport'
50
50
  Backport.run do
51
- Signal.trap("INT") do
51
+ Signal.trap('INT') do
52
52
  Backport.stop
53
53
  end
54
- Signal.trap("TERM") do
54
+ Signal.trap('TERM') do
55
55
  Backport.stop
56
56
  end
57
57
  # @sg-ignore Wrong argument type for Backport.prepare_stdio_server: adapter expected Backport::Adapter, received Module<Solargraph::LanguageServer::Transport::Adapter>
58
58
  Backport.prepare_stdio_server adapter: Solargraph::LanguageServer::Transport::Adapter
59
- STDERR.puts "Solargraph is listening on stdio PID=#{Process.pid}"
59
+ warn "Solargraph is listening on stdio PID=#{Process.pid}"
60
60
  end
61
61
  end
62
62
 
@@ -64,11 +64,11 @@ module Solargraph
64
64
  option :extensions, type: :boolean, aliases: :e, desc: 'Add installed extensions', default: true
65
65
  # @param directory [String]
66
66
  # @return [void]
67
- def config(directory = '.')
67
+ def config directory = '.'
68
68
  matches = []
69
69
  if options[:extensions]
70
70
  Gem::Specification.each do |g|
71
- if g.name.match(/^solargraph\-[A-Za-z0-9_\-]*?\-ext/)
71
+ if g.name.match(/^solargraph-[A-Za-z0-9_-]*?-ext/)
72
72
  require g.name
73
73
  matches.push g.name
74
74
  end
@@ -84,7 +84,7 @@ module Solargraph
84
84
  File.open(File.join(directory, '.solargraph.yml'), 'w') do |file|
85
85
  file.puts conf.to_yaml
86
86
  end
87
- STDOUT.puts "Configuration file initialized."
87
+ $stdout.puts 'Configuration file initialized.'
88
88
  end
89
89
 
90
90
  desc 'clear', 'Delete all cached documentation'
@@ -93,7 +93,7 @@ module Solargraph
93
93
  )
94
94
  # @return [void]
95
95
  def clear
96
- puts "Deleting all cached documentation (gems, core and stdlib)"
96
+ puts 'Deleting all cached documentation (gems, core and stdlib)'
97
97
  Solargraph::PinCache.clear
98
98
  end
99
99
  map 'clear-cache' => :clear
@@ -109,7 +109,7 @@ module Solargraph
109
109
  # '
110
110
  end
111
111
 
112
- desc 'uncache GEM [...GEM]', "Delete specific cached gem documentation"
112
+ desc 'uncache GEM [...GEM]', 'Delete specific cached gem documentation'
113
113
  long_desc %(
114
114
  Specify one or more gem names to clear. 'core' or 'stdlib' may
115
115
  also be specified to clear cached system documentation.
@@ -174,7 +174,7 @@ module Solargraph
174
174
  if names.empty?
175
175
  workspace.cache_all_for_workspace!($stdout, rebuild: options[:rebuild])
176
176
  else
177
- $stderr.puts("Caching these gems: #{names}")
177
+ warn("Caching these gems: #{names}")
178
178
  names.each do |name|
179
179
  if name == 'core'
180
180
  PinCache.cache_core(out: $stdout) if !PinCache.core? || options[:rebuild]
@@ -195,7 +195,7 @@ module Solargraph
195
195
  # @sg-ignore Need to add nil check here
196
196
  warn e.backtrace.join("\n")
197
197
  end
198
- $stderr.puts "Documentation cached for #{names.count} gems."
198
+ warn "Documentation cached for #{names.count} gems."
199
199
  end
200
200
  end
201
201
 
@@ -212,7 +212,7 @@ module Solargraph
212
212
 
213
213
  Type checking levels are normal, typed, strict, and strong.
214
214
  )
215
- option :level, type: :string, aliases: [:mode, :m, :l], desc: 'Type checking level', default: 'normal'
215
+ option :level, type: :string, aliases: %i[mode m l], desc: 'Type checking level', default: 'normal'
216
216
  option :directory, type: :string, aliases: :d, desc: 'The workspace directory', default: '.'
217
217
  # @return [void]
218
218
  def typecheck *files
@@ -231,21 +231,28 @@ module Solargraph
231
231
  files.map! { |file| File.realpath(file) }
232
232
  end
233
233
  filecount = 0
234
- time = Benchmark.measure {
234
+ time = Benchmark.measure do
235
235
  files.each do |file|
236
- checker = TypeChecker.new(file, api_map: api_map, rules: rules, level: options[:level].to_sym, workspace: workspace)
236
+ checker = TypeChecker.new(file, api_map: api_map, rules: rules, level: options[:level].to_sym,
237
+ workspace: workspace)
237
238
  problems = checker.problems
238
239
  next if problems.empty?
239
240
  problems.sort! { |a, b| a.location.range.start.line <=> b.location.range.start.line }
240
- puts problems.map { |prob| "#{prob.location.filename}:#{prob.location.range.start.line + 1} - #{prob.message}" }.join("\n")
241
+ puts problems.map { |prob|
242
+ "#{prob.location.filename}:#{prob.location.range.start.line + 1} - #{prob.message}"
243
+ }.join("\n")
241
244
  filecount += 1
242
245
  probcount += problems.length
243
246
  end
244
- }
247
+ end
245
248
  puts "Typecheck finished in #{time.real} seconds."
246
- puts "#{probcount} problem#{probcount != 1 ? 's' : ''} found#{files.length != 1 ? " in #{filecount} of #{files.length} files" : ''}."
249
+ puts "#{probcount} problem#{if probcount != 1
250
+ 's'
251
+ end} found#{if files.length != 1
252
+ " in #{filecount} of #{files.length} files"
253
+ end}."
247
254
  # "
248
- exit 1 if probcount > 0
255
+ exit 1 if probcount.positive?
249
256
  end
250
257
 
251
258
  desc 'scan', 'Test the workspace for problems'
@@ -262,26 +269,26 @@ module Solargraph
262
269
  directory = File.realpath(options[:directory])
263
270
  # @type [Solargraph::ApiMap, nil]
264
271
  api_map = nil
265
- time = Benchmark.measure {
272
+ time = Benchmark.measure do
266
273
  api_map = Solargraph::ApiMap.load_with_cache(directory, $stdout)
267
274
  # @sg-ignore flow sensitive typing should be able to handle redefinition
268
275
  api_map.pins.each do |pin|
269
- begin
270
- puts pin_description(pin) if options[:verbose]
271
- pin.typify api_map
272
- pin.probe api_map
273
- rescue StandardError => e
274
- # @todo to add nil check here
275
- # @todo should warn on nil dereference below
276
- STDERR.puts "Error testing #{pin_description(pin)} #{pin.location ? "at #{pin.location.filename}:#{pin.location.range.start.line + 1}" : ''}"
277
- STDERR.puts "[#{e.class}]: #{e.message}"
278
- # @todo Need to add nil check here
279
- # @todo flow sensitive typing should be able to handle redefinition
280
- STDERR.puts e.backtrace.join("\n")
281
- exit 1
282
- end
276
+ puts pin_description(pin) if options[:verbose]
277
+ pin.typify api_map
278
+ pin.probe api_map
279
+ rescue StandardError => e
280
+ # @todo to add nil check here
281
+ # @todo should warn on nil dereference below
282
+ warn "Error testing #{pin_description(pin)} #{if pin.location
283
+ "at #{pin.location.filename}:#{pin.location.range.start.line + 1}"
284
+ end}"
285
+ warn "[#{e.class}]: #{e.message}"
286
+ # @todo Need to add nil check here
287
+ # @todo flow sensitive typing should be able to handle redefinition
288
+ warn e.backtrace.join("\n")
289
+ exit 1
283
290
  end
284
- }
291
+ end
285
292
  # @sg-ignore Need to add nil check here
286
293
  puts "Scanned #{directory} (#{api_map.pins.length} pins) in #{time.real} seconds."
287
294
  end
@@ -296,12 +303,15 @@ module Solargraph
296
303
  puts "#{workspace.filenames.length} files total."
297
304
  end
298
305
 
299
- desc 'pin [PATH]', 'Describe a pin', hide: true
306
+ desc 'pin [PATH]', 'Describe a pin'
300
307
  option :rbs, type: :boolean, desc: 'Output the pin as RBS', default: false
301
- option :typify, type: :boolean, desc: 'Output the calculated return type of the pin from annotations', default: false
308
+ option :typify, type: :boolean, desc: 'Output the calculated return type of the pin from annotations',
309
+ default: false
302
310
  option :references, type: :boolean, desc: 'Show references', default: false
303
- option :probe, type: :boolean, desc: 'Output the calculated return type of the pin from annotations and inference', default: false
304
- option :stack, type: :boolean, desc: 'Show entire stack of a method pin by including definitions in superclasses', default: false
311
+ option :probe, type: :boolean, desc: 'Output the calculated return type of the pin from annotations and inference',
312
+ default: false
313
+ option :stack, type: :boolean, desc: 'Show entire stack of a method pin by including definitions in superclasses',
314
+ default: false
305
315
  # @param path [String] The path to the method pin, e.g. 'Class#method' or 'Class.method'
306
316
  # @return [void]
307
317
  def pin path
@@ -326,7 +336,7 @@ module Solargraph
326
336
  pin = pins.first
327
337
  case pin
328
338
  when nil
329
- $stderr.puts "Pin not found for path '#{path}'"
339
+ warn "Pin not found for path '#{path}'"
330
340
  exit 1
331
341
  when Pin::Namespace
332
342
  if options[:references]
@@ -360,15 +370,15 @@ module Solargraph
360
370
  # @return [String]
361
371
  def pin_description pin
362
372
  desc = if pin.path.nil? || pin.path.empty?
363
- if pin.closure
364
- # @sg-ignore Need to add nil check here
365
- "#{pin.closure.path} | #{pin.name}"
366
- else
367
- "#{pin.context.namespace} | #{pin.name}"
368
- end
369
- else
370
- pin.path
371
- end
373
+ if pin.closure
374
+ # @sg-ignore Need to add nil check here
375
+ "#{pin.closure.path} | #{pin.name}"
376
+ else
377
+ "#{pin.context.namespace} | #{pin.name}"
378
+ end
379
+ else
380
+ pin.path
381
+ end
372
382
  # @sg-ignore Need to add nil check here
373
383
  desc += " (#{pin.location.filename} #{pin.location.range.start.line})" if pin.location
374
384
  desc
@@ -376,7 +386,7 @@ module Solargraph
376
386
 
377
387
  # @param type [ComplexType, ComplexType::UniqueType]
378
388
  # @return [void]
379
- def print_type(type)
389
+ def print_type type
380
390
  if options[:rbs]
381
391
  puts type.to_rbs
382
392
  else
@@ -386,7 +396,7 @@ module Solargraph
386
396
 
387
397
  # @param pin [Solargraph::Pin::Base]
388
398
  # @return [void]
389
- def print_pin(pin)
399
+ def print_pin pin
390
400
  if options[:rbs]
391
401
  puts pin.to_rbs
392
402
  else
@@ -1,37 +1,39 @@
1
- module Solargraph
2
- class Source
3
- class Chain
4
- class Array < Literal
5
- # @param children [::Array<Chain>]
6
- # @param node [Parser::AST::Node]
7
- def initialize children, node
8
- super('::Array', node)
9
- @children = children
10
- end
11
-
12
- def word
13
- @word ||= "<#{@type}>"
14
- end
15
-
16
- # @param api_map [ApiMap]
17
- # @param name_pin [Pin::Base]
18
- # @param locals [::Array<Pin::Parameter, Pin::LocalVariable>]
19
- def resolve api_map, name_pin, locals
20
- child_types = @children.map do |child|
21
- child.infer(api_map, name_pin, locals).simplify_literals
22
- end
23
- type = if child_types.length == 0 || child_types.any?(&:undefined?)
24
- ComplexType::UniqueType.new('Array', rooted: true)
25
- elsif child_types.uniq.length == 1 && child_types.first.defined?
26
- ComplexType::UniqueType.new('Array', [], child_types.uniq, rooted: true, parameters_type: :list)
27
- elsif child_types.length == 0
28
- ComplexType::UniqueType.new('Array', rooted: true, parameters_type: :list)
29
- else
30
- ComplexType::UniqueType.new('Array', [], child_types, rooted: true, parameters_type: :fixed)
31
- end
32
- [Pin::ProxyType.anonymous(type, source: :chain)]
33
- end
34
- end
35
- end
36
- end
37
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Solargraph
4
+ class Source
5
+ class Chain
6
+ class Array < Literal
7
+ # @param children [::Array<Chain>]
8
+ # @param node [Parser::AST::Node]
9
+ def initialize children, node
10
+ super('::Array', node)
11
+ @children = children
12
+ end
13
+
14
+ def word
15
+ @word ||= "<#{@type}>"
16
+ end
17
+
18
+ # @param api_map [ApiMap]
19
+ # @param name_pin [Pin::Base]
20
+ # @param locals [::Array<Pin::Parameter, Pin::LocalVariable>]
21
+ def resolve api_map, name_pin, locals
22
+ child_types = @children.map do |child|
23
+ child.infer(api_map, name_pin, locals).simplify_literals
24
+ end
25
+ type = if child_types.empty? || child_types.any?(&:undefined?)
26
+ ComplexType::UniqueType.new('Array', rooted: true)
27
+ elsif child_types.uniq.length == 1 && child_types.first.defined?
28
+ ComplexType::UniqueType.new('Array', [], child_types.uniq, rooted: true, parameters_type: :list)
29
+ elsif child_types.empty?
30
+ ComplexType::UniqueType.new('Array', rooted: true, parameters_type: :list)
31
+ else
32
+ ComplexType::UniqueType.new('Array', [], child_types, rooted: true, parameters_type: :fixed)
33
+ end
34
+ [Pin::ProxyType.anonymous(type, source: :chain)]
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end