solargraph 0.47.2 → 0.54.0

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 (191) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +1 -0
  3. data/.github/workflows/plugins.yml +40 -0
  4. data/.github/workflows/rspec.yml +4 -8
  5. data/.github/workflows/typecheck.yml +34 -0
  6. data/.yardopts +2 -2
  7. data/CHANGELOG.md +166 -3
  8. data/LICENSE +1 -1
  9. data/README.md +19 -16
  10. data/SPONSORS.md +2 -9
  11. data/lib/solargraph/api_map/cache.rb +50 -20
  12. data/lib/solargraph/api_map/source_to_yard.rb +17 -10
  13. data/lib/solargraph/api_map/store.rb +68 -15
  14. data/lib/solargraph/api_map.rb +238 -112
  15. data/lib/solargraph/bench.rb +3 -2
  16. data/lib/solargraph/cache.rb +77 -0
  17. data/lib/solargraph/complex_type/type_methods.rb +116 -35
  18. data/lib/solargraph/complex_type/unique_type.rb +261 -33
  19. data/lib/solargraph/complex_type.rb +149 -30
  20. data/lib/solargraph/convention/rakefile.rb +17 -0
  21. data/lib/solargraph/convention.rb +2 -3
  22. data/lib/solargraph/converters/dd.rb +5 -0
  23. data/lib/solargraph/converters/dl.rb +3 -0
  24. data/lib/solargraph/converters/dt.rb +3 -0
  25. data/lib/solargraph/diagnostics/rubocop.rb +23 -8
  26. data/lib/solargraph/diagnostics/rubocop_helpers.rb +4 -1
  27. data/lib/solargraph/diagnostics/type_check.rb +1 -0
  28. data/lib/solargraph/diagnostics.rb +2 -2
  29. data/lib/solargraph/doc_map.rb +187 -0
  30. data/lib/solargraph/gem_pins.rb +72 -0
  31. data/lib/solargraph/language_server/host/diagnoser.rb +2 -2
  32. data/lib/solargraph/language_server/host/dispatch.rb +22 -5
  33. data/lib/solargraph/language_server/host/message_worker.rb +4 -0
  34. data/lib/solargraph/language_server/host/sources.rb +8 -65
  35. data/lib/solargraph/language_server/host.rb +88 -93
  36. data/lib/solargraph/language_server/message/base.rb +1 -1
  37. data/lib/solargraph/language_server/message/completion_item/resolve.rb +3 -1
  38. data/lib/solargraph/language_server/message/extended/check_gem_version.rb +13 -1
  39. data/lib/solargraph/language_server/message/extended/download_core.rb +1 -5
  40. data/lib/solargraph/language_server/message/initialize.rb +27 -0
  41. data/lib/solargraph/language_server/message/initialized.rb +1 -0
  42. data/lib/solargraph/language_server/message/text_document/document_symbol.rb +4 -1
  43. data/lib/solargraph/language_server/message/text_document/formatting.rb +5 -4
  44. data/lib/solargraph/language_server/message/text_document/hover.rb +2 -0
  45. data/lib/solargraph/language_server/message/text_document/signature_help.rb +1 -6
  46. data/lib/solargraph/language_server/message/text_document/type_definition.rb +24 -0
  47. data/lib/solargraph/language_server/message/text_document.rb +1 -1
  48. data/lib/solargraph/language_server/message/workspace/did_change_configuration.rb +5 -0
  49. data/lib/solargraph/language_server/message/workspace/did_change_watched_files.rb +10 -3
  50. data/lib/solargraph/language_server/message.rb +1 -0
  51. data/lib/solargraph/language_server/progress.rb +118 -0
  52. data/lib/solargraph/language_server/transport/adapter.rb +16 -1
  53. data/lib/solargraph/language_server/transport/data_reader.rb +2 -0
  54. data/lib/solargraph/language_server.rb +1 -0
  55. data/lib/solargraph/library.rb +231 -104
  56. data/lib/solargraph/location.rb +1 -0
  57. data/lib/solargraph/page.rb +6 -0
  58. data/lib/solargraph/parser/comment_ripper.rb +4 -0
  59. data/lib/solargraph/parser/node_methods.rb +47 -7
  60. data/lib/solargraph/parser/node_processor/base.rb +11 -1
  61. data/lib/solargraph/parser/node_processor.rb +1 -0
  62. data/lib/solargraph/parser/{legacy → parser_gem}/class_methods.rb +31 -9
  63. data/lib/solargraph/parser/{legacy → parser_gem}/flawed_builder.rb +3 -1
  64. data/lib/solargraph/parser/{legacy → parser_gem}/node_chainer.rb +57 -41
  65. data/lib/solargraph/parser/parser_gem/node_methods.rb +495 -0
  66. data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/alias_node.rb +1 -1
  67. data/lib/solargraph/parser/parser_gem/node_processors/args_node.rb +53 -0
  68. data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/begin_node.rb +1 -1
  69. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/block_node.rb +3 -2
  70. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/casgn_node.rb +14 -4
  71. data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/cvasgn_node.rb +1 -1
  72. data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/def_node.rb +7 -20
  73. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/defs_node.rb +2 -2
  74. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/gvasgn_node.rb +1 -1
  75. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/ivasgn_node.rb +2 -2
  76. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/lvasgn_node.rb +2 -2
  77. data/lib/solargraph/parser/parser_gem/node_processors/masgn_node.rb +47 -0
  78. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/namespace_node.rb +2 -2
  79. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/orasgn_node.rb +1 -1
  80. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/resbody_node.rb +3 -3
  81. data/lib/solargraph/parser/parser_gem/node_processors/sclass_node.rb +42 -0
  82. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/send_node.rb +7 -5
  83. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/sym_node.rb +1 -1
  84. data/lib/solargraph/parser/parser_gem/node_processors.rb +56 -0
  85. data/lib/solargraph/parser/parser_gem.rb +12 -0
  86. data/lib/solargraph/parser/region.rb +1 -1
  87. data/lib/solargraph/parser/snippet.rb +2 -0
  88. data/lib/solargraph/parser.rb +9 -10
  89. data/lib/solargraph/pin/base.rb +69 -11
  90. data/lib/solargraph/pin/base_variable.rb +40 -7
  91. data/lib/solargraph/pin/block.rb +81 -33
  92. data/lib/solargraph/pin/closure.rb +17 -2
  93. data/lib/solargraph/pin/common.rb +7 -3
  94. data/lib/solargraph/pin/conversions.rb +34 -8
  95. data/lib/solargraph/pin/delegated_method.rb +101 -0
  96. data/lib/solargraph/pin/documenting.rb +25 -32
  97. data/lib/solargraph/pin/instance_variable.rb +4 -0
  98. data/lib/solargraph/pin/local_variable.rb +13 -1
  99. data/lib/solargraph/pin/method.rb +273 -17
  100. data/lib/solargraph/pin/namespace.rb +17 -1
  101. data/lib/solargraph/pin/parameter.rb +40 -28
  102. data/lib/solargraph/pin/reference/override.rb +2 -2
  103. data/lib/solargraph/pin/reference.rb +8 -0
  104. data/lib/solargraph/pin/search.rb +4 -4
  105. data/lib/solargraph/pin/signature.rb +143 -0
  106. data/lib/solargraph/pin.rb +2 -1
  107. data/lib/solargraph/range.rb +4 -6
  108. data/lib/solargraph/rbs_map/conversions.rb +607 -0
  109. data/lib/solargraph/rbs_map/core_fills.rb +50 -0
  110. data/lib/solargraph/rbs_map/core_map.rb +28 -0
  111. data/lib/solargraph/rbs_map/stdlib_map.rb +33 -0
  112. data/lib/solargraph/rbs_map.rb +92 -0
  113. data/lib/solargraph/shell.rb +85 -59
  114. data/lib/solargraph/source/chain/array.rb +32 -0
  115. data/lib/solargraph/source/chain/block_symbol.rb +13 -0
  116. data/lib/solargraph/source/chain/call.rb +125 -61
  117. data/lib/solargraph/source/chain/constant.rb +15 -1
  118. data/lib/solargraph/source/chain/if.rb +23 -0
  119. data/lib/solargraph/source/chain/link.rb +8 -2
  120. data/lib/solargraph/source/chain/or.rb +1 -1
  121. data/lib/solargraph/source/chain/z_super.rb +3 -3
  122. data/lib/solargraph/source/chain.rb +64 -14
  123. data/lib/solargraph/source/change.rb +3 -0
  124. data/lib/solargraph/source/cursor.rb +2 -0
  125. data/lib/solargraph/source/source_chainer.rb +8 -5
  126. data/lib/solargraph/source/updater.rb +1 -0
  127. data/lib/solargraph/source.rb +18 -63
  128. data/lib/solargraph/source_map/clip.rb +31 -23
  129. data/lib/solargraph/source_map/mapper.rb +23 -7
  130. data/lib/solargraph/source_map.rb +36 -11
  131. data/lib/solargraph/type_checker/checks.rb +10 -2
  132. data/lib/solargraph/type_checker.rb +229 -100
  133. data/lib/solargraph/version.rb +1 -1
  134. data/lib/solargraph/views/environment.erb +2 -2
  135. data/lib/solargraph/workspace/config.rb +15 -11
  136. data/lib/solargraph/workspace.rb +41 -17
  137. data/lib/solargraph/yard_map/cache.rb +6 -0
  138. data/lib/solargraph/yard_map/helpers.rb +1 -1
  139. data/lib/solargraph/yard_map/mapper/to_method.rb +23 -7
  140. data/lib/solargraph/yard_map/mapper.rb +1 -1
  141. data/lib/solargraph/yard_map/to_method.rb +11 -4
  142. data/lib/solargraph/yard_map.rb +1 -443
  143. data/lib/solargraph/yard_tags.rb +20 -0
  144. data/lib/solargraph/yardoc.rb +52 -0
  145. data/lib/solargraph.rb +8 -6
  146. data/solargraph.gemspec +19 -8
  147. metadata +164 -99
  148. data/.travis.yml +0 -19
  149. data/lib/solargraph/api_map/bundler_methods.rb +0 -22
  150. data/lib/solargraph/compat.rb +0 -37
  151. data/lib/solargraph/convention/rspec.rb +0 -30
  152. data/lib/solargraph/documentor.rb +0 -76
  153. data/lib/solargraph/language_server/host/cataloger.rb +0 -56
  154. data/lib/solargraph/parser/legacy/node_methods.rb +0 -325
  155. data/lib/solargraph/parser/legacy/node_processors/alias_node.rb +0 -23
  156. data/lib/solargraph/parser/legacy/node_processors/args_node.rb +0 -35
  157. data/lib/solargraph/parser/legacy/node_processors/begin_node.rb +0 -15
  158. data/lib/solargraph/parser/legacy/node_processors/cvasgn_node.rb +0 -23
  159. data/lib/solargraph/parser/legacy/node_processors/def_node.rb +0 -63
  160. data/lib/solargraph/parser/legacy/node_processors/sclass_node.rb +0 -21
  161. data/lib/solargraph/parser/legacy/node_processors.rb +0 -54
  162. data/lib/solargraph/parser/legacy.rb +0 -12
  163. data/lib/solargraph/parser/rubyvm/class_methods.rb +0 -144
  164. data/lib/solargraph/parser/rubyvm/node_chainer.rb +0 -160
  165. data/lib/solargraph/parser/rubyvm/node_methods.rb +0 -315
  166. data/lib/solargraph/parser/rubyvm/node_processors/args_node.rb +0 -85
  167. data/lib/solargraph/parser/rubyvm/node_processors/block_node.rb +0 -42
  168. data/lib/solargraph/parser/rubyvm/node_processors/casgn_node.rb +0 -22
  169. data/lib/solargraph/parser/rubyvm/node_processors/defs_node.rb +0 -57
  170. data/lib/solargraph/parser/rubyvm/node_processors/gvasgn_node.rb +0 -23
  171. data/lib/solargraph/parser/rubyvm/node_processors/ivasgn_node.rb +0 -38
  172. data/lib/solargraph/parser/rubyvm/node_processors/kw_arg_node.rb +0 -39
  173. data/lib/solargraph/parser/rubyvm/node_processors/lit_node.rb +0 -20
  174. data/lib/solargraph/parser/rubyvm/node_processors/lvasgn_node.rb +0 -27
  175. data/lib/solargraph/parser/rubyvm/node_processors/namespace_node.rb +0 -39
  176. data/lib/solargraph/parser/rubyvm/node_processors/opt_arg_node.rb +0 -26
  177. data/lib/solargraph/parser/rubyvm/node_processors/orasgn_node.rb +0 -15
  178. data/lib/solargraph/parser/rubyvm/node_processors/resbody_node.rb +0 -45
  179. data/lib/solargraph/parser/rubyvm/node_processors/sclass_node.rb +0 -21
  180. data/lib/solargraph/parser/rubyvm/node_processors/scope_node.rb +0 -15
  181. data/lib/solargraph/parser/rubyvm/node_processors/send_node.rb +0 -277
  182. data/lib/solargraph/parser/rubyvm/node_processors/sym_node.rb +0 -18
  183. data/lib/solargraph/parser/rubyvm/node_processors.rb +0 -63
  184. data/lib/solargraph/parser/rubyvm.rb +0 -40
  185. data/lib/solargraph/yard_map/core_docs.rb +0 -170
  186. data/lib/solargraph/yard_map/core_fills.rb +0 -208
  187. data/lib/solargraph/yard_map/core_gen.rb +0 -76
  188. data/lib/solargraph/yard_map/rdoc_to_yard.rb +0 -140
  189. data/lib/solargraph/yard_map/stdlib_fills.rb +0 -43
  190. data/lib/yard-solargraph.rb +0 -33
  191. data/yardoc/2.2.2.tar.gz +0 -0
