solargraph 0.33.0 → 0.33.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 158c70ae0a463e58b036390de759450ff08ef9021338fac799b572c2ca31c705
4
- data.tar.gz: 5ff363662d8bca00cd0e66dc34845532d9d19e9812d5a04c6f9c8c18319ee609
3
+ metadata.gz: 2c8b3e2034dbbcdaafda5c6f9183261078f9f91902ef1c0fd6b8381de923119d
4
+ data.tar.gz: 520d5c332a8f6077b8aabefbf5ffa27a40c2d6472dd82e512cd84bccd739944f
5
5
  SHA512:
6
- metadata.gz: dddd44984f04c8307e590cd96344dad5bf25e5765ca0a03d8de03028820ca7e58abc248d5dd9430ee9e6841de491f5a46a68a63f6b4db8b0508347fa2b3fd7b2
7
- data.tar.gz: 9e394ad6f0558f8c194dd8efb667c58a3bc512ff65f98b11342e07270ed96f854a50904740b01bd23d0a4c31d4f944a82a8369a65802b1857425ea881a4d0058
6
+ metadata.gz: f967c5c5ae37b8c10417b953af1f663c3b6576602519990f32c5f43864d7318b86c5af14e0eabad85b6eba55147a722b7d4a178aab043e8ef8792c04aee77881
7
+ data.tar.gz: f6d7d2a0563226bfde47f077a0ac856bbc9fb24271c4bcd723a55901ca85cc547e9ce2fa4a128042d1d4f37346078aeb29d6c7fe92a3db1b0f7c7cf7d4faa6f7
@@ -33,6 +33,7 @@ module Solargraph
33
33
  @cache.clear
34
34
  @store = Store.new(pins + YardMap.new.pins)
35
35
  @unresolved_requires = []
36
+ workspace_filenames.clear
36
37
  }
37
38
  self
38
39
  end
@@ -112,6 +113,8 @@ module Solargraph
112
113
  @source_map_hash = new_map_hash
113
114
  @store = new_store
114
115
  @unresolved_requires = yard_map.unresolved_requires
116
+ workspace_filenames.clear
117
+ workspace_filenames.concat bundle.workspace.filenames
115
118
  }
116
119
  self
117
120
  end
@@ -463,6 +466,10 @@ module Solargraph
463
466
  source_map_hash.keys.include?(filename)
464
467
  end
465
468
 
469
+ def workspaced? filename
470
+ workspace_filenames.include?(filename)
471
+ end
472
+
466
473
  # @param location [Location]
467
474
  def require_reference_at location
468
475
  map = source_map(location.filename)
@@ -493,6 +500,10 @@ module Solargraph
493
500
 
494
501
  private
495
502
 
503
+ def workspace_filenames
504
+ @workspace_filenames ||= []
505
+ end
506
+
496
507
  # @return [YardMap]
497
508
  def yard_map
498
509
  @yard_map ||= YardMap.new
@@ -5,6 +5,7 @@ module Solargraph
5
5
  #
6
6
  class TypeCheck < Base
7
7
  def diagnose source, api_map
8
+ return [] unless args.include?('always') || api_map.workspaced?(source.filename)
8
9
  severity = (args.include?('strict') ? Diagnostics::Severities::ERROR : Diagnostics::Severities::WARNING)
9
10
  checker = Solargraph::TypeChecker.new(source.filename, api_map: api_map)
10
11
  result = checker.return_type_problems + checker.param_type_problems
@@ -4,6 +4,7 @@ module Solargraph
4
4
  # @return [::Symbol] :reader or :writer
5
5
  attr_reader :access
6
6
 
7
+ # @param access [::Symbol] :reader or :writer
7
8
  def initialize access: :reader, **splat
8
9
  super(splat)
9
10
  @access = access
@@ -1,3 +1,5 @@
1
+ require 'htmlentities'
2
+
1
3
  module Solargraph
2
4
  module Pin
3
5
  class Method < BaseMethod
@@ -9,6 +11,8 @@ module Solargraph
9
11
  # @return [Parser::AST::Node]
10
12
  attr_reader :node
11
13
 
14
+ # @param args [Array<String>]
15
+ # @param node [Parser::AST::Node, nil]
12
16
  def initialize args: [], node: nil, **splat
13
17
  super(splat)
