solargraph 0.59.1 → 0.59.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 (42) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/linting.yml +6 -0
  3. data/.github/workflows/plugins.yml +8 -0
  4. data/.github/workflows/typecheck.yml +2 -0
  5. data/CHANGELOG.md +7 -0
  6. data/lib/solargraph/api_map/store.rb +1 -2
  7. data/lib/solargraph/api_map.rb +4 -6
  8. data/lib/solargraph/complex_type/type_methods.rb +1 -0
  9. data/lib/solargraph/complex_type/unique_type.rb +12 -13
  10. data/lib/solargraph/complex_type.rb +1 -0
  11. data/lib/solargraph/convention/active_support_concern.rb +111 -111
  12. data/lib/solargraph/convention/base.rb +50 -50
  13. data/lib/solargraph/diagnostics.rb +55 -55
  14. data/lib/solargraph/environ.rb +52 -52
  15. data/lib/solargraph/gem_pins.rb +0 -11
  16. data/lib/solargraph/language_server/message/extended/environment.rb +25 -25
  17. data/lib/solargraph/language_server/message/initialized.rb +28 -28
  18. data/lib/solargraph/language_server/message/text_document.rb +28 -28
  19. data/lib/solargraph/language_server/progress.rb +143 -143
  20. data/lib/solargraph/language_server/transport/adapter.rb +68 -68
  21. data/lib/solargraph/language_server.rb +20 -20
  22. data/lib/solargraph/parser/parser_gem/node_chainer.rb +1 -0
  23. data/lib/solargraph/parser/parser_gem/node_processors/alias_node.rb +24 -24
  24. data/lib/solargraph/parser/parser_gem/node_processors/casgn_node.rb +36 -36
  25. data/lib/solargraph/parser/parser_gem/node_processors/cvasgn_node.rb +24 -24
  26. data/lib/solargraph/parser/parser_gem/node_processors/gvasgn_node.rb +24 -24
  27. data/lib/solargraph/parser/parser_gem/node_processors/sym_node.rb +20 -20
  28. data/lib/solargraph/pin/reference/require.rb +14 -14
  29. data/lib/solargraph/pin/singleton.rb +11 -11
  30. data/lib/solargraph/rbs_map/conversions.rb +14 -7
  31. data/lib/solargraph/shell.rb +1 -1
  32. data/lib/solargraph/source/chain/array.rb +1 -12
  33. data/lib/solargraph/source/chain/block_symbol.rb +13 -13
  34. data/lib/solargraph/source/chain/block_variable.rb +13 -13
  35. data/lib/solargraph/source/chain/head.rb +19 -19
  36. data/lib/solargraph/source/chain/literal.rb +18 -14
  37. data/lib/solargraph/source/source_chainer.rb +4 -4
  38. data/lib/solargraph/version.rb +1 -1
  39. data/lib/solargraph/yard_map/cache.rb +25 -25
  40. data/lib/solargraph/yard_map/mapper/to_constant.rb +28 -28
  41. metadata +1 -2
  42. data/rbs/fills/tuple/tuple.rbs +0 -177