@@ -3,7 +3,6 @@
3
3
  require 'diff/lcs'
4
4
  require 'observer'
5
5
  require 'securerandom'
6
- require 'set'
7
6
 
8
7
  module Solargraph
9
8
  module LanguageServer
@@ -13,7 +12,6 @@ module Solargraph
13
12
  #
14
13
  class Host
15
14
  autoload :Diagnoser, 'solargraph/language_server/host/diagnoser'
16
- autoload :Cataloger, 'solargraph/language_server/host/cataloger'
17
15
  autoload :Sources, 'solargraph/language_server/host/sources'
18
16
  autoload :Dispatch, 'solargraph/language_server/host/dispatch'
19
17
  autoload :MessageWorker, 'solargraph/language_server/host/message_worker'
@@ -44,8 +42,6 @@ module Solargraph
44
42
  return unless stopped?
45
43
  @stopped = false
46
44
  diagnoser.start
47
- cataloger.start
48
- sources.start
49
45
  message_worker.start
50
46
  end
51
47
 
@@ -59,7 +55,7 @@ module Solargraph
59
55
  logger.level = LOG_LEVELS[options['logLevel']] || DEFAULT_LOG_LEVEL
60
56
  end
61
57
 
62
- # @return [Hash]
58
+ # @return [Hash{String => [Boolean, String]}]
63
59
  def options
