solargraph 0.61.0 → 0.62.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 (82) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/linting.yml +24 -2
  3. data/.github/workflows/plugins.yml +18 -0
  4. data/.github/workflows/rspec.yml +14 -1
  5. data/.github/workflows/typecheck.yml +6 -0
  6. data/CHANGELOG.md +38 -0
  7. data/lib/solargraph/api_map/index.rb +14 -3
  8. data/lib/solargraph/api_map/store.rb +6 -0
  9. data/lib/solargraph/api_map.rb +34 -2
  10. data/lib/solargraph/collection/gem.rb +12 -10
  11. data/lib/solargraph/collection.rb +0 -1
  12. data/lib/solargraph/complex_type/unique_type.rb +13 -0
  13. data/lib/solargraph/complex_type.rb +23 -3
  14. data/lib/solargraph/convention.rb +0 -4
  15. data/lib/solargraph/diagnostics/type_check.rb +0 -1
  16. data/lib/solargraph/external.rb +56 -28
  17. data/lib/solargraph/language_server/host/diagnoser.rb +1 -1
  18. data/lib/solargraph/language_server/host/dispatch.rb +4 -2
  19. data/lib/solargraph/language_server/host.rb +10 -2
  20. data/lib/solargraph/language_server/message/completion_item/resolve.rb +10 -3
  21. data/lib/solargraph/language_server/message/text_document/definition.rb +1 -1
  22. data/lib/solargraph/library.rb +19 -33
  23. data/lib/solargraph/parser/node_processor/base.rb +6 -0
  24. data/lib/solargraph/parser/parser_gem/node_methods.rb +29 -6
  25. data/lib/solargraph/parser/parser_gem/node_processors/class_definition/class_assignment_node.rb +98 -0
  26. data/lib/solargraph/parser/parser_gem/node_processors/class_definition.rb +54 -0
  27. data/lib/solargraph/parser/parser_gem/node_processors/cvasgn_node.rb +1 -0
  28. data/lib/solargraph/parser/parser_gem/node_processors/data_definition/data_assignment_node.rb +65 -0
  29. data/lib/solargraph/parser/parser_gem/node_processors/data_definition/data_definition_node.rb +97 -0
  30. data/lib/solargraph/parser/parser_gem/node_processors/data_definition.rb +110 -0
  31. data/lib/solargraph/parser/parser_gem/node_processors/gvasgn_node.rb +1 -0
  32. data/lib/solargraph/parser/parser_gem/node_processors/ivasgn_node.rb +2 -0
  33. data/lib/solargraph/parser/parser_gem/node_processors/lvasgn_node.rb +1 -0
  34. data/lib/solargraph/parser/parser_gem/node_processors/send_node.rb +185 -0
  35. data/lib/solargraph/parser/parser_gem/node_processors/struct_definition/struct_assignment_node.rb +66 -0
  36. data/lib/solargraph/parser/parser_gem/node_processors/struct_definition/struct_definition_node.rb +108 -0
  37. data/lib/solargraph/parser/parser_gem/node_processors/struct_definition.rb +170 -0
  38. data/lib/solargraph/parser/parser_gem/node_processors.rb +33 -29
  39. data/lib/solargraph/pin/base.rb +25 -1
  40. data/lib/solargraph/pin/base_variable.rb +31 -1
  41. data/lib/solargraph/pin/callable.rb +11 -2
  42. data/lib/solargraph/pin/delegated_method.rb +5 -0
  43. data/lib/solargraph/pin/duck_method.rb +36 -16
  44. data/lib/solargraph/pin/instance_variable.rb +45 -0
  45. data/lib/solargraph/pin/method.rb +10 -0
  46. data/lib/solargraph/pin/method_alias.rb +4 -0
  47. data/lib/solargraph/pin/parameter.rb +1 -1
  48. data/lib/solargraph/pin/reference/included_mixin.rb +22 -0
  49. data/lib/solargraph/pin/reference.rb +1 -0
  50. data/lib/solargraph/plugin/active_support.rb +100 -0
  51. data/lib/solargraph/plugin/addon.rb +16 -0
  52. data/lib/solargraph/plugin/base.rb +25 -0
  53. data/lib/solargraph/plugin/panel.rb +37 -0
  54. data/lib/solargraph/plugin.rb +26 -0
  55. data/lib/solargraph/rbs_collection.rb +119 -0
  56. data/lib/solargraph/rbs_map/conversions.rb +106 -47
  57. data/lib/solargraph/rbs_map/gem.rb +4 -1
  58. data/lib/solargraph/rbs_map/helpers.rb +7 -6
  59. data/lib/solargraph/rbs_translator.rb +105 -70
  60. data/lib/solargraph/repo.rb +1 -1
  61. data/lib/solargraph/source/chain/call.rb +32 -13
  62. data/lib/solargraph/source/node_map.rb +27 -0
  63. data/lib/solargraph/source.rb +17 -0
  64. data/lib/solargraph/source_map/call.rb +18 -0
  65. data/lib/solargraph/source_map/mapper.rb +1 -1
  66. data/lib/solargraph/source_map.rb +18 -4
  67. data/lib/solargraph/type_checker/rules.rb +2 -2
  68. data/lib/solargraph/type_checker.rb +4 -1
  69. data/lib/solargraph/version.rb +1 -1
  70. data/lib/solargraph/yard_map/macro.rb +51 -1
  71. data/lib/solargraph.rb +2 -0
  72. data/rbs/fills/boolean/0/boolean.rbs +12 -0
  73. data/solargraph.gemspec +1 -1
  74. metadata +21 -11
  75. data/lib/solargraph/collection/rbs.rb +0 -49
  76. data/lib/solargraph/convention/active_support_concern.rb +0 -111
  77. data/lib/solargraph/convention/data_definition/data_assignment_node.rb +0 -61
  78. data/lib/solargraph/convention/data_definition/data_definition_node.rb +0 -93
  79. data/lib/solargraph/convention/data_definition.rb +0 -108
  80. data/lib/solargraph/convention/struct_definition/struct_assignment_node.rb +0 -62
  81. data/lib/solargraph/convention/struct_definition/struct_definition_node.rb +0 -103
  82. data/lib/solargraph/convention/struct_definition.rb +0 -168
