cosmicgraph 0.49.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 +7 -0
- data/.github/FUNDING.yml +1 -0
- data/.github/workflows/rspec.yml +41 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.yardopts +2 -0
- data/CHANGELOG.md +1150 -0
- data/Gemfile +7 -0
- data/LICENSE +21 -0
- data/README.md +136 -0
- data/Rakefile +25 -0
- data/SPONSORS.md +15 -0
- data/bin/solargraph +5 -0
- data/cosmicgraph.gemspec +44 -0
- data/lib/.rubocop.yml +22 -0
- data/lib/solargraph/api_map/bundler_methods.rb +22 -0
- data/lib/solargraph/api_map/cache.rb +70 -0
- data/lib/solargraph/api_map/source_to_yard.rb +81 -0
- data/lib/solargraph/api_map/store.rb +268 -0
- data/lib/solargraph/api_map.rb +704 -0
- data/lib/solargraph/bench.rb +27 -0
- data/lib/solargraph/cache.rb +51 -0
- data/lib/solargraph/complex_type/type_methods.rb +134 -0
- data/lib/solargraph/complex_type/unique_type.rb +132 -0
- data/lib/solargraph/complex_type.rb +254 -0
- data/lib/solargraph/convention/base.rb +33 -0
- data/lib/solargraph/convention/gemfile.rb +15 -0
- data/lib/solargraph/convention/gemspec.rb +22 -0
- data/lib/solargraph/convention/rakefile.rb +17 -0
- data/lib/solargraph/convention/rspec.rb +30 -0
- data/lib/solargraph/convention.rb +49 -0
- data/lib/solargraph/converters/dd.rb +12 -0
- data/lib/solargraph/converters/dl.rb +12 -0
- data/lib/solargraph/converters/dt.rb +12 -0
- data/lib/solargraph/converters/misc.rb +1 -0
- data/lib/solargraph/diagnostics/base.rb +29 -0
- data/lib/solargraph/diagnostics/require_not_found.rb +53 -0
- data/lib/solargraph/diagnostics/rubocop.rb +112 -0
- data/lib/solargraph/diagnostics/rubocop_helpers.rb +65 -0
- data/lib/solargraph/diagnostics/severities.rb +15 -0
- data/lib/solargraph/diagnostics/type_check.rb +54 -0
- data/lib/solargraph/diagnostics/update_errors.rb +41 -0
- data/lib/solargraph/diagnostics.rb +55 -0
- data/lib/solargraph/documentor.rb +76 -0
- data/lib/solargraph/environ.rb +45 -0
- data/lib/solargraph/language_server/completion_item_kinds.rb +35 -0
- data/lib/solargraph/language_server/error_codes.rb +20 -0
- data/lib/solargraph/language_server/host/cataloger.rb +56 -0
- data/lib/solargraph/language_server/host/diagnoser.rb +89 -0
- data/lib/solargraph/language_server/host/dispatch.rb +111 -0
- data/lib/solargraph/language_server/host/message_worker.rb +59 -0
- data/lib/solargraph/language_server/host/sources.rb +156 -0
- data/lib/solargraph/language_server/host.rb +869 -0
- data/lib/solargraph/language_server/message/base.rb +89 -0
- data/lib/solargraph/language_server/message/cancel_request.rb +13 -0
- data/lib/solargraph/language_server/message/client/register_capability.rb +15 -0
- data/lib/solargraph/language_server/message/client.rb +11 -0
- data/lib/solargraph/language_server/message/completion_item/resolve.rb +58 -0
- data/lib/solargraph/language_server/message/completion_item.rb +11 -0
- data/lib/solargraph/language_server/message/exit_notification.rb +13 -0
- data/lib/solargraph/language_server/message/extended/check_gem_version.rb +100 -0
- data/lib/solargraph/language_server/message/extended/document.rb +20 -0
- data/lib/solargraph/language_server/message/extended/document_gems.rb +32 -0
- data/lib/solargraph/language_server/message/extended/download_core.rb +19 -0
- data/lib/solargraph/language_server/message/extended/environment.rb +25 -0
- data/lib/solargraph/language_server/message/extended/search.rb +20 -0
- data/lib/solargraph/language_server/message/extended.rb +21 -0
- data/lib/solargraph/language_server/message/initialize.rb +164 -0
- data/lib/solargraph/language_server/message/initialized.rb +27 -0
- data/lib/solargraph/language_server/message/method_not_found.rb +16 -0
- data/lib/solargraph/language_server/message/method_not_implemented.rb +14 -0
- data/lib/solargraph/language_server/message/shutdown.rb +13 -0
- data/lib/solargraph/language_server/message/text_document/base.rb +19 -0
- data/lib/solargraph/language_server/message/text_document/code_action.rb +17 -0
- data/lib/solargraph/language_server/message/text_document/completion.rb +59 -0
- data/lib/solargraph/language_server/message/text_document/definition.rb +38 -0
- data/lib/solargraph/language_server/message/text_document/did_change.rb +15 -0
- data/lib/solargraph/language_server/message/text_document/did_close.rb +15 -0
- data/lib/solargraph/language_server/message/text_document/did_open.rb +15 -0
- data/lib/solargraph/language_server/message/text_document/did_save.rb +17 -0
- data/lib/solargraph/language_server/message/text_document/document_highlight.rb +16 -0
- data/lib/solargraph/language_server/message/text_document/document_symbol.rb +23 -0
- data/lib/solargraph/language_server/message/text_document/folding_range.rb +26 -0
- data/lib/solargraph/language_server/message/text_document/formatting.rb +126 -0
- data/lib/solargraph/language_server/message/text_document/hover.rb +56 -0
- data/lib/solargraph/language_server/message/text_document/on_type_formatting.rb +34 -0
- data/lib/solargraph/language_server/message/text_document/prepare_rename.rb +11 -0
- data/lib/solargraph/language_server/message/text_document/references.rb +16 -0
- data/lib/solargraph/language_server/message/text_document/rename.rb +19 -0
- data/lib/solargraph/language_server/message/text_document/signature_help.rb +24 -0
- data/lib/solargraph/language_server/message/text_document.rb +28 -0
- data/lib/solargraph/language_server/message/workspace/did_change_configuration.rb +30 -0
- data/lib/solargraph/language_server/message/workspace/did_change_watched_files.rb +40 -0
- data/lib/solargraph/language_server/message/workspace/did_change_workspace_folders.rb +24 -0
- data/lib/solargraph/language_server/message/workspace/workspace_symbol.rb +23 -0
- data/lib/solargraph/language_server/message/workspace.rb +14 -0
- data/lib/solargraph/language_server/message.rb +93 -0
- data/lib/solargraph/language_server/message_types.rb +14 -0
- data/lib/solargraph/language_server/request.rb +24 -0
- data/lib/solargraph/language_server/symbol_kinds.rb +36 -0
- data/lib/solargraph/language_server/transport/adapter.rb +53 -0
- data/lib/solargraph/language_server/transport/data_reader.rb +72 -0
- data/lib/solargraph/language_server/transport.rb +13 -0
- data/lib/solargraph/language_server/uri_helpers.rb +49 -0
- data/lib/solargraph/language_server.rb +19 -0
- data/lib/solargraph/library.rb +547 -0
- data/lib/solargraph/location.rb +37 -0
- data/lib/solargraph/logging.rb +27 -0
- data/lib/solargraph/page.rb +83 -0
- data/lib/solargraph/parser/comment_ripper.rb +52 -0
- data/lib/solargraph/parser/legacy/class_methods.rb +135 -0
- data/lib/solargraph/parser/legacy/flawed_builder.rb +16 -0
- data/lib/solargraph/parser/legacy/node_chainer.rb +148 -0
- data/lib/solargraph/parser/legacy/node_methods.rb +325 -0
- data/lib/solargraph/parser/legacy/node_processors/alias_node.rb +23 -0
- data/lib/solargraph/parser/legacy/node_processors/args_node.rb +35 -0
- data/lib/solargraph/parser/legacy/node_processors/begin_node.rb +15 -0
- data/lib/solargraph/parser/legacy/node_processors/block_node.rb +42 -0
- data/lib/solargraph/parser/legacy/node_processors/casgn_node.rb +35 -0
- data/lib/solargraph/parser/legacy/node_processors/cvasgn_node.rb +23 -0
- data/lib/solargraph/parser/legacy/node_processors/def_node.rb +63 -0
- data/lib/solargraph/parser/legacy/node_processors/defs_node.rb +36 -0
- data/lib/solargraph/parser/legacy/node_processors/gvasgn_node.rb +23 -0
- data/lib/solargraph/parser/legacy/node_processors/ivasgn_node.rb +38 -0
- data/lib/solargraph/parser/legacy/node_processors/lvasgn_node.rb +28 -0
- data/lib/solargraph/parser/legacy/node_processors/namespace_node.rb +39 -0
- data/lib/solargraph/parser/legacy/node_processors/orasgn_node.rb +16 -0
- data/lib/solargraph/parser/legacy/node_processors/resbody_node.rb +36 -0
- data/lib/solargraph/parser/legacy/node_processors/sclass_node.rb +42 -0
- data/lib/solargraph/parser/legacy/node_processors/send_node.rb +257 -0
- data/lib/solargraph/parser/legacy/node_processors/sym_node.rb +18 -0
- data/lib/solargraph/parser/legacy/node_processors.rb +54 -0
- data/lib/solargraph/parser/legacy.rb +12 -0
- data/lib/solargraph/parser/node_methods.rb +43 -0
- data/lib/solargraph/parser/node_processor/base.rb +77 -0
- data/lib/solargraph/parser/node_processor.rb +43 -0
- data/lib/solargraph/parser/region.rb +66 -0
- data/lib/solargraph/parser/rubyvm/class_methods.rb +149 -0
- data/lib/solargraph/parser/rubyvm/node_chainer.rb +160 -0
- data/lib/solargraph/parser/rubyvm/node_methods.rb +315 -0
- data/lib/solargraph/parser/rubyvm/node_processors/alias_node.rb +23 -0
- data/lib/solargraph/parser/rubyvm/node_processors/args_node.rb +85 -0
- data/lib/solargraph/parser/rubyvm/node_processors/begin_node.rb +15 -0
- data/lib/solargraph/parser/rubyvm/node_processors/block_node.rb +42 -0
- data/lib/solargraph/parser/rubyvm/node_processors/casgn_node.rb +33 -0
- data/lib/solargraph/parser/rubyvm/node_processors/cvasgn_node.rb +23 -0
- data/lib/solargraph/parser/rubyvm/node_processors/def_node.rb +75 -0
- data/lib/solargraph/parser/rubyvm/node_processors/defs_node.rb +68 -0
- data/lib/solargraph/parser/rubyvm/node_processors/gvasgn_node.rb +23 -0
- data/lib/solargraph/parser/rubyvm/node_processors/ivasgn_node.rb +38 -0
- data/lib/solargraph/parser/rubyvm/node_processors/kw_arg_node.rb +39 -0
- data/lib/solargraph/parser/rubyvm/node_processors/lit_node.rb +20 -0
- data/lib/solargraph/parser/rubyvm/node_processors/lvasgn_node.rb +27 -0
- data/lib/solargraph/parser/rubyvm/node_processors/namespace_node.rb +39 -0
- data/lib/solargraph/parser/rubyvm/node_processors/opt_arg_node.rb +26 -0
- data/lib/solargraph/parser/rubyvm/node_processors/orasgn_node.rb +15 -0
- data/lib/solargraph/parser/rubyvm/node_processors/resbody_node.rb +45 -0
- data/lib/solargraph/parser/rubyvm/node_processors/sclass_node.rb +32 -0
- data/lib/solargraph/parser/rubyvm/node_processors/scope_node.rb +15 -0
- data/lib/solargraph/parser/rubyvm/node_processors/send_node.rb +279 -0
- data/lib/solargraph/parser/rubyvm/node_processors/sym_node.rb +18 -0
- data/lib/solargraph/parser/rubyvm/node_processors.rb +63 -0
- data/lib/solargraph/parser/rubyvm/node_wrapper.rb +47 -0
- data/lib/solargraph/parser/rubyvm.rb +40 -0
- data/lib/solargraph/parser/snippet.rb +13 -0
- data/lib/solargraph/parser.rb +26 -0
- data/lib/solargraph/pin/base.rb +299 -0
- data/lib/solargraph/pin/base_variable.rb +84 -0
- data/lib/solargraph/pin/block.rb +73 -0
- data/lib/solargraph/pin/class_variable.rb +8 -0
- data/lib/solargraph/pin/closure.rb +37 -0
- data/lib/solargraph/pin/common.rb +70 -0
- data/lib/solargraph/pin/constant.rb +43 -0
- data/lib/solargraph/pin/conversions.rb +92 -0
- data/lib/solargraph/pin/documenting.rb +105 -0
- data/lib/solargraph/pin/duck_method.rb +16 -0
- data/lib/solargraph/pin/global_variable.rb +8 -0
- data/lib/solargraph/pin/instance_variable.rb +30 -0
- data/lib/solargraph/pin/keyword.rb +15 -0
- data/lib/solargraph/pin/keyword_param.rb +8 -0
- data/lib/solargraph/pin/local_variable.rb +55 -0
- data/lib/solargraph/pin/method.rb +335 -0
- data/lib/solargraph/pin/method_alias.rb +31 -0
- data/lib/solargraph/pin/namespace.rb +94 -0
- data/lib/solargraph/pin/parameter.rb +206 -0
- data/lib/solargraph/pin/proxy_type.rb +29 -0
- data/lib/solargraph/pin/reference/extend.rb +10 -0
- data/lib/solargraph/pin/reference/include.rb +10 -0
- data/lib/solargraph/pin/reference/override.rb +29 -0
- data/lib/solargraph/pin/reference/prepend.rb +10 -0
- data/lib/solargraph/pin/reference/require.rb +14 -0
- data/lib/solargraph/pin/reference/superclass.rb +10 -0
- data/lib/solargraph/pin/reference.rb +14 -0
- data/lib/solargraph/pin/search.rb +56 -0
- data/lib/solargraph/pin/signature.rb +23 -0
- data/lib/solargraph/pin/singleton.rb +11 -0
- data/lib/solargraph/pin/symbol.rb +47 -0
- data/lib/solargraph/pin.rb +38 -0
- data/lib/solargraph/position.rb +100 -0
- data/lib/solargraph/range.rb +95 -0
- data/lib/solargraph/rbs_map/conversions.rb +394 -0
- data/lib/solargraph/rbs_map/core_fills.rb +61 -0
- data/lib/solargraph/rbs_map/core_map.rb +38 -0
- data/lib/solargraph/rbs_map/core_signs.rb +33 -0
- data/lib/solargraph/rbs_map/stdlib_map.rb +36 -0
- data/lib/solargraph/rbs_map.rb +73 -0
- data/lib/solargraph/server_methods.rb +16 -0
- data/lib/solargraph/shell.rb +234 -0
- data/lib/solargraph/source/chain/block_variable.rb +13 -0
- data/lib/solargraph/source/chain/call.rb +215 -0
- data/lib/solargraph/source/chain/class_variable.rb +13 -0
- data/lib/solargraph/source/chain/constant.rb +75 -0
- data/lib/solargraph/source/chain/global_variable.rb +13 -0
- data/lib/solargraph/source/chain/hash.rb +28 -0
- data/lib/solargraph/source/chain/head.rb +19 -0
- data/lib/solargraph/source/chain/instance_variable.rb +13 -0
- data/lib/solargraph/source/chain/link.rb +71 -0
- data/lib/solargraph/source/chain/literal.rb +23 -0
- data/lib/solargraph/source/chain/or.rb +23 -0
- data/lib/solargraph/source/chain/q_call.rb +11 -0
- data/lib/solargraph/source/chain/variable.rb +13 -0
- data/lib/solargraph/source/chain/z_super.rb +30 -0
- data/lib/solargraph/source/chain.rb +179 -0
- data/lib/solargraph/source/change.rb +79 -0
- data/lib/solargraph/source/cursor.rb +164 -0
- data/lib/solargraph/source/encoding_fixes.rb +23 -0
- data/lib/solargraph/source/source_chainer.rb +191 -0
- data/lib/solargraph/source/updater.rb +54 -0
- data/lib/solargraph/source.rb +522 -0
- data/lib/solargraph/source_map/clip.rb +229 -0
- data/lib/solargraph/source_map/completion.rb +23 -0
- data/lib/solargraph/source_map/mapper.rb +241 -0
- data/lib/solargraph/source_map.rb +180 -0
- data/lib/solargraph/type_checker/checks.rb +112 -0
- data/lib/solargraph/type_checker/param_def.rb +35 -0
- data/lib/solargraph/type_checker/problem.rb +32 -0
- data/lib/solargraph/type_checker/rules.rb +57 -0
- data/lib/solargraph/type_checker.rb +549 -0
- data/lib/solargraph/version.rb +5 -0
- data/lib/solargraph/views/_method.erb +62 -0
- data/lib/solargraph/views/_name_type_tag.erb +10 -0
- data/lib/solargraph/views/_namespace.erb +24 -0
- data/lib/solargraph/views/document.erb +23 -0
- data/lib/solargraph/views/environment.erb +58 -0
- data/lib/solargraph/views/layout.erb +44 -0
- data/lib/solargraph/views/search.erb +11 -0
- data/lib/solargraph/workspace/config.rb +231 -0
- data/lib/solargraph/workspace.rb +212 -0
- data/lib/solargraph/yard_map/cache.rb +19 -0
- data/lib/solargraph/yard_map/helpers.rb +16 -0
- data/lib/solargraph/yard_map/mapper/to_constant.rb +25 -0
- data/lib/solargraph/yard_map/mapper/to_method.rb +81 -0
- data/lib/solargraph/yard_map/mapper/to_namespace.rb +27 -0
- data/lib/solargraph/yard_map/mapper.rb +77 -0
- data/lib/solargraph/yard_map/to_method.rb +79 -0
- data/lib/solargraph/yard_map.rb +301 -0
- data/lib/solargraph.rb +69 -0
- data/lib/yard-solargraph.rb +33 -0
- metadata +587 -0
@@ -0,0 +1,206 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Solargraph
|
4
|
+
module Pin
|
5
|
+
class Parameter < LocalVariable
|
6
|
+
# @return [Symbol]
|
7
|
+
attr_reader :decl
|
8
|
+
|
9
|
+
# @return [String]
|
10
|
+
attr_reader :asgn_code
|
11
|
+
|
12
|
+
def initialize decl: :arg, asgn_code: nil, return_type: nil, **splat
|
13
|
+
super(**splat)
|
14
|
+
@asgn_code = asgn_code
|
15
|
+
@decl = decl
|
16
|
+
@return_type = return_type
|
17
|
+
end
|
18
|
+
|
19
|
+
def keyword?
|
20
|
+
[:kwarg, :kwoptarg].include?(decl)
|
21
|
+
end
|
22
|
+
|
23
|
+
def kwrestarg?
|
24
|
+
decl == :kwrestarg || (assignment && [:HASH, :hash].include?(assignment.type))
|
25
|
+
end
|
26
|
+
|
27
|
+
def restarg?
|
28
|
+
decl == :restarg
|
29
|
+
end
|
30
|
+
|
31
|
+
def rest?
|
32
|
+
decl == :restarg || decl == :kwrestarg
|
33
|
+
end
|
34
|
+
|
35
|
+
def block?
|
36
|
+
[:block, :blockarg].include?(decl)
|
37
|
+
end
|
38
|
+
|
39
|
+
def full
|
40
|
+
case decl
|
41
|
+
when :optarg
|
42
|
+
"#{name} = #{asgn_code || '?'}"
|
43
|
+
when :kwarg
|
44
|
+
"#{name}:"
|
45
|
+
when :kwoptarg
|
46
|
+
"#{name}: #{asgn_code || '?'}"
|
47
|
+
when :restarg
|
48
|
+
"*#{name}"
|
49
|
+
when :kwrestarg
|
50
|
+
"**#{name}"
|
51
|
+
when :block, :blockarg
|
52
|
+
"&#{name}"
|
53
|
+
else
|
54
|
+
name
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def return_type
|
59
|
+
if @return_type.nil?
|
60
|
+
@return_type = ComplexType::UNDEFINED
|
61
|
+
found = param_tag
|
62
|
+
@return_type = ComplexType.try_parse(*found.types) unless found.nil? or found.types.nil?
|
63
|
+
if @return_type.undefined?
|
64
|
+
if decl == :restarg
|
65
|
+
@return_type = ComplexType.try_parse('Array')
|
66
|
+
elsif decl == :kwrestarg
|
67
|
+
@return_type = ComplexType.try_parse('Hash')
|
68
|
+
elsif decl == :blockarg
|
69
|
+
@return_type = ComplexType.try_parse('Proc')
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
super
|
74
|
+
@return_type
|
75
|
+
end
|
76
|
+
|
77
|
+
# The parameter's zero-based location in the block's signature.
|
78
|
+
#
|
79
|
+
# @return [Integer]
|
80
|
+
def index
|
81
|
+
closure.parameter_names.index(name)
|
82
|
+
end
|
83
|
+
|
84
|
+
# @param api_map [ApiMap]
|
85
|
+
def typify api_map
|
86
|
+
return return_type.qualify(api_map, closure.context.namespace) unless return_type.undefined?
|
87
|
+
closure.is_a?(Pin::Block) ? typify_block_param(api_map) : typify_method_param(api_map)
|
88
|
+
end
|
89
|
+
|
90
|
+
def documentation
|
91
|
+
tag = param_tag
|
92
|
+
return '' if tag.nil? || tag.text.nil?
|
93
|
+
tag.text
|
94
|
+
end
|
95
|
+
|
96
|
+
def try_merge! pin
|
97
|
+
return false unless super && closure == pin.closure
|
98
|
+
true
|
99
|
+
end
|
100
|
+
|
101
|
+
private
|
102
|
+
|
103
|
+
# @return [YARD::Tags::Tag]
|
104
|
+
def param_tag
|
105
|
+
found = nil
|
106
|
+
params = closure.docstring.tags(:param)
|
107
|
+
params.each do |p|
|
108
|
+
next unless p.name == name
|
109
|
+
found = p
|
110
|
+
break
|
111
|
+
end
|
112
|
+
if found.nil? and !index.nil?
|
113
|
+
found = params[index] if params[index] && (params[index].name.nil? || params[index].name.empty?)
|
114
|
+
end
|
115
|
+
found
|
116
|
+
end
|
117
|
+
|
118
|
+
# @param api_map [ApiMap]
|
119
|
+
# @return [ComplexType]
|
120
|
+
def typify_block_param api_map
|
121
|
+
if closure.is_a?(Pin::Block) && closure.receiver
|
122
|
+
chain = Parser.chain(closure.receiver, filename)
|
123
|
+
clip = api_map.clip_at(location.filename, location.range.start)
|
124
|
+
locals = clip.locals - [self]
|
125
|
+
meths = chain.define(api_map, closure, locals)
|
126
|
+
meths.each do |meth|
|
127
|
+
if meth.docstring.has_tag?(:yieldparam_single_parameter)
|
128
|
+
type = chain.base.infer(api_map, closure, locals)
|
129
|
+
if type.defined? && !type.subtypes.empty?
|
130
|
+
bmeth = chain.base.define(api_map, closure, locals).first
|
131
|
+
return type.subtypes.first.qualify(api_map, bmeth.context.namespace)
|
132
|
+
end
|
133
|
+
else
|
134
|
+
yps = meth.docstring.tags(:yieldparam)
|
135
|
+
unless yps[index].nil? or yps[index].types.nil? or yps[index].types.empty?
|
136
|
+
return ComplexType.try_parse(yps[index].types.first).self_to(chain.base.infer(api_map, closure, locals).namespace).qualify(api_map, meth.context.namespace)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
ComplexType::UNDEFINED
|
142
|
+
end
|
143
|
+
|
144
|
+
# @param api_map [ApiMap]
|
145
|
+
# @return [ComplexType]
|
146
|
+
def typify_method_param api_map
|
147
|
+
meths = api_map.get_method_stack(closure.full_context.namespace, closure.name, scope: closure.scope)
|
148
|
+
# meths.shift # Ignore the first one
|
149
|
+
meths.each do |meth|
|
150
|
+
found = nil
|
151
|
+
params = meth.docstring.tags(:param) + see_reference(docstring, api_map)
|
152
|
+
params.each do |p|
|
153
|
+
next unless p.name == name
|
154
|
+
found = p
|
155
|
+
break
|
156
|
+
end
|
157
|
+
if found.nil? and !index.nil?
|
158
|
+
found = params[index] if params[index] && (params[index].name.nil? || params[index].name.empty?)
|
159
|
+
end
|
160
|
+
return ComplexType.try_parse(*found.types).qualify(api_map, meth.context.namespace) unless found.nil? || found.types.nil?
|
161
|
+
end
|
162
|
+
ComplexType::UNDEFINED
|
163
|
+
end
|
164
|
+
|
165
|
+
# @param heredoc [YARD::Docstring]
|
166
|
+
# @param api_map [ApiMap]
|
167
|
+
# @param skip [Array]
|
168
|
+
# @return [Array<YARD::Tags::Tag>]
|
169
|
+
def see_reference heredoc, api_map, skip = []
|
170
|
+
heredoc.ref_tags.each do |ref|
|
171
|
+
next unless ref.tag_name == 'param' && ref.owner
|
172
|
+
result = resolve_reference(ref.owner.to_s, api_map, skip)
|
173
|
+
return result unless result.nil?
|
174
|
+
end
|
175
|
+
[]
|
176
|
+
end
|
177
|
+
|
178
|
+
# @param ref [String]
|
179
|
+
# @param api_map [ApiMap]
|
180
|
+
# @param skip [Array]
|
181
|
+
# @return [Array<YARD::Tags::Tag>, nil]
|
182
|
+
def resolve_reference ref, api_map, skip
|
183
|
+
return nil if skip.include?(ref)
|
184
|
+
skip.push ref
|
185
|
+
parts = ref.split(/[\.#]/)
|
186
|
+
if parts.first.empty?
|
187
|
+
path = "#{namespace}#{ref}"
|
188
|
+
else
|
189
|
+
fqns = api_map.qualify(parts.first, namespace)
|
190
|
+
return nil if fqns.nil?
|
191
|
+
path = fqns + ref[parts.first.length] + parts.last
|
192
|
+
end
|
193
|
+
pins = api_map.get_path_pins(path)
|
194
|
+
pins.each do |pin|
|
195
|
+
params = pin.docstring.tags(:param)
|
196
|
+
return params unless params.empty?
|
197
|
+
end
|
198
|
+
pins.each do |pin|
|
199
|
+
params = see_reference(pin.docstring, api_map, skip)
|
200
|
+
return params unless params.empty?
|
201
|
+
end
|
202
|
+
nil
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Solargraph
|
4
|
+
module Pin
|
5
|
+
class ProxyType < Base
|
6
|
+
# @param return_type [ComplexType]
|
7
|
+
def initialize return_type: ComplexType::UNDEFINED, **splat
|
8
|
+
super(**splat)
|
9
|
+
@return_type = return_type
|
10
|
+
end
|
11
|
+
|
12
|
+
def context
|
13
|
+
@return_type
|
14
|
+
end
|
15
|
+
|
16
|
+
# @param return_type [ComplexType]
|
17
|
+
# @return [ProxyType]
|
18
|
+
def self.anonymous return_type
|
19
|
+
parts = return_type.namespace.split('::')
|
20
|
+
namespace = parts[0..-2].join('::').to_s
|
21
|
+
name = parts.last.to_s
|
22
|
+
# ProxyType.new(nil, namespace, name, return_type)
|
23
|
+
ProxyType.new(
|
24
|
+
closure: Solargraph::Pin::Namespace.new(name: namespace), return_type: return_type
|
25
|
+
)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Solargraph
|
4
|
+
module Pin
|
5
|
+
class Reference
|
6
|
+
class Override < Reference
|
7
|
+
# @return [Array<YARD::Tags::Tag>]
|
8
|
+
attr_reader :tags
|
9
|
+
|
10
|
+
# @return [Array<Symbol>]
|
11
|
+
attr_reader :delete
|
12
|
+
|
13
|
+
def initialize location, name, tags, delete = []
|
14
|
+
super(location: location, name: name)
|
15
|
+
@tags = tags
|
16
|
+
@delete = delete
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.method_return name, *tags, delete: []
|
20
|
+
new(nil, name, [YARD::Tags::Tag.new('return', nil, tags)], delete)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.from_comment name, comment
|
24
|
+
new(nil, name, Solargraph::Source.parse_docstring(comment).to_docstring.tags)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Solargraph
|
4
|
+
module Pin
|
5
|
+
class Reference < Base
|
6
|
+
autoload :Require, 'solargraph/pin/reference/require'
|
7
|
+
autoload :Superclass, 'solargraph/pin/reference/superclass'
|
8
|
+
autoload :Include, 'solargraph/pin/reference/include'
|
9
|
+
autoload :Prepend, 'solargraph/pin/reference/prepend'
|
10
|
+
autoload :Extend, 'solargraph/pin/reference/extend'
|
11
|
+
autoload :Override, 'solargraph/pin/reference/override'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'jaro_winkler'
|
4
|
+
|
5
|
+
module Solargraph
|
6
|
+
module Pin
|
7
|
+
class Search
|
8
|
+
class Result
|
9
|
+
# @return [Float]
|
10
|
+
attr_reader :match
|
11
|
+
|
12
|
+
# @return [Pin::Base]
|
13
|
+
attr_reader :pin
|
14
|
+
|
15
|
+
def initialize match, pin
|
16
|
+
@match = match
|
17
|
+
@pin = pin
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# @param pins [Array<Pin::Base>]
|
22
|
+
# @param query [String]
|
23
|
+
def initialize pins, query
|
24
|
+
@pins = pins
|
25
|
+
@query = query
|
26
|
+
end
|
27
|
+
|
28
|
+
# @return [Array<Pin::Base>]
|
29
|
+
def results
|
30
|
+
@results ||= do_query
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
# @return [Array<Pin::Base>]
|
36
|
+
def do_query
|
37
|
+
return @pins if @query.nil? || @query.empty?
|
38
|
+
@pins.map do |pin|
|
39
|
+
match = [fuzzy_string_match(pin.path, @query), fuzzy_string_match(pin.name, @query)].max
|
40
|
+
Result.new(match, pin) if match > 0.7
|
41
|
+
end
|
42
|
+
.compact
|
43
|
+
.sort { |a, b| b.match <=> a.match }
|
44
|
+
.map(&:pin)
|
45
|
+
end
|
46
|
+
|
47
|
+
# @param str1 [String]
|
48
|
+
# @param str2 [String]
|
49
|
+
# @return [Float]
|
50
|
+
def fuzzy_string_match str1, str2
|
51
|
+
return (1.0 + (str2.length.to_f / str1.length.to_f)) if str1.downcase.include?(str2.downcase)
|
52
|
+
JaroWinkler.distance(str1, str2, ignore_case: true)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Solargraph
|
2
|
+
module Pin
|
3
|
+
class Signature
|
4
|
+
# @return [Array<Parameter>]
|
5
|
+
attr_reader :parameters
|
6
|
+
|
7
|
+
# @return [ComplexType]
|
8
|
+
attr_reader :return_type
|
9
|
+
|
10
|
+
attr_reader :block
|
11
|
+
|
12
|
+
def initialize parameters, return_type, block = nil
|
13
|
+
@parameters = parameters
|
14
|
+
@return_type = return_type
|
15
|
+
@block = block
|
16
|
+
end
|
17
|
+
|
18
|
+
def block?
|
19
|
+
!!@block
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Solargraph
|
4
|
+
module Pin
|
5
|
+
class Symbol < Base
|
6
|
+
# @param location [Solargraph::Location]
|
7
|
+
# @param name [String]
|
8
|
+
def initialize location, name
|
9
|
+
super(location: location, name: name)
|
10
|
+
# @name = name
|
11
|
+
# @location = location
|
12
|
+
end
|
13
|
+
|
14
|
+
def namespace
|
15
|
+
''
|
16
|
+
end
|
17
|
+
|
18
|
+
def path
|
19
|
+
''
|
20
|
+
end
|
21
|
+
|
22
|
+
def completion_item_kind
|
23
|
+
Solargraph::LanguageServer::CompletionItemKinds::KEYWORD
|
24
|
+
end
|
25
|
+
|
26
|
+
def comments
|
27
|
+
''
|
28
|
+
end
|
29
|
+
|
30
|
+
def return_type
|
31
|
+
@return_type ||= Solargraph::ComplexType::SYMBOL
|
32
|
+
end
|
33
|
+
|
34
|
+
def directives
|
35
|
+
[]
|
36
|
+
end
|
37
|
+
|
38
|
+
def visibility
|
39
|
+
:public
|
40
|
+
end
|
41
|
+
|
42
|
+
def deprecated?
|
43
|
+
false
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'yard'
|
4
|
+
|
5
|
+
module Solargraph
|
6
|
+
# The namespace for pins used in maps.
|
7
|
+
#
|
8
|
+
module Pin
|
9
|
+
autoload :Common, 'solargraph/pin/common'
|
10
|
+
autoload :Conversions, 'solargraph/pin/conversions'
|
11
|
+
autoload :Base, 'solargraph/pin/base'
|
12
|
+
autoload :Method, 'solargraph/pin/method'
|
13
|
+
autoload :Signature, 'solargraph/pin/signature'
|
14
|
+
autoload :MethodAlias, 'solargraph/pin/method_alias'
|
15
|
+
autoload :BaseVariable, 'solargraph/pin/base_variable'
|
16
|
+
autoload :InstanceVariable, 'solargraph/pin/instance_variable'
|
17
|
+
autoload :ClassVariable, 'solargraph/pin/class_variable'
|
18
|
+
autoload :LocalVariable, 'solargraph/pin/local_variable'
|
19
|
+
autoload :GlobalVariable, 'solargraph/pin/global_variable'
|
20
|
+
autoload :Constant, 'solargraph/pin/constant'
|
21
|
+
autoload :Symbol, 'solargraph/pin/symbol'
|
22
|
+
autoload :Closure, 'solargraph/pin/closure'
|
23
|
+
autoload :Namespace, 'solargraph/pin/namespace'
|
24
|
+
autoload :Keyword, 'solargraph/pin/keyword'
|
25
|
+
autoload :Parameter, 'solargraph/pin/parameter'
|
26
|
+
autoload :Reference, 'solargraph/pin/reference'
|
27
|
+
autoload :Documenting, 'solargraph/pin/documenting'
|
28
|
+
autoload :Block, 'solargraph/pin/block'
|
29
|
+
autoload :Localized, 'solargraph/pin/localized'
|
30
|
+
autoload :ProxyType, 'solargraph/pin/proxy_type'
|
31
|
+
autoload :DuckMethod, 'solargraph/pin/duck_method'
|
32
|
+
autoload :Singleton, 'solargraph/pin/singleton'
|
33
|
+
autoload :KeywordParam, 'solargraph/pin/keyword_param'
|
34
|
+
autoload :Search, 'solargraph/pin/search'
|
35
|
+
|
36
|
+
ROOT_PIN = Pin::Namespace.new(type: :class, name: '', closure: nil)
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Solargraph
|
4
|
+
# The zero-based line and column numbers of a position in a string.
|
5
|
+
#
|
6
|
+
class Position
|
7
|
+
# @return [Integer]
|
8
|
+
attr_reader :line
|
9
|
+
|
10
|
+
# @return [Integer]
|
11
|
+
attr_reader :character
|
12
|
+
|
13
|
+
alias column character
|
14
|
+
|
15
|
+
# @param line [Integer]
|
16
|
+
# @param character [Integer]
|
17
|
+
def initialize line, character
|
18
|
+
@line = line
|
19
|
+
@character = character
|
20
|
+
end
|
21
|
+
|
22
|
+
# Get a hash of the position. This representation is suitable for use in
|
23
|
+
# the language server protocol.
|
24
|
+
#
|
25
|
+
# @return [Hash]
|
26
|
+
def to_hash
|
27
|
+
{
|
28
|
+
line: line,
|
29
|
+
character: character
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
def inspect
|
34
|
+
"#<#{self.class} #{line}, #{character}>"
|
35
|
+
end
|
36
|
+
|
37
|
+
# Get a numeric offset for the specified text and position.
|
38
|
+
#
|
39
|
+
# @param text [String]
|
40
|
+
# @param position [Position]
|
41
|
+
# @return [Integer]
|
42
|
+
def self.to_offset text, position
|
43
|
+
return 0 if text.empty?
|
44
|
+
text.lines[0...position.line].sum(&:length) + position.character
|
45
|
+
end
|
46
|
+
|
47
|
+
# Get a numeric offset for the specified text and a position identified
|
48
|
+
# by its line and character.
|
49
|
+
#
|
50
|
+
# @param text [String]
|
51
|
+
# @param line [Integer]
|
52
|
+
# @param character [Integer]
|
53
|
+
# @return [Integer]
|
54
|
+
def self.line_char_to_offset text, line, character
|
55
|
+
to_offset(text, Position.new(line, character))
|
56
|
+
end
|
57
|
+
|
58
|
+
# Get a position for the specified text and offset.
|
59
|
+
#
|
60
|
+
# @param text [String]
|
61
|
+
# @param offset [Integer]
|
62
|
+
# @return [Position]
|
63
|
+
def self.from_offset text, offset
|
64
|
+
cursor = 0
|
65
|
+
line = 0
|
66
|
+
character = nil
|
67
|
+
text.lines.each do |l|
|
68
|
+
line_length = l.length
|
69
|
+
char_length = l.chomp.length
|
70
|
+
if cursor + char_length >= offset
|
71
|
+
character = offset - cursor
|
72
|
+
break
|
73
|
+
end
|
74
|
+
cursor += line_length
|
75
|
+
line += 1
|
76
|
+
end
|
77
|
+
character = 0 if character.nil? and (cursor - offset).between?(0, 1)
|
78
|
+
raise InvalidOffsetError if character.nil?
|
79
|
+
Position.new(line, character)
|
80
|
+
end
|
81
|
+
|
82
|
+
# A helper method for generating positions from arrays of integers. The
|
83
|
+
# original parameter is returned if it is already a position.
|
84
|
+
#
|
85
|
+
# @raise [ArgumentError] if the object cannot be converted to a position.
|
86
|
+
#
|
87
|
+
# @param object [Position, Array(Integer, Integer)]
|
88
|
+
# @return [Position]
|
89
|
+
def self.normalize object
|
90
|
+
return object if object.is_a?(Position)
|
91
|
+
return Position.new(object[0], object[1]) if object.is_a?(Array)
|
92
|
+
raise ArgumentError, "Unable to convert #{object.class} to Position"
|
93
|
+
end
|
94
|
+
|
95
|
+
def == other
|
96
|
+
return false unless other.is_a?(Position)
|
97
|
+
line == other.line and character == other.character
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|