@@ -1,68 +1,68 @@
1
- # frozen_string_literal: true
2
-
3
- require 'backport'
4
-
5
- module Solargraph
6
- module LanguageServer
7
- module Transport
8
- # A common module for running language servers in Backport.
9
- #
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]
22
- def opening
23
- @host = Solargraph::LanguageServer::Host.new
24
- @host.add_observer self
25
- @host.start
26
- @data_reader = Solargraph::LanguageServer::Transport::DataReader.new
27
- @data_reader.set_message_handler do |message|
28
- process message
29
- end
30
- end
31
-
32
- # @return [void]
33
- def closing
34
- @host.stop
35
- end
36
-
37
- # @param data [String]
38
- # @return [void]
39
- def receiving data
40
- @data_reader.receive data
41
- end
42
-
43
- # @return [void]
44
- def update
45
- if @host.stopped?
46
- shutdown
47
- else
48
- tmp = @host.flush
49
- write tmp unless tmp.empty?
50
- end
51
- end
52
-
53
- private
54
-
55
- # @param request [Hash]
56
- # @return [void]
57
- def process request
58
- @host.process(request)
59
- end
60
-
61
- # @return [void]
62
- def shutdown
63
- Backport.stop unless @host.options['transport'] == 'external'
64
- end
65
- end
66
- end
67
- end
68
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'backport'
4
+
5
+ module Solargraph
6
+ module LanguageServer
7
+ module Transport
8
+ # A common module for running language servers in Backport.
9
+ #
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]
22
+ def opening
23
+ @host = Solargraph::LanguageServer::Host.new
24
+ @host.add_observer self
25
+ @host.start
26
+ @data_reader = Solargraph::LanguageServer::Transport::DataReader.new
27
+ @data_reader.set_message_handler do |message|
28
+ process message
29
+ end
30
+ end
31
+
32
+ # @return [void]
33
+ def closing
34
+ @host.stop
35
+ end
36
+
37
+ # @param data [String]
38
+ # @return [void]
39
+ def receiving data
40
+ @data_reader.receive data
41
+ end
42
+
43
+ # @return [void]
44
+ def update
45
+ if @host.stopped?
46
+ shutdown
47
+ else
48
+ tmp = @host.flush
49
+ write tmp unless tmp.empty?
50
+ end
51
+ end
52
+
53
+ private
54
+
55
+ # @param request [Hash]
56
+ # @return [void]
57
+ def process request
58
+ @host.process(request)
59
+ end
60
+
61
+ # @return [void]
62
+ def shutdown
63
+ Backport.stop unless @host.options['transport'] == 'external'
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -1,20 +1,20 @@
1
- # frozen_string_literal: true
2
-
3
- require 'solargraph/language_server/error_codes'
4
- require 'solargraph/language_server/completion_item_kinds'
5
- require 'solargraph/language_server/symbol_kinds'
6
-
7
- module Solargraph
8
- # The LanguageServer namespace contains the classes and modules that compose
9
- # concrete implementations of language servers.
10
- #
11
- module LanguageServer
12
- autoload :Host, 'solargraph/language_server/host'
13
- autoload :Message, 'solargraph/language_server/message'
14
- autoload :UriHelpers, 'solargraph/language_server/uri_helpers'
15
- autoload :MessageTypes, 'solargraph/language_server/message_types'
16
- autoload :Request, 'solargraph/language_server/request'
17
- autoload :Transport, 'solargraph/language_server/transport'
18
- autoload :Progress, 'solargraph/language_server/progress'
19
- end
20
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'solargraph/language_server/error_codes'
4
+ require 'solargraph/language_server/completion_item_kinds'
5
+ require 'solargraph/language_server/symbol_kinds'
6
+
7
+ module Solargraph
8
+ # The LanguageServer namespace contains the classes and modules that compose
9
+ # concrete implementations of language servers.
10
+ #
11
+ module LanguageServer
12
+ autoload :Host, 'solargraph/language_server/host'
13
+ autoload :Message, 'solargraph/language_server/message'
14
+ autoload :UriHelpers, 'solargraph/language_server/uri_helpers'
15
+ autoload :MessageTypes, 'solargraph/language_server/message_types'
16
+ autoload :Request, 'solargraph/language_server/request'
17
+ autoload :Transport, 'solargraph/language_server/transport'
18
+ autoload :Progress, 'solargraph/language_server/progress'
19
+ end
20
+ end
@@ -153,6 +153,7 @@ module Solargraph
153
153
  else
154
154
  lit = infer_literal_node_type(n)
155
155
  result.push(lit ? Chain::Literal.new(lit, n) : Chain::Link.new)
156
+ # result.push Chain::Link.new
156
157
  end
157
158
  result
158
159
  end
