solargraph 0.47.2 → 0.53.3

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 (185) 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 +137 -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 +60 -20
  12. data/lib/solargraph/api_map/source_to_yard.rb +17 -10
  13. data/lib/solargraph/api_map/store.rb +60 -12
  14. data/lib/solargraph/api_map.rb +171 -99
  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 +61 -12
  18. data/lib/solargraph/complex_type/unique_type.rb +193 -16
  19. data/lib/solargraph/complex_type.rb +113 -10
  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 +171 -0
  30. data/lib/solargraph/gem_pins.rb +64 -0
  31. data/lib/solargraph/language_server/host/cataloger.rb +2 -1
  32. data/lib/solargraph/language_server/host/diagnoser.rb +2 -2
  33. data/lib/solargraph/language_server/host/dispatch.rb +15 -5
  34. data/lib/solargraph/language_server/host/message_worker.rb +4 -0
  35. data/lib/solargraph/language_server/host/sources.rb +7 -4
  36. data/lib/solargraph/language_server/host.rb +50 -26
  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 +13 -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 +4 -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/transport/adapter.rb +16 -1
  52. data/lib/solargraph/language_server/transport/data_reader.rb +2 -0
  53. data/lib/solargraph/library.rb +124 -37
  54. data/lib/solargraph/location.rb +1 -0
  55. data/lib/solargraph/page.rb +6 -0
  56. data/lib/solargraph/parser/comment_ripper.rb +4 -0
  57. data/lib/solargraph/parser/node_methods.rb +47 -7
  58. data/lib/solargraph/parser/node_processor/base.rb +9 -0
  59. data/lib/solargraph/parser/{legacy → parser_gem}/class_methods.rb +31 -5
  60. data/lib/solargraph/parser/{legacy → parser_gem}/flawed_builder.rb +3 -1
  61. data/lib/solargraph/parser/{legacy → parser_gem}/node_chainer.rb +57 -41
  62. data/lib/solargraph/parser/parser_gem/node_methods.rb +499 -0
  63. data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/alias_node.rb +1 -1
  64. data/lib/solargraph/parser/parser_gem/node_processors/args_node.rb +53 -0
  65. data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/begin_node.rb +1 -1
  66. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/block_node.rb +3 -2
  67. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/casgn_node.rb +14 -4
  68. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/cvasgn_node.rb +1 -1
  69. data/lib/solargraph/parser/{rubyvm → parser_gem}/node_processors/def_node.rb +7 -20
  70. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/defs_node.rb +2 -2
  71. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/gvasgn_node.rb +1 -1
  72. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/ivasgn_node.rb +2 -2
  73. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/lvasgn_node.rb +2 -2
  74. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/namespace_node.rb +2 -2
  75. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/orasgn_node.rb +1 -1
  76. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/resbody_node.rb +3 -3
  77. data/lib/solargraph/parser/parser_gem/node_processors/sclass_node.rb +42 -0
  78. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/send_node.rb +2 -2
  79. data/lib/solargraph/parser/{legacy → parser_gem}/node_processors/sym_node.rb +1 -1
  80. data/lib/solargraph/parser/parser_gem/node_processors.rb +54 -0
  81. data/lib/solargraph/parser/parser_gem.rb +12 -0
  82. data/lib/solargraph/parser/region.rb +1 -1
  83. data/lib/solargraph/parser/snippet.rb +2 -0
  84. data/lib/solargraph/parser.rb +9 -10
  85. data/lib/solargraph/pin/base.rb +69 -11
  86. data/lib/solargraph/pin/base_variable.rb +8 -4
  87. data/lib/solargraph/pin/block.rb +21 -28
  88. data/lib/solargraph/pin/closure.rb +17 -2
  89. data/lib/solargraph/pin/common.rb +7 -3
  90. data/lib/solargraph/pin/conversions.rb +34 -8
  91. data/lib/solargraph/pin/delegated_method.rb +97 -0
  92. data/lib/solargraph/pin/documenting.rb +25 -34
  93. data/lib/solargraph/pin/instance_variable.rb +4 -0
  94. data/lib/solargraph/pin/local_variable.rb +13 -1
  95. data/lib/solargraph/pin/method.rb +270 -16
  96. data/lib/solargraph/pin/namespace.rb +17 -1
  97. data/lib/solargraph/pin/parameter.rb +52 -17
  98. data/lib/solargraph/pin/reference/override.rb +2 -2
  99. data/lib/solargraph/pin/reference.rb +8 -0
  100. data/lib/solargraph/pin/search.rb +4 -4
  101. data/lib/solargraph/pin/signature.rb +143 -0
  102. data/lib/solargraph/pin.rb +2 -1
  103. data/lib/solargraph/range.rb +4 -6
  104. data/lib/solargraph/rbs_map/conversions.rb +601 -0
  105. data/lib/solargraph/rbs_map/core_fills.rb +47 -0
  106. data/lib/solargraph/rbs_map/core_map.rb +28 -0
  107. data/lib/solargraph/rbs_map/stdlib_map.rb +33 -0
  108. data/lib/solargraph/rbs_map.rb +84 -0
  109. data/lib/solargraph/shell.rb +69 -48
  110. data/lib/solargraph/source/chain/array.rb +32 -0
  111. data/lib/solargraph/source/chain/block_symbol.rb +13 -0
  112. data/lib/solargraph/source/chain/call.rb +125 -61
  113. data/lib/solargraph/source/chain/constant.rb +15 -1
  114. data/lib/solargraph/source/chain/if.rb +23 -0
  115. data/lib/solargraph/source/chain/link.rb +8 -2
  116. data/lib/solargraph/source/chain/or.rb +1 -1
  117. data/lib/solargraph/source/chain/z_super.rb +3 -3
  118. data/lib/solargraph/source/chain.rb +44 -14
  119. data/lib/solargraph/source/change.rb +3 -0
  120. data/lib/solargraph/source/cursor.rb +2 -0
  121. data/lib/solargraph/source/source_chainer.rb +8 -5
  122. data/lib/solargraph/source.rb +18 -19
  123. data/lib/solargraph/source_map/clip.rb +30 -23
  124. data/lib/solargraph/source_map/mapper.rb +20 -5
  125. data/lib/solargraph/source_map.rb +28 -13
  126. data/lib/solargraph/type_checker/checks.rb +10 -2
  127. data/lib/solargraph/type_checker.rb +201 -98
  128. data/lib/solargraph/version.rb +1 -1
  129. data/lib/solargraph/views/environment.erb +2 -2
  130. data/lib/solargraph/workspace/config.rb +14 -11
  131. data/lib/solargraph/workspace.rb +28 -17
  132. data/lib/solargraph/yard_map/cache.rb +6 -0
  133. data/lib/solargraph/yard_map/helpers.rb +1 -1
  134. data/lib/solargraph/yard_map/mapper/to_method.rb +18 -5
  135. data/lib/solargraph/yard_map/mapper.rb +1 -1
  136. data/lib/solargraph/yard_map/to_method.rb +11 -4
  137. data/lib/solargraph/yard_map.rb +1 -443
  138. data/lib/solargraph/yard_tags.rb +20 -0
  139. data/lib/solargraph/yardoc.rb +52 -0
  140. data/lib/solargraph.rb +8 -6
  141. data/solargraph.gemspec +19 -8
  142. metadata +162 -98
  143. data/.travis.yml +0 -19
  144. data/lib/solargraph/api_map/bundler_methods.rb +0 -22
  145. data/lib/solargraph/compat.rb +0 -37
  146. data/lib/solargraph/convention/rspec.rb +0 -30
  147. data/lib/solargraph/documentor.rb +0 -76
  148. data/lib/solargraph/parser/legacy/node_methods.rb +0 -325
  149. data/lib/solargraph/parser/legacy/node_processors/alias_node.rb +0 -23
  150. data/lib/solargraph/parser/legacy/node_processors/args_node.rb +0 -35
  151. data/lib/solargraph/parser/legacy/node_processors/begin_node.rb +0 -15
  152. data/lib/solargraph/parser/legacy/node_processors/def_node.rb +0 -63
  153. data/lib/solargraph/parser/legacy/node_processors/sclass_node.rb +0 -21
  154. data/lib/solargraph/parser/legacy/node_processors.rb +0 -54
  155. data/lib/solargraph/parser/legacy.rb +0 -12
  156. data/lib/solargraph/parser/rubyvm/class_methods.rb +0 -144
  157. data/lib/solargraph/parser/rubyvm/node_chainer.rb +0 -160
  158. data/lib/solargraph/parser/rubyvm/node_methods.rb +0 -315
  159. data/lib/solargraph/parser/rubyvm/node_processors/args_node.rb +0 -85
  160. data/lib/solargraph/parser/rubyvm/node_processors/block_node.rb +0 -42
  161. data/lib/solargraph/parser/rubyvm/node_processors/casgn_node.rb +0 -22
  162. data/lib/solargraph/parser/rubyvm/node_processors/cvasgn_node.rb +0 -23
  163. data/lib/solargraph/parser/rubyvm/node_processors/defs_node.rb +0 -57
  164. data/lib/solargraph/parser/rubyvm/node_processors/gvasgn_node.rb +0 -23
  165. data/lib/solargraph/parser/rubyvm/node_processors/ivasgn_node.rb +0 -38
  166. data/lib/solargraph/parser/rubyvm/node_processors/kw_arg_node.rb +0 -39
  167. data/lib/solargraph/parser/rubyvm/node_processors/lit_node.rb +0 -20
  168. data/lib/solargraph/parser/rubyvm/node_processors/lvasgn_node.rb +0 -27
  169. data/lib/solargraph/parser/rubyvm/node_processors/namespace_node.rb +0 -39
  170. data/lib/solargraph/parser/rubyvm/node_processors/opt_arg_node.rb +0 -26
  171. data/lib/solargraph/parser/rubyvm/node_processors/orasgn_node.rb +0 -15
  172. data/lib/solargraph/parser/rubyvm/node_processors/resbody_node.rb +0 -45
  173. data/lib/solargraph/parser/rubyvm/node_processors/sclass_node.rb +0 -21
  174. data/lib/solargraph/parser/rubyvm/node_processors/scope_node.rb +0 -15
  175. data/lib/solargraph/parser/rubyvm/node_processors/send_node.rb +0 -277
  176. data/lib/solargraph/parser/rubyvm/node_processors/sym_node.rb +0 -18
  177. data/lib/solargraph/parser/rubyvm/node_processors.rb +0 -63
  178. data/lib/solargraph/parser/rubyvm.rb +0 -40
  179. data/lib/solargraph/yard_map/core_docs.rb +0 -170
  180. data/lib/solargraph/yard_map/core_fills.rb +0 -208
  181. data/lib/solargraph/yard_map/core_gen.rb +0 -76
  182. data/lib/solargraph/yard_map/rdoc_to_yard.rb +0 -140
  183. data/lib/solargraph/yard_map/stdlib_fills.rb +0 -43
  184. data/lib/yard-solargraph.rb +0 -33
  185. 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
