solargraph 0.17.0 → 0.17.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/solargraph/api_map.rb +22 -11
- data/lib/solargraph/api_map/source_to_yard.rb +13 -11
- data/lib/solargraph/code_map.rb +46 -3
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/yard_map.rb +46 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e75af30aa57a99e118082d7c337d889f7aa6151
|
4
|
+
data.tar.gz: 2937ed78501b758858b304127987eb822540163f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 110b41dcd353afc575f30a096e9e83d311ff8d664e37847097d4618ab8bfe76f7d4825ff730838f971ba3af503015cde7b156e7a1d8afef504dfa3b1515dc13e
|
7
|
+
data.tar.gz: 5e0bc35e2d8c06a73e452451ddb3167f06f00fc8e52add97f9ea4152387e14ea366d4e2b715491697f65194d601feb0d04d23c2b09d5bef31ec5136d29dc3b50
|
data/lib/solargraph/api_map.rb
CHANGED
@@ -104,7 +104,7 @@ module Solargraph
|
|
104
104
|
true
|
105
105
|
end
|
106
106
|
end
|
107
|
-
if filename.nil? or filename.end_with?('.rb')
|
107
|
+
if filename.nil? or filename.end_with?('.rb') or filename.end_with?('.erb')
|
108
108
|
eliminate @virtual_filename unless @virtual_source.nil? or @virtual_filename == filename or workspace_files.include?(@virtual_filename)
|
109
109
|
@virtual_filename = filename
|
110
110
|
@virtual_source = Source.fix(code, filename, cursor)
|
@@ -208,16 +208,22 @@ module Solargraph
|
|
208
208
|
result = []
|
209
209
|
skip = []
|
210
210
|
fqns = find_fully_qualified_namespace(namespace, root)
|
211
|
+
return [] if fqns.nil?
|
211
212
|
if fqns.empty?
|
212
|
-
result.concat inner_get_constants('', skip, false, :public)
|
213
|
+
result.concat inner_get_constants('', skip, false, [:public])
|
213
214
|
else
|
214
215
|
parts = fqns.split('::')
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
216
|
+
while parts.length > 0
|
217
|
+
resolved = find_namespace_pins(parts.join('::'))
|
218
|
+
resolved.each do |pin|
|
219
|
+
visi = :public
|
220
|
+
visi = :private if namespace == '' and root != '' and pin.path == fqns
|
221
|
+
result.concat inner_get_constants(pin.path, skip, true, visi)
|
222
|
+
end
|
223
|
+
parts.pop
|
224
|
+
break unless namespace.empty?
|
220
225
|
end
|
226
|
+
result.concat inner_get_constants('', [], false) if namespace.empty?
|
221
227
|
end
|
222
228
|
result.concat yard_map.get_constants(fqns)
|
223
229
|
result
|
@@ -832,7 +838,9 @@ module Solargraph
|
|
832
838
|
unless sc.nil?
|
833
839
|
sc_visi = [:public]
|
834
840
|
sc_visi.push :protected if root == fqns
|
835
|
-
|
841
|
+
nfqns = find_fully_qualified_namespace(sc, fqns)
|
842
|
+
meths.concat inner_get_methods('', nfqns, skip, sc_visi)
|
843
|
+
meths.concat yard_map.get_methods(nfqns, '', visibility: sc_visi)
|
836
844
|
end
|
837
845
|
end
|
838
846
|
em = @namespace_extends[fqns]
|
@@ -866,13 +874,16 @@ module Solargraph
|
|
866
874
|
unless sc.nil?
|
867
875
|
sc_visi = [:public]
|
868
876
|
sc_visi.push :protected if sc == fqns
|
869
|
-
|
877
|
+
nfqns = find_fully_qualified_namespace(sc, fqns)
|
878
|
+
meths.concat inner_get_instance_methods('', nfqns, skip, sc_visi)
|
879
|
+
meths.concat yard_map.get_instance_methods(nfqns, '', visibility: sc_visi)
|
870
880
|
end
|
871
881
|
end
|
872
882
|
im = @namespace_includes[fqns]
|
873
883
|
unless im.nil?
|
874
884
|
im.each do |i|
|
875
|
-
|
885
|
+
nfqns = find_fully_qualified_namespace(i, fqns)
|
886
|
+
meths.concat inner_get_instance_methods('', nfqns, skip, visibility)
|
876
887
|
end
|
877
888
|
end
|
878
889
|
meths.uniq
|
@@ -949,7 +960,7 @@ module Solargraph
|
|
949
960
|
type
|
950
961
|
end
|
951
962
|
|
952
|
-
def inner_get_constants here, skip = [], deep = true, visibility
|
963
|
+
def inner_get_constants here, skip = [], deep = true, visibility = [:public]
|
953
964
|
return [] if skip.include?(here)
|
954
965
|
skip.push here
|
955
966
|
result = []
|
@@ -2,8 +2,6 @@ module Solargraph
|
|
2
2
|
class ApiMap
|
3
3
|
module SourceToYard
|
4
4
|
|
5
|
-
private
|
6
|
-
|
7
5
|
# Get the YARD CodeObject at the specified path.
|
8
6
|
#
|
9
7
|
# @return [YARD::CodeObjects::Base]
|
@@ -15,14 +13,6 @@ module Solargraph
|
|
15
13
|
code_object_map.keys
|
16
14
|
end
|
17
15
|
|
18
|
-
def code_object_map
|
19
|
-
@code_object_map ||= {}
|
20
|
-
end
|
21
|
-
|
22
|
-
def root_code_object
|
23
|
-
@root_code_object ||= YARD::CodeObjects::RootObject.new(nil, 'root')
|
24
|
-
end
|
25
|
-
|
26
16
|
# @param sources [Array<Solargraph::ApiMap::Source>] Sources for code objects
|
27
17
|
def rake_yard sources
|
28
18
|
code_object_map.clear
|
@@ -37,7 +27,9 @@ module Solargraph
|
|
37
27
|
code_object_map[pin.path].files.push pin.source.filename
|
38
28
|
end
|
39
29
|
s.namespace_includes.each_pair do |n, i|
|
40
|
-
|
30
|
+
i.each do |inc|
|
31
|
+
code_object_map[n].instance_mixins.push code_object_map[inc] unless code_object_map[inc].nil?
|
32
|
+
end
|
41
33
|
end
|
42
34
|
s.attribute_pins.each do |pin|
|
43
35
|
code_object_map[pin.path] ||= YARD::CodeObjects::MethodObject.new(code_object_at(pin.namespace), pin.name, :instance)
|
@@ -60,6 +52,16 @@ module Solargraph
|
|
60
52
|
end
|
61
53
|
end
|
62
54
|
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def code_object_map
|
59
|
+
@code_object_map ||= {}
|
60
|
+
end
|
61
|
+
|
62
|
+
def root_code_object
|
63
|
+
@root_code_object ||= YARD::CodeObjects::RootObject.new(nil, 'root')
|
64
|
+
end
|
63
65
|
end
|
64
66
|
end
|
65
67
|
end
|
data/lib/solargraph/code_map.rb
CHANGED
@@ -2,8 +2,6 @@ require 'parser/current'
|
|
2
2
|
|
3
3
|
module Solargraph
|
4
4
|
class CodeMap
|
5
|
-
autoload :Statement, 'solargraph/code_map/statement'
|
6
|
-
|
7
5
|
# The root node of the parsed code.
|
8
6
|
#
|
9
7
|
# @return [Parser::AST::Node]
|
@@ -32,7 +30,11 @@ module Solargraph
|
|
32
30
|
filename = filename.gsub(File::ALT_SEPARATOR, File::SEPARATOR) unless filename.nil? or File::ALT_SEPARATOR.nil?
|
33
31
|
@filename = filename
|
34
32
|
@api_map = api_map
|
35
|
-
|
33
|
+
if !filename.nil? and filename.end_with?('.erb')
|
34
|
+
@source = self.api_map.virtualize(convert_erb(code), filename, cursor)
|
35
|
+
else
|
36
|
+
@source = self.api_map.virtualize(code, filename, cursor)
|
37
|
+
end
|
36
38
|
@node = @source.node
|
37
39
|
@code = @source.code
|
38
40
|
@comments = @source.comments
|
@@ -813,5 +815,46 @@ module Solargraph
|
|
813
815
|
return [] if match.nil?
|
814
816
|
match[1].split(',').map(&:strip)
|
815
817
|
end
|
818
|
+
|
819
|
+
# @param template [String]
|
820
|
+
def convert_erb template
|
821
|
+
result = ''
|
822
|
+
i = 0
|
823
|
+
in_code = false
|
824
|
+
if template.start_with?('<%=')
|
825
|
+
i += 3
|
826
|
+
result += ';;;'
|
827
|
+
in_code = true
|
828
|
+
elsif template.start_with? '<%'
|
829
|
+
i += 2
|
830
|
+
result += ';;'
|
831
|
+
in_code = true
|
832
|
+
end
|
833
|
+
while i < template.length
|
834
|
+
if in_code
|
835
|
+
if template[i, 2] == '%>'
|
836
|
+
i += 2
|
837
|
+
result += ';;'
|
838
|
+
in_code = false
|
839
|
+
else
|
840
|
+
result += template[i]
|
841
|
+
end
|
842
|
+
else
|
843
|
+
if template[i, 3] == '<%='
|
844
|
+
i += 2
|
845
|
+
result += ';;;'
|
846
|
+
in_code = true
|
847
|
+
elsif template[i, 2] == '<%'
|
848
|
+
i += 1
|
849
|
+
result += ';;'
|
850
|
+
in_code = true
|
851
|
+
else
|
852
|
+
result += template[i].sub(/[^\s]/, ' ')
|
853
|
+
end
|
854
|
+
end
|
855
|
+
i += 1
|
856
|
+
end
|
857
|
+
result
|
858
|
+
end
|
816
859
|
end
|
817
860
|
end
|
data/lib/solargraph/version.rb
CHANGED
data/lib/solargraph/yard_map.rb
CHANGED
@@ -22,6 +22,8 @@ module Solargraph
|
|
22
22
|
# HACK: YardMap needs its own copy of this array
|
23
23
|
@required = required.clone
|
24
24
|
@namespace_yardocs = {}
|
25
|
+
@gem_paths = {}
|
26
|
+
process_gem_paths
|
25
27
|
if !workspace.nil? and File.exist?(File.join workspace, 'Gemfile')
|
26
28
|
Bundler.with_clean_env do
|
27
29
|
Bundler.environment.chdir(workspace) do
|
@@ -246,7 +248,7 @@ module Solargraph
|
|
246
248
|
meths = obj.meths(scope: [:instance]).keep_if{|m| m.name.to_s == parts[1]}
|
247
249
|
meths.each do |m|
|
248
250
|
args = get_method_args(m)
|
249
|
-
result.push Solargraph::Suggestion.new(m.name, kind: 'Method', detail: m.path, code_object: m, arguments: args)
|
251
|
+
result.push Solargraph::Suggestion.new(m.name, kind: 'Method', detail: m.path, code_object: m, arguments: args, location: object_location(m))
|
250
252
|
end
|
251
253
|
end
|
252
254
|
else
|
@@ -254,7 +256,7 @@ module Solargraph
|
|
254
256
|
args = []
|
255
257
|
args = get_method_args(obj) if obj.kind_of?(YARD::CodeObjects::MethodObject)
|
256
258
|
kind = kind_of_object(obj)
|
257
|
-
result.push Solargraph::Suggestion.new(obj.name, kind: kind, detail: obj.path, code_object: obj, arguments: args)
|
259
|
+
result.push Solargraph::Suggestion.new(obj.name, kind: kind, detail: obj.path, code_object: obj, arguments: args, location: object_location(obj))
|
258
260
|
end
|
259
261
|
end
|
260
262
|
end
|
@@ -374,6 +376,37 @@ module Solargraph
|
|
374
376
|
end
|
375
377
|
end
|
376
378
|
|
379
|
+
def process_gem_paths
|
380
|
+
if !has_bundle?
|
381
|
+
required.each do |r|
|
382
|
+
spec = Gem::Specification.find_by_path(r)
|
383
|
+
if spec.nil?
|
384
|
+
STDERR.puts "Required path not found: #{r}"
|
385
|
+
else
|
386
|
+
@gem_paths[spec.name] = spec.full_gem_path
|
387
|
+
end
|
388
|
+
end
|
389
|
+
else
|
390
|
+
Bundler.with_clean_env do
|
391
|
+
Bundler.environment.chdir(workspace) do
|
392
|
+
Bundler.environment.gems.to_a.each do |g|
|
393
|
+
@gem_paths[g.name] = g.full_gem_path
|
394
|
+
end
|
395
|
+
end
|
396
|
+
#Bundler.environment.chdir(workspace) do
|
397
|
+
# required.each do |r|
|
398
|
+
# spec = Bundler.rubygems.gem_from_path(r)
|
399
|
+
# if spec.nil?
|
400
|
+
# STDERR.puts "Required path not found: #{r}"
|
401
|
+
# else
|
402
|
+
# @gem_paths[spec.name] = spec.full_gem_path
|
403
|
+
# end
|
404
|
+
# end
|
405
|
+
#end
|
406
|
+
end
|
407
|
+
end
|
408
|
+
end
|
409
|
+
|
377
410
|
def find_yardoc path
|
378
411
|
result = nil
|
379
412
|
spec = Gem::Specification.find_by_path(path)
|
@@ -441,11 +474,18 @@ module Solargraph
|
|
441
474
|
|
442
475
|
# @param obj [YARD::CodeObjects::Base]
|
443
476
|
def object_location obj
|
444
|
-
# @todo Locations from YardMaps are temporarily disabled pending a
|
445
|
-
# method for resolving the source file's absolute path.
|
446
|
-
return nil
|
447
477
|
return nil if obj.file.nil? or obj.line.nil?
|
448
|
-
|
478
|
+
@gem_paths.values.each do |path|
|
479
|
+
file = File.join(path, obj.file)
|
480
|
+
if File.exist?(file)
|
481
|
+
return "#{file}:#{obj.line - 1}:0"
|
482
|
+
end
|
483
|
+
end
|
484
|
+
nil
|
485
|
+
end
|
486
|
+
|
487
|
+
def has_bundle?
|
488
|
+
!workspace.nil? and File.exist?(File.join workspace, 'Gemfile')
|
449
489
|
end
|
450
490
|
end
|
451
491
|
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.17.
|
4
|
+
version: 0.17.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: 2018-02-
|
11
|
+
date: 2018-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|