@@ -0,0 +1,12 @@
1
+ # Boolean is Solargraph's name for the RBS `bool` type. Store#get_superclass
2
+ # already gives TrueClass and FalseClass `Boolean` as their superclass, but
3
+ # nothing defined it, so it had no pin and carried only Object's methods.
4
+ #
5
+ # The members are the ones TrueClass and FalseClass share beyond Object.
6
+ class Boolean
7
+ def &: (untyped obj) -> bool
8
+
9
+ def ^: (untyped obj) -> bool
10
+
11
+ def |: (untyped obj) -> bool
12
+ end
data/solargraph.gemspec CHANGED
@@ -66,7 +66,7 @@ Gem::Specification.new do |s|
66
66
  # even more specific on RuboCop itself, which is written into _todo
67
67
  # file.
68
68
  s.add_development_dependency 'overcommit', '~> 0.71.0'
69
- s.add_development_dependency 'rubocop', '~> 1.80.0.0'
69
+ s.add_development_dependency 'rubocop', '~> 1.80'
70
70
  s.add_development_dependency 'rubocop-rake', '~> 0.7.1'
71
71
  s.add_development_dependency 'rubocop-rspec', '~> 3.6.0'
72
72
  s.add_development_dependency 'rubocop-yard', '~> 1.0.0'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solargraph
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.61.0
4
+ version: 0.62.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fred Snyder
@@ -433,14 +433,14 @@ dependencies:
433
433
  requirements:
434
434
  - - "~>"
435
435
  - !ruby/object:Gem::Version
436
- version: 1.80.0.0
436
+ version: '1.80'
437
437
  type: :development
438
438
  prerelease: false
439
439
  version_requirements: !ruby/object:Gem::Requirement
440
440
  requirements:
441
441
  - - "~>"
442
442
  - !ruby/object:Gem::Version
443
- version: 1.80.0.0
443
+ version: '1.80'
444
444
  - !ruby/object:Gem::Dependency
445
445
  name: rubocop-rake
446
446
  requirement: !ruby/object:Gem::Requirement
@@ -593,24 +593,16 @@ files:
593
593
  - lib/solargraph/collection/base.rb
594
594
  - lib/solargraph/collection/core.rb
595
595
  - lib/solargraph/collection/gem.rb
596
- - lib/solargraph/collection/rbs.rb
597
596
  - lib/solargraph/collection/stdlib.rb
598
597
  - lib/solargraph/complex_type.rb