@@ -59,7 +58,7 @@ module Solargraph
59
58
  logger.level = LOG_LEVELS[options['logLevel']] || DEFAULT_LOG_LEVEL
60
59
  end
61
60
 
62
- # @return [Hash]
61
+ # @return [Hash{String => [Boolean, String]}]
63
62
  def options
64
63
  @options ||= default_configuration
65
64
  end
@@ -101,8 +100,8 @@ module Solargraph
101
100
  # Start processing a request from the client. After the message is
102
101
  # processed, caller is responsible for sending the response.
103
102
  #
104
- # @param request [Hash] The contents of the message.
105
- # @return [Solargraph::LanguageServer::Message::Base] The message handler.
103
+ # @param request [Hash{String => unspecified}] The contents of the message.
104
+ # @return [Solargraph::LanguageServer::Message::Base, nil] The message handler.
106
105
  def receive request
107
106
  if request['method']
108
107
  logger.info "Server received #{request['method']}"
@@ -127,38 +126,43 @@ module Solargraph
127
126
  else
128
127
  logger.warn "Invalid message received."
129
128
  logger.debug request
129
+ nil
130
130
  end
131
131
  end
132
132
 
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
133
+ # Respond to a notification that files were created in the workspace.
134
+ # The libraries will determine whether the files should be merged; see
135
135
  # Solargraph::Library#create_from_disk.
