solargraph 0.55.4 → 0.55.5
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/.github/workflows/plugins.yml +2 -0
- data/.github/workflows/typecheck.yml +2 -0
- data/.gitignore +2 -0
- data/CHANGELOG.md +3 -0
- data/README.md +13 -3
- data/lib/solargraph/api_map/index.rb +23 -15
- data/lib/solargraph/api_map/store.rb +2 -1
- data/lib/solargraph/api_map.rb +53 -27
- data/lib/solargraph/complex_type/type_methods.rb +5 -1
- data/lib/solargraph/complex_type/unique_type.rb +7 -0
- data/lib/solargraph/convention/base.rb +3 -3
- data/lib/solargraph/convention.rb +3 -3
- data/lib/solargraph/doc_map.rb +189 -43
- data/lib/solargraph/gem_pins.rb +53 -38
- data/lib/solargraph/language_server/host.rb +9 -1
- data/lib/solargraph/language_server/message/extended/check_gem_version.rb +1 -0
- data/lib/solargraph/language_server/message/extended/document.rb +5 -2
- data/lib/solargraph/language_server/message/extended/document_gems.rb +3 -3
- data/lib/solargraph/library.rb +7 -4
- data/lib/solargraph/location.rb +13 -0
- data/lib/solargraph/parser/parser_gem/class_methods.rb +5 -8
- data/lib/solargraph/parser/parser_gem/node_processors/casgn_node.rb +2 -2
- data/lib/solargraph/parser/parser_gem/node_processors/namespace_node.rb +2 -2
- data/lib/solargraph/pin/base.rb +268 -24
- data/lib/solargraph/pin/base_variable.rb +9 -8
- data/lib/solargraph/pin/callable.rb +69 -0
- data/lib/solargraph/pin/closure.rb +12 -0
- data/lib/solargraph/pin/local_variable.rb +8 -5
- data/lib/solargraph/pin/method.rb +134 -17
- data/lib/solargraph/pin/parameter.rb +43 -6
- data/lib/solargraph/pin/signature.rb +38 -0
- data/lib/solargraph/pin_cache.rb +185 -0
- data/lib/solargraph/position.rb +9 -0
- data/lib/solargraph/range.rb +9 -0
- data/lib/solargraph/rbs_map/conversions.rb +19 -8
- data/lib/solargraph/rbs_map/core_map.rb +31 -9
- data/lib/solargraph/rbs_map/stdlib_map.rb +15 -5
- data/lib/solargraph/rbs_map.rb +74 -17
- data/lib/solargraph/shell.rb +11 -15
- data/lib/solargraph/source_map.rb +0 -17
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/views/_method.erb +10 -10
- data/lib/solargraph/views/_namespace.erb +3 -3
- data/lib/solargraph/views/document.erb +10 -10
- data/lib/solargraph/workspace.rb +15 -5
- data/lib/solargraph/yardoc.rb +3 -11
- data/lib/solargraph.rb +10 -12
- data/rbs_collection.yaml +19 -0
- data/solargraph.gemspec +1 -0
- metadata +19 -7
- data/lib/solargraph/cache.rb +0 -77
@@ -6,7 +6,7 @@ module Solargraph
|
|
6
6
|
class RbsMap
|
7
7
|
# Functions for converting RBS declarations to Solargraph pins
|
8
8
|
#
|
9
|
-
|
9
|
+
class Conversions
|
10
10
|
include Logging
|
11
11
|
|
12
12
|
# A container for tracking the current context of the RBS conversion
|
@@ -22,11 +22,17 @@ module Solargraph
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
@pins
|
25
|
+
def initialize(loader:)
|
26
|
+
@loader = loader
|
27
|
+
@pins = []
|
28
|
+
load_environment_to_pins(loader)
|
28
29
|
end
|
29
30
|
|
31
|
+
attr_reader :loader
|
32
|
+
|
33
|
+
# @return [Array<Pin::Base>]
|
34
|
+
attr_reader :pins
|
35
|
+
|
30
36
|
private
|
31
37
|
|
32
38
|
# @return [Hash{String => RBS::AST::Declarations::TypeAlias}]
|
@@ -39,6 +45,10 @@ module Solargraph
|
|
39
45
|
def load_environment_to_pins(loader)
|
40
46
|
environment = RBS::Environment.from_loader(loader).resolve_type_names
|
41
47
|
cursor = pins.length
|
48
|
+
if environment.declarations.empty?
|
49
|
+
Solargraph.logger.info "No RBS declarations found in environment for core_root #{loader.core_root.inspect}, libraries #{loader.libs} and directories #{loader.dirs}"
|
50
|
+
return
|
51
|
+
end
|
42
52
|
environment.declarations.each { |decl| convert_decl_to_pin(decl, Solargraph::Pin::ROOT_PIN) }
|
43
53
|
end
|
44
54
|
|
@@ -488,7 +498,7 @@ module Solargraph
|
|
488
498
|
type_location: location_decl_to_pin_location(decl.location),
|
489
499
|
closure: closure,
|
490
500
|
comments: decl.comment&.string,
|
491
|
-
scope:
|
501
|
+
scope: final_scope,
|
492
502
|
attribute: true,
|
493
503
|
visibility: visibility,
|
494
504
|
source: :rbs
|
@@ -512,7 +522,7 @@ module Solargraph
|
|
512
522
|
closure: closure,
|
513
523
|
parameters: [],
|
514
524
|
comments: decl.comment&.string,
|
515
|
-
scope:
|
525
|
+
scope: final_scope,
|
516
526
|
attribute: true,
|
517
527
|
visibility: visibility,
|
518
528
|
source: :rbs
|
@@ -628,11 +638,13 @@ module Solargraph
|
|
628
638
|
# @param closure [Pin::Namespace]
|
629
639
|
# @return [void]
|
630
640
|
def alias_to_pin decl, closure
|
641
|
+
final_scope = decl.singleton? ? :class : :instance
|
631
642
|
pins.push Solargraph::Pin::MethodAlias.new(
|
632
643
|
name: decl.new_name.to_s,
|
633
644
|
type_location: location_decl_to_pin_location(decl.location),
|
634
645
|
original: decl.old_name.to_s,
|
635
646
|
closure: closure,
|
647
|
+
scope: final_scope,
|
636
648
|
source: :rbs,
|
637
649
|
)
|
638
650
|
end
|
@@ -683,8 +695,7 @@ module Solargraph
|
|
683
695
|
if type.is_a?(RBS::Types::Optional)
|
684
696
|
"#{other_type_to_tag(type.type)}, nil"
|
685
697
|
elsif type.is_a?(RBS::Types::Bases::Any)
|
686
|
-
|
687
|
-
'BasicObject'
|
698
|
+
'undefined'
|
688
699
|
elsif type.is_a?(RBS::Types::Bases::Bool)
|
689
700
|
'Boolean'
|
690
701
|
elsif type.is_a?(RBS::Types::Tuple)
|
@@ -5,24 +5,46 @@ module Solargraph
|
|
5
5
|
# Ruby core pins
|
6
6
|
#
|
7
7
|
class CoreMap
|
8
|
-
|
8
|
+
|
9
|
+
def resolved?
|
10
|
+
true
|
11
|
+
end
|
9
12
|
|
10
13
|
FILLS_DIRECTORY = File.join(File.dirname(__FILE__), '..', '..', '..', 'rbs', 'fills')
|
11
14
|
|
12
|
-
def initialize
|
13
|
-
|
15
|
+
def initialize; end
|
16
|
+
|
17
|
+
def pins
|
18
|
+
return @pins if @pins
|
19
|
+
|
20
|
+
@pins = []
|
21
|
+
cache = PinCache.deserialize_core
|
14
22
|
if cache
|
15
|
-
pins.replace cache
|
23
|
+
@pins.replace cache
|
16
24
|
else
|
17
|
-
loader = RBS::EnvironmentLoader.new(repository: RBS::Repository.new(no_stdlib: false))
|
18
25
|
loader.add(path: Pathname(FILLS_DIRECTORY))
|
19
|
-
|
20
|
-
pins.concat RbsMap::CoreFills::ALL
|
26
|
+
@pins = conversions.pins
|
27
|
+
@pins.concat RbsMap::CoreFills::ALL
|
21
28
|
processed = ApiMap::Store.new(pins).pins.reject { |p| p.is_a?(Solargraph::Pin::Reference::Override) }
|
22
|
-
pins.replace processed
|
29
|
+
@pins.replace processed
|
23
30
|
|
24
|
-
|
31
|
+
PinCache.serialize_core @pins
|
25
32
|
end
|
33
|
+
@pins
|
34
|
+
end
|
35
|
+
|
36
|
+
def loader
|
37
|
+
@loader ||= RBS::EnvironmentLoader.new(repository: RBS::Repository.new(no_stdlib: false))
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def loader
|
43
|
+
@loader ||= RBS::EnvironmentLoader.new(repository: RBS::Repository.new(no_stdlib: false))
|
44
|
+
end
|
45
|
+
|
46
|
+
def conversions
|
47
|
+
@conversions ||= Conversions.new(loader: loader)
|
26
48
|
end
|
27
49
|
end
|
28
50
|
end
|
@@ -7,19 +7,29 @@ module Solargraph
|
|
7
7
|
# Ruby stdlib pins
|
8
8
|
#
|
9
9
|
class StdlibMap < RbsMap
|
10
|
+
include Logging
|
11
|
+
|
10
12
|
# @type [Hash{String => RbsMap}]
|
11
13
|
@stdlib_maps_hash = {}
|
12
14
|
|
13
15
|
# @param library [String]
|
14
16
|
def initialize library
|
15
|
-
|
16
|
-
if
|
17
|
-
pins
|
17
|
+
cached_pins = PinCache.deserialize_stdlib_require library
|
18
|
+
if cached_pins
|
19
|
+
@pins = cached_pins
|
18
20
|
@resolved = true
|
21
|
+
@loaded = true
|
22
|
+
logger.debug { "Deserialized #{cached_pins.length} cached pins for stdlib require #{library.inspect}" }
|
19
23
|
else
|
20
24
|
super
|
21
|
-
|
22
|
-
|
25
|
+
unless resolved?
|
26
|
+
@pins = []
|
27
|
+
logger.info { "Could not resolve #{library.inspect}" }
|
28
|
+
return
|
29
|
+
end
|
30
|
+
generated_pins = pins
|
31
|
+
logger.debug { "Found #{generated_pins.length} pins for stdlib library #{library}" }
|
32
|
+
PinCache.serialize_stdlib_require library, generated_pins
|
23
33
|
end
|
24
34
|
end
|
25
35
|
|
data/lib/solargraph/rbs_map.rb
CHANGED
@@ -10,25 +10,78 @@ module Solargraph
|
|
10
10
|
autoload :CoreFills, 'solargraph/rbs_map/core_fills'
|
11
11
|
autoload :StdlibMap, 'solargraph/rbs_map/stdlib_map'
|
12
12
|
|
13
|
-
include
|
13
|
+
include Logging
|
14
14
|
|
15
15
|
# @type [Hash{String => RbsMap}]
|
16
16
|
@@rbs_maps_hash = {}
|
17
17
|
|
18
18
|
attr_reader :library
|
19
19
|
|
20
|
+
attr_reader :rbs_collection_paths
|
21
|
+
|
22
|
+
attr_reader :rbs_collection_config_path
|
23
|
+
|
20
24
|
# @param library [String]
|
21
25
|
# @param version [String, nil]
|
22
|
-
# @param
|
23
|
-
def initialize library, version = nil,
|
26
|
+
# @param rbs_collection_paths [Array<Pathname, String>]
|
27
|
+
def initialize library, version = nil, rbs_collection_config_path: nil, rbs_collection_paths: []
|
28
|
+
if rbs_collection_config_path.nil? && !rbs_collection_paths.empty?
|
29
|
+
raise 'Please provide rbs_collection_config_path if you provide rbs_collection_paths'
|
30
|
+
end
|
24
31
|
@library = library
|
25
32
|
@version = version
|
26
|
-
@
|
27
|
-
@
|
28
|
-
loader = RBS::EnvironmentLoader.new(core_root: nil, repository: repository)
|
33
|
+
@rbs_collection_config_path = rbs_collection_config_path
|
34
|
+
@rbs_collection_paths = rbs_collection_paths
|
29
35
|
add_library loader, library, version
|
30
|
-
|
31
|
-
|
36
|
+
end
|
37
|
+
|
38
|
+
def loader
|
39
|
+
@loader ||= RBS::EnvironmentLoader.new(core_root: nil, repository: repository)
|
40
|
+
end
|
41
|
+
|
42
|
+
# @return string representing the version of the RBS info fetched
|
43
|
+
# for the given library. Must change when the RBS info is
|
44
|
+
# updated upstream for the same library and version. May change
|
45
|
+
# if the config for where information comes form changes.
|
46
|
+
def cache_key
|
47
|
+
@hextdigest ||= begin
|
48
|
+
data = nil
|
49
|
+
if rbs_collection_config_path
|
50
|
+
lockfile_path = RBS::Collection::Config.to_lockfile_path(Pathname.new(rbs_collection_config_path))
|
51
|
+
if lockfile_path.exist?
|
52
|
+
collection_config = RBS::Collection::Config.from_path lockfile_path
|
53
|
+
gem_config = collection_config.gem(library)
|
54
|
+
data = gem_config&.to_s
|
55
|
+
end
|
56
|
+
end
|
57
|
+
if data.nil? || data.empty?
|
58
|
+
if resolved?
|
59
|
+
# definitely came from the gem itself and not elsewhere -
|
60
|
+
# only one version per gem
|
61
|
+
'gem-export'
|
62
|
+
else
|
63
|
+
'unresolved'
|
64
|
+
end
|
65
|
+
else
|
66
|
+
Digest::SHA1.hexdigest(data)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.from_gemspec gemspec, rbs_collection_path, rbs_collection_config_path
|
72
|
+
rbs_map = RbsMap.new(gemspec.name, gemspec.version,
|
73
|
+
rbs_collection_paths: [rbs_collection_path].compact,
|
74
|
+
rbs_collection_config_path: rbs_collection_config_path)
|
75
|
+
return rbs_map if rbs_map.resolved?
|
76
|
+
|
77
|
+
# try any version of the gem in the collection
|
78
|
+
RbsMap.new(gemspec.name, nil,
|
79
|
+
rbs_collection_paths: [rbs_collection_path].compact,
|
80
|
+
rbs_collection_config_path: rbs_collection_config_path)
|
81
|
+
end
|
82
|
+
|
83
|
+
def pins
|
84
|
+
@pins ||= resolved? ? conversions.pins : []
|
32
85
|
end
|
33
86
|
|
34
87
|
# @generic T
|
@@ -52,9 +105,10 @@ module Solargraph
|
|
52
105
|
|
53
106
|
def repository
|
54
107
|
@repository ||= RBS::Repository.new(no_stdlib: false).tap do |repo|
|
55
|
-
|
56
|
-
|
57
|
-
|
108
|
+
@rbs_collection_paths.each do |dir|
|
109
|
+
dir_path = Pathname.new(dir)
|
110
|
+
repo.add(dir_path) if dir_path.exist? && dir_path.directory?
|
111
|
+
end
|
58
112
|
end
|
59
113
|
end
|
60
114
|
|
@@ -64,12 +118,15 @@ module Solargraph
|
|
64
118
|
@@rbs_maps_hash[library] ||= RbsMap.new(library)
|
65
119
|
end
|
66
120
|
|
67
|
-
|
68
|
-
|
69
|
-
|
121
|
+
private
|
122
|
+
|
123
|
+
def loader
|
124
|
+
@loader ||= RBS::EnvironmentLoader.new(core_root: nil, repository: repository)
|
70
125
|
end
|
71
126
|
|
72
|
-
|
127
|
+
def conversions
|
128
|
+
@conversions ||= Conversions.new(loader: loader)
|
129
|
+
end
|
73
130
|
|
74
131
|
# @param loader [RBS::EnvironmentLoader]
|
75
132
|
# @param library [String]
|
@@ -77,10 +134,10 @@ module Solargraph
|
|
77
134
|
def add_library loader, library, version
|
78
135
|
@resolved = if loader.has_library?(library: library, version: version)
|
79
136
|
loader.add library: library, version: version
|
80
|
-
|
137
|
+
logger.debug { "#{short_name} successfully loaded library #{library}:#{version}" }
|
81
138
|
true
|
82
139
|
else
|
83
|
-
|
140
|
+
logger.info { "#{short_name} did not find data for library #{library}:#{version}" }
|
84
141
|
false
|
85
142
|
end
|
86
143
|
end
|
data/lib/solargraph/shell.rb
CHANGED
@@ -90,19 +90,20 @@ module Solargraph
|
|
90
90
|
# @return [void]
|
91
91
|
def clear
|
92
92
|
puts "Deleting all cached documentation (gems, core and stdlib)"
|
93
|
-
Solargraph::
|
93
|
+
Solargraph::PinCache.clear
|
94
94
|
end
|
95
95
|
map 'clear-cache' => :clear
|
96
96
|
map 'clear-cores' => :clear
|
97
97
|
|
98
98
|
desc 'cache', 'Cache a gem', hide: true
|
99
|
+
option :rebuild, type: :boolean, desc: 'Rebuild existing documentation', default: false
|
99
100
|
# @return [void]
|
100
101
|
# @param gem [String]
|
101
102
|
# @param version [String, nil]
|
102
103
|
def cache gem, version = nil
|
104
|
+
api_map = Solargraph::ApiMap.load(Dir.pwd)
|
103
105
|
spec = Gem::Specification.find_by_name(gem, version)
|
104
|
-
|
105
|
-
Cache.save('gems', "#{spec.name}-#{spec.version}.ser", pins)
|
106
|
+
api_map.cache_gem(spec, rebuild: options[:rebuild], out: $stdout)
|
106
107
|
end
|
107
108
|
|
108
109
|
desc 'uncache GEM [...GEM]', "Delete specific cached gem documentation"
|
@@ -117,18 +118,17 @@ module Solargraph
|
|
117
118
|
raise ArgumentError, 'No gems specified.' if gems.empty?
|
118
119
|
gems.each do |gem|
|
119
120
|
if gem == 'core'
|
120
|
-
|
121
|
+
PinCache.uncache_core
|
121
122
|
next
|
122
123
|
end
|
123
124
|
|
124
125
|
if gem == 'stdlib'
|
125
|
-
|
126
|
+
PinCache.uncache_stdlib
|
126
127
|
next
|
127
128
|
end
|
128
129
|
|
129
130
|
spec = Gem::Specification.find_by_name(gem)
|
130
|
-
|
131
|
-
Cache.uncache('gems', "#{spec.name}-#{spec.version}.yardoc")
|
131
|
+
PinCache.uncache_gem(spec, out: $stdout)
|
132
132
|
end
|
133
133
|
end
|
134
134
|
|
@@ -257,14 +257,10 @@ module Solargraph
|
|
257
257
|
# @param gemspec [Gem::Specification]
|
258
258
|
# @return [void]
|
259
259
|
def do_cache gemspec
|
260
|
-
|
261
|
-
if
|
262
|
-
|
263
|
-
|
264
|
-
puts "#{cached ? 'Rebuilding' : 'Caching'} gem documentation for #{gemspec.name} #{gemspec.version}"
|
265
|
-
pins = GemPins.build(gemspec)
|
266
|
-
Cache.save('gems', "#{gemspec.name}-#{gemspec.version}.ser", pins)
|
267
|
-
end
|
260
|
+
api_map = ApiMap.load('.')
|
261
|
+
# @todo if the rebuild: option is passed as a positional arg,
|
262
|
+
# typecheck doesn't complain on the below line
|
263
|
+
api_map.cache_gem(gemspec, rebuild: options.rebuild, out: $stdout)
|
268
264
|
end
|
269
265
|
end
|
270
266
|
end
|
@@ -118,23 +118,6 @@ module Solargraph
|
|
118
118
|
_locate_pin line, character, Pin::Namespace, Pin::Method, Pin::Block
|
119
119
|
end
|
120
120
|
|
121
|
-
# @todo Candidate for deprecation
|
122
|
-
#
|
123
|
-
# @param other_map [SourceMap]
|
124
|
-
# @return [Boolean]
|
125
|
-
def try_merge! other_map
|
126
|
-
return false if pins.length != other_map.pins.length || locals.length != other_map.locals.length || requires.map(&:name).uniq.sort != other_map.requires.map(&:name).uniq.sort
|
127
|
-
|
128
|
-
pins.each_index do |i|
|
129
|
-
return false unless pins[i].try_merge!(other_map.pins[i])
|
130
|
-
end
|
131
|
-
locals.each_index do |i|
|
132
|
-
return false unless locals[i].try_merge!(other_map.locals[i])
|
133
|
-
end
|
134
|
-
@source = other_map.source
|
135
|
-
true
|
136
|
-
end
|
137
|
-
|
138
121
|
# @param name [String]
|
139
122
|
# @return [Array<Location>]
|
140
123
|
def references name
|
data/lib/solargraph/version.rb
CHANGED
@@ -2,33 +2,33 @@
|
|
2
2
|
Namespace:
|
3
3
|
</h2>
|
4
4
|
<p>
|
5
|
-
<a href="solargraph:/document?query=<%= CGI.escape
|
5
|
+
<a href="solargraph:/document?query=<%= CGI.escape pin.namespace.path %>"><%= pin.namespace %></a>
|
6
6
|
</p>
|
7
7
|
<h2>
|
8
8
|
Overview:
|
9
9
|
</h2>
|
10
|
-
<%= htmlify
|
10
|
+
<%= htmlify pin.docstring %>
|
11
11
|
<p class="document-section">
|
12
|
-
<big><strong>Visibility:</strong></big> <%=
|
12
|
+
<big><strong>Visibility:</strong></big> <%= pin.visibility %>
|
13
13
|
</p>
|
14
|
-
<% unless
|
14
|
+
<% unless pin.docstring.tags(:param).empty? %>
|
15
15
|
<h2>
|
16
16
|
Parameters:
|
17
17
|
</h2>
|
18
18
|
<ul>
|
19
|
-
<%
|
19
|
+
<% pin.docstring.tags(:param).each do |tag| %>
|
20
20
|
<li>
|
21
21
|
<%= erb :_name_type_tag, layout: false, locals: {tag: tag} %>
|
22
22
|
</li>
|
23
23
|
<% end %>
|
24
24
|
</ul>
|
25
25
|
<% end %>
|
26
|
-
<% unless
|
26
|
+
<% unless pin.docstring.tags(:raise).empty? %>
|
27
27
|
<h2>
|
28
28
|
Raises:
|
29
29
|
</h2>
|
30
30
|
<ul>
|
31
|
-
<%
|
31
|
+
<% pin.docstring.tags(:raise).each do |tag| %>
|
32
32
|
<li>
|
33
33
|
<%= erb :_name_type_tag, layout: false, locals: {tag: tag} %>
|
34
34
|
</li>
|
@@ -38,20 +38,20 @@
|
|
38
38
|
<h2>
|
39
39
|
Returns:
|
40
40
|
</h2>
|
41
|
-
<% if
|
41
|
+
<% if pin.docstring.tag(:return).nil? %>
|
42
42
|
<p>
|
43
43
|
Undefined/unknown
|
44
44
|
</p>
|
45
45
|
<% else %>
|
46
46
|
<ul>
|
47
|
-
<%
|
47
|
+
<% pin.tags(:return).each do |tag| %>
|
48
48
|
<li>
|
49
49
|
<%= erb :_name_type_tag, layout: false, locals: {tag: tag} %>
|
50
50
|
</li>
|
51
51
|
<% end %>
|
52
52
|
</ul>
|
53
53
|
<% end %>
|
54
|
-
<% examples =
|
54
|
+
<% examples = pin.docstring.tags(:example) %>
|
55
55
|
<% unless examples.nil? %>
|
56
56
|
<% examples.each do |example| %>
|
57
57
|
<h2>
|
@@ -1,12 +1,12 @@
|
|
1
1
|
<h2>
|
2
2
|
Overview:
|
3
3
|
</h2>
|
4
|
-
<%= htmlify
|
4
|
+
<%= htmlify pin.docstring %>
|
5
5
|
<h2>
|
6
6
|
Class Methods
|
7
7
|
</h2>
|
8
8
|
<ul class="doc-list">
|
9
|
-
<%
|
9
|
+
<% api_map.get_methods(pin.path, scope: :class, deep: false).sort{|a, b| a.name <=> b.name}.each do |meth| %>
|
10
10
|
<li>
|
11
11
|
<a href="solargraph:/document?query=<%= CGI.escape(meth.path) %>"><%= meth.name %></a>
|
12
12
|
</li>
|
@@ -16,7 +16,7 @@
|
|
16
16
|
Instance Methods
|
17
17
|
</h2>
|
18
18
|
<ul class="doc-list">
|
19
|
-
<%
|
19
|
+
<% api_map.get_methods(pin.path, scope: :instance, deep: false).sort{|a, b| a.name <=> b.name}.each do |meth| %>
|
20
20
|
<li>
|
21
21
|
<a href="solargraph:/document?query=<%= CGI.escape(meth.path) %>"><%= meth.name %></a>
|
22
22
|
</li>
|
@@ -1,23 +1,23 @@
|
|
1
|
-
<%
|
1
|
+
<% pins.each do |pin| %>
|
2
2
|
<h1>
|
3
|
-
<%=
|
4
|
-
<% if
|
5
|
-
<small>(<%=
|
3
|
+
<%= pin.name %>
|
4
|
+
<% if pin.is_a?(Solargraph::Pin::Method) && !pin.parameters.empty? %>
|
5
|
+
<small>(<%= pin.parameters.map {|p| "#{p[0]}#{p[1] and p[0].end_with?(':') ? ' ' : (p[1] ? ' = ' : '')}#{p[1]}"}.join(', ') %>)</small>
|
6
6
|
<% end %>
|
7
7
|
</h1>
|
8
|
-
<% unless
|
8
|
+
<% unless pins.map(&:location).compact.empty? %>
|
9
9
|
<h2>
|
10
10
|
Defined in:
|
11
11
|
</h2>
|
12
12
|
<ul>
|
13
|
-
<%
|
13
|
+
<% pins.map(&:location).compact.map(&:filename).each do |f| %>
|
14
14
|
<li><%= f %></li>
|
15
15
|
<% end %>
|
16
16
|
</ul>
|
17
17
|
<% end %>
|
18
|
-
<% if
|
19
|
-
<%= erb :_namespace, layout: false, locals: {
|
20
|
-
<% elsif
|
21
|
-
<%= erb :_method, layout: false, locals: {
|
18
|
+
<% if pin.is_a?(Solargraph::Pin::Namespace) %>
|
19
|
+
<%= erb :_namespace, layout: false, locals: {api_map: api_map, pin: pin} %>
|
20
|
+
<% elsif pin.is_a?(Solargraph::Pin::Method) %>
|
21
|
+
<%= erb :_method, layout: false, locals: {api_map: api_map, pin: pin} %>
|
22
22
|
<% end %>
|
23
23
|
<% end %>
|
data/lib/solargraph/workspace.rb
CHANGED
@@ -106,7 +106,7 @@ module Solargraph
|
|
106
106
|
def would_require? path
|
107
107
|
require_paths.each do |rp|
|
108
108
|
full = File.join rp, path
|
109
|
-
return true if File.
|
109
|
+
return true if File.file?(full) || File.file?(full << ".rb")
|
110
110
|
end
|
111
111
|
false
|
112
112
|
end
|
@@ -133,6 +133,15 @@ module Solargraph
|
|
133
133
|
@gem_rbs_collection ||= read_rbs_collection_path
|
134
134
|
end
|
135
135
|
|
136
|
+
def rbs_collection_config_path
|
137
|
+
@rbs_collection_config_path ||= begin
|
138
|
+
unless directory.empty? || directory == '*'
|
139
|
+
yaml_file = File.join(directory, 'rbs_collection.yaml')
|
140
|
+
yaml_file if File.file?(yaml_file)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
136
145
|
# Synchronize the workspace from the provided updater.
|
137
146
|
#
|
138
147
|
# @param updater [Source::Updater]
|
@@ -214,7 +223,7 @@ module Solargraph
|
|
214
223
|
def configured_require_paths
|
215
224
|
return ['lib'] if directory.empty?
|
216
225
|
return [File.join(directory, 'lib')] if config.require_paths.empty?
|
217
|
-
config.require_paths.map{|p| File.join(directory, p)}
|
226
|
+
config.require_paths.map { |p| File.join(directory, p) }
|
218
227
|
end
|
219
228
|
|
220
229
|
# @return [void]
|
@@ -230,10 +239,11 @@ module Solargraph
|
|
230
239
|
|
231
240
|
# @return [String, nil]
|
232
241
|
def read_rbs_collection_path
|
233
|
-
|
234
|
-
return unless File.file?(yaml_file)
|
242
|
+
return unless rbs_collection_config_path
|
235
243
|
|
236
|
-
YAML.load_file(
|
244
|
+
path = YAML.load_file(rbs_collection_config_path)&.fetch('path')
|
245
|
+
# make fully qualified
|
246
|
+
File.expand_path(path, directory)
|
237
247
|
end
|
238
248
|
end
|
239
249
|
end
|
data/lib/solargraph/yardoc.rb
CHANGED
@@ -12,7 +12,7 @@ module Solargraph
|
|
12
12
|
# @param gemspec [Gem::Specification]
|
13
13
|
# @return [String] The path to the cached yardoc.
|
14
14
|
def cache(gemspec)
|
15
|
-
path =
|
15
|
+
path = PinCache.yardoc_path gemspec
|
16
16
|
return path if cached?(gemspec)
|
17
17
|
|
18
18
|
Solargraph.logger.info "Caching yardoc for #{gemspec.name} #{gemspec.version}"
|
@@ -26,18 +26,10 @@ module Solargraph
|
|
26
26
|
#
|
27
27
|
# @param gemspec [Gem::Specification]
|
28
28
|
def cached?(gemspec)
|
29
|
-
yardoc = File.join(
|
29
|
+
yardoc = File.join(PinCache.yardoc_path(gemspec), 'complete')
|
30
30
|
File.exist?(yardoc)
|
31
31
|
end
|
32
32
|
|
33
|
-
# Get the absolute path for a cached gem yardoc.
|
34
|
-
#
|
35
|
-
# @param gemspec [Gem::Specification]
|
36
|
-
# @return [String]
|
37
|
-
def path_for(gemspec)
|
38
|
-
File.join(Solargraph::Cache.base_dir, "yard-#{YARD::VERSION}", "#{gemspec.name}-#{gemspec.version}.yardoc")
|
39
|
-
end
|
40
|
-
|
41
33
|
# Load a gem's yardoc and return its code objects.
|
42
34
|
#
|
43
35
|
# @note This method modifies the global YARD registry.
|
@@ -45,7 +37,7 @@ module Solargraph
|
|
45
37
|
# @param gemspec [Gem::Specification]
|
46
38
|
# @return [Array<YARD::CodeObjects::Base>]
|
47
39
|
def load!(gemspec)
|
48
|
-
YARD::Registry.load!
|
40
|
+
YARD::Registry.load! PinCache.yardoc_path gemspec
|
49
41
|
YARD::Registry.all
|
50
42
|
end
|
51
43
|
end
|
data/lib/solargraph.rb
CHANGED
@@ -48,23 +48,21 @@ module Solargraph
|
|
48
48
|
autoload :Parser, 'solargraph/parser'
|
49
49
|
autoload :RbsMap, 'solargraph/rbs_map'
|
50
50
|
autoload :GemPins, 'solargraph/gem_pins'
|
51
|
-
autoload :
|
51
|
+
autoload :PinCache, 'solargraph/pin_cache'
|
52
52
|
|
53
53
|
dir = File.dirname(__FILE__)
|
54
54
|
VIEWS_PATH = File.join(dir, 'solargraph', 'views')
|
55
55
|
|
56
|
-
# @param type [Symbol] Type of assert.
|
57
|
-
# used in the future to allow configurable asserts mixes for
|
58
|
-
# different situations.
|
56
|
+
# @param type [Symbol] Type of assert.
|
59
57
|
def self.asserts_on?(type)
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
58
|
+
if ENV['SOLARGRAPH_ASSERTS'].nil? || ENV['SOLARGRAPH_ASSERTS'].empty?
|
59
|
+
false
|
60
|
+
elsif ENV['SOLARGRAPH_ASSERTS'] == 'on'
|
61
|
+
true
|
62
|
+
else
|
63
|
+
logger.warn "Unrecognized SOLARGRAPH_ASSERTS value: #{ENV['SOLARGRAPH_ASSERTS']}"
|
64
|
+
false
|
65
|
+
end
|
68
66
|
end
|
69
67
|
|
70
68
|
def self.assert_or_log(type, msg = nil, &block)
|
data/rbs_collection.yaml
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Download sources
|
2
|
+
sources:
|
3
|
+
- type: git
|
4
|
+
name: ruby/gem_rbs_collection
|
5
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
6
|
+
revision: main
|
7
|
+
repo_dir: gems
|
8
|
+
|
9
|
+
# You can specify local directories as sources also.
|
10
|
+
# - type: local
|
11
|
+
# path: path/to/your/local/repository
|
12
|
+
|
13
|
+
# A directory to install the downloaded RBSs
|
14
|
+
path: .gem_rbs_collection
|
15
|
+
|
16
|
+
# gems:
|
17
|
+
# # If you want to avoid installing rbs files for gems, you can specify them here.
|
18
|
+
# - name: GEM_NAME
|
19
|
+
# ignore: true
|