599
598
  - lib/solargraph/complex_type/conformance.rb
600
599
  - lib/solargraph/complex_type/type_methods.rb
601
600
  - lib/solargraph/complex_type/unique_type.rb
602
601
  - lib/solargraph/convention.rb
603
- - lib/solargraph/convention/active_support_concern.rb
604
602
  - lib/solargraph/convention/base.rb
605
- - lib/solargraph/convention/data_definition.rb
606
- - lib/solargraph/convention/data_definition/data_assignment_node.rb
607
- - lib/solargraph/convention/data_definition/data_definition_node.rb
608
603
  - lib/solargraph/convention/gemfile.rb
609
604
  - lib/solargraph/convention/gemspec.rb
610
605
  - lib/solargraph/convention/rakefile.rb
611
- - lib/solargraph/convention/struct_definition.rb
612
- - lib/solargraph/convention/struct_definition/struct_assignment_node.rb
613
- - lib/solargraph/convention/struct_definition/struct_definition_node.rb
614
606
  - lib/solargraph/converters/dd.rb
615
607
  - lib/solargraph/converters/dl.rb
616
608
  - lib/solargraph/converters/dt.rb
@@ -709,7 +701,12 @@ files:
709
701
  - lib/solargraph/parser/parser_gem/node_processors/begin_node.rb
710
702
  - lib/solargraph/parser/parser_gem/node_processors/block_node.rb
711
703
  - lib/solargraph/parser/parser_gem/node_processors/casgn_node.rb
704
+ - lib/solargraph/parser/parser_gem/node_processors/class_definition.rb
705
+ - lib/solargraph/parser/parser_gem/node_processors/class_definition/class_assignment_node.rb
712
706
  - lib/solargraph/parser/parser_gem/node_processors/cvasgn_node.rb
707
+ - lib/solargraph/parser/parser_gem/node_processors/data_definition.rb
708
+ - lib/solargraph/parser/parser_gem/node_processors/data_definition/data_assignment_node.rb
709
+ - lib/solargraph/parser/parser_gem/node_processors/data_definition/data_definition_node.rb
713
710
  - lib/solargraph/parser/parser_gem/node_processors/def_node.rb
714
711
  - lib/solargraph/parser/parser_gem/node_processors/defs_node.rb
715
712
  - lib/solargraph/parser/parser_gem/node_processors/gvasgn_node.rb
@@ -724,6 +721,9 @@ files:
724
721
  - lib/solargraph/parser/parser_gem/node_processors/resbody_node.rb
725
722
  - lib/solargraph/parser/parser_gem/node_processors/sclass_node.rb
726
723
  - lib/solargraph/parser/parser_gem/node_processors/send_node.rb
724
+ - lib/solargraph/parser/parser_gem/node_processors/struct_definition.rb
725
+ - lib/solargraph/parser/parser_gem/node_processors/struct_definition/struct_assignment_node.rb
726
+ - lib/solargraph/parser/parser_gem/node_processors/struct_definition/struct_definition_node.rb
727
727
  - lib/solargraph/parser/parser_gem/node_processors/sym_node.rb
728
728
  - lib/solargraph/parser/parser_gem/node_processors/until_node.rb
729
729
  - lib/solargraph/parser/parser_gem/node_processors/when_node.rb
@@ -759,6 +759,7 @@ files:
759
759
  - lib/solargraph/pin/reference.rb
760
760
  - lib/solargraph/pin/reference/extend.rb
761
761
  - lib/solargraph/pin/reference/include.rb
762
+ - lib/solargraph/pin/reference/included_mixin.rb
762
763
  - lib/solargraph/pin/reference/override.rb
763
764
  - lib/solargraph/pin/reference/prepend.rb
764
765
  - lib/solargraph/pin/reference/require.rb
@@ -770,8 +771,14 @@ files:
770
771
  - lib/solargraph/pin/symbol.rb
771
772
  - lib/solargraph/pin/until.rb
772
773
  - lib/solargraph/pin/while.rb
774
+ - lib/solargraph/plugin.rb
775
+ - lib/solargraph/plugin/active_support.rb
776
+ - lib/solargraph/plugin/addon.rb
777
+ - lib/solargraph/plugin/base.rb
778
+ - lib/solargraph/plugin/panel.rb
773
779
  - lib/solargraph/position.rb