136
136
  #
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)
137
+ # @param uris [Array<String>] The URIs of the files.
138
+ # @return [Boolean] True if at least one library accepted at least one file.
139
+ def create *uris
140
+ filenames = uris.map { |uri| uri_to_file(uri) }
141
141
  result = false
142
142
  libraries.each do |lib|
143
- result = true if lib.create_from_disk(filename)
143
+ result = true if lib.create_from_disk(*filenames)
144
+ end
145
+ uris.each do |uri|
146
+ diagnoser.schedule uri if open?(uri)
144
147
  end
145
- diagnoser.schedule uri if open?(uri)
146
148
  result
147
149
  end
148
150
 
149
- # Delete the specified file from the library.
151
+ # Delete the specified files from the library.
150
152
  #
151
- # @param uri [String] The file uri.
153
+ # @param uris [Array<String>] The file uris.
152
154
  # @return [void]
153
- def delete uri
154
- filename = uri_to_file(uri)
155
+ def delete *uris
156
+ filenames = uris.map { |uri| uri_to_file(uri) }
155
157
  libraries.each do |lib|
156
- lib.delete(filename)
158
+ lib.delete(*filenames)
159
+ end
160
+ uris.each do |uri|
161
+ send_notification "textDocument/publishDiagnostics", {
162
+ uri: uri,
163
+ diagnostics: []
164
+ }
157
165
  end
