solargraph 0.10.3 → 0.11.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.
- checksums.yaml +4 -4
- data/lib/solargraph/api_map/cache.rb +11 -0
- data/lib/solargraph/api_map/config.rb +2 -0
- data/lib/solargraph/api_map.rb +122 -89
- data/lib/solargraph/code_map.rb +30 -25
- data/lib/solargraph/node_methods.rb +1 -0
- data/lib/solargraph/server.rb +2 -2
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/yard_map/cache.rb +8 -7
- data/lib/solargraph/yard_map.rb +0 -25
- data/lib/solargraph.rb +0 -1
- metadata +7 -8
- data/lib/solargraph/mapper.rb +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0d57ee417fd4007c31d34a555f76701a51a19be
|
4
|
+
data.tar.gz: 8b254f32899b99c3e2faa25361f043d05de235f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 764e250b3ba7f52b0d4dbaaf4b7180cf4094bfc8b7dabf6e4054ddf342c02f9587470823c2629b3b132c83627ace4e8c738c10755e76c373a922d192f4fd6e43
|
7
|
+
data.tar.gz: 0abe5016eb85276abc4d2fc44a8f66c166986630b7dd5ba04878b19062e16b4fc45c2b6f195032cd73792964d1ae5dec3b1f0ff5607b6fb47404c6f31c8c6b74
|
@@ -3,13 +3,24 @@ module Solargraph
|
|
3
3
|
class Cache
|
4
4
|
def initialize
|
5
5
|
@signature_types = {}
|
6
|
+
@assignment_node_types = {}
|
6
7
|
end
|
8
|
+
|
7
9
|
def get_signature_type signature, namespace, scope
|
8
10
|
@signature_types[[signature, namespace, scope]]
|
9
11
|
end
|
12
|
+
|
10
13
|
def set_signature_type signature, namespace, scope, value
|
11
14
|
@signature_types[[signature, namespace, scope]] = value
|
12
15
|
end
|
16
|
+
|
17
|
+
def get_assignment_node_type node, namespace
|
18
|
+
@assignment_node_types[[node, namespace]]
|
19
|
+
end
|
20
|
+
|
21
|
+
def set_assignment_node_type node, namespace, value
|
22
|
+
@assignment_node_types[[node, namespace]] = value
|
23
|
+
end
|
13
24
|
end
|
14
25
|
end
|
15
26
|
end
|
data/lib/solargraph/api_map.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'parser/current'
|
3
|
-
require 'yaml'
|
4
3
|
|
5
4
|
module Solargraph
|
6
5
|
class ApiMap
|
@@ -29,7 +28,13 @@ module Solargraph
|
|
29
28
|
include NodeMethods
|
30
29
|
include YardMethods
|
31
30
|
|
31
|
+
# The root directory of the project. The ApiMap will search here for
|
32
|
+
# additional files to parse and analyze.
|
33
|
+
#
|
34
|
+
# @return [String]
|
32
35
|
attr_reader :workspace
|
36
|
+
|
37
|
+
# @return [Array<String>]
|
33
38
|
attr_reader :required
|
34
39
|
|
35
40
|
# @param workspace [String]
|
@@ -46,28 +51,24 @@ module Solargraph
|
|
46
51
|
end
|
47
52
|
end
|
48
53
|
|
49
|
-
def clear
|
50
|
-
@file_source = {}
|
51
|
-
@file_nodes = {}
|
52
|
-
@file_comments = {}
|
53
|
-
@parent_stack = {}
|
54
|
-
@namespace_map = {}
|
55
|
-
@namespace_tree = {}
|
56
|
-
@required = []
|
57
|
-
end
|
58
|
-
|
59
54
|
# @return [Solargraph::YardMap]
|
60
55
|
def yard_map
|
61
56
|
@yard_map ||= YardMap.new(required: required, workspace: workspace)
|
62
57
|
end
|
63
58
|
|
59
|
+
# Add a file to the map.
|
60
|
+
#
|
64
61
|
# @param filename [String]
|
62
|
+
# @return [AST::Node]
|
65
63
|
def append_file filename
|
66
64
|
append_source File.read(filename), filename
|
67
65
|
end
|
68
66
|
|
67
|
+
# Add a string of source code to the map.
|
68
|
+
#
|
69
69
|
# @param text [String]
|
70
70
|
# @param filename [String]
|
71
|
+
# @return [AST::Node]
|
71
72
|
def append_source text, filename = nil
|
72
73
|
@file_source[filename] = text
|
73
74
|
begin
|
@@ -79,6 +80,9 @@ module Solargraph
|
|
79
80
|
end
|
80
81
|
end
|
81
82
|
|
83
|
+
# Add an AST node to the map.
|
84
|
+
#
|
85
|
+
# @return [AST::Node]
|
82
86
|
def append_node node, comments, filename = nil
|
83
87
|
@file_comments[filename] = associate_comments(node, comments)
|
84
88
|
mapified = reduce(node, @file_comments[filename])
|
@@ -90,29 +94,21 @@ module Solargraph
|
|
90
94
|
root
|
91
95
|
end
|
92
96
|
|
97
|
+
# Get the docstring associated with a node.
|
98
|
+
#
|
99
|
+
# @param node [AST::Node]
|
100
|
+
# @return [YARD::Docstring]
|
93
101
|
def get_comment_for node
|
94
102
|
filename = get_filename_for(node)
|
95
103
|
return nil if @file_comments[filename].nil?
|
96
104
|
@file_comments[filename][node.loc]
|
97
105
|
end
|
98
106
|
|
107
|
+
# @return [Array<Solargraph::Suggestion>]
|
99
108
|
def self.get_keywords
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
result.push Suggestion.new(k, kind: Suggestion::KEYWORD, detail: 'Keyword')
|
104
|
-
}
|
105
|
-
result
|
106
|
-
end
|
107
|
-
|
108
|
-
def process_maps
|
109
|
-
@parent_stack = {}
|
110
|
-
@namespace_map = {}
|
111
|
-
@namespace_tree = {}
|
112
|
-
@file_nodes.values.each { |f|
|
113
|
-
map_parents f
|
114
|
-
map_namespaces f
|
115
|
-
}
|
109
|
+
@keyword_suggestions ||= (KEYWORDS + MAPPABLE_METHODS).map{ |s|
|
110
|
+
Suggestion.new(s.to_s, kind: Suggestion::KEYWORD, detail: 'Keyword')
|
111
|
+
}.freeze
|
116
112
|
end
|
117
113
|
|
118
114
|
def namespaces
|
@@ -237,18 +233,7 @@ module Solargraph
|
|
237
233
|
break unless vn.nil?
|
238
234
|
}
|
239
235
|
end
|
240
|
-
unless vn.nil?
|
241
|
-
cmnt = get_comment_for(vn)
|
242
|
-
unless cmnt.nil?
|
243
|
-
tag = cmnt.tag(:type)
|
244
|
-
result = tag.types[0] unless tag.nil? or tag.types.empty?
|
245
|
-
end
|
246
|
-
result = infer_literal_node_type(vn.children[1]) if result.nil?
|
247
|
-
if result.nil?
|
248
|
-
signature = resolve_node_signature(vn.children[1])
|
249
|
-
result = infer_signature_type(signature, namespace)
|
250
|
-
end
|
251
|
-
end
|
236
|
+
result = infer_assignment_node_type(vn, namespace) unless vn.nil?
|
252
237
|
result
|
253
238
|
end
|
254
239
|
|
@@ -314,6 +299,32 @@ module Solargraph
|
|
314
299
|
[]
|
315
300
|
end
|
316
301
|
|
302
|
+
def infer_assignment_node_type node, namespace
|
303
|
+
type = cache.get_assignment_node_type(node, namespace)
|
304
|
+
if type.nil?
|
305
|
+
cmnt = get_comment_for(node)
|
306
|
+
if cmnt.nil?
|
307
|
+
type = infer_literal_node_type(node.children[1])
|
308
|
+
if type.nil?
|
309
|
+
sig = resolve_node_signature(node.children[1])
|
310
|
+
# Avoid infinite loops from variable assignments that reference themselves
|
311
|
+
return nil if node.children[0].to_s == sig.split('.').first
|
312
|
+
type = infer_signature_type(sig, namespace)
|
313
|
+
end
|
314
|
+
else
|
315
|
+
t = cmnt.tag(:type)
|
316
|
+
if t.nil?
|
317
|
+
sig = resolve_node_signature(node.children[1])
|
318
|
+
type = infer_signature_type(sig, namespace)
|
319
|
+
else
|
320
|
+
type = t.types[0]
|
321
|
+
end
|
322
|
+
end
|
323
|
+
cache.set_assignment_node_type(node, namespace, type)
|
324
|
+
end
|
325
|
+
type
|
326
|
+
end
|
327
|
+
|
317
328
|
def infer_signature_type signature, namespace, scope: :class
|
318
329
|
cached = cache.get_signature_type(signature, namespace, scope)
|
319
330
|
return cached unless cached.nil?
|
@@ -388,6 +399,7 @@ module Solargraph
|
|
388
399
|
end
|
389
400
|
end
|
390
401
|
|
402
|
+
# @return [Array<String>]
|
391
403
|
def get_method_args node
|
392
404
|
list = nil
|
393
405
|
args = []
|
@@ -422,7 +434,7 @@ module Solargraph
|
|
422
434
|
return get_methods(namespace.split('#').first, root, visibility: visibility)
|
423
435
|
end
|
424
436
|
meths = []
|
425
|
-
meths += inner_get_instance_methods(namespace, root, []) #unless has_yardoc?
|
437
|
+
meths += inner_get_instance_methods(namespace, root, [], visibility) #unless has_yardoc?
|
426
438
|
fqns = find_fully_qualified_namespace(namespace, root)
|
427
439
|
yard_meths = yard_map.get_instance_methods(fqns, '', visibility: visibility)
|
428
440
|
if yard_meths.any?
|
@@ -493,6 +505,27 @@ module Solargraph
|
|
493
505
|
|
494
506
|
private
|
495
507
|
|
508
|
+
def clear
|
509
|
+
@file_source = {}
|
510
|
+
@file_nodes = {}
|
511
|
+
@file_comments = {}
|
512
|
+
@parent_stack = {}
|
513
|
+
@namespace_map = {}
|
514
|
+
@namespace_tree = {}
|
515
|
+
@required = []
|
516
|
+
end
|
517
|
+
|
518
|
+
def process_maps
|
519
|
+
@parent_stack = {}
|
520
|
+
@namespace_map = {}
|
521
|
+
@namespace_tree = {}
|
522
|
+
@file_nodes.values.each { |f|
|
523
|
+
map_parents f
|
524
|
+
map_namespaces f
|
525
|
+
}
|
526
|
+
end
|
527
|
+
|
528
|
+
# @return [Solargraph::ApiMap::Cache]
|
496
529
|
def cache
|
497
530
|
@cache ||= Cache.new
|
498
531
|
end
|
@@ -568,12 +601,13 @@ module Solargraph
|
|
568
601
|
meths
|
569
602
|
end
|
570
603
|
|
571
|
-
def inner_get_instance_methods(namespace, root, skip)
|
604
|
+
def inner_get_instance_methods(namespace, root, skip, visibility = [:public])
|
572
605
|
fqns = find_fully_qualified_namespace(namespace, root)
|
573
606
|
meths = []
|
574
607
|
return meths if skip.include?(fqns)
|
575
608
|
skip.push fqns
|
576
609
|
nodes = get_namespace_nodes(fqns)
|
610
|
+
current_scope = :public
|
577
611
|
nodes.each { |n|
|
578
612
|
f = get_filename_for(n)
|
579
613
|
unless yardoc_has_file?(get_filename_for(n))
|
@@ -582,23 +616,22 @@ module Solargraph
|
|
582
616
|
s = unpack_name(n.children[1])
|
583
617
|
# @todo This skip might not work properly. We might need to get a
|
584
618
|
# fully qualified namespace from it first
|
585
|
-
meths += get_instance_methods(s, namespace) unless skip.include?(s)
|
619
|
+
meths += get_instance_methods(s, namespace, visibility: visibility - [:private]) unless skip.include?(s)
|
586
620
|
end
|
587
|
-
current_scope = :public
|
588
621
|
n.children.each { |c|
|
589
622
|
if c.kind_of?(AST::Node) and c.type == :send and [:public, :protected, :private].include?(c.children[1])
|
590
|
-
|
591
|
-
# exclude protected or private methods. Right now we're just
|
592
|
-
# assuming public only
|
623
|
+
current_scope = c.children[1]
|
593
624
|
elsif c.kind_of?(AST::Node) and c.type == :send and c.children[1] == :include
|
594
625
|
fqmod = find_fully_qualified_namespace(const_from(c.children[2]), root)
|
595
626
|
meths += get_instance_methods(fqmod) unless fqmod.nil? or skip.include?(fqmod)
|
596
|
-
|
627
|
+
else
|
597
628
|
if c.kind_of?(AST::Node) and c.type == :def
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
629
|
+
if visibility.include?(current_scope)
|
630
|
+
cmnt = get_comment_for(c)
|
631
|
+
label = "#{c.children[0]}"
|
632
|
+
args = get_method_args(c)
|
633
|
+
meths.push Suggestion.new(label, insert: c.children[0].to_s.gsub(/=/, ' = '), kind: Suggestion::METHOD, documentation: cmnt, detail: fqns, arguments: args) if c.children[0].to_s[0].match(/[a-z]/i)
|
634
|
+
end
|
602
635
|
elsif c.kind_of?(AST::Node) and c.type == :send and c.children[1] == :attr_reader
|
603
636
|
c.children[2..-1].each { |x|
|
604
637
|
meths.push Suggestion.new(x.children[0], kind: Suggestion::FIELD) if x.type == :sym
|
@@ -610,7 +643,7 @@ module Solargraph
|
|
610
643
|
elsif c.kind_of?(AST::Node) and c.type == :send and c.children[1] == :attr_accessor
|
611
644
|
c.children[2..-1].each { |x|
|
612
645
|
meths.push Suggestion.new(x.children[0], kind: Suggestion::FIELD) if x.type == :sym
|
613
|
-
meths.push Suggestion.new("#{x.children[0]}=", kind: Suggestion::FIELD) if x.type == :sym
|
646
|
+
meths.push Suggestion.new("#{x.children[0]}=", insert: "#{x.children[0]} = ", kind: Suggestion::FIELD) if x.type == :sym
|
614
647
|
}
|
615
648
|
end
|
616
649
|
end
|
@@ -619,7 +652,7 @@ module Solargraph
|
|
619
652
|
end
|
620
653
|
# This is necessary to get included modules from workspace definitions
|
621
654
|
get_include_strings_from(n).each { |i|
|
622
|
-
meths += inner_get_instance_methods(i, fqns, skip)
|
655
|
+
meths += inner_get_instance_methods(i, fqns, skip, visibility)
|
623
656
|
}
|
624
657
|
}
|
625
658
|
meths.uniq
|
@@ -671,21 +704,8 @@ module Solargraph
|
|
671
704
|
if c.kind_of?(AST::Node)
|
672
705
|
is_inst = !find_parent(c, :def).nil?
|
673
706
|
if c.type == :ivasgn and c.children[0] and ( (scope == :instance and is_inst) or (scope != :instance and !is_inst) )
|
674
|
-
type =
|
675
|
-
|
676
|
-
if cmnt.nil?
|
677
|
-
sig = resolve_node_signature(c.children[1])
|
678
|
-
type = infer_signature_type(sig, namespace)
|
679
|
-
else
|
680
|
-
t = cmnt.tag(:type)
|
681
|
-
if t.nil?
|
682
|
-
sig = resolve_node_signature(c.children[1])
|
683
|
-
type = infer_signature_type(sig, namespace)
|
684
|
-
else
|
685
|
-
type = t.types[0]
|
686
|
-
end
|
687
|
-
end
|
688
|
-
arr.push Suggestion.new(c.children[0], kind: Suggestion::VARIABLE, documentation: cmnt, return_type: type)
|
707
|
+
type = infer_assignment_node_type(c, namespace)
|
708
|
+
arr.push Suggestion.new(c.children[0], kind: Suggestion::VARIABLE, documentation: get_comment_for(c), return_type: type)
|
689
709
|
end
|
690
710
|
arr += inner_get_instance_variables(c, namespace, scope) unless [:class, :module].include?(c.type)
|
691
711
|
end
|
@@ -700,21 +720,8 @@ module Solargraph
|
|
700
720
|
node.children.each { |c|
|
701
721
|
next unless c.kind_of?(AST::Node)
|
702
722
|
if c.type == :cvasgn
|
703
|
-
type =
|
704
|
-
|
705
|
-
if cmnt.nil?
|
706
|
-
sig = resolve_node_signature(c.children[1])
|
707
|
-
type = infer_signature_type(sig, namespace)
|
708
|
-
else
|
709
|
-
t = cmnt.tag(:type)
|
710
|
-
if t.nil?
|
711
|
-
sig = resolve_node_signature(c.children[1])
|
712
|
-
type = infer_signature_type(sig, namespace)
|
713
|
-
else
|
714
|
-
type = t.types[0]
|
715
|
-
end
|
716
|
-
end
|
717
|
-
arr.push Suggestion.new(c.children[0], kind: Suggestion::VARIABLE, documentation: cmnt, return_type: type)
|
723
|
+
type = infer_assignment_node_type(c, namespace)
|
724
|
+
arr.push Suggestion.new(c.children[0], kind: Suggestion::VARIABLE, documentation: get_comment_for(c), return_type: type)
|
718
725
|
end
|
719
726
|
arr += inner_get_class_variables(c, namespace) unless [:class, :module].include?(c.type)
|
720
727
|
}
|
@@ -729,6 +736,7 @@ module Solargraph
|
|
729
736
|
# @return [String] The fully qualified namespace for the signature's type
|
730
737
|
# or nil if a type could not be determined
|
731
738
|
def inner_infer_signature_type signature, namespace, scope: :instance
|
739
|
+
namespace = clean_namespace_string(namespace)
|
732
740
|
return nil if signature.nil?
|
733
741
|
signature.gsub!(/\.$/, '')
|
734
742
|
if signature.nil? or signature.empty?
|
@@ -749,7 +757,13 @@ module Solargraph
|
|
749
757
|
p = parts.shift
|
750
758
|
next if p.empty?
|
751
759
|
if top and scope == :class
|
752
|
-
|
760
|
+
if p == 'self'
|
761
|
+
top = false
|
762
|
+
return "Class<#{type}>" if parts.empty?
|
763
|
+
sub = inner_infer_signature_type(parts.join('.'), type, scope: :class)
|
764
|
+
return sub unless sub.to_s == ''
|
765
|
+
next
|
766
|
+
end
|
753
767
|
if p == 'new'
|
754
768
|
scope = :instance
|
755
769
|
type = namespace
|
@@ -758,12 +772,19 @@ module Solargraph
|
|
758
772
|
end
|
759
773
|
first_class = find_fully_qualified_namespace(p, namespace)
|
760
774
|
sub = nil
|
761
|
-
sub =
|
775
|
+
sub = inner_infer_signature_type(parts.join('.'), first_class, scope: :class) unless first_class.nil?
|
776
|
+
return sub unless sub.to_s == ''
|
777
|
+
end
|
778
|
+
if top and scope == :instance and p == 'self'
|
779
|
+
return type if parts.empty?
|
780
|
+
sub = infer_signature_type(parts.join('.'), type, scope: :instance)
|
762
781
|
return sub unless sub.to_s == ''
|
763
782
|
end
|
764
783
|
unless p == 'new' and scope != :instance
|
765
784
|
if scope == :instance
|
766
|
-
|
785
|
+
visibility = [:public]
|
786
|
+
visibility.push :private, :protected if top
|
787
|
+
meths = get_instance_methods(type, visibility: visibility)
|
767
788
|
meths += get_methods('') if top or type.to_s == ''
|
768
789
|
else
|
769
790
|
meths = get_methods(type)
|
@@ -772,7 +793,14 @@ module Solargraph
|
|
772
793
|
return nil if meths.empty?
|
773
794
|
type = nil
|
774
795
|
match = meths[0].return_type
|
775
|
-
|
796
|
+
unless match.nil?
|
797
|
+
cleaned = clean_namespace_string(match)
|
798
|
+
if cleaned.end_with?('#class')
|
799
|
+
return inner_infer_signature_type(parts.join('.'), cleaned.split('#').first, scope: :class)
|
800
|
+
else
|
801
|
+
type = find_fully_qualified_namespace(cleaned)
|
802
|
+
end
|
803
|
+
end
|
776
804
|
end
|
777
805
|
scope = :instance
|
778
806
|
top = false
|
@@ -855,7 +883,7 @@ module Solargraph
|
|
855
883
|
result = node.updated(type, children)
|
856
884
|
result
|
857
885
|
end
|
858
|
-
|
886
|
+
|
859
887
|
def local_path? path
|
860
888
|
return false if workspace.nil?
|
861
889
|
return true if File.exist?(File.join workspace, 'lib', path)
|
@@ -908,7 +936,12 @@ module Solargraph
|
|
908
936
|
end
|
909
937
|
|
910
938
|
def clean_namespace_string namespace
|
911
|
-
namespace.to_s.gsub(/<.*$/, '')
|
939
|
+
result = namespace.to_s.gsub(/<.*$/, '')
|
940
|
+
if result == 'Class' and namespace.include?('<')
|
941
|
+
subtype = namespace.match(/<([a-z0-9:_]*)/i)[1]
|
942
|
+
result = "#{subtype}#class"
|
943
|
+
end
|
944
|
+
result
|
912
945
|
end
|
913
946
|
end
|
914
947
|
end
|
data/lib/solargraph/code_map.rb
CHANGED
@@ -2,10 +2,32 @@ require 'parser/current'
|
|
2
2
|
|
3
3
|
module Solargraph
|
4
4
|
class CodeMap
|
5
|
+
|
6
|
+
# The root node of the parsed code.
|
7
|
+
#
|
8
|
+
# @return [AST::Node]
|
5
9
|
attr_accessor :node
|
10
|
+
|
11
|
+
# The source code being analyzed.
|
12
|
+
#
|
13
|
+
# @return [String]
|
6
14
|
attr_reader :code
|
15
|
+
|
16
|
+
# The source code after modification to fix syntax errors during parsing.
|
17
|
+
# This string will match #code if no modifications were made.
|
18
|
+
#
|
19
|
+
# @return [String]
|
7
20
|
attr_reader :parsed
|
21
|
+
|
22
|
+
# The filename for the source code.
|
23
|
+
#
|
24
|
+
# @return [String]
|
8
25
|
attr_reader :filename
|
26
|
+
|
27
|
+
# The root directory of the project. The ApiMap will search here for
|
28
|
+
# additional files to parse and analyze.
|
29
|
+
#
|
30
|
+
# @return [String]
|
9
31
|
attr_reader :workspace
|
10
32
|
|
11
33
|
include NodeMethods
|
@@ -39,7 +61,11 @@ module Solargraph
|
|
39
61
|
if !fixed_cursor and !cursor.nil? and e.message.include?('token $end') and cursor >= 2
|
40
62
|
fixed_cursor = true
|
41
63
|
spot = cursor - 2
|
42
|
-
|
64
|
+
if tmp[cursor - 1] == '.'
|
65
|
+
repl = ';'
|
66
|
+
else
|
67
|
+
repl = '#'
|
68
|
+
end
|
43
69
|
else
|
44
70
|
spot = e.diagnostic.location.begin_pos
|
45
71
|
repl = '_'
|
@@ -402,7 +428,7 @@ module Solargraph
|
|
402
428
|
return api_map.infer_signature_type(remainder.join('.'), type, scope: :instance)
|
403
429
|
elsif start.start_with?('@')
|
404
430
|
scope = (node.type == :def ? :instance : :scope)
|
405
|
-
type = api_map.infer_instance_variable(start, ns_here, scope
|
431
|
+
type = api_map.infer_instance_variable(start, ns_here, scope)
|
406
432
|
return nil if type.nil?
|
407
433
|
return type if remainder.empty?
|
408
434
|
return api_map.infer_signature_type(remainder.join('.'), type, scope: :instance)
|
@@ -438,13 +464,6 @@ module Solargraph
|
|
438
464
|
inferred
|
439
465
|
end
|
440
466
|
|
441
|
-
def suggest_for_signature_at index
|
442
|
-
result = []
|
443
|
-
type = infer_signature_at(index)
|
444
|
-
result.concat api_map.get_instance_methods(type) unless type.nil?
|
445
|
-
result
|
446
|
-
end
|
447
|
-
|
448
467
|
def get_type_comment node
|
449
468
|
obj = nil
|
450
469
|
cmnt = api_map.get_comment_for(node)
|
@@ -502,21 +521,6 @@ module Solargraph
|
|
502
521
|
signature
|
503
522
|
end
|
504
523
|
|
505
|
-
# Build a signature from the specified node. This method returns the node
|
506
|
-
# as an array of strings.
|
507
|
-
#
|
508
|
-
# @return [Array<String>]
|
509
|
-
def build_signature(node, parts)
|
510
|
-
if node.kind_of?(AST::Node)
|
511
|
-
if node.type == :send
|
512
|
-
parts.unshift node.children[1].to_s
|
513
|
-
elsif node.type == :const
|
514
|
-
parts.unshift unpack_name(node)
|
515
|
-
end
|
516
|
-
build_signature(node.children[0], parts)
|
517
|
-
end
|
518
|
-
end
|
519
|
-
|
520
524
|
def get_snippets_at(index)
|
521
525
|
result = []
|
522
526
|
Snippets.definitions.each_pair { |name, detail|
|
@@ -637,7 +641,8 @@ module Solargraph
|
|
637
641
|
node.children.each { |c|
|
638
642
|
if c.kind_of?(AST::Node)
|
639
643
|
if c.type == :lvasgn
|
640
|
-
|
644
|
+
type = api_map.infer_assignment_node_type(c, namespace_from(c))
|
645
|
+
arr.push Suggestion.new(c.children[0], kind: Suggestion::VARIABLE, documentation: api_map.get_comment_for(c), return_type: type)
|
641
646
|
else
|
642
647
|
arr += get_local_variables_from(c) unless [:class, :module, :def, :defs].include?(c.type)
|
643
648
|
end
|
data/lib/solargraph/server.rb
CHANGED
@@ -27,7 +27,7 @@ module Solargraph
|
|
27
27
|
workspace = params['workspace']
|
28
28
|
Server.prepare_workspace workspace unless @@api_hash.has_key?(workspace)
|
29
29
|
@@semaphore.synchronize {
|
30
|
-
code_map = CodeMap.new(code: params['text'], filename: params['filename'], api_map: @@api_hash[workspace])
|
30
|
+
code_map = CodeMap.new(code: params['text'], filename: params['filename'], api_map: @@api_hash[workspace], cursor: [params['line'].to_i, params['column'].to_i])
|
31
31
|
offset = code_map.get_offset(params['line'].to_i, params['column'].to_i)
|
32
32
|
sugg = code_map.suggest_at(offset, with_snippets: params['with_snippets'] == '1' ? true : false, filtered: (params['filtered'] || false))
|
33
33
|
}
|
@@ -46,7 +46,7 @@ module Solargraph
|
|
46
46
|
workspace = params['workspace'] || nil
|
47
47
|
Server.prepare_workspace workspace unless @@api_hash.has_key?(workspace)
|
48
48
|
@@semaphore.synchronize {
|
49
|
-
code_map = CodeMap.new(code: params['text'], filename: params['filename'], api_map: @@api_hash[workspace])
|
49
|
+
code_map = CodeMap.new(code: params['text'], filename: params['filename'], api_map: @@api_hash[workspace], cursor: [params['line'].to_i, params['column'].to_i])
|
50
50
|
offset = code_map.get_offset(params['line'].to_i, params['column'].to_i)
|
51
51
|
sugg = code_map.signatures_at(offset)
|
52
52
|
}
|
data/lib/solargraph/version.rb
CHANGED
@@ -10,24 +10,25 @@ module Solargraph
|
|
10
10
|
@constants[[namespace, scope]] = suggestions
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
14
|
-
@
|
13
|
+
def get_constants namespace, scope
|
14
|
+
@constants[[namespace, scope]]
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
18
|
-
@
|
17
|
+
def set_methods namespace, scope, visibility, suggestions
|
18
|
+
@methods[[namespace, scope, visibility]] = suggestions
|
19
19
|
end
|
20
20
|
|
21
21
|
def get_methods namespace, scope, visibility
|
22
22
|
@methods[[namespace, scope, visibility]]
|
23
23
|
end
|
24
24
|
|
25
|
+
def set_instance_methods namespace, scope, visibility, suggestions
|
26
|
+
@instance_methods[[namespace, scope, visibility]] = suggestions
|
27
|
+
end
|
28
|
+
|
25
29
|
def get_instance_methods namespace, scope, visibility
|
26
30
|
@instance_methods[[namespace, scope, visibility]]
|
27
31
|
end
|
28
32
|
|
29
|
-
def get_constants namespace, scope
|
30
|
-
@constants[[namespace, scope]]
|
31
|
-
end
|
32
33
|
end
|
33
34
|
end
|
data/lib/solargraph/yard_map.rb
CHANGED
@@ -139,31 +139,6 @@ module Solargraph
|
|
139
139
|
result
|
140
140
|
end
|
141
141
|
|
142
|
-
# @param signature [String]
|
143
|
-
def at signature
|
144
|
-
yardocs.each { |y|
|
145
|
-
yard = load_yardoc(y)
|
146
|
-
unless yard.nil?
|
147
|
-
obj = yard.at(signature)
|
148
|
-
return obj unless obj.nil?
|
149
|
-
end
|
150
|
-
}
|
151
|
-
nil
|
152
|
-
end
|
153
|
-
|
154
|
-
# @param signature [String]
|
155
|
-
# @param scope [String]
|
156
|
-
def resolve signature, scope
|
157
|
-
yardocs.each { |y|
|
158
|
-
yard = load_yardoc(y)
|
159
|
-
unless yard.nil?
|
160
|
-
obj = yard.resolve(P(scope), signature)
|
161
|
-
return obj unless obj.nil?
|
162
|
-
end
|
163
|
-
}
|
164
|
-
nil
|
165
|
-
end
|
166
|
-
|
167
142
|
# @return [Array<Suggestion>]
|
168
143
|
def get_methods namespace, scope = '', visibility: [:public]
|
169
144
|
cached = cache.get_methods(namespace, scope, visibility)
|
data/lib/solargraph.rb
CHANGED
@@ -11,7 +11,6 @@ module Solargraph
|
|
11
11
|
autoload :NodeMethods, 'solargraph/node_methods'
|
12
12
|
autoload :Suggestion, 'solargraph/suggestion'
|
13
13
|
autoload :Snippets, 'solargraph/snippets'
|
14
|
-
autoload :Mapper, 'solargraph/mapper'
|
15
14
|
autoload :Server, 'solargraph/server'
|
16
15
|
autoload :YardMap, 'solargraph/yard_map'
|
17
16
|
autoload :YardMethods, 'solargraph/yard_methods'
|
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.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fred Snyder
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|
@@ -50,14 +50,14 @@ dependencies:
|
|
50
50
|
requirements:
|
51
51
|
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: '
|
53
|
+
version: '2'
|
54
54
|
type: :runtime
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
58
|
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version: '
|
60
|
+
version: '2'
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
62
|
name: yard
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -98,14 +98,14 @@ dependencies:
|
|
98
98
|
requirements:
|
99
99
|
- - "~>"
|
100
100
|
- !ruby/object:Gem::Version
|
101
|
-
version: '0'
|
101
|
+
version: '0.7'
|
102
102
|
type: :development
|
103
103
|
prerelease: false
|
104
104
|
version_requirements: !ruby/object:Gem::Requirement
|
105
105
|
requirements:
|
106
106
|
- - "~>"
|
107
107
|
- !ruby/object:Gem::Version
|
108
|
-
version: '0'
|
108
|
+
version: '0.7'
|
109
109
|
- !ruby/object:Gem::Dependency
|
110
110
|
name: simplecov
|
111
111
|
requirement: !ruby/object:Gem::Requirement
|
@@ -133,7 +133,6 @@ files:
|
|
133
133
|
- lib/solargraph/api_map/cache.rb
|
134
134
|
- lib/solargraph/api_map/config.rb
|
135
135
|
- lib/solargraph/code_map.rb
|
136
|
-
- lib/solargraph/mapper.rb
|
137
136
|
- lib/solargraph/node_methods.rb
|
138
137
|
- lib/solargraph/server.rb
|
139
138
|
- lib/solargraph/shell.rb
|
@@ -162,7 +161,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
162
161
|
requirements:
|
163
162
|
- - ">="
|
164
163
|
- !ruby/object:Gem::Version
|
165
|
-
version:
|
164
|
+
version: 2.2.2
|
166
165
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
166
|
requirements:
|
168
167
|
- - ">="
|
data/lib/solargraph/mapper.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
module Solargraph
|
2
|
-
class Mapper
|
3
|
-
def initialize
|
4
|
-
@default_api_map = Solargraph::ApiMap.new
|
5
|
-
stub = Parser::CurrentRuby.parse(Solargraph::LiveParser.parse(nil))
|
6
|
-
@default_api_map.merge(stub)
|
7
|
-
@default_api_map.freeze
|
8
|
-
@require_nodes = {}
|
9
|
-
end
|
10
|
-
|
11
|
-
def get filename, text
|
12
|
-
workspace = find_workspace(filename)
|
13
|
-
CodeMap.new(text, api_map: @default_api_map, workspace: workspace, require_nodes: @require_nodes)
|
14
|
-
end
|
15
|
-
|
16
|
-
def find_workspace filename
|
17
|
-
dirname = filename
|
18
|
-
lastname = nil
|
19
|
-
result = nil
|
20
|
-
until dirname == lastname
|
21
|
-
if File.file?("#{dirname}/Gemfile")
|
22
|
-
result = dirname
|
23
|
-
break
|
24
|
-
end
|
25
|
-
lastname = dirname
|
26
|
-
dirname = File.dirname(dirname)
|
27
|
-
end
|
28
|
-
result || File.dirname(filename)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|