774
780
  - lib/solargraph/range.rb
781
+ - lib/solargraph/rbs_collection.rb
775
782
  - lib/solargraph/rbs_map.rb
776
783
  - lib/solargraph/rbs_map/base.rb
777
784
  - lib/solargraph/rbs_map/conversions.rb
@@ -808,9 +815,11 @@ files:
808
815
  - lib/solargraph/source/change.rb
809
816
  - lib/solargraph/source/cursor.rb
810
817
  - lib/solargraph/source/encoding_fixes.rb
818
+ - lib/solargraph/source/node_map.rb
811
819
  - lib/solargraph/source/source_chainer.rb
812
820
  - lib/solargraph/source/updater.rb
813
821
  - lib/solargraph/source_map.rb
822
+ - lib/solargraph/source_map/call.rb
814
823
  - lib/solargraph/source_map/clip.rb
815
824
  - lib/solargraph/source_map/completion.rb
816
825
  - lib/solargraph/source_map/data.rb
@@ -847,6 +856,7 @@ files:
847
856
  - lib/solargraph/yard_map/mapper/to_namespace.rb
848
857
  - lib/solargraph/yard_tags.rb
849
858
  - lib/solargraph/yardoc.rb
859
+ - rbs/fills/boolean/0/boolean.rbs
850
860
  - rbs/fills/bundler/0/bundler.rbs
851
861
  - rbs/fills/open3/0/open3.rbs
852
862
  - rbs/fills/rubygems/0/basic_specification.rbs
