solargraph 0.54.0 → 0.58.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/.github/workflows/linting.yml +127 -0
- data/.github/workflows/plugins.yml +184 -6
- data/.github/workflows/rspec.yml +55 -5
- data/.github/workflows/typecheck.yml +8 -3
- data/.gitignore +7 -0
- data/.overcommit.yml +72 -0
- data/.rspec +1 -0
- data/.rubocop.yml +66 -0
- data/.rubocop_todo.yml +1279 -0
- data/.yardopts +1 -0
- data/CHANGELOG.md +171 -0
- data/README.md +20 -6
- data/Rakefile +125 -13
- data/bin/solargraph +8 -5
- data/lib/solargraph/api_map/cache.rb +13 -3
- data/lib/solargraph/api_map/constants.rb +279 -0
- data/lib/solargraph/api_map/index.rb +193 -0
- data/lib/solargraph/api_map/source_to_yard.rb +13 -4
- data/lib/solargraph/api_map/store.rb +207 -132
- data/lib/solargraph/api_map.rb +394 -261
- data/lib/solargraph/bench.rb +18 -1
- data/lib/solargraph/complex_type/type_methods.rb +29 -12
- data/lib/solargraph/complex_type/unique_type.rb +205 -26
- data/lib/solargraph/complex_type.rb +126 -26
- data/lib/solargraph/convention/active_support_concern.rb +111 -0
- data/lib/solargraph/convention/base.rb +20 -3
- data/lib/solargraph/convention/data_definition/data_assignment_node.rb +61 -0
- data/lib/solargraph/convention/data_definition/data_definition_node.rb +91 -0
- data/lib/solargraph/convention/data_definition.rb +105 -0
- data/lib/solargraph/convention/gemspec.rb +3 -2
- data/lib/solargraph/convention/struct_definition/struct_assignment_node.rb +61 -0
- data/lib/solargraph/convention/struct_definition/struct_definition_node.rb +102 -0
- data/lib/solargraph/convention/struct_definition.rb +164 -0
- data/lib/solargraph/convention.rb +36 -4
- data/lib/solargraph/diagnostics/rubocop.rb +6 -1
- data/lib/solargraph/diagnostics/rubocop_helpers.rb +5 -3
- data/lib/solargraph/doc_map.rb +316 -64
- data/lib/solargraph/environ.rb +9 -2
- data/lib/solargraph/equality.rb +34 -0
- data/lib/solargraph/gem_pins.rb +64 -38
- data/lib/solargraph/language_server/host/dispatch.rb +2 -0
- data/lib/solargraph/language_server/host/message_worker.rb +54 -5
- data/lib/solargraph/language_server/host.rb +36 -18
- data/lib/solargraph/language_server/message/base.rb +20 -12
- data/lib/solargraph/language_server/message/extended/check_gem_version.rb +2 -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/language_server/message/initialize.rb +3 -1
- data/lib/solargraph/language_server/message/text_document/completion.rb +0 -3
- data/lib/solargraph/language_server/message/text_document/definition.rb +5 -3
- data/lib/solargraph/language_server/message/text_document/document_symbol.rb +3 -3
- data/lib/solargraph/language_server/message/text_document/formatting.rb +23 -2
- data/lib/solargraph/language_server/message/text_document/hover.rb +1 -1
- data/lib/solargraph/language_server/message/text_document/type_definition.rb +4 -3
- data/lib/solargraph/language_server/message/workspace/did_change_workspace_folders.rb +2 -0
- data/lib/solargraph/language_server/message/workspace/workspace_symbol.rb +2 -2
- data/lib/solargraph/language_server/progress.rb +27 -2
- data/lib/solargraph/language_server/request.rb +4 -1
- data/lib/solargraph/library.rb +83 -73
- data/lib/solargraph/location.rb +45 -1
- data/lib/solargraph/logging.rb +12 -2
- data/lib/solargraph/page.rb +3 -0
- data/lib/solargraph/parser/comment_ripper.rb +20 -7
- data/lib/solargraph/parser/flow_sensitive_typing.rb +255 -0
- data/lib/solargraph/parser/node_processor/base.rb +10 -5
- data/lib/solargraph/parser/node_processor.rb +26 -8
- data/lib/solargraph/parser/parser_gem/class_methods.rb +10 -18
- data/lib/solargraph/parser/parser_gem/flawed_builder.rb +1 -0
- data/lib/solargraph/parser/parser_gem/node_chainer.rb +13 -11
- data/lib/solargraph/parser/parser_gem/node_methods.rb +10 -19
- data/lib/solargraph/parser/parser_gem/node_processors/alias_node.rb +2 -1
- data/lib/solargraph/parser/parser_gem/node_processors/and_node.rb +22 -0
- data/lib/solargraph/parser/parser_gem/node_processors/args_node.rb +26 -20
- data/lib/solargraph/parser/parser_gem/node_processors/block_node.rb +7 -4
- data/lib/solargraph/parser/parser_gem/node_processors/casgn_node.rb +2 -1
- data/lib/solargraph/parser/parser_gem/node_processors/cvasgn_node.rb +2 -1
- data/lib/solargraph/parser/parser_gem/node_processors/def_node.rb +6 -3
- data/lib/solargraph/parser/parser_gem/node_processors/defs_node.rb +2 -1
- data/lib/solargraph/parser/parser_gem/node_processors/gvasgn_node.rb +2 -1
- data/lib/solargraph/parser/parser_gem/node_processors/if_node.rb +23 -0
- data/lib/solargraph/parser/parser_gem/node_processors/ivasgn_node.rb +4 -2
- data/lib/solargraph/parser/parser_gem/node_processors/lvasgn_node.rb +2 -1
- data/lib/solargraph/parser/parser_gem/node_processors/masgn_node.rb +14 -2
- data/lib/solargraph/parser/parser_gem/node_processors/namespace_node.rb +8 -7
- data/lib/solargraph/parser/parser_gem/node_processors/opasgn_node.rb +98 -0
- data/lib/solargraph/parser/parser_gem/node_processors/orasgn_node.rb +1 -0
- data/lib/solargraph/parser/parser_gem/node_processors/resbody_node.rb +3 -1
- data/lib/solargraph/parser/parser_gem/node_processors/sclass_node.rb +16 -6
- data/lib/solargraph/parser/parser_gem/node_processors/send_node.rb +64 -32
- data/lib/solargraph/parser/parser_gem/node_processors/sym_node.rb +3 -1
- data/lib/solargraph/parser/parser_gem/node_processors/until_node.rb +29 -0
- data/lib/solargraph/parser/parser_gem/node_processors/while_node.rb +29 -0
- data/lib/solargraph/parser/parser_gem/node_processors.rb +14 -0
- data/lib/solargraph/parser/region.rb +4 -1
- data/lib/solargraph/parser/snippet.rb +2 -0
- data/lib/solargraph/parser.rb +3 -5
- data/lib/solargraph/pin/base.rb +417 -42
- data/lib/solargraph/pin/base_variable.rb +21 -12
- data/lib/solargraph/pin/block.rb +9 -26
- data/lib/solargraph/pin/breakable.rb +9 -0
- data/lib/solargraph/pin/callable.rb +231 -0
- data/lib/solargraph/pin/closure.rb +30 -10
- data/lib/solargraph/pin/common.rb +12 -7
- data/lib/solargraph/pin/constant.rb +2 -0
- data/lib/solargraph/pin/conversions.rb +3 -2
- data/lib/solargraph/pin/delegated_method.rb +20 -1
- data/lib/solargraph/pin/documenting.rb +16 -0
- data/lib/solargraph/pin/instance_variable.rb +2 -2
- data/lib/solargraph/pin/keyword.rb +7 -2
- data/lib/solargraph/pin/local_variable.rb +15 -7
- data/lib/solargraph/pin/method.rb +241 -70
- data/lib/solargraph/pin/method_alias.rb +3 -0
- data/lib/solargraph/pin/namespace.rb +21 -13
- data/lib/solargraph/pin/parameter.rb +94 -32
- data/lib/solargraph/pin/proxy_type.rb +17 -7
- data/lib/solargraph/pin/reference/override.rb +24 -6
- data/lib/solargraph/pin/reference/require.rb +2 -2
- data/lib/solargraph/pin/reference/superclass.rb +5 -0
- data/lib/solargraph/pin/reference.rb +17 -0
- data/lib/solargraph/pin/search.rb +6 -1
- data/lib/solargraph/pin/signature.rb +39 -121
- data/lib/solargraph/pin/singleton.rb +1 -1
- data/lib/solargraph/pin/symbol.rb +8 -2
- data/lib/solargraph/pin/until.rb +18 -0
- data/lib/solargraph/pin/while.rb +18 -0
- data/lib/solargraph/pin.rb +8 -2
- data/lib/solargraph/pin_cache.rb +245 -0
- data/lib/solargraph/position.rb +19 -0
- data/lib/solargraph/range.rb +23 -4
- data/lib/solargraph/rbs_map/conversions.rb +315 -99
- data/lib/solargraph/rbs_map/core_fills.rb +50 -16
- data/lib/solargraph/rbs_map/core_map.rb +41 -11
- data/lib/solargraph/rbs_map/stdlib_map.rb +15 -5
- data/lib/solargraph/rbs_map.rb +87 -16
- data/lib/solargraph/shell.rb +117 -17
- data/lib/solargraph/source/chain/array.rb +13 -8
- data/lib/solargraph/source/chain/block_symbol.rb +1 -1
- data/lib/solargraph/source/chain/block_variable.rb +1 -1
- data/lib/solargraph/source/chain/call.rb +135 -66
- data/lib/solargraph/source/chain/constant.rb +3 -66
- data/lib/solargraph/source/chain/hash.rb +9 -3
- data/lib/solargraph/source/chain/head.rb +1 -1
- data/lib/solargraph/source/chain/if.rb +7 -2
- data/lib/solargraph/source/chain/link.rb +38 -6
- data/lib/solargraph/source/chain/literal.rb +27 -2
- data/lib/solargraph/source/chain/or.rb +2 -2
- data/lib/solargraph/source/chain/z_super.rb +1 -1
- data/lib/solargraph/source/chain.rb +140 -63
- data/lib/solargraph/source/change.rb +2 -2
- data/lib/solargraph/source/cursor.rb +4 -4
- data/lib/solargraph/source/source_chainer.rb +3 -3
- data/lib/solargraph/source.rb +110 -89
- data/lib/solargraph/source_map/clip.rb +22 -28
- data/lib/solargraph/source_map/data.rb +34 -0
- data/lib/solargraph/source_map/mapper.rb +11 -7
- data/lib/solargraph/source_map.rb +50 -43
- data/lib/solargraph/type_checker/checks.rb +4 -0
- data/lib/solargraph/type_checker/param_def.rb +2 -0
- data/lib/solargraph/type_checker/rules.rb +35 -8
- data/lib/solargraph/type_checker.rb +331 -189
- 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/views/environment.erb +3 -5
- data/lib/solargraph/workspace/config.rb +25 -5
- data/lib/solargraph/workspace/require_paths.rb +97 -0
- data/lib/solargraph/workspace.rb +53 -72
- data/lib/solargraph/yard_map/helpers.rb +29 -1
- data/lib/solargraph/yard_map/mapper/to_constant.rb +8 -5
- data/lib/solargraph/yard_map/mapper/to_method.rb +55 -19
- data/lib/solargraph/yard_map/mapper/to_namespace.rb +11 -7
- data/lib/solargraph/yard_map/mapper.rb +5 -3
- data/lib/solargraph/yard_map/to_method.rb +6 -3
- data/lib/solargraph/yardoc.rb +45 -10
- data/lib/solargraph.rb +35 -1
- data/rbs/fills/bundler/0/bundler.rbs +4271 -0
- data/rbs/fills/open3/0/open3.rbs +172 -0
- data/rbs/fills/rubygems/0/basic_specification.rbs +326 -0
- data/rbs/fills/rubygems/0/errors.rbs +364 -0
- data/rbs/fills/rubygems/0/spec_fetcher.rbs +107 -0
- data/rbs/fills/rubygems/0/specification.rbs +1753 -0
- data/rbs/fills/tuple/tuple.rbs +149 -0
- data/rbs_collection.yaml +19 -0
- data/sig/shims/ast/0/node.rbs +5 -0
- data/sig/shims/ast/2.4/.rbs_meta.yaml +9 -0
- data/sig/shims/ast/2.4/ast.rbs +73 -0
- data/sig/shims/parser/3.2.0.1/builders/default.rbs +195 -0
- data/sig/shims/parser/3.2.0.1/manifest.yaml +7 -0
- data/sig/shims/parser/3.2.0.1/parser.rbs +201 -0
- data/sig/shims/parser/3.2.0.1/polyfill.rbs +4 -0
- data/sig/shims/thor/1.2.0.1/.rbs_meta.yaml +9 -0
- data/sig/shims/thor/1.2.0.1/manifest.yaml +7 -0
- data/sig/shims/thor/1.2.0.1/thor.rbs +17 -0
- data/solargraph.gemspec +32 -10
- metadata +237 -37
- data/lib/.rubocop.yml +0 -22
- data/lib/solargraph/cache.rb +0 -77
- data/lib/solargraph/parser/node_methods.rb +0 -83
|
@@ -6,7 +6,12 @@ module Solargraph
|
|
|
6
6
|
module ToMethod
|
|
7
7
|
extend YardMap::Helpers
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
VISIBILITY_OVERRIDE = {
|
|
10
|
+
# YARD pays attention to 'private' statements prior to class methods but shouldn't
|
|
11
|
+
["Rails::Engine", :class, "find_root_with_flag"] => :public
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
# @param code_object [YARD::CodeObjects::MethodObject]
|
|
10
15
|
# @param name [String, nil]
|
|
11
16
|
# @param scope [Symbol, nil]
|
|
12
17
|
# @param visibility [Symbol, nil]
|
|
@@ -14,31 +19,60 @@ module Solargraph
|
|
|
14
19
|
# @param spec [Gem::Specification, nil]
|
|
15
20
|
# @return [Solargraph::Pin::Method]
|
|
16
21
|
def self.make code_object, name = nil, scope = nil, visibility = nil, closure = nil, spec = nil
|
|
17
|
-
closure ||=
|
|
18
|
-
name: code_object.namespace.to_s,
|
|
19
|
-
gates: [code_object.namespace.to_s]
|
|
20
|
-
)
|
|
22
|
+
closure ||= create_closure_namespace_for(code_object, spec)
|
|
21
23
|
location = object_location(code_object, spec)
|
|
22
24
|
name ||= code_object.name.to_s
|
|
23
25
|
return_type = ComplexType::SELF if name == 'new'
|
|
24
26
|
comments = code_object.docstring ? code_object.docstring.all.to_s : ''
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
27
|
+
final_scope = scope || code_object.scope
|
|
28
|
+
override_key = [closure.path, final_scope, name]
|
|
29
|
+
final_visibility = VISIBILITY_OVERRIDE[override_key]
|
|
30
|
+
final_visibility ||= VISIBILITY_OVERRIDE[[closure.path, final_scope]]
|
|
31
|
+
final_visibility ||= :private if closure.path == 'Kernel' && Kernel.private_instance_methods(false).include?(name.to_sym)
|
|
32
|
+
final_visibility ||= visibility
|
|
33
|
+
final_visibility ||= :private if code_object.module_function? && final_scope == :instance
|
|
34
|
+
final_visibility ||= :public if code_object.module_function? && final_scope == :class
|
|
35
|
+
final_visibility ||= code_object.visibility
|
|
36
|
+
if code_object.is_alias?
|
|
37
|
+
origin_code_object = code_object.namespace.aliases[code_object]
|
|
38
|
+
pin = Pin::MethodAlias.new(
|
|
39
|
+
name: name,
|
|
40
|
+
location: location,
|
|
41
|
+
original: origin_code_object.name.to_s,
|
|
42
|
+
closure: closure,
|
|
43
|
+
comments: comments,
|
|
44
|
+
scope: final_scope,
|
|
45
|
+
visibility: final_visibility,
|
|
46
|
+
explicit: code_object.is_explicit?,
|
|
47
|
+
return_type: return_type,
|
|
48
|
+
parameters: [],
|
|
49
|
+
source: :yardoc,
|
|
50
|
+
)
|
|
51
|
+
else
|
|
52
|
+
pin = Pin::Method.new(
|
|
53
|
+
location: location,
|
|
54
|
+
closure: closure,
|
|
55
|
+
name: name,
|
|
56
|
+
comments: comments,
|
|
57
|
+
scope: final_scope,
|
|
58
|
+
visibility: final_visibility,
|
|
59
|
+
# @todo Might need to convert overloads to signatures
|
|
60
|
+
explicit: code_object.is_explicit?,
|
|
61
|
+
return_type: return_type,
|
|
62
|
+
attribute: code_object.is_attribute?,
|
|
63
|
+
parameters: [],
|
|
64
|
+
source: :yardoc,
|
|
65
|
+
)
|
|
66
|
+
pin.parameters.concat get_parameters(code_object, location, comments, pin)
|
|
67
|
+
pin.parameters.freeze
|
|
68
|
+
end
|
|
69
|
+
logger.debug { "ToMethod.make: Just created method pin: #{pin.inspect}" }
|
|
38
70
|
pin
|
|
39
71
|
end
|
|
40
72
|
|
|
41
73
|
class << self
|
|
74
|
+
include Logging
|
|
75
|
+
|
|
42
76
|
private
|
|
43
77
|
|
|
44
78
|
# @param code_object [YARD::CodeObjects::Base]
|
|
@@ -51,6 +85,7 @@ module Solargraph
|
|
|
51
85
|
# HACK: Skip `nil` and `self` parameters that are sometimes emitted
|
|
52
86
|
# for methods defined in C
|
|
53
87
|
# See https://github.com/castwide/solargraph/issues/345
|
|
88
|
+
# @sg-ignore https://github.com/castwide/solargraph/pull/1114
|
|
54
89
|
code_object.parameters.select { |a| a[0] && a[0] != 'self' }.map do |a|
|
|
55
90
|
Solargraph::Pin::Parameter.new(
|
|
56
91
|
location: location,
|
|
@@ -59,7 +94,8 @@ module Solargraph
|
|
|
59
94
|
name: arg_name(a),
|
|
60
95
|
presence: nil,
|
|
61
96
|
decl: arg_type(a),
|
|
62
|
-
asgn_code: a[1]
|
|
97
|
+
asgn_code: a[1],
|
|
98
|
+
source: :yardoc,
|
|
63
99
|
)
|
|
64
100
|
end
|
|
65
101
|
end
|
|
@@ -6,19 +6,23 @@ module Solargraph
|
|
|
6
6
|
module ToNamespace
|
|
7
7
|
extend YardMap::Helpers
|
|
8
8
|
|
|
9
|
+
# @param code_object [YARD::CodeObjects::NamespaceObject]
|
|
10
|
+
# @param spec [Gem::Specification, nil]
|
|
11
|
+
# @param closure [Pin::Closure, nil]
|
|
12
|
+
# @return [Pin::Namespace]
|
|
9
13
|
def self.make code_object, spec, closure = nil
|
|
10
|
-
closure ||=
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
gates: [code_object.namespace.to_s]
|
|
14
|
-
)
|
|
14
|
+
closure ||= create_closure_namespace_for(code_object, spec)
|
|
15
|
+
location = object_location(code_object, spec)
|
|
16
|
+
|
|
15
17
|
Pin::Namespace.new(
|
|
16
|
-
location:
|
|
18
|
+
location: location,
|
|
17
19
|
name: code_object.name.to_s,
|
|
18
20
|
comments: code_object.docstring ? code_object.docstring.all.to_s : '',
|
|
19
21
|
type: code_object.is_a?(YARD::CodeObjects::ClassObject) ? :class : :module,
|
|
20
22
|
visibility: code_object.visibility,
|
|
21
|
-
closure: closure
|
|
23
|
+
closure: closure,
|
|
24
|
+
gates: closure.gates,
|
|
25
|
+
source: :yardoc,
|
|
22
26
|
)
|
|
23
27
|
end
|
|
24
28
|
end
|
|
@@ -12,6 +12,7 @@ module Solargraph
|
|
|
12
12
|
def initialize code_objects, spec = nil
|
|
13
13
|
@code_objects = code_objects
|
|
14
14
|
@spec = spec
|
|
15
|
+
# @type [Array<Solargraph::Pin::Base>]
|
|
15
16
|
@pins = []
|
|
16
17
|
@namespace_pins = {}
|
|
17
18
|
end
|
|
@@ -46,15 +47,16 @@ module Solargraph
|
|
|
46
47
|
else
|
|
47
48
|
code_object.superclass.to_s
|
|
48
49
|
end
|
|
49
|
-
result.push Solargraph::Pin::Reference::Superclass.new(name: superclass, closure: nspin)
|
|
50
|
+
result.push Solargraph::Pin::Reference::Superclass.new(name: superclass, closure: nspin, source: :yard_map)
|
|
50
51
|
end
|
|
51
52
|
code_object.class_mixins.each do |m|
|
|
52
|
-
result.push Solargraph::Pin::Reference::Extend.new(closure: nspin, name: m.path)
|
|
53
|
+
result.push Solargraph::Pin::Reference::Extend.new(closure: nspin, name: m.path, source: :yard_map)
|
|
53
54
|
end
|
|
54
55
|
code_object.instance_mixins.each do |m|
|
|
55
56
|
result.push Solargraph::Pin::Reference::Include.new(
|
|
56
57
|
closure: nspin, # @todo Fix this
|
|
57
|
-
name: m.path
|
|
58
|
+
name: m.path,
|
|
59
|
+
source: :yard_map
|
|
58
60
|
)
|
|
59
61
|
end
|
|
60
62
|
elsif code_object.is_a?(YARD::CodeObjects::MethodObject)
|
|
@@ -15,6 +15,7 @@ module Solargraph
|
|
|
15
15
|
# HACK: Skip `nil` and `self` parameters that are sometimes emitted
|
|
16
16
|
# for methods defined in C
|
|
17
17
|
# See https://github.com/castwide/solargraph/issues/345
|
|
18
|
+
# @sg-ignore https://github.com/castwide/solargraph/pull/1114
|
|
18
19
|
code_object.parameters.select { |a| a[0] && a[0] != 'self' }.map do |a|
|
|
19
20
|
Solargraph::Pin::Parameter.new(
|
|
20
21
|
location: location,
|
|
@@ -23,7 +24,8 @@ module Solargraph
|
|
|
23
24
|
name: arg_name(a),
|
|
24
25
|
presence: nil,
|
|
25
26
|
decl: arg_type(a),
|
|
26
|
-
asgn_code: a[1]
|
|
27
|
+
asgn_code: a[1],
|
|
28
|
+
source: :yard_map
|
|
27
29
|
)
|
|
28
30
|
end
|
|
29
31
|
end
|
|
@@ -56,7 +58,7 @@ module Solargraph
|
|
|
56
58
|
|
|
57
59
|
include Helpers
|
|
58
60
|
|
|
59
|
-
# @param code_object [YARD::CodeObjects::
|
|
61
|
+
# @param code_object [YARD::CodeObjects::MethodObject]
|
|
60
62
|
# @param name [String, nil]
|
|
61
63
|
# @param scope [Symbol, nil]
|
|
62
64
|
# @param visibility [Symbol, nil]
|
|
@@ -78,7 +80,8 @@ module Solargraph
|
|
|
78
80
|
scope: scope || code_object.scope,
|
|
79
81
|
visibility: visibility || code_object.visibility,
|
|
80
82
|
parameters: InnerMethods.get_parameters(code_object, location, comments),
|
|
81
|
-
explicit: code_object.is_explicit
|
|
83
|
+
explicit: code_object.is_explicit?,
|
|
84
|
+
source: :yard_map
|
|
82
85
|
)
|
|
83
86
|
end
|
|
84
87
|
end
|
data/lib/solargraph/yardoc.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'open3'
|
|
4
|
+
|
|
3
5
|
module Solargraph
|
|
4
6
|
# Methods for caching and loading YARD documentation for gems.
|
|
5
7
|
#
|
|
@@ -9,15 +11,31 @@ module Solargraph
|
|
|
9
11
|
# Build and cache a gem's yardoc and return the path. If the cache already
|
|
10
12
|
# exists, do nothing and return the path.
|
|
11
13
|
#
|
|
14
|
+
# @param yard_plugins [Array<String>] The names of YARD plugins to use.
|
|
12
15
|
# @param gemspec [Gem::Specification]
|
|
13
16
|
# @return [String] The path to the cached yardoc.
|
|
14
|
-
def cache(gemspec)
|
|
15
|
-
path =
|
|
17
|
+
def cache(yard_plugins, gemspec)
|
|
18
|
+
path = PinCache.yardoc_path gemspec
|
|
16
19
|
return path if cached?(gemspec)
|
|
17
20
|
|
|
21
|
+
unless Dir.exist? gemspec.gem_dir
|
|
22
|
+
# Can happen in at least some (old?) RubyGems versions when we
|
|
23
|
+
# have a gemspec describing a standard library like bundler.
|
|
24
|
+
#
|
|
25
|
+
# https://github.com/apiology/solargraph/actions/runs/17650140201/job/50158676842?pr=10
|
|
26
|
+
Solargraph.logger.info { "Bad info from gemspec - #{gemspec.gem_dir} does not exist" }
|
|
27
|
+
return path
|
|
28
|
+
end
|
|
29
|
+
|
|
18
30
|
Solargraph.logger.info "Caching yardoc for #{gemspec.name} #{gemspec.version}"
|
|
19
|
-
|
|
20
|
-
|
|
31
|
+
cmd = "yardoc --db #{path} --no-output --plugin solargraph"
|
|
32
|
+
yard_plugins.each { |plugin| cmd << " --plugin #{plugin}" }
|
|
33
|
+
Solargraph.logger.debug { "Running: #{cmd}" }
|
|
34
|
+
# @todo set these up to run in parallel
|
|
35
|
+
stdout_and_stderr_str, status = Open3.capture2e(current_bundle_env_tweaks, cmd, chdir: gemspec.gem_dir)
|
|
36
|
+
unless status.success?
|
|
37
|
+
Solargraph.logger.warn { "YARD failed running #{cmd.inspect} in #{gemspec.gem_dir}" }
|
|
38
|
+
Solargraph.logger.info stdout_and_stderr_str
|
|
21
39
|
end
|
|
22
40
|
path
|
|
23
41
|
end
|
|
@@ -26,16 +44,16 @@ module Solargraph
|
|
|
26
44
|
#
|
|
27
45
|
# @param gemspec [Gem::Specification]
|
|
28
46
|
def cached?(gemspec)
|
|
29
|
-
yardoc = File.join(
|
|
47
|
+
yardoc = File.join(PinCache.yardoc_path(gemspec), 'complete')
|
|
30
48
|
File.exist?(yardoc)
|
|
31
49
|
end
|
|
32
50
|
|
|
33
|
-
#
|
|
51
|
+
# True if another process is currently building the yardoc cache.
|
|
34
52
|
#
|
|
35
53
|
# @param gemspec [Gem::Specification]
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
File.
|
|
54
|
+
def processing?(gemspec)
|
|
55
|
+
yardoc = File.join(PinCache.yardoc_path(gemspec), 'processing')
|
|
56
|
+
File.exist?(yardoc)
|
|
39
57
|
end
|
|
40
58
|
|
|
41
59
|
# Load a gem's yardoc and return its code objects.
|
|
@@ -45,8 +63,25 @@ module Solargraph
|
|
|
45
63
|
# @param gemspec [Gem::Specification]
|
|
46
64
|
# @return [Array<YARD::CodeObjects::Base>]
|
|
47
65
|
def load!(gemspec)
|
|
48
|
-
YARD::Registry.load!
|
|
66
|
+
YARD::Registry.load! PinCache.yardoc_path gemspec
|
|
49
67
|
YARD::Registry.all
|
|
50
68
|
end
|
|
69
|
+
|
|
70
|
+
# If the BUNDLE_GEMFILE environment variable is set, we need to
|
|
71
|
+
# make sure it's an absolute path, as we'll be changing
|
|
72
|
+
# directories.
|
|
73
|
+
#
|
|
74
|
+
# 'bundle exec' sets an absolute path here, but at least the
|
|
75
|
+
# overcommit gem does not, breaking on-the-fly documention with a
|
|
76
|
+
# spawned yardoc command from our current bundle
|
|
77
|
+
#
|
|
78
|
+
# @return [Hash{String => String}] a hash of environment variables to override
|
|
79
|
+
def current_bundle_env_tweaks
|
|
80
|
+
tweaks = {}
|
|
81
|
+
if ENV['BUNDLE_GEMFILE'] && !ENV['BUNDLE_GEMFILE'].empty?
|
|
82
|
+
tweaks['BUNDLE_GEMFILE'] = File.expand_path(ENV['BUNDLE_GEMFILE'])
|
|
83
|
+
end
|
|
84
|
+
tweaks
|
|
85
|
+
end
|
|
51
86
|
end
|
|
52
87
|
end
|
data/lib/solargraph.rb
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Encoding.default_external = 'UTF-8'
|
|
4
4
|
|
|
5
|
+
require 'bundler'
|
|
5
6
|
require 'set'
|
|
6
7
|
require 'yard-solargraph'
|
|
7
8
|
require 'solargraph/yard_tags'
|
|
@@ -42,15 +43,39 @@ module Solargraph
|
|
|
42
43
|
autoload :Logging, 'solargraph/logging'
|
|
43
44
|
autoload :TypeChecker, 'solargraph/type_checker'
|
|
44
45
|
autoload :Environ, 'solargraph/environ'
|
|
46
|
+
autoload :Equality, 'solargraph/equality'
|
|
45
47
|
autoload :Convention, 'solargraph/convention'
|
|
46
48
|
autoload :Parser, 'solargraph/parser'
|
|
47
49
|
autoload :RbsMap, 'solargraph/rbs_map'
|
|
48
50
|
autoload :GemPins, 'solargraph/gem_pins'
|
|
49
|
-
autoload :
|
|
51
|
+
autoload :PinCache, 'solargraph/pin_cache'
|
|
50
52
|
|
|
51
53
|
dir = File.dirname(__FILE__)
|
|
52
54
|
VIEWS_PATH = File.join(dir, 'solargraph', 'views')
|
|
53
55
|
|
|
56
|
+
CHDIR_MUTEX = Mutex.new
|
|
57
|
+
|
|
58
|
+
# @param type [Symbol] Type of assert.
|
|
59
|
+
def self.asserts_on?(type)
|
|
60
|
+
if ENV['SOLARGRAPH_ASSERTS'].nil? || ENV['SOLARGRAPH_ASSERTS'].empty?
|
|
61
|
+
false
|
|
62
|
+
elsif ENV['SOLARGRAPH_ASSERTS'] == 'on'
|
|
63
|
+
true
|
|
64
|
+
else
|
|
65
|
+
logger.warn "Unrecognized SOLARGRAPH_ASSERTS value: #{ENV['SOLARGRAPH_ASSERTS']}"
|
|
66
|
+
false
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# @param type [Symbol] The type of assertion to perform.
|
|
71
|
+
# @param msg [String, nil] An optional message to log
|
|
72
|
+
# @param block [Proc] A block that returns a message to log
|
|
73
|
+
# @return [void]
|
|
74
|
+
def self.assert_or_log(type, msg = nil, &block)
|
|
75
|
+
raise (msg || block.call) if asserts_on?(type) && ![:combine_with_visibility].include?(type)
|
|
76
|
+
logger.info msg, &block
|
|
77
|
+
end
|
|
78
|
+
|
|
54
79
|
# A convenience method for Solargraph::Logging.logger.
|
|
55
80
|
#
|
|
56
81
|
# @return [Logger]
|
|
@@ -60,6 +85,11 @@ module Solargraph
|
|
|
60
85
|
|
|
61
86
|
# A helper method that runs Bundler.with_unbundled_env or falls back to
|
|
62
87
|
# Bundler.with_clean_env for earlier versions of Bundler.
|
|
88
|
+
#
|
|
89
|
+
# @generic T
|
|
90
|
+
# @yieldreturn [generic<T>]
|
|
91
|
+
# @sg-ignore dynamic call, but both functions behave the same
|
|
92
|
+
# @return [generic<T>]
|
|
63
93
|
def self.with_clean_env &block
|
|
64
94
|
meth = if Bundler.respond_to?(:with_original_env)
|
|
65
95
|
:with_original_env
|
|
@@ -69,3 +99,7 @@ module Solargraph
|
|
|
69
99
|
Bundler.send meth, &block
|
|
70
100
|
end
|
|
71
101
|
end
|
|
102
|
+
|
|
103
|
+
# Ensure that ParserGem node processors are properly loaded to avoid conflicts
|
|
104
|
+
# with Convention node processors
|
|
105
|
+
require 'solargraph/parser/parser_gem/node_processors'
|