solargraph 0.29.4 → 0.29.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -66,9 +66,10 @@ module Solargraph
66
66
  type = ComplexType::UNDEFINED
67
67
  pins = define(api_map, name_pin, locals)
68
68
  pins.each do |pin|
69
- type = pin.infer(api_map)
69
+ type = pin.typify(api_map)
70
70
  break unless type.undefined?
71
71
  end
72
+ type = pins.first.probe(api_map) unless type.defined? || pins.empty?
72
73
  @@inference_stack.pop
73
74
  type
74
75
  end
@@ -107,9 +108,11 @@ module Solargraph
107
108
  def infer_first_defined pins, api_map
108
109
  type = ComplexType::UNDEFINED
109
110
  pins.each do |pin|
110
- type = pin.infer(api_map)
111
+ # type = pin.infer(api_map)
112
+ type = pin.typify(api_map)
111
113
  break unless type.undefined?
112
114
  end
115
+ type = pins.first.probe(api_map) unless type.defined? || pins.empty?
113
116
  type
114
117
  end
115
118
  end
@@ -55,7 +55,9 @@ module Solargraph
55
55
  next result unless result.return_type.undefined?
56
56
  end
57
57
  next p if p.kind == Pin::METHOD || p.kind == Pin::ATTRIBUTE || p.kind == Pin::NAMESPACE
58
- type = p.infer(api_map)
58
+ # type = p.infer(api_map)
59
+ type = p.typify(api_map)
60
+ type = p.probe(api_map) if type.undefined?
59
61
  next p if p.return_complex_type == type
60
62
  Pin::ProxyType.new(p.location, nil, p.name, type)
61
63
  end
@@ -57,9 +57,9 @@ module Solargraph
57
57
  else
58
58
  result = commit text, fixed
59
59
  off = Position.to_offset(text, range.start)
60
- match = result[0..off].match(/[\.:]+\z/)
60
+ match = result[0, off].match(/[\.:]+\z/)
61
61
  if match