@@ -1,24 +1,24 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- module Parser
5
- module ParserGem
6
- module NodeProcessors
7
- class AliasNode < Parser::NodeProcessor::Base
8
- def process
9
- loc = get_node_location(node)
10
- pins.push Solargraph::Pin::MethodAlias.new(
11
- location: loc,
12
- closure: region.closure,
13
- name: node.children[0].children[0].to_s,
14
- original: node.children[1].children[0].to_s,
15
- scope: region.scope || :instance,
16
- source: :parser
17
- )
18
- process_children
19
- end
20
- end
21
- end
22
- end
23
- end
24
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Solargraph
4
+ module Parser
5
+ module ParserGem
6
+ module NodeProcessors
7
+ class AliasNode < Parser::NodeProcessor::Base
8
+ def process
9
+ loc = get_node_location(node)
10
+ pins.push Solargraph::Pin::MethodAlias.new(
11
+ location: loc,
12
+ closure: region.closure,
13
+ name: node.children[0].children[0].to_s,
14
+ original: node.children[1].children[0].to_s,
15
+ scope: region.scope || :instance,
16
+ source: :parser
17
+ )
18
+ process_children
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,36 +1,36 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- module Parser
5
- module ParserGem
6
- module NodeProcessors
7
- class CasgnNode < Parser::NodeProcessor::Base
8
- include ParserGem::NodeMethods
9
-
10
- def process
11
- pins.push Solargraph::Pin::Constant.new(
12
- location: get_node_location(node),
13
- closure: region.closure,
14
- name: const_name,
15
- comments: comments_for(node),
16
- assignment: node.children[2],
17
- source: :parser
18
- )
19
- process_children
20
- end
21
-
22
- private
23
-
24
- # @return [String]
25
- def const_name
26
- if node.children[0]
27
- Parser::NodeMethods.unpack_name(node.children[0]) + "::#{node.children[1]}"
28
- else
29
- node.children[1].to_s
30
- end
31
- end
32
- end
33
- end
34
- end
35
- end
36
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Solargraph
4
+ module Parser
5
+ module ParserGem
6
+ module NodeProcessors
7
+ class CasgnNode < Parser::NodeProcessor::Base
8
+ include ParserGem::NodeMethods
9
+
10
+ def process
11
+ pins.push Solargraph::Pin::Constant.new(
12
+ location: get_node_location(node),
13
+ closure: region.closure,
14
+ name: const_name,
15
+ comments: comments_for(node),
16
+ assignment: node.children[2],
17
+ source: :parser
18
+ )
19
+ process_children
20
+ end
21
+
22
+ private
23
+
24
+ # @return [String]
25
+ def const_name
26
+ if node.children[0]
27
+ Parser::NodeMethods.unpack_name(node.children[0]) + "::#{node.children[1]}"
28
+ else
29
+ node.children[1].to_s
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -1,24 +1,24 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- module Parser
5
- module ParserGem
6
- module NodeProcessors
7
- class CvasgnNode < Parser::NodeProcessor::Base
8
- def process
9
- loc = get_node_location(node)
10
- pins.push Solargraph::Pin::ClassVariable.new(
11
- location: loc,
12
- closure: region.closure,
13
- name: node.children[0].to_s,
14
- comments: comments_for(node),
15
- assignment: node.children[1],
16
- source: :parser
17
- )
18
- process_children
19
- end
20
- end
21
- end
22
- end
23
- end
24
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Solargraph
4
+ module Parser
5
+ module ParserGem
6
+ module NodeProcessors
7
+ class CvasgnNode < Parser::NodeProcessor::Base
8
+ def process
9
+ loc = get_node_location(node)
10
+ pins.push Solargraph::Pin::ClassVariable.new(
11
+ location: loc,
12
+ closure: region.closure,
13
+ name: node.children[0].to_s,
14
+ comments: comments_for(node),
15
+ assignment: node.children[1],
16
+ source: :parser
17
+ )
18
+ process_children
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,24 +1,24 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- module Parser
5
- module ParserGem
6
- module NodeProcessors
7
- class GvasgnNode < Parser::NodeProcessor::Base
8
- def process
9
- loc = get_node_location(node)
10
- pins.push Solargraph::Pin::GlobalVariable.new(
11
- location: loc,
12
- closure: region.closure,
13
- name: node.children[0].to_s,
14
- comments: comments_for(node),
15
- assignment: node.children[1],
16
- source: :parser
17
- )
18
- process_children
19
- end
20
- end
21
- end
22
- end
23
- end
24
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Solargraph
4
+ module Parser
5
+ module ParserGem
6
+ module NodeProcessors
7
+ class GvasgnNode < Parser::NodeProcessor::Base
8
+ def process
9
+ loc = get_node_location(node)
10
+ pins.push Solargraph::Pin::GlobalVariable.new(
11
+ location: loc,
12
+ closure: region.closure,
13
+ name: node.children[0].to_s,
14
+ comments: comments_for(node),
15
+ assignment: node.children[1],
16
+ source: :parser
17
+ )
18
+ process_children
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,20 +1,20 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- module Parser
5
- module ParserGem
6
- module NodeProcessors
7
- class SymNode < Parser::NodeProcessor::Base
8
- # @return [void]
9
- def process
10
- pins.push Solargraph::Pin::Symbol.new(
11
- get_node_location(node),
12
- ":#{node.children[0]}",
13
- source: :parser
14
- )
15
- end
16
- end
17
- end
18
- end
19
- end
20
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Solargraph
4
+ module Parser
5
+ module ParserGem
6
+ module NodeProcessors
7
+ class SymNode < Parser::NodeProcessor::Base
8
+ # @return [void]
9
+ def process
10
+ pins.push Solargraph::Pin::Symbol.new(
11
+ get_node_location(node),
12
+ ":#{node.children[0]}",
13
+ source: :parser
14
+ )
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,14 +1,14 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- module Pin
5
- class Reference
6
- class Require < Reference
7
- def initialize location, name, **splat
8
- # super(location, '', name)
9
- super(location: location, name: name, closure: Pin::ROOT_PIN, **splat)
10
- end
11
- end
12
- end
13
- end
14
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Solargraph
4
+ module Pin
5
+ class Reference
6
+ class Require < Reference
7
+ def initialize location, name, **splat
8
+ # super(location, '', name)
9
+ super(location: location, name: name, closure: Pin::ROOT_PIN, **splat)
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,11 +1,11 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- module Pin
5
- class Singleton < Closure
6
- def initialize name: '', location: nil, closure: nil, **splat
7
- super
8
- end
9
- end
10
- end
11
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Solargraph
4
+ module Pin
5
+ class Singleton < Closure
6
+ def initialize name: '', location: nil, closure: nil, **splat
7
+ super
8
+ end
9
+ end
10
+ end
11
+ end
@@ -552,16 +552,19 @@ module Solargraph
552
552
  # @param pin [Pin::Method]
