solargraph 0.39.16 → 0.40.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +4 -8
  3. data/CHANGELOG.md +998 -0
  4. data/SPONSORS.md +1 -0
  5. data/lib/solargraph.rb +2 -4
  6. data/lib/solargraph/api_map.rb +61 -63
  7. data/lib/solargraph/api_map/cache.rb +2 -2
  8. data/lib/solargraph/api_map/store.rb +3 -7
  9. data/lib/solargraph/{bundle.rb → bench.rb} +6 -2
  10. data/lib/solargraph/compat.rb +14 -0
  11. data/lib/solargraph/convention.rb +13 -4
  12. data/lib/solargraph/convention/base.rb +16 -8
  13. data/lib/solargraph/convention/gemfile.rb +2 -5
  14. data/lib/solargraph/convention/gemspec.rb +3 -6
  15. data/lib/solargraph/convention/rspec.rb +3 -6
  16. data/lib/solargraph/diagnostics/rubocop_helpers.rb +1 -20
  17. data/lib/solargraph/environ.rb +11 -6
  18. data/lib/solargraph/language_server/host.rb +5 -0
  19. data/lib/solargraph/language_server/message/extended/check_gem_version.rb +6 -1
  20. data/lib/solargraph/language_server/message/text_document/definition.rb +1 -1
  21. data/lib/solargraph/language_server/message/text_document/formatting.rb +47 -20
  22. data/lib/solargraph/library.rb +6 -8
  23. data/lib/solargraph/parser/legacy/node_methods.rb +9 -0
  24. data/lib/solargraph/parser/legacy/node_processors/ivasgn_node.rb +1 -1
  25. data/lib/solargraph/parser/legacy/node_processors/send_node.rb +34 -22
  26. data/lib/solargraph/parser/node_processor/base.rb +3 -0
  27. data/lib/solargraph/parser/rubyvm/node_methods.rb +18 -1
  28. data/lib/solargraph/parser/rubyvm/node_processors/args_node.rb +1 -1
  29. data/lib/solargraph/parser/rubyvm/node_processors/ivasgn_node.rb +1 -1
  30. data/lib/solargraph/parser/rubyvm/node_processors/send_node.rb +38 -28
  31. data/lib/solargraph/pin.rb +0 -3
  32. data/lib/solargraph/pin/common.rb +1 -1
  33. data/lib/solargraph/pin/conversions.rb +1 -1
  34. data/lib/solargraph/pin/documenting.rb +3 -9
  35. data/lib/solargraph/pin/method.rb +141 -7
  36. data/lib/solargraph/pin/method_alias.rb +1 -1
  37. data/lib/solargraph/position.rb +2 -14
  38. data/lib/solargraph/source.rb +10 -6
  39. data/lib/solargraph/source/chain.rb +3 -3
  40. data/lib/solargraph/source_map.rb +4 -1
  41. data/lib/solargraph/source_map/clip.rb +3 -2
  42. data/lib/solargraph/source_map/mapper.rb +10 -6
  43. data/lib/solargraph/type_checker.rb +50 -44
  44. data/lib/solargraph/type_checker/checks.rb +5 -1
  45. data/lib/solargraph/type_checker/param_def.rb +1 -1
  46. data/lib/solargraph/type_checker/rules.rb +5 -1
  47. data/lib/solargraph/version.rb +1 -1
  48. data/lib/solargraph/workspace/config.rb +15 -0
  49. data/lib/solargraph/yard_map.rb +38 -47
  50. data/lib/solargraph/yard_map/core_fills.rb +185 -0
  51. data/lib/solargraph/yard_map/helpers.rb +16 -0
  52. data/lib/solargraph/yard_map/mapper.rb +11 -5
  53. data/lib/solargraph/{pin/yard_pin/constant.rb → yard_map/mapper/to_constant.rb} +6 -6
  54. data/lib/solargraph/yard_map/mapper/to_method.rb +78 -0
  55. data/lib/solargraph/{pin/yard_pin/namespace.rb → yard_map/mapper/to_namespace.rb} +6 -6
  56. data/lib/solargraph/yard_map/rdoc_to_yard.rb +1 -1
  57. data/lib/solargraph/yard_map/stdlib_fills.rb +43 -0
  58. data/lib/solargraph/{pin/yard_pin/method.rb → yard_map/to_method.rb} +29 -30
  59. data/solargraph.gemspec +5 -5
  60. metadata +22 -36
  61. data/lib/solargraph/core_fills.rb +0 -164
  62. data/lib/solargraph/pin/attribute.rb +0 -49
  63. data/lib/solargraph/pin/base_method.rb +0 -149
  64. data/lib/solargraph/pin/yard_pin.rb +0 -12
  65. data/lib/solargraph/pin/yard_pin/yard_mixin.rb +0 -20
  66. data/lib/solargraph/stdlib_fills.rb +0 -40
  67. data/travis-bundler.rb +0 -11