158
- send_notification "textDocument/publishDiagnostics", {
159
- uri: uri,
160
- diagnostics: []
161
- }
162
166
  end
163
167
 
164
168
  # Open the specified file in the library.
@@ -288,7 +292,8 @@ module Solargraph
288
292
  path = ''
289
293
  path = normalize_separators(directory) unless directory.nil?
290
294
  begin
291
- lib = Solargraph::Library.load(path, name)
295
+ workspace = Solargraph::Workspace.new(path, nil, options)
296
+ lib = Solargraph::Library.new(workspace, name)
292
297
  libraries.push lib
293
298
  async_library_map lib
294
299
  rescue WorkspaceTooLargeError => e
@@ -501,6 +506,8 @@ module Solargraph
501
506
  library.read_text(filename)
502
507
  end
503
508
 
509
+ # @param uri [String]
510
+ # @return [Hash]
504
511
  def formatter_config uri
505
512
  library = library_for(uri)
506
513
  library.workspace.config.formatter
@@ -529,6 +536,15 @@ module Solargraph
529
536
  library.definitions_at(uri_to_file(uri), line, column)
530
537
  end
531
538
 
539
+ # @param uri [String]
540
+ # @param line [Integer]
541
+ # @param column [Integer]
542
+ # @return [Array<Solargraph::Pin::Base>]
543
+ def type_definitions_at uri, line, column
544
+ library = library_for(uri)
545
+ library.type_definitions_at(uri_to_file(uri), line, column)
546
+ end
547
+
532
548
  # @param uri [String]
533
549
  # @param line [Integer]
534
550
  # @param column [Integer]
@@ -619,17 +635,18 @@ module Solargraph
619
635
  requests.keys
620
636
  end
621
637
 
622
- # @return [Hash{String => Object}]
638
+ # @return [Hash{String => [Boolean,String]}]
623
639
  def default_configuration