64
60
  @options ||= default_configuration
65
61
  end
@@ -101,8 +97,8 @@ module Solargraph
101
97
  # Start processing a request from the client. After the message is
102
98
  # processed, caller is responsible for sending the response.
103
99
  #
104
- # @param request [Hash] The contents of the message.
105
- # @return [Solargraph::LanguageServer::Message::Base] The message handler.
100
+ # @param request [Hash{String => unspecified}] The contents of the message.
101
+ # @return [Solargraph::LanguageServer::Message::Base, nil] The message handler.
106
102
  def receive request
107
103
  if request['method']
108
104
  logger.info "Server received #{request['method']}"
@@ -127,38 +123,44 @@ module Solargraph
127
123
  else
128
124
  logger.warn "Invalid message received."
129
125
  logger.debug request
126
+ nil
130
127
  end
131
128
  end
132
129
 
133
- # Respond to a notification that a file was created in the workspace.
134
- # The libraries will determine whether the file should be merged; see
130
+ # Respond to a notification that files were created in the workspace.
131
+ # The libraries will determine whether the files should be merged; see
135
132
  # Solargraph::Library#create_from_disk.
136
133
  #
137
- # @param uri [String] The file uri.
138
- # @return [Boolean] True if a library accepted the file.
139
- def create uri
140
- filename = uri_to_file(uri)
134
+ # @param uris [Array<String>] The URIs of the files.
135
+ # @return [Boolean] True if at least one library accepted at least one file.
136
+ def create *uris
137
+ filenames = uris.map { |uri| uri_to_file(uri) }
141
138
  result = false
