solargraph 0.33.0 → 0.33.1
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.
- checksums.yaml +4 -4
- data/lib/solargraph/api_map.rb +11 -0
- data/lib/solargraph/diagnostics/type_check.rb +1 -0
- data/lib/solargraph/pin/attribute.rb +1 -0
- data/lib/solargraph/pin/method.rb +4 -0
- data/lib/solargraph/source/chain.rb +5 -1
- data/lib/solargraph/source/chain/or.rb +21 -0
- data/lib/solargraph/source/node_chainer.rb +6 -0
- data/lib/solargraph/source_map/mapper.rb +16 -1
- data/lib/solargraph/type_checker.rb +8 -4
- data/lib/solargraph/type_checker/problem.rb +6 -1
- data/lib/solargraph/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c8b3e2034dbbcdaafda5c6f9183261078f9f91902ef1c0fd6b8381de923119d
|
4
|
+
data.tar.gz: 520d5c332a8f6077b8aabefbf5ffa27a40c2d6472dd82e512cd84bccd739944f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f967c5c5ae37b8c10417b953af1f663c3b6576602519990f32c5f43864d7318b86c5af14e0eabad85b6eba55147a722b7d4a178aab043e8ef8792c04aee77881
|
7
|
+
data.tar.gz: f6d7d2a0563226bfde47f077a0ac856bbc9fb24271c4bcd723a55901ca85cc547e9ce2fa4a128042d1d4f37346078aeb29d6c7fe92a3db1b0f7c7cf7d4faa6f7
|
data/lib/solargraph/api_map.rb
CHANGED
@@ -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
|
@@ -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
|
-
|
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
|
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
|
data/lib/solargraph/version.rb
CHANGED
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.
|
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-
|
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
|