624
640
  {
625
641
  'completion' => true,
626
642
  'hover' => true,
627
643
  'symbols' => true,
628
644
  'definitions' => true,
645
+ 'typeDefinitions' => true,
629
646
  'rename' => true,
630
647
  'references' => true,
631
648
  'autoformat' => false,
632
- 'diagnostics' => false,
649
+ 'diagnostics' => true,
633
650
  'formatting' => false,
634
651
  'folding' => true,
635
652
  'highlights' => true,
@@ -649,6 +666,7 @@ module Solargraph
649
666
  libraries.each(&:catalog)
650
667
  end
651
668
 
669
+ # @return [Hash{String => BasicObject}]
652
670
  def client_capabilities
653
671
  @client_capabilities ||= {}
654
672
  end
@@ -673,7 +691,7 @@ module Solargraph
673
691
  # A hash of client requests by ID. The host uses this to keep track of
674
692
  # pending responses.
675
693
  #
676
- # @return [Hash{Integer => Hash}]
694
+ # @return [Hash{Integer => Solargraph::LanguageServer::Host}]
677
695
  def requests
678
696
  @requests ||= {}
679
697
  end
@@ -692,7 +710,7 @@ module Solargraph
692
710
  params['contentChanges'].each do |recvd|
693
711
  chng = check_diff(params['textDocument']['uri'], recvd)
694
712
  changes.push Solargraph::Source::Change.new(
695
- (chng['range'].nil? ?
713
+ (chng['range'].nil? ?
696
714
  nil :
697
715
  Solargraph::Range.from_to(chng['range']['start']['line'], chng['range']['start']['character'], chng['range']['end']['line'], chng['range']['end']['character'])
698
716
  ),
@@ -765,6 +783,9 @@ module Solargraph
765
783
  'textDocument/definition' => {
766
784
  definitionProvider: true
767
785
  },
786
+ 'textDocument/typeDefinition' => {
787
+ typeDefinitionProvider: true
788
+ },
768
789
  'textDocument/references' => {
769
790
  referencesProvider: true
770
791
  },
@@ -818,6 +839,9 @@ module Solargraph
818
839
  end
819
840
  end
820
841
 
842
+ # @param library [Library]
843
+ # @param uuid [String, nil]
844
+ # @return [void]
821
845
  def do_async_library_map library, uuid = nil
822
846
  total = library.workspace.sources.length
823
847
  if uuid
@@ -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')
@@ -51,6 +54,7 @@ module Solargraph
51
54
  params['workspaceFolders']
52
55
  end
53
56
 
57
+ # @return [Hash{Symbol => undefined}]
54
58
  def static_completion
55
59
  return {} unless host.options['completion']
56
60
  {
@@ -61,6 +65,7 @@ module Solargraph
61
65
  }
62
66
  end
63
67
 
68
+ # @return [Hash{Symbol => BasicObject}]
64
69
  def static_code_action
65
70
  {
66
71
  codeActionProvider: true,
@@ -68,6 +73,7 @@ module Solargraph
68
73
  }
69
74
  end
70
75
 
76
+ # @return [Hash{Symbol => BasicObject}]
71
77
  def static_signature_help
72
78
  {
73
79
  signatureHelpProvider: {
@@ -119,6 +125,13 @@ module Solargraph
119
125
  }
120
126
  end
121
127
 
128
+ def static_type_definitions
129
+ return {} unless host.options['typeDefinitions']
130
+ {
131
+ typeDefinitionProvider: true
132
+ }
133
+ end
134
+
122
135
  def static_rename
123
136
  {
124
137
  renameProvider: {prepareProvider: 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
  ]
@@ -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
@@ -12,9 +12,9 @@ module Solargraph
12
12
  autoload :DidSave, 'solargraph/language_server/message/text_document/did_save'
13
13
  autoload :Hover, 'solargraph/language_server/message/text_document/hover'
14
14
  autoload :SignatureHelp, 'solargraph/language_server/message/text_document/signature_help'
15
- autoload :DiagnosticsQueue, 'solargraph/language_server/message/text_document/diagnostics_queue'
16
15
  autoload :OnTypeFormatting, 'solargraph/language_server/message/text_document/on_type_formatting'
17
16
  autoload :Definition, 'solargraph/language_server/message/text_document/definition'
17
+ autoload :TypeDefinition, 'solargraph/language_server/message/text_document/type_definition'
18
18
  autoload :DocumentSymbol, 'solargraph/language_server/message/text_document/document_symbol'
19
19
  autoload :Formatting, 'solargraph/language_server/message/text_document/formatting'
20
20
  autoload :References, 'solargraph/language_server/message/text_document/references'
@@ -11,8 +11,12 @@ module Solargraph::LanguageServer::Message::Workspace
11
11
 
12
12
  private
13
13
 
14
+ # @return [void]
14
15
  def register_from_options
16
+ Solargraph.logger.debug "Registering capabilities from options: #{host.options.inspect}"
17
+ # @type [Array<String>]
15
18
  y = []
19
+ # @type [Array<String>]
16
20
  n = []
17
21
  (host.options['completion'] ? y : n).push('textDocument/completion')
18
22
  (host.options['hover'] ? y : n).push('textDocument/hover', 'textDocument/signatureHelp')
@@ -20,6 +24,7 @@ module Solargraph::LanguageServer::Message::Workspace
20
24
  (host.options['formatting'] ? y : n).push('textDocument/formatting')
21
25
  (host.options['symbols'] ? y : n).push('textDocument/documentSymbol', 'workspace/symbol')
22
26
  (host.options['definitions'] ? y : n).push('textDocument/definition')
27
+ (host.options['typeDefinitions'] ? y : n).push('textDocument/typeDefinition')
23
28
  (host.options['references'] ? y : n).push('textDocument/references')
24
29
  (host.options['folding'] ? y : n).push('textDocument/folding')
25
30
  (host.options['highlights'] ? y : n).push('textDocument/documentHighlight')
@@ -10,22 +10,29 @@ module Solargraph::LanguageServer::Message::Workspace
10
10
 
11
11
  def process
12
12
  need_catalog = false
13
+ to_create = []
14
+ to_delete = []
15
+
13
16
  # @param change [Hash]
14
17
  params['changes'].each do |change|
15
18
  if change['type'] == CREATED
16
- host.create change['uri']
19
+ to_create << change['uri']
17
20
  need_catalog = true
18
21
  elsif change['type'] == CHANGED
19
22
  next if host.open?(change['uri'])
20
- host.create change['uri']
23
+ to_create << change['uri']
21
24
  need_catalog = true
22
25
  elsif change['type'] == DELETED
23
- host.delete change['uri']
26
+ to_delete << change['uri']
24
27
  need_catalog = true
25
28
  else
26
29
  set_error Solargraph::LanguageServer::ErrorCodes::INVALID_PARAMS, "Unknown change type ##{change['type']} for #{uri_to_file(change['uri'])}"
27
30
  end
28
31
  end
32
+
33
+ host.create *to_create
34
+ host.delete *to_delete
35
+
29
36
  # Force host to catalog libraries after file changes (see castwide/solargraph#139)
30
37
  host.catalog if need_catalog
31
38
  end
@@ -66,6 +66,7 @@ module Solargraph
66
66
  register 'textDocument/didClose', TextDocument::DidClose
67
67
  register 'textDocument/hover', TextDocument::Hover
68
68
  register 'textDocument/definition', TextDocument::Definition
69
+ register 'textDocument/typeDefinition', TextDocument::TypeDefinition
69
70
  register 'textDocument/formatting', TextDocument::Formatting
70
71
  register 'textDocument/onTypeFormatting', TextDocument::OnTypeFormatting
71
72
  register 'textDocument/documentSymbol', TextDocument::DocumentSymbol
@@ -8,6 +8,17 @@ module Solargraph
8
8
  # A common module for running language servers in Backport.
9
9
  #
10
10
  module Adapter
11
+ # This runs in the context of Backport::Adapter, which
12
+ # provides write() - but if we didn't hide this behind a parse
13
+ # tag, it would override the one in the class.
14
+ #
15
+ # @!method write(text)
16
+ # @abstract
17
+ # Write the change to the specified text.
18
+ # @param text [String] The text to be changed.
19
+ # @return [String] The updated text.
20
+
21
+ # @return [void]
11
22
  def opening
12
23
  @host = Solargraph::LanguageServer::Host.new
13
24
  @host.add_observer self
@@ -18,15 +29,18 @@ module Solargraph
18
29
  end
19
30
  end
20
31
 
32
+ # @return [void]
21
33
  def closing
22
34
  @host.stop
23
35
  end
24
36
 
25
37
  # @param data [String]
38
+ # @return [void]
26
39
  def receiving data
27
40
  @data_reader.receive data
28
41
  end
29
42
 
43
+ # @return [void]
30
44
  def update
31
45
  if @host.stopped?
32
46
  shutdown
@@ -38,12 +52,13 @@ module Solargraph
38
52
 
39
53
  private
40
54
 
41
- # @param request [String]
55
+ # @param request [Hash]
42
56
  # @return [void]
43
57
  def process request
44
58
  @host.process(request)
45
59
  end
46
60
 
61
+ # @return [void]
47
62
  def shutdown
48
63
  Backport.stop unless @host.options['transport'] == 'external'
49
64
  end
@@ -16,6 +16,7 @@ module Solargraph
16
16
  # client.
17
17
  #
18
18
  # @yieldparam [Hash] The message received from the client
19
+ # @return [void]
19
20
  def set_message_handler &block
20
21
  @message_handler = block
21
22
  end
@@ -26,6 +27,7 @@ module Solargraph
26
27
  # will be buffered and subsequent data will be appended to the buffer.
27
28
  #
28
29
  # @param data [String]
30
+ # @return [void]
29
31
  def receive data
30
32
  data.each_char do |char|
31
33
  @buffer.concat char