142
139
  libraries.each do |lib|
143
- result = true if lib.create_from_disk(filename)
140
+ result = true if lib.create_from_disk(*filenames)
141
+ end
142
+ uris.each do |uri|
143
+ diagnoser.schedule uri if open?(uri)
144
144
  end
145
- diagnoser.schedule uri if open?(uri)
146
145
  result
147
146
  end
148
147
 
149
- # Delete the specified file from the library.
148
+ # Delete the specified files from the library.
150
149
  #
151
- # @param uri [String] The file uri.
150
+ # @param uris [Array<String>] The file uris.
152
151
  # @return [void]
153
- def delete uri
154
- filename = uri_to_file(uri)
152
+ def delete *uris
153
+ filenames = uris.map { |uri| uri_to_file(uri) }
155
154
  libraries.each do |lib|
156
- lib.delete(filename)
155
+ lib.delete_observer self
156
+ lib.delete(*filenames)
157
+ end
158
+ uris.each do |uri|
159
+ send_notification "textDocument/publishDiagnostics", {
160
+ uri: uri,
161
+ diagnostics: []
162
+ }
157
163
  end
158
- send_notification "textDocument/publishDiagnostics", {
159
- uri: uri,
160
- diagnostics: []
161
- }
162
164
  end
163
165
 
164
166
  # Open the specified file in the library.
@@ -249,7 +251,7 @@ module Solargraph
249
251
  # @return [void]
250
252
  def change params
251
253
  updater = generate_updater(params)
252
- sources.async_update params['textDocument']['uri'], updater
254
+ sources.update params['textDocument']['uri'], updater
253
255
  diagnoser.schedule params['textDocument']['uri']
254
256
  end
255
257
 
@@ -288,9 +290,11 @@ module Solargraph
288
290
  path = ''
289
291
  path = normalize_separators(directory) unless directory.nil?
290
292
  begin
291
- lib = Solargraph::Library.load(path, name)
293
+ workspace = Solargraph::Workspace.new(path, nil, options)
294
+ lib = Solargraph::Library.new(workspace, name)
295
+ lib.add_observer self
292
296
  libraries.push lib
293
- async_library_map lib
297
+ library_map lib
294
298
  rescue WorkspaceTooLargeError => e