62
- result = result[0..off].sub(/#{match[0]}\z/, ' ' * match[0].length) + result[off..-1]
62
+ result = result[0, off].sub(/#{match[0]}\z/, ' ' * match[0].length) + result[off..-1]
63
63
  end
64
64
  result
65
65
  end
@@ -80,6 +80,8 @@ module Solargraph
80
80
  result.push Chain::ClassVariable.new(n.children[0].to_s)
81
81
  elsif [:gvar, :gvasgn].include?(n.type)
82
82
  result.push Chain::GlobalVariable.new(n.children[0].to_s)
83
+ elsif n.type == :or_asgn
84
+ result.concat generate_links n.children[1]
83
85
  elsif [:class, :module, :def, :defs].include?(n.type)
84
86
  # @todo Undefined or what?
85
87
  result.push Chain::UNDEFINED_CALL
@@ -3,11 +3,13 @@ module Solargraph
3
3
  module NodeMethods
4
4
  module_function
5
5
 
6
+ # @param node [Parser::AST::Node]
6
7
  # @return [String]
7
8
  def unpack_name(node)
8
9
  pack_name(node).join("::")
9
10
  end
10
11
 
12
+ # @param node [Parser::AST::Node]
11
13
  # @return [Array<String>]
12
14
  def pack_name(node)
13
15
  parts = []
@@ -27,6 +29,7 @@ module Solargraph
27
29
  parts
28
30
  end
29
31
 
32
+ # @param node [Parser::AST::Node]
30
33
  # @return [String]
31
34
  def const_from node
32
35
  if node.kind_of?(AST::Node) and node.type == :const
@@ -45,6 +48,7 @@ module Solargraph
45
48
  end
46
49
  end
47
50
 
51
+ # @param node [Parser::AST::Node]
48
52
  # @return [String]
49
53
  def infer_literal_node_type node
50
54
  return nil unless node.kind_of?(AST::Node)
@@ -73,6 +77,7 @@ module Solargraph
73
77
  # The result should be a string in the form of a method path, e.g.,
74
78
  # String.new or variable.method.
75
79
  #
80
+ # @param node [Parser::AST::Node]
76
81
  # @return [String]
77
82
  def resolve_node_signature node
78
83
  result = drill_signature node, ''
@@ -80,10 +85,14 @@ module Solargraph
80
85
  result
81
86
  end
82
87
 
88
+ # @param node [Parser::AST::Node]
89
+ # @return [Position]
83
90
  def get_node_start_position(node)
84
91
  Position.new(node.loc.line, node.loc.column)
85
92
  end
86
93
 
94
+ # @param node [Parser::AST::Node]
95
+ # @return [Position]
87
96
  def get_node_end_position(node)
88
97
  Position.new(node.loc.last_line, node.loc.last_column)
89
98
  end
@@ -135,6 +144,8 @@ module Solargraph
135
144
  REDUCEABLE = [:begin, :kwbegin]
136
145
  SKIPPABLE = [:def, :defs, :class, :sclass, :module]
137
146
 
147
+ # @param node [Parser::AST::Node]
148
+ # @return [Array<Parser::AST::Node>]
138
149
  def get_return_nodes node
139
150
  return [] unless node.is_a?(Parser::AST::Node)
140
151
  result = []
@@ -142,6 +153,8 @@ module Solargraph
142
153
  result.concat get_return_nodes_from_children(node)
143
154
  elsif CONDITIONAL.include?(node.type)
144
155
  result.concat reduce_to_value_nodes(node.children[1..-1])
156
+ elsif node.type == :and || node.type == :or
157
+ result.concat reduce_to_value_nodes(node.children)
145
158
  elsif node.type == :return
146
159
  result.concat reduce_to_value_nodes([node.children[0]])
147
160
  else
@@ -197,6 +210,8 @@ module Solargraph
197
210
  result.concat reduce_to_value_nodes(node.children[1..-1])
198
211
  elsif node.type == :return
199
212
  result.concat get_return_nodes(node.children[0])
213
+ elsif node.type == :and || node.type == :or
214
+ result.concat reduce_to_value_nodes(node.children)
200
215
  else
201
216
  result.push node
202
217
  end
@@ -31,7 +31,6 @@ module Solargraph
31
31
  # @return [Source::Chain]
32
32
  def chain
33
33
  return Chain.new([Chain::Literal.new('Symbol')]) if phrase.start_with?(':') && !phrase.start_with?('::')
34
- # return Chain.new([Chain::UNDEFINED_CALL]) unless infer_literal_node_type(source.node_at(position.line, position.column)).nil?
35
34
  begin
36
35
  return Chain.new([]) if phrase.end_with?('..')
37
36
  if !source.repaired? && source.parsed?
@@ -170,27 +169,6 @@ module Solargraph
170
169
  end
171
170
  index -= 1
172
171
  end
173
- # @todo Smelly exceptional case for integer literals
174
- # match = signature.match(/^[0-9]+/)
175
- # if match
176
- # index += match[0].length
177
- # signature = signature[match[0].length..-1].to_s
178
- # @base_literal = 'Integer'
179
- # # @todo Smelly exceptional case for array literals
180
- # elsif signature.start_with?('.[]')
181
- # index += 2
182
- # signature = signature[3..-1].to_s
183
- # @base_literal = 'Array'
184
- # elsif signature.start_with?('.')
185
- # pos = Position.from_offset(@source.code, index)
186
- # node = @source.node_at(pos.line, pos.character)
187
- # lit = infer_literal_node_type(node)
188
- # unless lit.nil?
189
- # signature = signature[1..-1].to_s
190
- # index += 1
191
- # @base_literal = lit
192
- # end
193
- # end
194
172
  [index + 1, signature]
195
173
  end
196
174
  end
@@ -42,15 +42,17 @@ module Solargraph
42
42
  @requires ||= pins.select{|p| p.kind == Pin::REQUIRE_REFERENCE}
43
43
  end
44
44
 
45
- # @param position [Position]
45
+ # @param position [Position, Array(Integer, Integer)]
46
46
  # @return [Boolean]
47
47
  def string_at? position
48
+ position = Position.normalize(position)
48
49
  @source.string_at?(position)
49
50
  end
50
51
 
51
- # @param position [Position]
52
+ # @param position [Position, Array(Integer, Integer)]
52
53
  # @return [Boolean]
53
54
  def comment_at? position
55
+ position = Position.normalize(position)
54
56
  @source.comment_at?(position)
55
57
  end
56
58
 
@@ -73,6 +75,8 @@ module Solargraph
73
75
  Source::Cursor.new(source, position)
74
76
  end
75
77
 
78
+ # @param path [String]
79
+ # @return [Pin::Base]
76
80
  def first_pin path
77
81
  pins.select { |p| p.path == path }.first
78
82
  end
@@ -93,7 +97,7 @@ module Solargraph
93
97
  end
94
98
 
95
99
  # @param other_map [SourceMap]
96
- # @return Boolean
100
+ # @return [Boolean]
97
101
  def try_merge! other_map
98
102
  return false if pins.length != other_map.pins.length || locals.length != other_map.locals.length || requires.map(&:name).uniq.sort != other_map.requires.map(&:name).uniq.sort
99
103
  pins.each_index do |i|
@@ -138,6 +142,10 @@ module Solargraph
138
142
 
139
143
  private
140
144
 
145
+ # @param line [Integer]
146
+ # @param character [Integer]
147
+ # @param *kinds [Array<Symbol>]
148
+ # @return [Pin::Base]
141
149
  def _locate_pin line, character, *kinds
142
150
  position = Position.new(line, character)
143
151
  found = nil
@@ -1,3 +1,3 @@
1
1
  module Solargraph
2
- VERSION = '0.29.4'
2
+ VERSION = '0.29.5'
3
3
  end
@@ -28,7 +28,7 @@ module Solargraph
28
28
  # @param source [Solargraph::Source]
29
29
  # @return [Boolean] True if the source was added to the workspace
30
30
  def merge source
31
- unless source_hash.has_key?(source.filename)
31
+ unless directory == '*' || source_hash.has_key?(source.filename)
32
32
  # Reload the config to determine if a new source should be included
33
33
  @config = Solargraph::Workspace::Config.new(directory)
34
34
  return false unless config.calculated.include?(source.filename)
@@ -42,7 +42,7 @@ module Solargraph
42
42
  # @param filename [String]
43
43
  # @return [Boolean]
44
44
  def would_merge? filename
45
- return true if source_hash.include?(filename)
45
+ return true if directory == '*' || source_hash.include?(filename)
46
46
  @config = Solargraph::Workspace::Config.new(directory)
47
47
  config.calculated.include?(filename)
48
48
  end
@@ -130,7 +130,7 @@ module Solargraph
130
130
 
131
131
  def load_sources
132
132
  source_hash.clear
133
- unless directory.empty?
133
+ unless directory.empty? || directory == '*'
134
134
  size = config.calculated.length
135
135
  raise WorkspaceTooLargeError, "The workspace is too large to index (#{size} files, #{config.max_files} max)" if config.max_files > 0 and size > config.max_files
136
136
  config.calculated.each do |filename|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solargraph
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.29.4
4
+ version: 0.29.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fred Snyder
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-07 00:00:00.000000000 Z
11
+ date: 2018-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eventmachine
@@ -178,22 +178,22 @@ dependencies:
178
178
  name: rspec
179
179
  requirement: !ruby/object:Gem::Requirement
180
180
  requirements:
181
- - - "~>"
182
- - !ruby/object:Gem::Version
183
- version: '3.5'
184
181
  - - ">="
185
182
  - !ruby/object:Gem::Version
186
183
  version: 3.5.0
184
+ - - "~>"
185
+ - !ruby/object:Gem::Version
186
+ version: '3.5'
187
187
  type: :development
188
188
  prerelease: false
189
189
  version_requirements: !ruby/object:Gem::Requirement
190
190
  requirements:
191
- - - "~>"
192
- - !ruby/object:Gem::Version
193
- version: '3.5'
194
191
  - - ">="
195
192
  - !ruby/object:Gem::Version
196
193
  version: 3.5.0
194
+ - - "~>"
195
+ - !ruby/object:Gem::Version
196
+ version: '3.5'
197
197
  - !ruby/object:Gem::Dependency
198
198
  name: simplecov
199
199
  requirement: !ruby/object:Gem::Requirement
@@ -296,6 +296,7 @@ files:
296
296
  - lib/solargraph/pin.rb
297
297
  - lib/solargraph/pin/attribute.rb
298
298
  - lib/solargraph/pin/base.rb
299
+ - lib/solargraph/pin/base_method.rb
299
300
  - lib/solargraph/pin/base_variable.rb
300
301
  - lib/solargraph/pin/block.rb
301
302
  - lib/solargraph/pin/block_parameter.rb
@@ -411,7 +412,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
411
412
  version: '0'
412
413
  requirements: []
413
414
  rubyforge_project:
414
- rubygems_version: 2.7.6
415
+ rubygems_version: 2.7.8
415
416
  signing_key:
416
417
  specification_version: 4
417
418
  summary: Solargraph for Ruby