@@ -1,49 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'digest'
4
-
5
- module Solargraph
6
- module Collection
7
- # Cacheable pins from an RBS collection directory.
8
- #
9
- class Rbs < Base
10
- # @return [String]
11
- attr_reader :path
12
-
13
- # @param path [String]
14
- # @return [Array<Pin::Base>]
15
- def self.load path
16
- new(path).load
17
- end
18
-
19
- # @param path [String]
20
- def initialize path
21
- super()
22
- @path = path
23
- end
24
-
25
- # @return [Array<Pin::Base>]
26
- def pins
27
- @pins ||= RbsMap::Path.pins(path)
28
- end
29
-
30
- # @return [String]
31
- def cache_file
32
- File.join CacheDir.rbs_dir, "#{key}.ser"
33
- end
34
-
35
- private
36
-
37
- # A collection is rewritten in place by `rbs collection install`, so the
38
- # newest signature mtime distinguishes one installation from the next.
39
- #
40
- # @return [String]
41
- def key
42
- @key ||= begin
43
- stamp = Dir.glob(File.join(path, '**', '*.rbs')).map { |file| File.mtime(file).to_i }.max
44
- format('%.32s', Digest::SHA256.hexdigest("#{File.expand_path(path)}:#{stamp}"))
45
- end
46
- end
47
- end
48
- end
49
- end
@@ -1,111 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- module Convention
5
- # ActiveSupport::Concern is syntactic sugar for a common
6
- # pattern to include class methods while mixing-in a Module
7
- # See https://api.rubyonrails.org/classes/ActiveSupport/Concern.html
8
- class ActiveSupportConcern < Base
9
- include Logging
10
-
11
- # @return [Array<Pin::Base>]
12
- attr_reader :pins
13
-
14
- # @param api_map [ApiMap]
15
- # @param rooted_tag [String]
16
- # @param scope [Symbol] :class or :instance
17
- # @param visibility [Array<Symbol>] :public, :protected, and/or :private
18
- # @param deep [Boolean] whether to include methods from included modules
19
- # @param skip [Set<String>]
20
- # @param _no_core [Boolean]n whether to skip core methods
21
- def object api_map, rooted_tag, scope, visibility, deep, skip, _no_core
22
- moo = ObjectProcessor.new(api_map, rooted_tag, scope, visibility, deep, skip)
23
- moo.environ
24
- end
25
-
26
- # yard-activesupport-concern pulls methods inside
27
- # 'class_methods' blocks into main class visible from YARD
28
- #
29
- # @param _doc_map [DocMap]
30
- def global _doc_map
31
- Environ.new(yard_plugins: ['activesupport-concern'])
32
- end
33
-
34
- # Process an object to add any class methods brought in via
35
- # ActiveSupport::Concern
36
- class ObjectProcessor
37
- include Logging
38
-
39
- attr_reader :environ
40
-
41
- # @param api_map [ApiMap]
42
- # @param rooted_tag [String] the tag of the class or module being processed
43
- # @param scope [Symbol] :class or :instance
44
- # @param visibility [Array<Symbol>] :public, :protected, and/or :private
45
- # @param deep [Boolean] whether to include methods from included modules
46
- # @param skip [Set<String>] a set of tags to skip
47
- def initialize api_map, rooted_tag, scope, visibility, deep, skip
48
- @api_map = api_map
49
- @rooted_tag = rooted_tag
50
- @scope = scope
51
- @visibility = visibility
52
- @deep = deep
53
- @skip = skip
54
-
55
- @environ = Environ.new
56
- return unless scope == :class
57
-
58
- @rooted_type = ComplexType.parse(rooted_tag).force_rooted
59
- @fqns = rooted_type.namespace
60
- @namespace_pin = api_map.get_path_pins(fqns).select { |p| p.is_a?(Pin::Namespace) }.first
61
-
62
- api_map.get_includes(fqns).reverse.each do |include_tag|
63
- process_include include_tag
64
- end
65
- end
66
-
67
- private
68
-
69
- attr_reader :api_map, :rooted_tag, :rooted_type, :scope,
70
- :visibility, :deep, :skip, :namespace_pin,
71
- :fqns
72
-
73
- # @param include_tag [Pin::Reference::Include] the include reference pin
74
- #
75
- # @return [void]
76
- def process_include include_tag
77
- rooted_include_tag = api_map.dereference(include_tag)
78
- return if rooted_include_tag.nil?
79
- logger.debug do
80
- "ActiveSupportConcern#object(#{fqns}, #{scope}, #{visibility}, #{deep}) - " \
81
- "Handling class include include_tag=#{include_tag}"
82
- end
83
- module_extends = api_map.get_extends(rooted_include_tag).map(&:type).map(&:to_s)
84
- logger.debug do
85
- "ActiveSupportConcern#object(#{fqns}, #{scope}, #{visibility}, #{deep}) - " \
86
- "found module extends of #{rooted_include_tag}: #{module_extends}"
87
- end
88
- return unless module_extends.include? 'ActiveSupport::Concern'
89
- included_class_pins = api_map.inner_get_methods_from_reference(rooted_include_tag, namespace_pin, rooted_type,
90
- :class, visibility, deep, skip, true)
91
- logger.debug do
92
- "ActiveSupportConcern#object(#{fqns}, #{scope}, #{visibility}, #{deep}) - " \
93
- "Found #{included_class_pins.length} inluded class methods for #{rooted_include_tag}"
94
- end
95
- environ.pins.concat included_class_pins
96
- # another pattern is to put class methods inside a submodule
97
- classmethods_include_tag = "#{rooted_include_tag}::ClassMethods"
98
- included_classmethods_pins =
99
- api_map.inner_get_methods_from_reference(classmethods_include_tag, namespace_pin, rooted_type,
100
- :instance, visibility, deep, skip, true)
101
- logger.debug do
102
- "ActiveSupportConcern#object(#{fqns}, #{scope}, #{visibility}, #{deep}) - " \
103
- "Found #{included_classmethods_pins.length} included classmethod " \
104
- "class methods for #{classmethods_include_tag}"
105
- end
106
- environ.pins.concat included_classmethods_pins
107
- end
108
- end
109
- end
110
- end
111
- end
@@ -1,61 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- module Convention
5
- module DataDefinition
6
- # A node wrapper for a Data definition via const assignment.
7
- # @example
8
- # MyData = Data.new(:bar, :baz) do
9
- # def foo
10
- # end
11
- # end
12
- class DataAssignmentNode < DataDefintionNode
13
- class << self
14
- # @example
15
- # s(:casgn, nil, :Foo,
16
- # s(:block,
17
- # s(:send,
18
- # s(:const, nil, :Data), :define,
19
- # s(:sym, :bar),
20
- # s(:sym, :baz)),
21
- # s(:args),
22
- # s(:def, :foo,
23
- # s(:args),
24
- # s(:send, nil, :bar))))
25
- # @param node [::Parser::AST::Node]
26
- def match? node
27
- return false unless node&.type == :casgn
28
- return false if node.children[2].nil?
29
-
30
- data_node = if node.children[2].type == :block
31
- node.children[2].children[0]
32
- else
33
- node.children[2]
34
- end
35
-
36
- data_definition_node?(data_node)
37
- end
38
- end
39
-
40
- def class_name
41
- if node.children[0]
42
- Parser::NodeMethods.unpack_name(node.children[0]) + "::#{node.children[1]}"
43
- else
44
- node.children[1].to_s
45
- end
46
- end
47
-
48
- private
49
-
50
- # @return [Parser::AST::Node]
51
- def data_node
52
- if node.children[2].type == :block
53
- node.children[2].children[0]
54
- else
55
- node.children[2]
56
- end
57
- end
58
- end
59
- end
60
- end
61
- end
@@ -1,93 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- module Convention
5
- module DataDefinition
6
- # A node wrapper for a Data definition via inheritance.
7
- # @example
8
- # class MyData < Data.new(:bar, :baz)
9
- # def foo
10
- # end
11
- # end
12
- class DataDefintionNode
13
- class << self
14
- # @example
15
- # s(:class,
16
- # s(:const, nil, :Foo),
17
- # s(:send,
18
- # s(:const, nil, :Data), :define,
19
- # s(:sym, :bar),
20
- # s(:sym, :baz)),
21
- # s(:hash,
22
- # s(:pair,
23
- # s(:sym, :keyword_init),
24
- # s(:true)))),
25
- # s(:def, :foo,
26
- # s(:args),
27
- # s(:send, nil, :bar)))
28
- #
29
- # @param node [Parser::AST::Node]
30
- def match? node
31
- return false unless node&.type == :class
32
-
33
- data_definition_node?(node.children[1])
34
- end
35
-
36
- private
37
-
38
- # @param data_node [Parser::AST::Node]
39
- # @return [Boolean]
40
- def data_definition_node? data_node
41
- return false unless data_node.is_a?(::Parser::AST::Node)
42
- return false unless data_node&.type == :send
43
- return false unless data_node.children[0]&.type == :const
44
- return false unless data_node.children[0].children[1] == :Data
45
- return false unless data_node.children[1] == :define
46
-
47
- true
48
- end
49
- end
50
-
51
- # @param node [Parser::AST::Node]
52
- def initialize node
53
- @node = node
54
- end
55
-
56
- # @return [String]
57
- def class_name
58
- Parser::NodeMethods.unpack_name(node)
59
- end
60
-
61
- # @return [Array<Array(Parser::AST::Node, String)>]
62
- def attributes
63
- data_attribute_nodes.map do |data_def_param|
64
- next unless data_def_param.type == :sym
65
- [data_def_param, data_def_param.children[0].to_s]
66
- end.compact
67
- end
68
-
69
- # @return [Parser::AST::Node, nil]
70
- def body_node
71
- node.children[2]
72
- end
73
-
74
- private
75
-
76
- # @return [Parser::AST::Node]
77
- attr_reader :node
78
-
79
- # @return [Parser::AST::Node, nil]
80
- def data_node
81
- node.children[1]
82
- end
83
-
84
- # @sg-ignore Need to add nil check here
85
- # @return [Array<Parser::AST::Node>]
86
- def data_attribute_nodes
87
- # @sg-ignore Need to add nil check here
88
- data_node.children[2..]
89
- end
90
- end
91
- end
92
- end
93
- end
@@ -1,108 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- module Convention
5
- module DataDefinition
6
- autoload :DataDefintionNode, 'solargraph/convention/data_definition/data_definition_node'
7
- autoload :DataAssignmentNode, 'solargraph/convention/data_definition/data_assignment_node'
8
-
9
- module NodeProcessors
10
- class DataNode < Parser::NodeProcessor::Base
11
- # @return [Boolean] continue processing the next processor of the same node.
12
- def process
13
- return true if data_definition_node.nil?
14
-
15
- loc = get_node_location(node)
16
- nspin = Solargraph::Pin::Namespace.new(
17
- type: :class,
18
- location: loc,
19
- closure: region.closure,
20
- # @sg-ignore flow sensitive typing needs to handle attrs
21
- name: data_definition_node.class_name,
22
- comments: comments_for(node),
23
- visibility: :public,
24
- gates: region.closure.gates.freeze
25
- )
26
- pins.push nspin
27
-
28
- # define initialize method
29
- initialize_method_pin = Pin::Method.new(
30
- name: 'initialize',
31
- parameters: [],
32
- scope: :instance,
33
- location: get_node_location(node),
34
- closure: nspin,
35
- visibility: :private,
36
- comments: comments_for(node)
37
- )
38
-
39
- # @todo Support both arg and kwarg initializers for Data.define
40
- # Solargraph::SourceMap::Clip#complete_keyword_parameters does not seem to currently take into account [Pin::Method#signatures] hence we only one for :kwarg
41
- pins.push initialize_method_pin
42
-
43
- # @sg-ignore flow sensitive typing needs to handle attrs
44
- data_definition_node.attributes.map do |attribute_node, attribute_name|
45
- initialize_method_pin.parameters.push(
46
- Pin::Parameter.new(
47
- name: attribute_name,
48
- decl: :kwarg,
49
- location: get_node_location(attribute_node),
50
- closure: initialize_method_pin
51
- )
52
- )
53
- end
54
-
55
- # define attribute readers and instance variables
56
- # @sg-ignore flow sensitive typing needs to handle attrs
57
- data_definition_node.attributes.each do |attribute_node, attribute_name|
58
- name = attribute_name.to_s
59
- method_pin = Pin::Method.new(
60
- name: name,
61
- parameters: [],
62
- scope: :instance,
63
- location: get_node_location(attribute_node),
64
- closure: nspin,
65
- comments: attribute_comments(attribute_node, attribute_name),
66
- visibility: :public
67
- )
68
-
69
- pins.push method_pin
70
-
71
- pins.push Pin::InstanceVariable.new(name: "@#{attribute_name}",
72
- closure: method_pin,
73
- location: get_node_location(attribute_node),
74
- comments: attribute_comments(attribute_node, attribute_name))
75
- end
76
-
77
- process_children region.update(closure: nspin, visibility: :public)
78
-
79
- false
80
- end
81
-
82
- private
83
-
84
- # @return [DataDefinition::DataDefintionNode, DataDefinition::DataAssignmentNode, nil]
85
- def data_definition_node
86
- @data_definition_node ||= if DataDefintionNode.match?(node)
87
- DataDefintionNode.new(node)
88
- elsif DataAssignmentNode.match?(node)
89
- DataAssignmentNode.new(node)
90
- end
91
- end
92
-
93
- # @param attribute_node [Parser::AST::Node]
94
- # @param attribute_name [String]
95
- # @return [String, nil]
96
- def attribute_comments attribute_node, attribute_name
97
- data_comments = comments_for(attribute_node)
98
- return if data_comments.nil? || data_comments.empty?
99
-
100
- data_comments.split("\n").find do |row|
101
- row.include?(attribute_name)
102
- end&.gsub('@param', '@return')&.gsub(attribute_name, '')
103
- end
104
- end
105
- end
106
- end
107
- end
108
- end
@@ -1,62 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- module Convention
5
- module StructDefinition
6
- # A node wrapper for a Struct definition via const assignment.
7
- # @example
8
- # MyStruct = Struct.new(:bar, :baz) do
9
- # def foo
10
- # end
11
- # end
12
- class StructAssignmentNode < StructDefintionNode
13
- class << self
14
- # @example
15
- # s(:casgn, nil, :Foo,
16
- # s(:block,
17
- # s(:send,
18
- # s(:const, nil, :Struct), :new,
19
- # s(:sym, :bar),
20
- # s(:sym, :baz)),
21
- # s(:args),
22
- # s(:def, :foo,
23
- # s(:args),
24
- # s(:send, nil, :bar))))
25
- #
26
- # @param node [Parser::AST::Node]
27
- def match? node
28
- return false unless node&.type == :casgn
29
- return false if node.children[2].nil?
30
-
31
- struct_node = if node.children[2].type == :block
32
- node.children[2].children[0]
33
- else
34
- node.children[2]
35
- end
36
-
37
- struct_definition_node?(struct_node)
38
- end
39
- end
40
-
41
- def class_name
42
- if node.children[0]
43
- Parser::NodeMethods.unpack_name(node.children[0]) + "::#{node.children[1]}"
44
- else
45
- node.children[1].to_s
46
- end
47
- end
48
-
49
- private
50
-
51
- # @return [Parser::AST::Node]
52
- def struct_node
53
- if node.children[2].type == :block
54
- node.children[2].children[0]
55
- else
56
- node.children[2]
57
- end
58
- end
59
- end
60
- end
61
- end
62
- end