14
18
  @parameters = args
@@ -16,6 +16,7 @@ module Solargraph
16
16
  autoload :GlobalVariable, 'solargraph/source/chain/global_variable'
17
17
  autoload :Literal, 'solargraph/source/chain/literal'
18
18
  autoload :Head, 'solargraph/source/chain/head'
19
+ autoload :Or, 'solargraph/source/chain/or'
19
20
 
20
21
  @@inference_depth = 0
21
22
 
@@ -73,11 +74,14 @@ module Solargraph
73
74
  links.last.is_a?(Chain::Literal)
74
75
  end
75
76
 
76
- # @return [Boolean]
77
77
  def undefined?
78
78
  links.any?(&:undefined?)
79
79
  end
80
80
 
81
+ def defined?
82
+ !undefined?
83
+ end
84
+
81
85
  # @return [Boolean]
82
86
  def constant?
83
87
  links.last.is_a?(Chain::Constant)
@@ -0,0 +1,21 @@
1
+ module Solargraph
2
+ class Source
3
+ class Chain
4
+ class Or < Link
5
+ def word
6
+ '<or>'
7
+ end
8
+
9
+ # @param type [String]
10
+ def initialize links
11
+ @links = links
12
+ end
13
+
14
+ def resolve api_map, name_pin, locals
15
+ types = @links.map { |link| link.infer(api_map, name_pin, locals) }
16
+ [Solargraph::Pin::ProxyType.anonymous(Solargraph::ComplexType.try_parse(types.map(&:tag).uniq.join(', ')))]
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -83,6 +83,12 @@ module Solargraph
83
83
  elsif [:class, :module, :def, :defs].include?(n.type)
84
84
  # @todo Undefined or what?
85
85
  result.push Chain::UNDEFINED_CALL
86
+ elsif n.type == :and
87
+ result.concat generate_links(n.children.last)
88
+ elsif n.type == :or
89
+ result.push Chain::Or.new([NodeChainer.chain(n.children[0], @filename), NodeChainer.chain(n.children[1], @filename)])
90
+ elsif [:begin, :kwbegin].include?(n.type)
91
+ result.concat generate_links(n.children[0])
86
92
  else
87
93
  lit = infer_literal_node_type(n)
88
94
  result.push (lit ? Chain::Literal.new(lit) : Chain::Link.new)
@@ -30,6 +30,9 @@ module Solargraph
30
30
  [[], []]
31
31
  end
32
32
 
33
+ # @param filename [String]
34
+ # @param code [String]
35
+ # @return [Array]
33
36
  def unmap filename, code
34
37
  s = Position.new(0, 0)
35
38
  e = Position.from_offset(code, code.length)
@@ -59,7 +62,15 @@ module Solargraph
59
62
  return unless comment =~ MACRO_REGEXP
60
63
  cmnt = remove_inline_comment_hashes(comment)
61
64
  parse = Solargraph::Source.parse_docstring(cmnt)
62
- parse.directives.each { |d| process_directive(source_position, comment_position, d) }
65
+ last_line = 0
66
+ # @param d [YARD::Tags::Directive]
67
+ parse.directives.each do |d|
68
+ line_num = cmnt.lines[last_line..-1].find_index { |l| l.include?("@!#{d.tag.tag_name}") }
69
+ line_num += last_line
70
+ pos = Solargraph::Position.new(comment_position.line + line_num, comment_position.column)
71
+ process_directive(source_position, pos, d)
72
+ last_line = line_num + 1
73
+ end
63
74
  end
64
75
 
65
76
  # @param position [Position]
@@ -70,6 +81,9 @@ module Solargraph
70
81
  case directive.tag.tag_name
71
82
  when 'method'
72
83
  namespace = closure_at(source_position)
84
+ if namespace.location.range.start.line < comment_position.line
85
+ namespace = closure_at(comment_position)
86
+ end
73
87
  region = Region.new(source: @source, closure: namespace)
74
88
  src_node = Solargraph::Source.parse("def #{directive.tag.name};end", @filename, location.range.start.line)
75
89
  gen_pin = Solargraph::SourceMap::NodeProcessor.process(src_node, region).first.last
@@ -78,6 +92,7 @@ module Solargraph
78
92
  gen_pin.instance_variable_set(:@comments, docstring.all)
79
93
  @pins.push gen_pin