@@ -1,164 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- # Overrides for the Ruby core.
5
- #
6
- # The YardMap uses this module to add type information to core methods.
7
- #
8
- module CoreFills
9
- Override = Pin::Reference::Override
10
-
11
- KEYWORDS = [
12
- '__ENCODING__', '__LINE__', '__FILE__', 'BEGIN', 'END', 'alias', 'and',
13
- 'begin', 'break', 'case', 'class', 'def', 'defined?', 'do', 'else',
14
- 'elsif', 'end', 'ensure', 'false', 'for', 'if', 'in', 'module', 'next',
15
- 'nil', 'not', 'or', 'redo', 'rescue', 'retry', 'return', 'self', 'super',
16
- 'then', 'true', 'undef', 'unless', 'until', 'when', 'while', 'yield'
17
- ].freeze
18
-
19
- methods_with_yieldparam_subtypes = %w[
20
- Array#each Array#map Array#map! Array#any? Array#all? Array#index
21
- Array#keep_if Array#delete_if
22
- Enumerable#each_entry Enumerable#map Enumerable#any? Enumerable#all?
23
- Enumerable#select Enumerable#reject
24
- Set#each
25
- ]
26
-
27
- OVERRIDES = [
28
- Override.method_return('Array#keep_if', 'self'),
29
- Override.method_return('Array#delete_if', 'self'),
30
- Override.from_comment('Array#reject', %(
31
- @overload reject(&block)
32
- @return [self]
33
- @overload reject()
34
- @return [Enumerator]
35
- )),
36
- Override.method_return('Array#reverse', 'self', delete: ['overload']),
37
- Override.from_comment('Array#select', %(
38
- @overload select(&block)
39
- @return [self]
40
- @overload select()
41
- @return [Enumerator]
42
- )),
43
- Override.from_comment('Array#[]', %(
44
- @overload [](range)
45
- @param range [Range]
46
- @return [self]
47
- @overload [](num1, num2)
48
- @param num1 [Integer]
49
- @param num2 [Integer]
50
- @return [self]
51
- @overload [](num)
52
- @param num [Integer]
53
- @return_single_parameter
54
- @return_single_parameter
55
- )),
56
- Override.method_return('Array#concat', 'Array'),
57
- Override.from_comment('Array#first', %(
58
- @overload first(num)
59
- @param num [Integer]
60
- @return [self]
61
- @return_single_parameter
62
- )),
63
- Override.from_comment('Array#last', %(
64
- @overload last(num)
65
- @param num [Integer]
66
- @return [self]
67
- @return_single_parameter
68
- )),
69
- Override.method_return('Array#map', 'Array'),
70
- Override.method_return('Array#uniq', 'self'),
71
- Override.method_return('Array#zip', 'Array, nil'),
72
-
73
- Override.from_comment('BasicObject#==', %(
74
- @param other [BasicObject]
75
- @return [Boolean]
76
- )),
77
- Override.method_return('BasicObject#initialize', 'void'),
78
-
79
- Override.method_return('Class#new', 'self'),
80
- Override.method_return('Class.new', 'Class<Object>'),
81
- Override.method_return('Class#allocate', 'self'),
82
- Override.method_return('Class.allocate', 'Class<Object>'),
83
-
84
- Override.method_return('Enumerable#select', 'self'),
85
-
86
- Override.method_return('File.absolute_path', 'String'),
87
- Override.method_return('File.basename', 'String'),
88
- Override.method_return('File.dirname', 'String'),
89
- Override.method_return('File.extname', 'String'),
90
- Override.method_return('File.join', 'String'),
91
-
92
- Override.from_comment('Float#+', %(
93
- @param y [Numeric]
94
- @return [Numeric]
95
- )),
96
-
97
- Override.from_comment('Hash#[]', %(
98
- @return_value_parameter
99
- )),
100
-
101
- # @todo This override isn't robust enough. It needs to allow for
102
- # parameterized Hash types, e.g., [Hash{Symbol => String}].
103
- Override.from_comment('Hash#[]=', %(
104
- @param_tuple
105
- )),
106
-
107
- Override.method_return('Hash#merge', 'Hash'),
108
-
109
- Override.from_comment('Integer#+', %(
110
- @param y [Numeric]
111
- @return [Numeric]
112
- )),
113
-
114
- Override.method_return('Kernel#puts', 'nil'),
115
-
116
- Override.from_comment('Numeric#+', %(
117
- @param y [Numeric]
118
- @return [Numeric]
119
- )),
120
-
121
- Override.method_return('Object#!', 'Boolean'),
122
- Override.method_return('Object#clone', 'self', delete: [:overload]),
123
- Override.method_return('Object#dup', 'self', delete: [:overload]),
124
- Override.method_return('Object#freeze', 'self', delete: [:overload]),
125
- Override.method_return('Object#inspect', 'String'),
126
- Override.method_return('Object#taint', 'self'),
127
- Override.method_return('Object#to_s', 'String'),
128
- Override.method_return('Object#untaint', 'self'),
129
- Override.from_comment('Object#tap', %(
130
- @return [self]
131
- @yieldparam [self]
132
- )),
133
-
134
- Override.from_comment('STDERR', %(
135
- @type [IO]
136
- )),
137
-
138
- Override.from_comment('STDIN', %(
139
- @type [IO]
140
- )),
141
-
142
- Override.from_comment('STDOUT', %(
143
- @type [IO]
144
- )),
145
-
146
- Override.method_return('String#freeze', 'self'),
147
- Override.method_return('String#split', 'Array<String>'),
148
- Override.method_return('String#lines', 'Array<String>'),
149
- Override.from_comment('String#each_line', %(
150
- @yieldparam [String]
151
- )),
152
- Override.from_comment('String.new', %(
153
- @overload new(*)
154
- @return [self]
155
- ))
156
- ].concat(
157
- methods_with_yieldparam_subtypes.map do |path|
158
- Override.from_comment(path, %(
159
- @yieldparam_single_parameter
160
- ))
161
- end
162
- )
163
- end
164
- end
@@ -1,49 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- module Pin
5
- class Attribute < BaseMethod
6
- # @return [::Symbol] :reader or :writer
7
- attr_reader :access
8
-
9
- # @param access [::Symbol] :reader or :writer
10
- def initialize access: :reader, **splat
11
- super(**splat)
12
- @access = access
13
- if access == :writer
14
- parameters.push(
15
- Pin::Parameter.new(name: 'value', decl: :arg, closure: self)
16
- )
17
- if return_type.defined?
18
- docstring.add_tag YARD::Tags::Tag.new(:param, '', return_type.to_s.split(', '), 'value')
19
- end
20
- end
21
- end
22
-
23
- def completion_item_kind
24
- Solargraph::LanguageServer::CompletionItemKinds::PROPERTY
25
- end
26
-
27
- def symbol_kind
28
- Solargraph::LanguageServer::SymbolKinds::PROPERTY
29
- end
30
-
31
- def path
32
- @path ||= namespace + (scope == :instance ? '#' : '.') + name
33
- end
34
-
35
- def probe api_map
36
- types = []
37
- varname = "@#{name.gsub(/=$/, '')}"
38
- pins = api_map.get_instance_variable_pins(binder.namespace, binder.scope).select { |iv| iv.name == varname }
39
- pins.each do |pin|
40
- type = pin.typify(api_map)
41
- type = pin.probe(api_map) if type.undefined?
42
- types.push type if type.defined?
43
- end
44
- return ComplexType::UNDEFINED if types.empty?
45
- ComplexType.try_parse(*types.map(&:tag).uniq)
46
- end
47
- end
48
- end
49
- end
@@ -1,149 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- module Pin
5
- # The base class for method and attribute pins.
6
- #
7
- class BaseMethod < Closure
8
- # @return [::Symbol] :public, :private, or :protected
9
- attr_reader :visibility
10
-
11
- # @return [Parser::AST::Node]
12
- attr_reader :node
13
-
14
- # @param visibility [::Symbol] :public, :protected, or :private
15
- # @param explicit [Boolean]
16
- def initialize visibility: :public, explicit: true, **splat
17
- super(**splat)
18
- @visibility = visibility
19
- @explicit = explicit
20
- end
21
-
22
- def return_type
23
- @return_type ||= generate_complex_type
24
- end
25
-
26
- def path
27
- @path ||= "#{namespace}#{(scope == :instance ? '#' : '.')}#{name}"
28
- end
29
-
30
- def typify api_map
31
- decl = super
32
- return decl unless decl.undefined?
33
- type = see_reference(api_map) || typify_from_super(api_map)
34
- return type.qualify(api_map, namespace) unless type.nil?
35
- name.end_with?('?') ? ComplexType::BOOLEAN : ComplexType::UNDEFINED
36
- end
37
-
38
- # @return [Array<Pin::Parameter>]
39
- def parameters
40
- @parameters ||= []
41
- end
42
-
43
- # @return [Array<String>]
44
- def parameter_names
45
- parameters.map(&:name)
46
- end
47
-
48
- def documentation
49
- if @documentation.nil?
50
- @documentation ||= super || ''
51
- param_tags = docstring.tags(:param)
52
- unless param_tags.nil? or param_tags.empty?
53
- @documentation += "\n\n" unless @documentation.empty?
54
- @documentation += "Params:\n"
55
- lines = []
56
- param_tags.each do |p|
57
- l = "* #{p.name}"
58
- l += " [#{escape_brackets(p.types.join(', '))}]" unless p.types.nil? or p.types.empty?
59
- l += " #{p.text}"
60
- lines.push l
61
- end
62
- @documentation += lines.join("\n")
63
- end
64
- return_tags = docstring.tags(:return)
65
- unless return_tags.empty?
66
- @documentation += "\n\n" unless @documentation.empty?
67
- @documentation += "Returns:\n"
68
- lines = []
69
- return_tags.each do |r|
70
- l = "*"
71
- l += " [#{escape_brackets(r.types.join(', '))}]" unless r.types.nil? or r.types.empty?
72
- l += " #{r.text}"
73
- lines.push l
74
- end
75
- @documentation += lines.join("\n")
76
- end
77
- @documentation += "\n\n" unless @documentation.empty?
78
- @documentation += "Visibility: #{visibility}"
79
- end
80
- @documentation.to_s
81
- end
82
-
83
- def explicit?
84
- @explicit
85
- end
86
-
87
- def completion_item_kind
88
- Solargraph::LanguageServer::CompletionItemKinds::METHOD
89
- end
90
-
91
- def symbol_kind
92
- Solargraph::LanguageServer::SymbolKinds::METHOD
93
- end
94
-
95
- private
96
-
97
- # @return [ComplexType]
98
- def generate_complex_type
99
- tags = docstring.tags(:return).map(&:types).flatten.reject(&:nil?)
100
- return ComplexType::UNDEFINED if tags.empty?
101
- ComplexType.try_parse *tags
102
- end
103
-
104
- # @param api_map [ApiMap]
105
- # @return [ComplexType, nil]
106
- def see_reference api_map
107
- docstring.ref_tags.each do |ref|
108
- next unless ref.tag_name == 'return' && ref.owner
109
- result = resolve_reference(ref.owner.to_s, api_map)
110
- return result unless result.nil?
111
- end
112
- match = comments.match(/^[ \t]*\(see (.*)\)/m)
113
- return nil if match.nil?
114
- resolve_reference match[1], api_map
115
- end
116
-
117
- # @param api_map [ApiMap]
118
- # @return [ComplexType, nil]
119
- def typify_from_super api_map
120
- stack = api_map.get_method_stack(namespace, name, scope: scope).reject { |pin| pin.path == path }
121
- return nil if stack.empty?
122
- stack.each do |pin|
123
- return pin.return_type unless pin.return_type.undefined?
124
- end
125
- nil
126
- end
127
-
128
- # @param ref [String]
129
- # @param api_map [ApiMap]
130
- # @return [ComplexType]
131
- def resolve_reference ref, api_map
132
- parts = ref.split(/[\.#]/)
133
- if parts.first.empty? || parts.one?
134
- path = "#{namespace}#{ref}"
135
- else
136
- fqns = api_map.qualify(parts.first, namespace)
137
- return ComplexType::UNDEFINED if fqns.nil?
138
- path = fqns + ref[parts.first.length] + parts.last
139
- end
140
- pins = api_map.get_path_pins(path)
141
- pins.each do |pin|
142
- type = pin.typify(api_map)
143
- return type unless type.undefined?
144
- end
145
- nil
146
- end
147
- end
148
- end
149
- end
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- module Pin
5
- module YardPin
6
- autoload :YardMixin, 'solargraph/pin/yard_pin/yard_mixin'
7
- autoload :Constant, 'solargraph/pin/yard_pin/constant'
8
- autoload :Method, 'solargraph/pin/yard_pin/method'
9
- autoload :Namespace, 'solargraph/pin/yard_pin/namespace'
10
- end
11
- end
12
- end
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- module Pin
5
- module YardPin
6
- module YardMixin
7
- private
8
-
9
- # @param code_object [YARD::CodeObjects::Base]
10
- # @param spec [Gem::Specification]
11
- # @return [Solargraph::Location, nil]
12
- def object_location code_object, spec
13
- return nil if spec.nil? || code_object.nil? || code_object.file.nil? || code_object.line.nil?
14
- file = File.join(spec.full_gem_path, code_object.file)
15
- Solargraph::Location.new(file, Solargraph::Range.from_to(code_object.line - 1, 0, code_object.line - 1, 0))
16
- end
17
- end
18
- end
19
- end
20
- end
@@ -1,40 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- # Overrides for the Ruby stdlib.
5
- #
6
- # The YardMap uses this module to add type information to stdlib methods.
7
- #
8
- module StdlibFills
9
- Override = Pin::Reference::Override
10
-
11
- LIBS = {
12
- 'benchmark' => [
13
- Override.method_return('Benchmark.measure', 'Benchmark::Tms')
14
- ],
15
-
16
- 'pathname' => [
17
- Override.method_return('Pathname#join', 'Pathname'),
18
- Override.method_return('Pathname#basename', 'Pathname'),
19
- Override.method_return('Pathname#dirname', 'Pathname'),
20
- Override.method_return('Pathname#cleanpath', 'Pathname'),
21
- Override.method_return('Pathname#children', 'Array<Pathname>'),
22
- Override.method_return('Pathname#entries', 'Array<Pathname>')
23
- ],
24
-
25
- 'set' => [
26
- Override.method_return('Enumerable#to_set', 'Set'),
27
- Override.method_return('Set#add', 'self'),
28
- Override.method_return('Set#add?', 'self, nil'),
29
- Override.method_return('Set#classify', 'Hash'),
30
- Override.from_comment('Set#each', '@yieldparam_single_parameter')
31
- ]
32
- }
33
-
34
- # @param path [String]
35
- # @return [Array<Pin::Reference::Override>]
36
- def self.get path
37
- LIBS[path] || []
38
- end
39
- end
40
- end
data/travis-bundler.rb DELETED
@@ -1,11 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- # Travis uses this script to select which version of bundler to install for
4
- # each job.
5
-
6
- if RUBY_VERSION =~ /^2\.(1|2)\./
7
- `gem install bundler -v '< 2'`
8
- else
9
- `gem update --system`
10
- `gem install bundler`
11
- end