solargraph 0.54.4 → 0.57.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 +125 -0
- data/.github/workflows/plugins.yml +149 -5
- data/.github/workflows/rspec.yml +39 -4
- 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 +2627 -0
- data/.yardopts +1 -0
- data/CHANGELOG.md +104 -0
- data/README.md +20 -6
- data/Rakefile +125 -13
- data/lib/solargraph/api_map/cache.rb +3 -2
- data/lib/solargraph/api_map/constants.rb +218 -0
- data/lib/solargraph/api_map/index.rb +44 -42
- data/lib/solargraph/api_map/source_to_yard.rb +10 -4
- data/lib/solargraph/api_map/store.rb +165 -32
- data/lib/solargraph/api_map.rb +319 -243
- data/lib/solargraph/bench.rb +18 -1
- data/lib/solargraph/complex_type/type_methods.rb +7 -1
- data/lib/solargraph/complex_type/unique_type.rb +105 -16
- data/lib/solargraph/complex_type.rb +40 -7
- 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 +35 -4
- data/lib/solargraph/diagnostics/rubocop.rb +6 -1
- data/lib/solargraph/diagnostics/rubocop_helpers.rb +1 -1
- data/lib/solargraph/doc_map.rb +313 -65
- data/lib/solargraph/environ.rb +9 -2
- data/lib/solargraph/gem_pins.rb +60 -38
- data/lib/solargraph/language_server/host/dispatch.rb +2 -0
- data/lib/solargraph/language_server/host/message_worker.rb +13 -7
- data/lib/solargraph/language_server/host.rb +14 -3
- data/lib/solargraph/language_server/message/base.rb +2 -1
- 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/text_document/definition.rb +2 -0
- data/lib/solargraph/language_server/message/text_document/formatting.rb +16 -2
- data/lib/solargraph/language_server/message/text_document/type_definition.rb +1 -0
- data/lib/solargraph/language_server/message/workspace/did_change_workspace_folders.rb +2 -0
- data/lib/solargraph/language_server/progress.rb +8 -0
- data/lib/solargraph/language_server/request.rb +1 -0
- data/lib/solargraph/library.rb +53 -32
- data/lib/solargraph/location.rb +23 -0
- data/lib/solargraph/logging.rb +12 -2
- data/lib/solargraph/page.rb +4 -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_methods.rb +16 -2
- data/lib/solargraph/parser/node_processor/base.rb +10 -5
- data/lib/solargraph/parser/node_processor.rb +26 -9
- data/lib/solargraph/parser/parser_gem/class_methods.rb +17 -15
- 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 +8 -4
- data/lib/solargraph/parser/parser_gem/node_processors/alias_node.rb +2 -1
- data/lib/solargraph/parser/parser_gem/node_processors/and_node.rb +21 -0
- data/lib/solargraph/parser/parser_gem/node_processors/args_node.rb +4 -2
- 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 +7 -1
- data/lib/solargraph/parser/parser_gem/node_processors/namespace_node.rb +8 -7
- data/lib/solargraph/parser/parser_gem/node_processors/opasgn_node.rb +42 -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 +4 -3
- data/lib/solargraph/parser/parser_gem/node_processors/send_node.rb +63 -30
- 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 +1 -0
- data/lib/solargraph/pin/base.rb +360 -30
- data/lib/solargraph/pin/base_variable.rb +16 -10
- data/lib/solargraph/pin/block.rb +2 -0
- data/lib/solargraph/pin/breakable.rb +9 -0
- data/lib/solargraph/pin/callable.rb +83 -3
- data/lib/solargraph/pin/closure.rb +20 -1
- data/lib/solargraph/pin/common.rb +10 -1
- data/lib/solargraph/pin/constant.rb +2 -0
- data/lib/solargraph/pin/delegated_method.rb +21 -1
- data/lib/solargraph/pin/documenting.rb +16 -0
- data/lib/solargraph/pin/keyword.rb +7 -2
- data/lib/solargraph/pin/local_variable.rb +18 -6
- data/lib/solargraph/pin/method.rb +175 -46
- data/lib/solargraph/pin/method_alias.rb +3 -0
- data/lib/solargraph/pin/namespace.rb +17 -9
- data/lib/solargraph/pin/parameter.rb +78 -19
- data/lib/solargraph/pin/proxy_type.rb +13 -6
- 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 +26 -0
- data/lib/solargraph/pin/search.rb +3 -1
- data/lib/solargraph/pin/signature.rb +44 -0
- 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 +4 -1
- data/lib/solargraph/pin_cache.rb +245 -0
- data/lib/solargraph/position.rb +11 -0
- data/lib/solargraph/range.rb +10 -0
- data/lib/solargraph/rbs_map/conversions.rb +226 -70
- data/lib/solargraph/rbs_map/core_fills.rb +32 -16
- data/lib/solargraph/rbs_map/core_map.rb +37 -11
- data/lib/solargraph/rbs_map/stdlib_map.rb +15 -5
- data/lib/solargraph/rbs_map.rb +88 -18
- data/lib/solargraph/shell.rb +20 -18
- data/lib/solargraph/source/chain/array.rb +11 -7
- 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 +53 -23
- data/lib/solargraph/source/chain/constant.rb +1 -1
- data/lib/solargraph/source/chain/hash.rb +4 -3
- data/lib/solargraph/source/chain/head.rb +1 -1
- data/lib/solargraph/source/chain/if.rb +1 -1
- data/lib/solargraph/source/chain/link.rb +12 -1
- data/lib/solargraph/source/chain/literal.rb +22 -2
- data/lib/solargraph/source/chain/or.rb +1 -1
- data/lib/solargraph/source/chain/z_super.rb +1 -1
- data/lib/solargraph/source/chain.rb +84 -47
- data/lib/solargraph/source/change.rb +2 -2
- data/lib/solargraph/source/cursor.rb +2 -3
- data/lib/solargraph/source/source_chainer.rb +3 -3
- data/lib/solargraph/source.rb +5 -2
- data/lib/solargraph/source_map/clip.rb +4 -2
- data/lib/solargraph/source_map/data.rb +4 -0
- data/lib/solargraph/source_map/mapper.rb +13 -7
- data/lib/solargraph/source_map.rb +21 -31
- 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 +8 -0
- data/lib/solargraph/type_checker.rb +208 -128
- 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/config.rb +1 -3
- data/lib/solargraph/workspace/require_paths.rb +98 -0
- data/lib/solargraph/workspace.rb +38 -52
- data/lib/solargraph/yard_map/helpers.rb +29 -1
- data/lib/solargraph/yard_map/mapper/to_constant.rb +7 -5
- data/lib/solargraph/yard_map/mapper/to_method.rb +53 -18
- data/lib/solargraph/yard_map/mapper/to_namespace.rb +9 -7
- data/lib/solargraph/yard_map/mapper.rb +4 -3
- data/lib/solargraph/yard_map/to_method.rb +4 -2
- data/lib/solargraph/yardoc.rb +22 -10
- data/lib/solargraph.rb +34 -1
- data/rbs/fills/tuple.rbs +149 -0
- data/rbs_collection.yaml +19 -0
- data/sig/shims/parser/3.2.0.1/builders/default.rbs +195 -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 +15 -4
- metadata +157 -15
- data/lib/.rubocop.yml +0 -22
- data/lib/solargraph/cache.rb +0 -77
@@ -10,18 +10,36 @@ module Solargraph
|
|
10
10
|
# @return [::Array<Symbol>]
|
11
11
|
attr_reader :delete
|
12
12
|
|
13
|
-
def
|
14
|
-
|
13
|
+
def closure
|
14
|
+
nil
|
15
|
+
end
|
16
|
+
|
17
|
+
# @param location [Location, nil]
|
18
|
+
# @param name [String]
|
19
|
+
# @param tags [::Array<YARD::Tags::Tag>]
|
20
|
+
# @param delete [::Array<Symbol>]
|
21
|
+
# @param splat [Hash]
|
22
|
+
def initialize location, name, tags, delete = [], **splat
|
23
|
+
super(location: location, name: name, **splat)
|
15
24
|
@tags = tags
|
16
25
|
@delete = delete
|
17
26
|
end
|
18
27
|
|
19
|
-
|
20
|
-
|
28
|
+
# @param name [String]
|
29
|
+
# @param tags [::Array<String>]
|
30
|
+
# @param delete [::Array<Symbol>]
|
31
|
+
# @param splat [Hash]
|
32
|
+
# @return [Solargraph::Pin::Reference::Override]
|
33
|
+
def self.method_return name, *tags, delete: [], **splat
|
34
|
+
new(nil, name, [YARD::Tags::Tag.new('return', '', tags)], delete, **splat)
|
21
35
|
end
|
22
36
|
|
23
|
-
|
24
|
-
|
37
|
+
# @param name [String]
|
38
|
+
# @param comment [String]
|
39
|
+
# @param splat [Hash]
|
40
|
+
# @return [Solargraph::Pin::Reference::Override]
|
41
|
+
def self.from_comment name, comment, **splat
|
42
|
+
new(nil, name, Solargraph::Source.parse_docstring(comment).to_docstring.tags, **splat)
|
25
43
|
end
|
26
44
|
end
|
27
45
|
end
|
@@ -4,9 +4,9 @@ module Solargraph
|
|
4
4
|
module Pin
|
5
5
|
class Reference
|
6
6
|
class Require < Reference
|
7
|
-
def initialize location, name
|
7
|
+
def initialize location, name, **splat
|
8
8
|
# super(location, '', name)
|
9
|
-
super(location: location, name: name)
|
9
|
+
super(location: location, name: name, closure: Pin::ROOT_PIN, **splat)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
@@ -17,6 +17,32 @@ module Solargraph
|
|
17
17
|
super(**splat)
|
18
18
|
@generic_values = generic_values
|
19
19
|
end
|
20
|
+
|
21
|
+
# @return [String]
|
22
|
+
def parameter_tag
|
23
|
+
@parameter_tag ||= if generic_values&.any?
|
24
|
+
"<#{generic_values.join(', ')}>"
|
25
|
+
else
|
26
|
+
''
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# @return [ComplexType]
|
31
|
+
def parametrized_tag
|
32
|
+
@parametrized_tag ||= ComplexType.try_parse(
|
33
|
+
name +
|
34
|
+
if generic_values&.length&.> 0
|
35
|
+
"<#{generic_values.join(', ')}>"
|
36
|
+
else
|
37
|
+
''
|
38
|
+
end
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
# @return [Array<String>]
|
43
|
+
def reference_gates
|
44
|
+
closure.gates
|
45
|
+
end
|
20
46
|
end
|
21
47
|
end
|
22
48
|
end
|
@@ -12,6 +12,8 @@ module Solargraph
|
|
12
12
|
# @return [Pin::Base]
|
13
13
|
attr_reader :pin
|
14
14
|
|
15
|
+
# @param match [Float] The match score for the pin
|
16
|
+
# @param pin [Pin::Base]
|
15
17
|
def initialize match, pin
|
16
18
|
@match = match
|
17
19
|
@pin = pin
|
@@ -48,7 +50,7 @@ module Solargraph
|
|
48
50
|
# @param str2 [String]
|
49
51
|
# @return [Float]
|
50
52
|
def fuzzy_string_match str1, str2
|
51
|
-
return
|
53
|
+
return 1.0 + (str2.length.to_f / str1.length.to_f) if str1.downcase.include?(str2.downcase)
|
52
54
|
JaroWinkler.similarity(str1, str2, ignore_case: true)
|
53
55
|
end
|
54
56
|
end
|
@@ -1,6 +1,10 @@
|
|
1
1
|
module Solargraph
|
2
2
|
module Pin
|
3
3
|
class Signature < Callable
|
4
|
+
# allow signature to be created before method pin, then set this
|
5
|
+
# to the method pin
|
6
|
+
attr_writer :closure
|
7
|
+
|
4
8
|
def initialize **splat
|
5
9
|
super(**splat)
|
6
10
|
end
|
@@ -12,6 +16,46 @@ module Solargraph
|
|
12
16
|
def identity
|
13
17
|
@identity ||= "signature#{object_id}"
|
14
18
|
end
|
19
|
+
|
20
|
+
attr_writer :closure
|
21
|
+
|
22
|
+
def dodgy_return_type_source?
|
23
|
+
super || closure&.dodgy_return_type_source?
|
24
|
+
end
|
25
|
+
|
26
|
+
def type_location
|
27
|
+
super || closure&.type_location
|
28
|
+
end
|
29
|
+
|
30
|
+
def location
|
31
|
+
super || closure&.location
|
32
|
+
end
|
33
|
+
|
34
|
+
def typify api_map
|
35
|
+
if return_type.defined?
|
36
|
+
qualified = return_type.qualify(api_map, closure.namespace)
|
37
|
+
logger.debug { "Signature#typify(self=#{self}) => #{qualified.rooted_tags.inspect}" }
|
38
|
+
return qualified
|
39
|
+
end
|
40
|
+
return ComplexType::UNDEFINED if closure.nil?
|
41
|
+
return ComplexType::UNDEFINED unless closure.is_a?(Pin::Method)
|
42
|
+
# @sg-ignore need is_a? support
|
43
|
+
# @type [Array<Pin::Method>]
|
44
|
+
method_stack = closure.rest_of_stack api_map
|
45
|
+
logger.debug { "Signature#typify(self=#{self}) - method_stack: #{method_stack}" }
|
46
|
+
method_stack.each do |pin|
|
47
|
+
sig = pin.signatures.find { |s| s.arity == self.arity }
|
48
|
+
next unless sig
|
49
|
+
unless sig.return_type.undefined?
|
50
|
+
qualified = sig.return_type.qualify(api_map, closure.namespace)
|
51
|
+
logger.debug { "Signature#typify(self=#{self}) => #{qualified.rooted_tags.inspect}" }
|
52
|
+
return qualified
|
53
|
+
end
|
54
|
+
end
|
55
|
+
out = super
|
56
|
+
logger.debug { "Signature#typify(self=#{self}) => #{out}" }
|
57
|
+
out
|
58
|
+
end
|
15
59
|
end
|
16
60
|
end
|
17
61
|
end
|
@@ -5,8 +5,9 @@ module Solargraph
|
|
5
5
|
class Symbol < Base
|
6
6
|
# @param location [Solargraph::Location]
|
7
7
|
# @param name [String]
|
8
|
-
def initialize
|
9
|
-
|
8
|
+
def initialize(location, name, **kwargs)
|
9
|
+
# @sg-ignore "Unrecognized keyword argument kwargs to Solargraph::Pin::Base#initialize"
|
10
|
+
super(location: location, name: name, **kwargs)
|
10
11
|
# @name = name
|
11
12
|
# @location = location
|
12
13
|
end
|
@@ -19,6 +20,10 @@ module Solargraph
|
|
19
20
|
''
|
20
21
|
end
|
21
22
|
|
23
|
+
def closure
|
24
|
+
@closure ||= Pin::ROOT_PIN
|
25
|
+
end
|
26
|
+
|
22
27
|
def completion_item_kind
|
23
28
|
Solargraph::LanguageServer::CompletionItemKinds::KEYWORD
|
24
29
|
end
|
@@ -35,6 +40,7 @@ module Solargraph
|
|
35
40
|
[]
|
36
41
|
end
|
37
42
|
|
43
|
+
# @return [::Symbol]
|
38
44
|
def visibility
|
39
45
|
:public
|
40
46
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Solargraph
|
4
|
+
module Pin
|
5
|
+
class Until < Base
|
6
|
+
include Breakable
|
7
|
+
|
8
|
+
# @param receiver [Parser::AST::Node, nil]
|
9
|
+
# @param node [Parser::AST::Node, nil]
|
10
|
+
# @param context [ComplexType, nil]
|
11
|
+
# @param args [::Array<Parameter>]
|
12
|
+
def initialize node: nil, **splat
|
13
|
+
super(**splat)
|
14
|
+
@node = node
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Solargraph
|
4
|
+
module Pin
|
5
|
+
class While < Base
|
6
|
+
include Breakable
|
7
|
+
|
8
|
+
# @param receiver [Parser::AST::Node, nil]
|
9
|
+
# @param node [Parser::AST::Node, nil]
|
10
|
+
# @param context [ComplexType, nil]
|
11
|
+
# @param args [::Array<Parameter>]
|
12
|
+
def initialize node: nil, **splat
|
13
|
+
super(**splat)
|
14
|
+
@node = node
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/solargraph/pin.rb
CHANGED
@@ -34,8 +34,11 @@ module Solargraph
|
|
34
34
|
autoload :Singleton, 'solargraph/pin/singleton'
|
35
35
|
autoload :KeywordParam, 'solargraph/pin/keyword_param'
|
36
36
|
autoload :Search, 'solargraph/pin/search'
|
37
|
+
autoload :Breakable, 'solargraph/pin/breakable'
|
38
|
+
autoload :Until, 'solargraph/pin/until'
|
39
|
+
autoload :While, 'solargraph/pin/while'
|
37
40
|
autoload :Callable, 'solargraph/pin/callable'
|
38
41
|
|
39
|
-
ROOT_PIN = Pin::Namespace.new(type: :class, name: '', closure: nil)
|
42
|
+
ROOT_PIN = Pin::Namespace.new(type: :class, name: '', closure: nil, source: :pin_rb)
|
40
43
|
end
|
41
44
|
end
|
@@ -0,0 +1,245 @@
|
|
1
|
+
require 'yard-activesupport-concern'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'rbs'
|
4
|
+
|
5
|
+
module Solargraph
|
6
|
+
module PinCache
|
7
|
+
class << self
|
8
|
+
include Logging
|
9
|
+
|
10
|
+
# The base directory where cached YARD documentation and serialized pins are serialized
|
11
|
+
#
|
12
|
+
# @return [String]
|
13
|
+
def base_dir
|
14
|
+
# The directory is not stored in a variable so it can be overridden
|
15
|
+
# in specs.
|
16
|
+
ENV['SOLARGRAPH_CACHE'] ||
|
17
|
+
(ENV['XDG_CACHE_HOME'] ? File.join(ENV['XDG_CACHE_HOME'], 'solargraph') : nil) ||
|
18
|
+
File.join(Dir.home, '.cache', 'solargraph')
|
19
|
+
end
|
20
|
+
|
21
|
+
# The working directory for the current Ruby, RBS, and Solargraph versions.
|
22
|
+
#
|
23
|
+
# @return [String]
|
24
|
+
def work_dir
|
25
|
+
# The directory is not stored in a variable so it can be overridden
|
26
|
+
# in specs.
|
27
|
+
File.join(base_dir, "ruby-#{RUBY_VERSION}", "rbs-#{RBS::VERSION}", "solargraph-#{Solargraph::VERSION}")
|
28
|
+
end
|
29
|
+
|
30
|
+
# @param gemspec [Gem::Specification]
|
31
|
+
# @return [String]
|
32
|
+
def yardoc_path gemspec
|
33
|
+
File.join(base_dir,
|
34
|
+
"yard-#{YARD::VERSION}",
|
35
|
+
"yard-activesupport-concern-#{YARD::ActiveSupport::Concern::VERSION}",
|
36
|
+
"#{gemspec.name}-#{gemspec.version}.yardoc")
|
37
|
+
end
|
38
|
+
|
39
|
+
# @return [String]
|
40
|
+
def stdlib_path
|
41
|
+
File.join(work_dir, 'stdlib')
|
42
|
+
end
|
43
|
+
|
44
|
+
# @param require [String]
|
45
|
+
# @return [String]
|
46
|
+
def stdlib_require_path require
|
47
|
+
File.join(stdlib_path, "#{require}.ser")
|
48
|
+
end
|
49
|
+
|
50
|
+
# @param require [String]
|
51
|
+
# @return [Array<Pin::Base>]
|
52
|
+
def deserialize_stdlib_require require
|
53
|
+
load(stdlib_require_path(require))
|
54
|
+
end
|
55
|
+
|
56
|
+
# @param require [String]
|
57
|
+
# @param pins [Array<Pin::Base>]
|
58
|
+
# @return [void]
|
59
|
+
def serialize_stdlib_require require, pins
|
60
|
+
save(stdlib_require_path(require), pins)
|
61
|
+
end
|
62
|
+
|
63
|
+
# @return [String]
|
64
|
+
def core_path
|
65
|
+
File.join(work_dir, 'core.ser')
|
66
|
+
end
|
67
|
+
|
68
|
+
# @return [Array<Pin::Base>]
|
69
|
+
def deserialize_core
|
70
|
+
load(core_path)
|
71
|
+
end
|
72
|
+
|
73
|
+
# @param pins [Array<Pin::Base>]
|
74
|
+
# @return [void]
|
75
|
+
def serialize_core pins
|
76
|
+
save(core_path, pins)
|
77
|
+
end
|
78
|
+
|
79
|
+
# @param gemspec [Gem::Specification]
|
80
|
+
# @return [String]
|
81
|
+
def yard_gem_path gemspec
|
82
|
+
File.join(work_dir, 'yard', "#{gemspec.name}-#{gemspec.version}.ser")
|
83
|
+
end
|
84
|
+
|
85
|
+
# @param gemspec [Gem::Specification]
|
86
|
+
# @return [Array<Pin::Base>]
|
87
|
+
def deserialize_yard_gem(gemspec)
|
88
|
+
load(yard_gem_path(gemspec))
|
89
|
+
end
|
90
|
+
|
91
|
+
# @param gemspec [Gem::Specification]
|
92
|
+
# @param pins [Array<Pin::Base>]
|
93
|
+
# @return [void]
|
94
|
+
def serialize_yard_gem(gemspec, pins)
|
95
|
+
save(yard_gem_path(gemspec), pins)
|
96
|
+
end
|
97
|
+
|
98
|
+
# @param gemspec [Gem::Specification]
|
99
|
+
# @return [Boolean]
|
100
|
+
def has_yard?(gemspec)
|
101
|
+
exist?(yard_gem_path(gemspec))
|
102
|
+
end
|
103
|
+
|
104
|
+
# @param gemspec [Gem::Specification]
|
105
|
+
# @param hash [String, nil]
|
106
|
+
# @return [String]
|
107
|
+
def rbs_collection_path(gemspec, hash)
|
108
|
+
File.join(work_dir, 'rbs', "#{gemspec.name}-#{gemspec.version}-#{hash || 0}.ser")
|
109
|
+
end
|
110
|
+
|
111
|
+
# @param gemspec [Gem::Specification]
|
112
|
+
# @return [String]
|
113
|
+
def rbs_collection_path_prefix(gemspec)
|
114
|
+
File.join(work_dir, 'rbs', "#{gemspec.name}-#{gemspec.version}-")
|
115
|
+
end
|
116
|
+
|
117
|
+
# @param gemspec [Gem::Specification]
|
118
|
+
# @param hash [String, nil]
|
119
|
+
# @return [Array<Pin::Base>]
|
120
|
+
def deserialize_rbs_collection_gem(gemspec, hash)
|
121
|
+
load(rbs_collection_path(gemspec, hash))
|
122
|
+
end
|
123
|
+
|
124
|
+
# @param gemspec [Gem::Specification]
|
125
|
+
# @param hash [String, nil]
|
126
|
+
# @param pins [Array<Pin::Base>]n
|
127
|
+
# @return [void]
|
128
|
+
def serialize_rbs_collection_gem(gemspec, hash, pins)
|
129
|
+
save(rbs_collection_path(gemspec, hash), pins)
|
130
|
+
end
|
131
|
+
|
132
|
+
# @param gemspec [Gem::Specification]
|
133
|
+
# @param hash [String, nil]
|
134
|
+
# @return [String]
|
135
|
+
def combined_path(gemspec, hash)
|
136
|
+
File.join(work_dir, 'combined', "#{gemspec.name}-#{gemspec.version}-#{hash || 0}.ser")
|
137
|
+
end
|
138
|
+
|
139
|
+
# @param gemspec [Gem::Specification]
|
140
|
+
# @return [String]
|
141
|
+
def combined_path_prefix(gemspec)
|
142
|
+
File.join(work_dir, 'combined', "#{gemspec.name}-#{gemspec.version}-")
|
143
|
+
end
|
144
|
+
|
145
|
+
# @param gemspec [Gem::Specification]
|
146
|
+
# @param hash [String, nil]
|
147
|
+
# @param pins [Array<Pin::Base>]
|
148
|
+
# @return [void]
|
149
|
+
def serialize_combined_gem(gemspec, hash, pins)
|
150
|
+
save(combined_path(gemspec, hash), pins)
|
151
|
+
end
|
152
|
+
|
153
|
+
# @param gemspec [Gem::Specification]
|
154
|
+
# @param hash [String, nil]
|
155
|
+
# @return [Array<Pin::Base>]
|
156
|
+
def deserialize_combined_gem gemspec, hash
|
157
|
+
load(combined_path(gemspec, hash))
|
158
|
+
end
|
159
|
+
|
160
|
+
# @param gemspec [Gem::Specification]
|
161
|
+
# @param hash [String, nil]
|
162
|
+
# @return [Boolean]
|
163
|
+
def has_rbs_collection?(gemspec, hash)
|
164
|
+
exist?(rbs_collection_path(gemspec, hash))
|
165
|
+
end
|
166
|
+
|
167
|
+
# @return [void]
|
168
|
+
def uncache_core
|
169
|
+
uncache(core_path)
|
170
|
+
end
|
171
|
+
|
172
|
+
# @return [void]
|
173
|
+
def uncache_stdlib
|
174
|
+
uncache(stdlib_path)
|
175
|
+
end
|
176
|
+
|
177
|
+
# @param gemspec [Gem::Specification]
|
178
|
+
# @param out [IO, nil]
|
179
|
+
# @return [void]
|
180
|
+
def uncache_gem(gemspec, out: nil)
|
181
|
+
uncache(yardoc_path(gemspec), out: out)
|
182
|
+
uncache_by_prefix(rbs_collection_path_prefix(gemspec), out: out)
|
183
|
+
uncache(yard_gem_path(gemspec), out: out)
|
184
|
+
uncache_by_prefix(combined_path_prefix(gemspec), out: out)
|
185
|
+
end
|
186
|
+
|
187
|
+
# @return [void]
|
188
|
+
def clear
|
189
|
+
FileUtils.rm_rf base_dir, secure: true
|
190
|
+
end
|
191
|
+
|
192
|
+
private
|
193
|
+
|
194
|
+
# @param file [String]
|
195
|
+
# @return [Array<Solargraph::Pin::Base>, nil]
|
196
|
+
def load file
|
197
|
+
return nil unless File.file?(file)
|
198
|
+
Marshal.load(File.read(file, mode: 'rb'))
|
199
|
+
rescue StandardError => e
|
200
|
+
Solargraph.logger.warn "Failed to load cached file #{file}: [#{e.class}] #{e.message}"
|
201
|
+
FileUtils.rm_f file
|
202
|
+
nil
|
203
|
+
end
|
204
|
+
|
205
|
+
# @param path [String]
|
206
|
+
def exist? *path
|
207
|
+
File.file? File.join(*path)
|
208
|
+
end
|
209
|
+
|
210
|
+
# @param file [String]
|
211
|
+
# @param pins [Array<Pin::Base>]
|
212
|
+
# @return [void]
|
213
|
+
def save file, pins
|
214
|
+
base = File.dirname(file)
|
215
|
+
FileUtils.mkdir_p base unless File.directory?(base)
|
216
|
+
ser = Marshal.dump(pins)
|
217
|
+
File.write file, ser, mode: 'wb'
|
218
|
+
logger.debug { "Cache#save: Saved #{pins.length} pins to #{file}" }
|
219
|
+
end
|
220
|
+
|
221
|
+
# @param path_segments [Array<String>]
|
222
|
+
# @return [void]
|
223
|
+
def uncache *path_segments, out: nil
|
224
|
+
path = File.join(*path_segments)
|
225
|
+
if File.exist?(path)
|
226
|
+
FileUtils.rm_rf path, secure: true
|
227
|
+
out.puts "Clearing pin cache in #{path}" unless out.nil?
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
# @return [void]
|
232
|
+
# @param path_segments [Array<String>]
|
233
|
+
def uncache_by_prefix *path_segments, out: nil
|
234
|
+
path = File.join(*path_segments)
|
235
|
+
glob = "#{path}*"
|
236
|
+
out.puts "Clearing pin cache in #{glob}" unless out.nil?
|
237
|
+
Dir.glob(glob).each do |file|
|
238
|
+
next unless File.file?(file)
|
239
|
+
FileUtils.rm_rf file, secure: true
|
240
|
+
out.puts "Clearing pin cache in #{file}" unless out.nil?
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
data/lib/solargraph/position.rb
CHANGED
@@ -26,6 +26,16 @@ module Solargraph
|
|
26
26
|
[line, character]
|
27
27
|
end
|
28
28
|
|
29
|
+
# @param other [Position]
|
30
|
+
def <=>(other)
|
31
|
+
return nil unless other.is_a?(Position)
|
32
|
+
if line == other.line
|
33
|
+
character <=> other.character
|
34
|
+
else
|
35
|
+
line <=> other.line
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
29
39
|
# Get a hash of the position. This representation is suitable for use in
|
30
40
|
# the language server protocol.
|
31
41
|
#
|
@@ -48,6 +58,7 @@ module Solargraph
|
|
48
58
|
# @return [Integer]
|
49
59
|
def self.to_offset text, position
|
50
60
|
return 0 if text.empty?
|
61
|
+
# @sg-ignore Unresolved call to + on Integer
|
51
62
|
text.lines[0...position.line].sum(&:length) + position.character
|
52
63
|
end
|
53
64
|
|
data/lib/solargraph/range.rb
CHANGED
@@ -24,6 +24,16 @@ module Solargraph
|
|
24
24
|
[start, ending]
|
25
25
|
end
|
26
26
|
|
27
|
+
# @param other [BasicObject]
|
28
|
+
def <=>(other)
|
29
|
+
return nil unless other.is_a?(Range)
|
30
|
+
if start == other.start
|
31
|
+
ending <=> other.ending
|
32
|
+
else
|
33
|
+
start <=> other.start
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
27
37
|
# Get a hash of the range. This representation is suitable for use in
|
28
38
|
# the language server protocol.
|
29
39
|
#
|