80
94
  when 'attribute'
95
+ return if directive.tag.name.nil?
81
96
  namespace = closure_at(source_position)
82
97
  t = (directive.tag.types.nil? || directive.tag.types.empty?) ? nil : directive.tag.types.flatten.join('')
83
98
  if t.nil? || t.include?('r')
@@ -45,8 +45,7 @@ module Solargraph
45
45
  pdefs = ParamDef.from(par.closure)
46
46
  if type.undefined?
47
47
  if par.return_type.undefined? && !pdefs.any? { |pd| pd.name == par.name && [:restarg, :kwrestarg].include?(pd.type) }
48
- result.push Problem.new(
49
- par.location, "#{par.closure.name} has undefined @param type for #{par.name}")
48
+ result.push Problem.new(par.location, "#{par.closure.name} has undefined @param type for #{par.name}")
50
49
  elsif !pdefs.any? { |pd| [:restarg, :kwrestarg].include?(pd.type) }
51
50
  result.push Problem.new(par.location, "#{par.closure.name} has unresolved @param type for #{par.name}")
52
51
  end
@@ -96,7 +95,7 @@ module Solargraph
96
95
  if tagged.undefined?
97
96
  if pin.return_type.undefined?
98
97
  probed = pin.probe(api_map)
99
- return [Problem.new(pin.location, "#{pin.name} has undefined @return type", probed.to_s)]
98
+ return [Problem.new(pin.location, "#{pin.name} has undefined @return type", pin: pin, suggestion: probed.to_s)]
100
99
  else
101
100
  return [Problem.new(pin.location, "#{pin.name} has unresolved @return type #{pin.return_type}")]
102
101
  end
@@ -143,11 +142,14 @@ module Solargraph
143
142
  end
144
143
  end
145
144
  return [] if all
146
- return [Problem.new(pin.location, "@return type `#{tagged.to_s}` does not match inferred type `#{probed.to_s}`", probed.to_s)]
145
+ return [Problem.new(pin.location, "@return type `#{tagged.to_s}` does not match inferred type `#{probed.to_s}`", pin: pin, suggestion: probed.to_s)]
147
146
  end
148
147
  []
149
148
  end
150
149
 
150
+ # @param node [Parser::AST::Node]
151
+ # @param skip_send [Boolean]
152
+ # @return [Array<Problem>]
151
153
  def check_send_args node, skip_send = false
152
154
  result = []
153
155
  if node.type == :send
@@ -231,6 +233,8 @@ module Solargraph
231
233
  result
232
234
  end
233
235
 
236
+ # @param pin [Pin::Base]
237
+ # @return [Hash]
234
238
  def param_tags_from pin
235
239
  # @todo Look for see references
236
240
  # and dig through all the pins
@@ -9,15 +9,20 @@ module Solargraph
9
9
  # @return [String]
10
10
  attr_reader :message
11
11
 
12
+ # @return [Pin::Base]
13
+ attr_reader :pin
14
+
12
15
  # @return [String, nil]
13
16
  attr_reader :suggestion
14
17
 
15
18
  # @param location [Solargraph::Location]
16
19
  # @param message [String]
20
+ # @param pin [Solargraph::Pin::Base, nil]
17
21
  # @param suggestion [String, nil]
18
- def initialize location, message, suggestion = nil
22
+ def initialize location, message, pin: nil, suggestion: nil
19
23
  @location = location
20
24
  @message = message
25
+ @pin = pin
21
26
  @suggestion = suggestion
22
27
  end
23
28
  end
@@ -1,3 +1,3 @@
1
1
  module Solargraph
2
- VERSION = '0.33.0'
2
+ VERSION = '0.33.1'
3
3
  end
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.33.0
4
+ version: 0.33.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fred Snyder
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-18 00:00:00.000000000 Z
11
+ date: 2019-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backport
@@ -383,6 +383,7 @@ files:
383
383
  - lib/solargraph/source/chain/instance_variable.rb
384
384
  - lib/solargraph/source/chain/link.rb
385
385
  - lib/solargraph/source/chain/literal.rb
386
+ - lib/solargraph/source/chain/or.rb
386
387
  - lib/solargraph/source/chain/variable.rb
387
388
  - lib/solargraph/source/change.rb
388
389
  - lib/solargraph/source/cursor.rb