553
553
  # @return [void]
554
554
  def method_def_to_sigs decl, pin
555
+ # rubocop:disable Style/SafeNavigationChainLength
556
+ implicit_nil = decl.overloads.first&.annotations&.map(&:string)&.include?('implicitly-returns-nil') || false
557
+ # rubocop:enable Style/SafeNavigationChainLength
555
558
  # @param overload [RBS::AST::Members::MethodDefinition::Overload]
556
559
  decl.overloads.map do |overload|
557
560
  # @sg-ignore Wrong argument type for Solargraph::RbsMap::Conversions#location_decl_to_pin_location:
558
561
  # location expected RBS::Location, nil, received RBS::Location<:type, :type_params>, RBS::AST::Members::Attribute::loc, nil
559
562
  type_location = location_decl_to_pin_location(overload.method_type.location)
560
563
  generics = type_parameter_names(overload.method_type)
561
- signature_parameters, signature_return_type = parts_of_function(overload.method_type, pin)
564
+ signature_parameters, signature_return_type = parts_of_function(overload.method_type, pin, implicit_nil)
562
565
  rbs_block = overload.method_type.block
563
566
  block = if rbs_block
564
- block_parameters, block_return_type = parts_of_function(rbs_block, pin)
567
+ block_parameters, block_return_type = parts_of_function(rbs_block, pin, implicit_nil)
565
568
  Pin::Signature.new(generics: generics, parameters: block_parameters,
566
569
  return_type: block_return_type, source: :rbs,
567
570
  type_location: type_location, closure: pin)
