16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/solargraph/yard_map/rdoc_to_yard.rb', line 16
def self.run spec, cache_dir: nil
Dir.mktmpdir do |tmpdir|
rdir = File.join(tmpdir, 'sg_tmp_rdoc')
FileUtils.cp_r Dir.glob(File.join(spec.full_gem_path, '*')), tmpdir
Dir.chdir tmpdir do
pins = []
pins.push Solargraph::Pin::ROOT_PIN
name_hash = {}
argv = ['-q', '-r', '-N', '-o', rdir]
spec.load_paths.each do |path|
argv.concat ['-i', path]
end
rdoc = RDoc::RDoc.new
rdoc.document argv
store = rdoc.store
store.path = rdir
store.cache[:modules].each do |mod|
mod = store.find_class_or_module(mod)
closure = pins.select { |pin| pin.path == mod.full_name.split('::')[0..-2].join('::') }.first || pins.first
namepin = Solargraph::Pin::Namespace.new(
type: (mod.module? ? :module : :class),
name: mod.name,
comments: (mod.),
closure: closure,
location: locate(mod)
)
mod.parse(mod.)
mod.includes.each do |inc|
pins.push Solargraph::Pin::Reference::Include.new(
location: locate(inc),
name: inc.name,
closure: namepin
)
end
mod.extends.each do |ext|
pins.push Solargraph::Pin::Reference::Extend.new(
location: locate(ext),
name: ext.name,
closure: namepin
)
end
pins.push namepin
name_hash[mod.full_name] = namepin
mod.each_method do |met|
pin = Solargraph::SourceMap.load_string("def Object.tmp#{met.param_seq};end").first_pin('Object.tmp') || Solargraph::Pin::Method.new
pins.push Solargraph::Pin::Method.new(
name: met.name,
closure: namepin,
comments: (met.),
scope: met.type.to_sym,
parameters: pin.parameters,
visibility: met.visibility,
location: locate(met)
)
end
mod.each_constant do |const|
pins.push Solargraph::Pin::Constant.new(
name: const.name,
closure: namepin,
comments: (const.),
location: locate(const)
)
end
end
mapstore = Solargraph::ApiMap::Store.new(pins)
rake_yard(mapstore)
YARD::Registry.clear
code_object_map.values.each do |co|
YARD::Registry.register(co)
end
cache_dir ||= File.join(Solargraph::YardMap::CoreDocs.cache_dir, 'gems', "#{spec.name}-#{spec.version}", "yardoc")
FileUtils.remove_entry_secure cache_dir if File.exist?(cache_dir)
FileUtils.mkdir_p cache_dir
YARD::Registry.save true, cache_dir
FileUtils.safe_unlink File.join(CoreDocs.cache_dir, 'gems', "#{spec.name}-#{spec.version}.ser")
end
end
end
|