295
299
  send_notification 'window/showMessage', {
296
300
  'type' => Solargraph::LanguageServer::MessageTypes::WARNING,
@@ -319,6 +323,7 @@ module Solargraph
319
323
  # @param lib [Library]
320
324
  libraries.delete_if do |lib|
321
325
  next false if lib.workspace.directory != directory
326
+ lib.delete_observer self
322
327
  true
323
328
  end
324
329
  end
@@ -453,9 +458,7 @@ module Solargraph
453
458
  return if @stopped
454
459
  @stopped = true
455
460
  message_worker.stop
456
- cataloger.stop
457
461
  diagnoser.stop
458
- sources.stop
459
462
  changed
460
463
  notify_observers
461
464
  end
@@ -488,6 +491,24 @@ module Solargraph
488
491
  end
489
492
  if params['data']['path']
490
493
  result.concat library.path_pins(params['data']['path'])
494
+ # @todo This exception is necessary because `Library#path_pins` does
495
+ # not perform a namespace method query, so the implicit `.new` pin
496
+ # might not exist.
497
+ if result.empty? && params['data']['path'] =~ /\.new$/
498
+ result.concat(library.path_pins(params['data']['path'].sub(/\.new$/, '#initialize')).map do |pin|
499
+ next pin unless pin.name == 'initialize'
500
+
501
+ Pin::Method.new(
502
+ name: 'new',
503
+ scope: :class,
504
+ location: pin.location,
505
+ parameters: pin.parameters,
506
+ return_type: ComplexType.try_parse(params['data']['path']),
507
+ comments: pin.comments,
508
+ closure: pin.closure
509
+ )
510
+ end)
511
+ end
491
512
  end
492
513
  # Selecting by both location and path can result in duplicate pins
493
514
  result.uniq { |p| [p.path, p.location] }
@@ -501,6 +522,8 @@ module Solargraph
501
522
  library.read_text(filename)
502
523
  end
503
524
 
525
+ # @param uri [String]
526
+ # @return [Hash]
504
527
  def formatter_config uri
505
528
  library = library_for(uri)
506
529
  library.workspace.config.formatter
@@ -529,6 +552,15 @@ module Solargraph
529
552
  library.definitions_at(uri_to_file(uri), line, column)
530
553
  end
531
554
 
555
+ # @param uri [String]
556
+ # @param line [Integer]
557
+ # @param column [Integer]
558
+ # @return [Array<Solargraph::Pin::Base>]
559
+ def type_definitions_at uri, line, column
560
+ library = library_for(uri)
561
+ library.type_definitions_at(uri_to_file(uri), line, column)
562
+ end
563
+
532
564
  # @param uri [String]
533
565
  # @param line [Integer]
534
566
  # @param column [Integer]
@@ -619,17 +651,18 @@ module Solargraph
619
651
  requests.keys
620
652
  end
621
653
 
622
- # @return [Hash{String => Object}]
654
+ # @return [Hash{String => [Boolean,String]}]
623
655
  def default_configuration
624
656
  {
625
657
  'completion' => true,
626
658
  'hover' => true,
627
659
  'symbols' => true,
628
660
  'definitions' => true,
661
+ 'typeDefinitions' => true,
629
662
  'rename' => true,
630
663
  'references' => true,
631
664
  'autoformat' => false,
632
- 'diagnostics' => false,
665
+ 'diagnostics' => true,
633
666
  'formatting' => false,
634
667
  'folding' => true,
635
668
  'highlights' => true,
@@ -649,10 +682,15 @@ module Solargraph
649
682
  libraries.each(&:catalog)
650
683
  end
651
684
 
685
+ # @return [Hash{String => Hash{String => Boolean}}]
652
686
  def client_capabilities
653
687
  @client_capabilities ||= {}
654
688
  end
655
689
 
690
+ def client_supports_progress?
691
+ client_capabilities['window'] && client_capabilities['window']['workDoneProgress']
692
+ end
693
+
656
694
  private
657
695
 
658
696
  # @return [MessageWorker]
@@ -665,15 +703,10 @@ module Solargraph
665
703
  @diagnoser ||= Diagnoser.new(self)
666
704
  end
667
705
 
668
- # @return [Cataloger]
669
- def cataloger
670
- @cataloger ||= Cataloger.new(self)
671
- end
672
-
673
706
  # A hash of client requests by ID. The host uses this to keep track of
674
707
  # pending responses.
675
708
  #
676
- # @return [Hash{Integer => Hash}]
709
+ # @return [Hash{Integer => Solargraph::LanguageServer::Host}]
677
710
  def requests
678
711
  @requests ||= {}
679
712
  end
@@ -692,7 +725,7 @@ module Solargraph
692
725
  params['contentChanges'].each do |recvd|
693
726
  chng = check_diff(params['textDocument']['uri'], recvd)
694
727
  changes.push Solargraph::Source::Change.new(
695
- (chng['range'].nil? ?
728
+ (chng['range'].nil? ?
696
729
  nil :
697
730
  Solargraph::Range.from_to(chng['range']['start']['line'], chng['range']['start']['character'], chng['range']['end']['line'], chng['range']['end']['character'])
698
731
  ),
@@ -765,6 +798,9 @@ module Solargraph
765
798
  'textDocument/definition' => {
766
799
  definitionProvider: true
767
800
  },
801
+ 'textDocument/typeDefinition' => {
802
+ typeDefinitionProvider: true
803
+ },
768
804
  'textDocument/references' => {
769
805
  referencesProvider: true
770
806
  },
@@ -796,69 +832,28 @@ module Solargraph
796
832
  client_capabilities['rename'] && client_capabilities['rename']['prepareSupport']
797
833
  end
798
834
 
799
- def client_supports_progress?
800
- client_capabilities['window'] && client_capabilities['window']['workDoneProgress']
801
- end
802
-
803
835
  # @param library [Library]
804
836
  # @return [void]
805
- def async_library_map library
837
+ def library_map library
806
838
  return if library.mapped?
807
- Thread.new do
808
- if client_supports_progress?
809
- uuid = SecureRandom.uuid
810
- send_request 'window/workDoneProgress/create', {
811
- token: uuid
812
- } do |response|
813
- do_async_library_map library, response.nil? ? uuid : nil
814
- end
815
- else
816
- do_async_library_map library
817
- end
818
- end
839
+ Thread.new { sync_library_map library }
819
840
  end
820
841
 
821
- def do_async_library_map library, uuid = nil
842
+ # @param library [Library]
843
+ # @param uuid [String, nil]
844
+ # @return [void]
845
+ def sync_library_map library
822
846
  total = library.workspace.sources.length
823
- if uuid
824
- send_notification '$/progress', {
825
- token: uuid,
826
- value: {
827
- kind: 'begin',
828
- title: "Mapping workspace",
829
- message: "0/#{total} files",
830
- cancellable: false,
831
- percentage: 0
832
- }
833
- }
834
- end
835
- pct = 0
836
- mod = 10
847
+ progress = Progress.new('Mapping workspace')
848
+ progress.begin "0/#{total} files", 0
849
+ progress.send self
837
850
  while library.next_map
838
- next unless uuid
839
- cur = ((library.source_map_hash.keys.length.to_f / total.to_f) * 100).to_i
840
- if cur > pct && cur % mod == 0
841
- pct = cur
842
- send_notification '$/progress', {
843
- token: uuid,
844
- value: {
845
- kind: 'report',
846
- cancellable: false,
847
- message: "#{library.source_map_hash.keys.length}/#{total} files",
848
- percentage: pct
849
- }
850
- }
851
- end
852
- end
853
- if uuid
854
- send_notification '$/progress', {
855
- token: uuid,
856
- value: {
857
- kind: 'end',
858
- message: 'Mapping complete'
859
- }
860
- }
851
+ pct = ((library.source_map_hash.keys.length.to_f / total) * 100).to_i
852
+ progress.report "#{library.source_map_hash.keys.length}/#{total} files", pct
853
+ progress.send self
861
854
  end
855
+ progress.finish 'done'
856
+ progress.send self
862
857
  end
863
858
  end
864
859
  end
@@ -16,7 +16,7 @@ module Solargraph
16
16
  # @return [String]
17
17
  attr_reader :method
18
18
 
19
- # @return [Hash]
19
+ # @return [Hash{String => Array, Hash, String, Integer}]
20
20
  attr_reader :params
21
21
 
22
22
  # @return [Hash, Array, nil]
@@ -29,7 +29,7 @@ module Solargraph
29
29
  end
30
30
 
31
31
  # @param text [String]
32
- # @return [Hash{Symbol => String}]
32
+ # @return [Hash{Symbol => String}, nil]
33
33
  def markup_content text
34
34
  return nil if text.strip.empty?
35
35
  {
@@ -38,6 +38,8 @@ module Solargraph
38
38
  }
39
39
  end
40
40
 
41
+ # @param pins [Array<Pin::Base>]
42
+ # @return [String]
41
43
  def join_docs pins
42
44
  result = []
43
45
  last_link = nil
@@ -1,6 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rubygems'
3
+
4
+ # @todo PR the RBS gem to add this
5
+ # @!parse
6
+ # module ::Gem
7
+ # class SpecFetcher; end
8
+ # end
4
9
 
5
10
  module Solargraph
6
11
  module LanguageServer
@@ -11,16 +16,23 @@ module Solargraph
11
16
  # is true, notify the client when the gem is up to date.
12
17
  #
13
18
  class CheckGemVersion < Base
19
+ # @return [Gem::SpecFetcher]
14
20
  def self.fetcher
15
21
  @fetcher ||= Gem::SpecFetcher.new
16
22
  end
17
23
 
24
+ # @param obj [Gem::SpecFetcher]
25
+ # @return [Gem::SpecFetcher]
18
26
  def self.fetcher= obj
19
27
  @fetcher = obj
20
28
  end
21
29
 
22
30
  GEM_ZERO = Gem::Version.new('0.0.0')
23
31
 
32
+ # @param host [Solargraph::LanguageServer::Host]
33
+ # @param request [Hash]
34
+ # @param current [Gem::Version]
35
+ # @param available [Gem::Version, nil]
24
36
  def initialize host, request, current: Gem::Version.new(Solargraph::VERSION), available: nil
25
37
  super(host, request)
26
38
  @current = current
@@ -10,11 +10,7 @@ module Solargraph
10
10
  #
11
11
  class DownloadCore < Base
12
12
  def process
13
- ver = Solargraph::YardMap::CoreDocs.best_download
14
- Solargraph::YardMap::CoreDocs.download ver
15
- host.show_message "Downloaded documentation for Ruby #{ver}.", LanguageServer::MessageTypes::INFO
16
- rescue StandardError => e
17
- host.show_message "An error occurred while downloading documentation: [#{e.class}] #{e.message}", LanguageServer::MessageTypes::ERROR
13
+ host.show_message "Downloading cores is deprecated. Solargraph currently uses RBS for core and stdlib documentation", LanguageServer::MessageTypes::INFO
18
14
  end
19
15
  end
20
16
  end
@@ -25,6 +25,8 @@ module Solargraph
25
25
  }
26
26
  }
27
27
  }
28
+ # FIXME: lsp default is utf-16, may have different position
29
+ result[:capabilities][:positionEncoding] = "utf-32" if params.dig("capabilities", "general", "positionEncodings")&.include?("utf-32")
28
30
  result[:capabilities].merge! static_completion unless dynamic_registration_for?('textDocument', 'completion')
29
31
  result[:capabilities].merge! static_signature_help unless dynamic_registration_for?('textDocument', 'signatureHelp')
30
32
  # result[:capabilities].merge! static_on_type_formatting unless dynamic_registration_for?('textDocument', 'onTypeFormatting')
@@ -32,6 +34,7 @@ module Solargraph
32
34
  result[:capabilities].merge! static_document_formatting unless dynamic_registration_for?('textDocument', 'formatting')
33
35
  result[:capabilities].merge! static_document_symbols unless dynamic_registration_for?('textDocument', 'documentSymbol')
34
36
  result[:capabilities].merge! static_definitions unless dynamic_registration_for?('textDocument', 'definition')
37
+ result[:capabilities].merge! static_type_definitions unless dynamic_registration_for?('textDocument', 'typeDefinition')
35
38
  result[:capabilities].merge! static_rename unless dynamic_registration_for?('textDocument', 'rename')
36
39
  result[:capabilities].merge! static_references unless dynamic_registration_for?('textDocument', 'references')
37
40
  result[:capabilities].merge! static_workspace_symbols unless dynamic_registration_for?('workspace', 'symbol')
@@ -44,6 +47,8 @@ module Solargraph
44
47
 
45
48
  private
46
49
 
50
+ # @todo '?' methods should type like RBS 'boolish' rather than a strict true or false
51
+ # @sg-ignore
47
52
  def support_workspace_folders?
48
53
  params['capabilities'] &&
49
54
  params['capabilities']['workspace'] &&
@@ -51,6 +56,7 @@ module Solargraph
51
56
  params['workspaceFolders']
52
57
  end
53
58
 
59
+ # @return [Hash{Symbol => undefined}]
54
60
  def static_completion
55
61
  return {} unless host.options['completion']
56
62
  {
@@ -61,6 +67,7 @@ module Solargraph
61
67
  }
62
68
  end
63
69
 
70
+ # @return [Hash{Symbol => BasicObject}]
64
71
  def static_code_action
65
72
  {
66
73
  codeActionProvider: true,
@@ -68,6 +75,7 @@ module Solargraph
68
75
  }
69
76
  end
70
77
 
78
+ # @return [Hash{Symbol => BasicObject}]
71
79
  def static_signature_help
72
80
  {
73
81
  signatureHelpProvider: {
@@ -76,6 +84,7 @@ module Solargraph
76
84
  }
77
85
  end
78
86
 
87
+ # @return [Hash{Symbol => Hash{Symbol => String, Array<String>}}]
79
88
  def static_on_type_formatting
80
89
  {
81
90
  documentOnTypeFormattingProvider: {
@@ -85,6 +94,7 @@ module Solargraph
85
94
  }
86
95
  end
87
96
 
97
+ # @return [Hash{Symbol => Boolean}]
88
98
  def static_hover
89
99
  return {} unless host.options['hover']
90
100
  {
@@ -92,6 +102,7 @@ module Solargraph
92
102
  }
93
103
  end
94
104
 
105
+ # @return [Hash{Symbol => Boolean}]
95
106
  def static_document_formatting
96
107
  return {} unless host.options['formatting']
97
108
  {
@@ -99,6 +110,7 @@ module Solargraph
99
110
  }
100
111
  end
101
112
 
113
+ # @return [Hash{Symbol => Boolean}]
102
114
  def static_document_symbols
103
115
  return {} unless host.options['symbols']
104
116
  {
@@ -106,12 +118,14 @@ module Solargraph
106
118
  }
107
119
  end
108
120
 
121
+ # @return [Hash{Symbol => Boolean}]
109
122
  def static_workspace_symbols
110
123
  {
111
124
  workspaceSymbolProvider: true
112
125
  }
113
126
  end
114
127
 
128
+ # @return [Hash{Symbol => Boolean}]
115
129
  def static_definitions
116
130
  return {} unless host.options['definitions']
117
131
  {
@@ -119,12 +133,23 @@ module Solargraph
119
133
  }
120
134
  end
121
135
 
136
+ # @return [Hash{Symbol => Boolean}]
137
+ def static_type_definitions
138
+ return {} unless host.options['typeDefinitions']
139
+ {
140
+ typeDefinitionProvider: true
141
+ }
142
+ end
143
+
144
+ # @return [Hash{Symbol => Hash{Symbol => Boolean}}]
122
145
  def static_rename
123
146
  {
124
147
  renameProvider: {prepareProvider: true}
125
148
  }
126
149
  end
127
150
 
151
+
152
+ # @return [Hash{Symbol => Boolean}]
128
153
  def static_references
129
154
  return {} unless host.options['references']
130
155
  {
@@ -132,6 +157,7 @@ module Solargraph
132
157
  }
133
158
  end
134
159
 
160
+ # @return [Hash{Symbol => Boolean}]
135
161
  def static_folding_range
136
162
  return {} unless host.options['folding']
137
163
  {
@@ -139,6 +165,7 @@ module Solargraph
139
165
  }
140
166
  end
141
167
 
168
+ # @return [Hash{Symbol => Boolean}]
142
169
  def static_highlights
143
170
  {
144
171
  documentHighlightProvider: true
@@ -13,6 +13,7 @@ module Solargraph
13
13
  textDocument/formatting
14
14
  textDocument/documentSymbol
15
15
  textDocument/definition
16
+ textDocument/typeDefinition
16
17
  textDocument/references
17
18
  textDocument/rename
18
19
  textDocument/prepareRename
@@ -6,6 +6,8 @@ class Solargraph::LanguageServer::Message::TextDocument::DocumentSymbol < Solarg
6
6
  def process
7
7
  pins = host.document_symbols params['textDocument']['uri']
8
8
  info = pins.map do |pin|
9
+ next nil unless pin.location&.filename
10
+
9
11
  result = {
10
12
  name: pin.name,
11
13
  containerName: pin.namespace,
@@ -17,7 +19,8 @@ class Solargraph::LanguageServer::Message::TextDocument::DocumentSymbol < Solarg
17
19
  deprecated: pin.deprecated?
18
20
  }
19
21
  result
20
- end
22
+ end.compact
23
+
21
24
  set_result info
22
25
  end
23
26
  end
@@ -17,17 +17,17 @@ module Solargraph
17
17
  args = cli_args(file_uri, config)
18
18
 
19
19
  require_rubocop(config['version'])
20
- options, paths = RuboCop::Options.new.parse(args)
20
+ options, paths = ::RuboCop::Options.new.parse(args)
21
21
  options[:stdin] = original
22
22
  corrections = redirect_stdout do
23
- RuboCop::Runner.new(options, RuboCop::ConfigStore.new).run(paths)
23
+ ::RuboCop::Runner.new(options, ::RuboCop::ConfigStore.new).run(paths)
24
24
  end
25
25
  result = options[:stdin]
26
26
 
27
27
  log_corrections(corrections)
28
28
 
29
29
  format original, result
30
- rescue RuboCop::ValidationError, RuboCop::ConfigNotFoundError => e
30
+ rescue ::RuboCop::ValidationError, ::RuboCop::ConfigNotFoundError => e
31
31
  set_error(Solargraph::LanguageServer::ErrorCodes::INTERNAL_ERROR, "[#{e.class}] #{e.message}")
32
32
  end
33
33
 
@@ -54,7 +54,7 @@ module Solargraph
54
54
  def cli_args file_uri, config
55
55
  file = UriHelpers.uri_to_file(file_uri)
56
56
  args = [
57
- config['cops'] == 'all' ? '--auto-correct-all' : '--auto-correct',
57
+ config['cops'] == 'all' ? '-A' : '-a',
58
58
  '--cache', 'false',
59
59
  '--format', formatter_class(config).name,
60
60
  ]
@@ -70,6 +70,7 @@ module Solargraph
70
70
 
71
71
  def formatter_class(config)
72
72
  if self.class.const_defined?('BlankRubocopFormatter')
73
+ # @sg-ignore
73
74
  BlankRubocopFormatter
74
75
  else
75
76
  require_rubocop(config['version'])
@@ -37,6 +37,8 @@ module Solargraph
37
37
 
38
38
  private
39
39
 
40
+ # @param contents [Array<String>]
41
+ # @return [Hash{Symbol => Hash{Symbol => String}}, nil]
40
42
  def contents_or_nil contents
41
43
  stripped = contents
42
44
  .map(&:strip)
@@ -9,13 +9,8 @@ module Solargraph
9
9
  line = params['position']['line']
10
10
  col = params['position']['character']
11
11
  suggestions = host.signatures_at(params['textDocument']['uri'], line, col)
12
- info = []
13
- suggestions.each do |pin|
14
- info.concat pin.overloads.map(&:signature_help)
15
- info.push pin.signature_help
16
- end
17
12
  set_result({
18
- signatures: info
13
+ signatures: suggestions.flat_map { |pin| pin.signature_help }
19
14
  })
20
15
  rescue FileNotFoundError => e
21
16
  Logging.logger.warn "[#{e.class}] #{e.message}"
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Solargraph::LanguageServer::Message::TextDocument
4
+ class TypeDefinition < Base
5
+ def process
6
+ @line = params['position']['line']
7
+ @column = params['position']['character']
8
+ set_result(code_location || [])
9
+ end
10
+
11
+ private
12
+
13
+ def code_location
14
+ suggestions = host.type_definitions_at(params['textDocument']['uri'], @line, @column)
15
+ return nil if suggestions.empty?
16
+ suggestions.reject { |pin| pin.location.nil? || pin.location.filename.nil? }.map do |pin|
17
+ {
18
+ uri: file_to_uri(pin.location.filename),
19
+ range: pin.location.range.to_hash
20
+ }
21
+ end
22
+ end
23
+ end
24
+ end