@@ -588,14 +591,15 @@ module Solargraph
588
591
 
589
592
  # @param type [RBS::MethodType, RBS::Types::Block]
590
593
  # @param pin [Pin::Method]
594
+ # @param implicit_nil [Boolean]
591
595
  # @return [Array(Array<Pin::Parameter>, ComplexType)]
592
- def parts_of_function type, pin
596
+ def parts_of_function type, pin, implicit_nil
593
597
  type_location = pin.type_location
594
598
  if defined?(RBS::Types::UntypedFunction) && type.type.is_a?(RBS::Types::UntypedFunction)
595
599
  return [
596
600
  [Solargraph::Pin::Parameter.new(decl: :restarg, name: 'arg', closure: pin, source: :rbs,
597
601
  type_location: type_location)],
598
- method_type_to_type(type)
602
+ method_type_to_type(type, implicit_nil)
599
603
  ]
600
604
  end
601
605
 
@@ -659,7 +663,7 @@ module Solargraph
659
663
  source: :rbs, type_location: type_location)
660
664
  end
661
665
 
662
- return_type = method_type_to_type(type)
666
+ return_type = method_type_to_type(type, implicit_nil)
663
667
  [parameters, return_type]
664
668
  end
665
669
 
@@ -842,9 +846,12 @@ module Solargraph
842
846
  end
843
847
 
844
848
  # @param type [RBS::MethodType, RBS::Types::Block]
849
+ # @param implicit_nil [Boolean]
845
850
  # @return [ComplexType, ComplexType::UniqueType]
846
- def method_type_to_type type
847
- other_type_to_type type.type.return_type
851
+ def method_type_to_type type, implicit_nil
852
+ tag = other_type_to_type type.type.return_type
853
+ return ComplexType.parse("#{tag}, nil") if tag && implicit_nil
854
+ tag
848
855
  end
849
856
 
850
857
  # @param type [RBS::Types::Bases::Base,Object] RBS type object.
@@ -188,7 +188,7 @@ module Solargraph
188
188
  names.each do |name|
189
189
  if name == 'core'
190
190
  # @sg-ignore cache_core and core? are dynamically defined
191
- PinCache.cache_core(out: $stdout) if !PinCache.core? || options[:rebuild]
191
+ PinCache.cache_core(out: $stdout) # if !PinCache.core? || options[:rebuild]
192
192
  next
193
193
  end
194
194
 
@@ -19,18 +19,7 @@ module Solargraph
19
19
  # @param name_pin [Pin::Base]
20
20
  # @param locals [::Array<Pin::Parameter, Pin::LocalVariable>]
21
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
22
+ type = ComplexType::UniqueType.new('Array', rooted: true)
34
23
  [Pin::ProxyType.anonymous(type, source: :chain)]
35
24
  end
36
25
  end
@@ -1,13 +1,13 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- class Source
5
- class Chain
6
- class BlockSymbol < Link
7
- def resolve api_map, name_pin, locals
8
- [Pin::ProxyType.anonymous(ComplexType.try_parse('::Proc'), source: :chain)]
9
- end
10
- end
11
- end
12
- end
13
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Solargraph
4
+ class Source
5
+ class Chain
6
+ class BlockSymbol < Link
7
+ def resolve api_map, name_pin, locals
8
+ [Pin::ProxyType.anonymous(ComplexType.try_parse('::Proc'), source: :chain)]
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,13 +1,13 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- class Source
5
- class Chain
6
- class BlockVariable < Link
7
- def resolve api_map, name_pin, locals
8
- [Pin::ProxyType.anonymous(ComplexType.try_parse('::Proc'), source: :chain)]
9
- end
10
- end
11
- end
12
- end
13
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Solargraph
4
+ class Source
5
+ class Chain
6
+ class BlockVariable < Link
7
+ def resolve api_map, name_pin, locals
8
+ [Pin::ProxyType.anonymous(ComplexType.try_parse('::Proc'), source: :chain)]
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end