solargraph 0.33.2 → 0.34.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/README.md +1 -1
- data/lib/solargraph.rb +5 -0
- data/lib/solargraph/api_map.rb +36 -18
- data/lib/solargraph/api_map/cache.rb +2 -0
- data/lib/solargraph/api_map/source_to_yard.rb +14 -5
- data/lib/solargraph/api_map/store.rb +17 -19
- data/lib/solargraph/bundle.rb +2 -0
- data/lib/solargraph/complex_type.rb +18 -4
- data/lib/solargraph/complex_type/type_methods.rb +2 -0
- data/lib/solargraph/complex_type/unique_type.rb +2 -0
- data/lib/solargraph/convention.rb +38 -0
- data/lib/solargraph/convention/base.rb +28 -0
- data/lib/solargraph/convention/gemfile.rb +18 -0
- data/lib/solargraph/convention/gemspec.rb +25 -0
- data/lib/solargraph/convention/rspec.rb +23 -0
- data/lib/solargraph/core_fills.rb +66 -42
- data/lib/solargraph/diagnostics.rb +2 -0
- data/lib/solargraph/diagnostics/base.rb +2 -0
- data/lib/solargraph/diagnostics/require_not_found.rb +2 -0
- data/lib/solargraph/diagnostics/rubocop.rb +2 -0
- data/lib/solargraph/diagnostics/rubocop_helpers.rb +2 -0
- data/lib/solargraph/diagnostics/severities.rb +15 -13
- data/lib/solargraph/diagnostics/type_check.rb +2 -0
- data/lib/solargraph/diagnostics/update_errors.rb +2 -0
- data/lib/solargraph/documentor.rb +42 -0
- data/lib/solargraph/environ.rb +40 -0
- data/lib/solargraph/language_server.rb +19 -17
- data/lib/solargraph/language_server/completion_item_kinds.rb +2 -0
- data/lib/solargraph/language_server/error_codes.rb +2 -0
- data/lib/solargraph/language_server/host.rb +3 -1
- data/lib/solargraph/language_server/host/cataloger.rb +2 -0
- data/lib/solargraph/language_server/host/diagnoser.rb +2 -0
- data/lib/solargraph/language_server/host/dispatch.rb +2 -0
- data/lib/solargraph/language_server/host/sources.rb +2 -0
- data/lib/solargraph/language_server/message.rb +2 -0
- data/lib/solargraph/language_server/message/base.rb +2 -0
- data/lib/solargraph/language_server/message/cancel_request.rb +13 -11
- data/lib/solargraph/language_server/message/client.rb +11 -9
- data/lib/solargraph/language_server/message/client/register_capability.rb +15 -13
- data/lib/solargraph/language_server/message/completion_item.rb +11 -9
- data/lib/solargraph/language_server/message/completion_item/resolve.rb +2 -0
- data/lib/solargraph/language_server/message/exit_notification.rb +2 -0
- data/lib/solargraph/language_server/message/extended.rb +2 -0
- data/lib/solargraph/language_server/message/extended/check_gem_version.rb +2 -0
- data/lib/solargraph/language_server/message/extended/document.rb +2 -0
- data/lib/solargraph/language_server/message/extended/document_gems.rb +2 -0
- data/lib/solargraph/language_server/message/extended/download_core.rb +27 -25
- data/lib/solargraph/language_server/message/extended/environment.rb +5 -0
- data/lib/solargraph/language_server/message/extended/search.rb +2 -0
- data/lib/solargraph/language_server/message/initialize.rb +2 -0
- data/lib/solargraph/language_server/message/initialized.rb +2 -0
- data/lib/solargraph/language_server/message/method_not_found.rb +16 -14
- data/lib/solargraph/language_server/message/method_not_implemented.rb +14 -12
- data/lib/solargraph/language_server/message/shutdown.rb +2 -0
- data/lib/solargraph/language_server/message/text_document.rb +2 -0
- data/lib/solargraph/language_server/message/text_document/base.rb +19 -17
- data/lib/solargraph/language_server/message/text_document/code_action.rb +2 -0
- data/lib/solargraph/language_server/message/text_document/completion.rb +3 -1
- data/lib/solargraph/language_server/message/text_document/definition.rb +2 -0
- data/lib/solargraph/language_server/message/text_document/did_change.rb +2 -0
- data/lib/solargraph/language_server/message/text_document/did_close.rb +15 -13
- data/lib/solargraph/language_server/message/text_document/did_open.rb +15 -13
- data/lib/solargraph/language_server/message/text_document/did_save.rb +17 -15
- data/lib/solargraph/language_server/message/text_document/document_symbol.rb +2 -0
- data/lib/solargraph/language_server/message/text_document/folding_range.rb +2 -0
- data/lib/solargraph/language_server/message/text_document/formatting.rb +8 -1
- data/lib/solargraph/language_server/message/text_document/hover.rb +3 -1
- data/lib/solargraph/language_server/message/text_document/on_type_formatting.rb +2 -0
- data/lib/solargraph/language_server/message/text_document/prepare_rename.rb +2 -0
- data/lib/solargraph/language_server/message/text_document/references.rb +2 -0
- data/lib/solargraph/language_server/message/text_document/rename.rb +2 -0
- data/lib/solargraph/language_server/message/text_document/signature_help.rb +7 -1
- data/lib/solargraph/language_server/message/workspace.rb +2 -0
- data/lib/solargraph/language_server/message/workspace/did_change_configuration.rb +2 -0
- data/lib/solargraph/language_server/message/workspace/did_change_watched_files.rb +2 -0
- 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 -0
- data/lib/solargraph/language_server/message_types.rb +14 -12
- data/lib/solargraph/language_server/request.rb +2 -0
- data/lib/solargraph/language_server/symbol_kinds.rb +2 -0
- data/lib/solargraph/language_server/transport.rb +2 -0
- data/lib/solargraph/language_server/transport/adapter.rb +2 -0
- data/lib/solargraph/language_server/transport/data_reader.rb +3 -1
- data/lib/solargraph/language_server/uri_helpers.rb +2 -0
- data/lib/solargraph/library.rb +2 -0
- data/lib/solargraph/location.rb +2 -0
- data/lib/solargraph/logging.rb +2 -0
- data/lib/solargraph/page.rb +2 -0
- data/lib/solargraph/pin.rb +3 -20
- data/lib/solargraph/pin/attribute.rb +2 -4
- data/lib/solargraph/pin/base.rb +3 -5
- data/lib/solargraph/pin/base_method.rb +2 -4
- data/lib/solargraph/pin/base_variable.rb +2 -0
- data/lib/solargraph/pin/block.rb +2 -4
- data/lib/solargraph/pin/class_variable.rb +2 -3
- data/lib/solargraph/pin/closure.rb +9 -0
- data/lib/solargraph/pin/common.rb +3 -5
- data/lib/solargraph/pin/constant.rb +2 -4
- data/lib/solargraph/pin/conversions.rb +4 -2
- data/lib/solargraph/pin/documenting.rb +2 -0
- data/lib/solargraph/pin/duck_method.rb +2 -0
- data/lib/solargraph/pin/global_variable.rb +2 -3
- data/lib/solargraph/pin/instance_variable.rb +2 -4
- data/lib/solargraph/pin/keyword.rb +2 -4
- data/lib/solargraph/pin/keyword_param.rb +8 -0
- data/lib/solargraph/pin/local_variable.rb +2 -4
- data/lib/solargraph/pin/localized.rb +2 -0
- data/lib/solargraph/pin/method.rb +14 -4
- data/lib/solargraph/pin/method_alias.rb +2 -4
- data/lib/solargraph/pin/namespace.rb +22 -14
- data/lib/solargraph/pin/parameter.rb +4 -6
- data/lib/solargraph/pin/proxy_type.rb +2 -0
- data/lib/solargraph/pin/reference.rb +2 -0
- data/lib/solargraph/pin/reference/extend.rb +2 -3
- data/lib/solargraph/pin/reference/include.rb +2 -3
- data/lib/solargraph/pin/reference/override.rb +12 -3
- data/lib/solargraph/pin/reference/require.rb +2 -4
- data/lib/solargraph/pin/reference/superclass.rb +2 -3
- data/lib/solargraph/pin/singleton.rb +2 -0
- data/lib/solargraph/pin/symbol.rb +2 -4
- data/lib/solargraph/pin/yard_pin.rb +2 -0
- data/lib/solargraph/pin/yard_pin/constant.rb +7 -3
- data/lib/solargraph/pin/yard_pin/method.rb +12 -10
- data/lib/solargraph/pin/yard_pin/namespace.rb +9 -4
- data/lib/solargraph/pin/yard_pin/yard_mixin.rb +30 -3
- data/lib/solargraph/position.rb +2 -0
- data/lib/solargraph/range.rb +2 -0
- data/lib/solargraph/server_methods.rb +2 -0
- data/lib/solargraph/shell.rb +33 -2
- data/lib/solargraph/source.rb +2 -0
- data/lib/solargraph/source/chain.rb +2 -0
- data/lib/solargraph/source/chain/call.rb +63 -14
- data/lib/solargraph/source/chain/class_variable.rb +2 -0
- data/lib/solargraph/source/chain/constant.rb +18 -11
- data/lib/solargraph/source/chain/global_variable.rb +2 -0
- data/lib/solargraph/source/chain/head.rb +2 -0
- data/lib/solargraph/source/chain/instance_variable.rb +2 -0
- data/lib/solargraph/source/chain/link.rb +2 -0
- data/lib/solargraph/source/chain/literal.rb +2 -0
- data/lib/solargraph/source/chain/or.rb +2 -0
- data/lib/solargraph/source/chain/variable.rb +2 -0
- data/lib/solargraph/source/change.rb +2 -0
- data/lib/solargraph/source/cursor.rb +4 -1
- data/lib/solargraph/source/encoding_fixes.rb +2 -0
- data/lib/solargraph/source/flawed_builder.rb +15 -13
- data/lib/solargraph/source/node_chainer.rb +2 -0
- data/lib/solargraph/source/node_methods.rb +9 -5
- data/lib/solargraph/source/source_chainer.rb +2 -0
- data/lib/solargraph/source/updater.rb +52 -50
- data/lib/solargraph/source_map.rb +15 -7
- data/lib/solargraph/source_map/clip.rb +35 -3
- data/lib/solargraph/source_map/completion.rb +2 -0
- data/lib/solargraph/source_map/mapper.rb +2 -0
- data/lib/solargraph/source_map/node_processor.rb +2 -0
- data/lib/solargraph/source_map/node_processor/alias_node.rb +2 -0
- data/lib/solargraph/source_map/node_processor/args_node.rb +2 -0
- data/lib/solargraph/source_map/node_processor/base.rb +5 -3
- data/lib/solargraph/source_map/node_processor/begin_node.rb +2 -0
- data/lib/solargraph/source_map/node_processor/block_node.rb +2 -0
- data/lib/solargraph/source_map/node_processor/casgn_node.rb +2 -0
- data/lib/solargraph/source_map/node_processor/cvasgn_node.rb +2 -0
- data/lib/solargraph/source_map/node_processor/def_node.rb +2 -0
- data/lib/solargraph/source_map/node_processor/defs_node.rb +2 -0
- data/lib/solargraph/source_map/node_processor/gvasgn_node.rb +2 -0
- data/lib/solargraph/source_map/node_processor/ivasgn_node.rb +3 -1
- data/lib/solargraph/source_map/node_processor/lvasgn_node.rb +2 -0
- data/lib/solargraph/source_map/node_processor/namespace_node.rb +4 -1
- data/lib/solargraph/source_map/node_processor/orasgn_node.rb +2 -0
- data/lib/solargraph/source_map/node_processor/resbody_node.rb +2 -0
- data/lib/solargraph/source_map/node_processor/sclass_node.rb +2 -0
- data/lib/solargraph/source_map/node_processor/send_node.rb +11 -6
- data/lib/solargraph/source_map/node_processor/sym_node.rb +2 -0
- data/lib/solargraph/source_map/region.rb +2 -0
- data/lib/solargraph/type_checker.rb +35 -17
- data/lib/solargraph/type_checker/param_def.rb +2 -0
- data/lib/solargraph/type_checker/problem.rb +2 -0
- data/lib/solargraph/version.rb +3 -1
- data/lib/solargraph/views/document.erb +3 -3
- data/lib/solargraph/views/environment.erb +3 -0
- data/lib/solargraph/workspace.rb +5 -1
- data/lib/solargraph/workspace/config.rb +14 -0
- data/lib/solargraph/yard_map.rb +64 -5
- data/lib/solargraph/yard_map/cache.rb +2 -0
- data/lib/solargraph/yard_map/core_docs.rb +2 -0
- data/lib/solargraph/yard_map/core_gen.rb +2 -0
- data/lib/solargraph/yard_map/mapper.rb +15 -14
- data/lib/solargraph/yard_map/rdoc_to_yard.rb +129 -0
- data/lib/yard-solargraph.rb +8 -0
- metadata +11 -2
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Solargraph
|
2
4
|
class Source
|
3
5
|
# Information about a position in a source, including the word located
|
@@ -140,6 +142,8 @@ module Solargraph
|
|
140
142
|
|
141
143
|
# @return [Parser::AST::Node, nil]
|
142
144
|
def recipient_node
|
145
|
+
tree = source.tree_at(position.line, position.column)
|
146
|
+
return tree[1] if tree[1] && tree[1].type == :send && tree[1].children[2..-1].include?(tree[0])
|
143
147
|
return nil if source.code[offset-1] == ')' || source.code[0..offset] =~ /[^,][ \t]*?\n[ \t]*?\Z/
|
144
148
|
return nil if first_char_offset < offset && source.code[first_char_offset..offset-1] =~ /\)[\s]*\Z/
|
145
149
|
pos = Position.from_offset(source.code, first_char_offset)
|
@@ -151,7 +155,6 @@ module Solargraph
|
|
151
155
|
end
|
152
156
|
return tree[1] if tree[1] && tree[1].type == :send
|
153
157
|
return tree[3] if tree[1] && tree[3] && tree[1].type == :pair && tree[3].type == :send
|
154
|
-
nil
|
155
158
|
end
|
156
159
|
|
157
160
|
private
|
@@ -1,13 +1,15 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
#
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Solargraph
|
4
|
+
class Source
|
5
|
+
# A custom builder for source parsers that ignores character encoding
|
6
|
+
# issues in literal strings.
|
7
|
+
#
|
8
|
+
class FlawedBuilder < Parser::Builders::Default
|
9
|
+
def string_value(token)
|
10
|
+
value(token)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
private_constant :FlawedBuilder
|
14
|
+
end
|
15
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Solargraph
|
2
4
|
class Source
|
3
5
|
module NodeMethods
|
@@ -13,9 +15,9 @@ module Solargraph
|
|
13
15
|
# @return [Array<String>]
|
14
16
|
def pack_name(node)
|
15
17
|
parts = []
|
16
|
-
if node.
|
18
|
+
if node.is_a?(AST::Node)
|
17
19
|
node.children.each { |n|
|
18
|
-
if n.
|
20
|
+
if n.is_a?(AST::Node)
|
19
21
|
if n.type == :cbase
|
20
22
|
parts = [''] + pack_name(n)
|
21
23
|
else
|
@@ -32,7 +34,7 @@ module Solargraph
|
|
32
34
|
# @param node [Parser::AST::Node]
|
33
35
|
# @return [String]
|
34
36
|
def const_from node
|
35
|
-
if node.
|
37
|
+
if node.is_a?(AST::Node) and node.type == :const
|
36
38
|
result = ''
|
37
39
|
unless node.children[0].nil?
|
38
40
|
result = const_from(node.children[0])
|
@@ -51,7 +53,7 @@ module Solargraph
|
|
51
53
|
# @param node [Parser::AST::Node]
|
52
54
|
# @return [String]
|
53
55
|
def infer_literal_node_type node
|
54
|
-
return nil unless node.
|
56
|
+
return nil unless node.is_a?(AST::Node)
|
55
57
|
if node.type == :str || node.type == :dstr
|
56
58
|
return 'String'
|
57
59
|
elsif node.type == :array
|
@@ -66,6 +68,8 @@ module Solargraph
|
|
66
68
|
return 'Symbol'
|
67
69
|
elsif node.type == :regexp
|
68
70
|
return 'Regexp'
|
71
|
+
elsif node.type == :irange
|
72
|
+
return 'Range'
|
69
73
|
# @todo Support `nil` keyword in types
|
70
74
|
# elsif node.type == :nil
|
71
75
|
# return 'NilClass'
|
@@ -98,7 +102,7 @@ module Solargraph
|
|
98
102
|
end
|
99
103
|
|
100
104
|
def drill_signature node, signature
|
101
|
-
return signature unless node.
|
105
|
+
return signature unless node.is_a?(AST::Node)
|
102
106
|
if node.type == :const or node.type == :cbase
|
103
107
|
unless node.children[0].nil?
|
104
108
|
signature += drill_signature(node.children[0], signature)
|
@@ -1,50 +1,52 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
#
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
# @param
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
@
|
23
|
-
@
|
24
|
-
@
|
25
|
-
@
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
@output
|
34
|
-
@
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Solargraph
|
4
|
+
class Source
|
5
|
+
# Updaters contain changes to be applied to a source. The source applies
|
6
|
+
# the update via the Source#synchronize method.
|
7
|
+
#
|
8
|
+
class Updater
|
9
|
+
# @return [String]
|
10
|
+
attr_reader :filename
|
11
|
+
|
12
|
+
# @return [Integer]
|
13
|
+
attr_reader :version
|
14
|
+
|
15
|
+
# @return [Array<Change>]
|
16
|
+
attr_reader :changes
|
17
|
+
|
18
|
+
# @param filename [String] The file to update.
|
19
|
+
# @param version [Integer] A version number associated with this update.
|
20
|
+
# @param changes [Array<Solargraph::Source::Change>] The changes.
|
21
|
+
def initialize filename, version, changes
|
22
|
+
@filename = filename
|
23
|
+
@version = version
|
24
|
+
@changes = changes
|
25
|
+
@input = nil
|
26
|
+
@did_nullify = nil
|
27
|
+
@output = nil
|
28
|
+
end
|
29
|
+
|
30
|
+
# @return [String]
|
31
|
+
def write text, nullable = false
|
32
|
+
can_nullify = (nullable and changes.length == 1)
|
33
|
+
return @output if @input == text and can_nullify == @did_nullify
|
34
|
+
@input = text
|
35
|
+
@output = text
|
36
|
+
@did_nullify = can_nullify
|
37
|
+
changes.each do |ch|
|
38
|
+
@output = ch.write(@output, can_nullify)
|
39
|
+
end
|
40
|
+
@output
|
41
|
+
end
|
42
|
+
|
43
|
+
# @return [String]
|
44
|
+
def repair text
|
45
|
+
changes.each do |ch|
|
46
|
+
text = ch.repair(text)
|
47
|
+
end
|
48
|
+
text
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'jaro_winkler'
|
2
4
|
|
3
5
|
module Solargraph
|
@@ -27,6 +29,7 @@ module Solargraph
|
|
27
29
|
@source = source.dup
|
28
30
|
@pins = pins
|
29
31
|
@locals = locals
|
32
|
+
environ.merge Convention.for(source)
|
30
33
|
end
|
31
34
|
|
32
35
|
# @return [String]
|
@@ -41,13 +44,18 @@ module Solargraph
|
|
41
44
|
|
42
45
|
# @return [Array<Pin::Reference::Require>]
|
43
46
|
def requires
|
44
|
-
@requires ||= pins.select{|p| p.
|
47
|
+
@requires ||= pins.select{ |p| p.is_a?(Pin::Reference::Require) }
|
48
|
+
end
|
49
|
+
|
50
|
+
# @return [Environ]
|
51
|
+
def environ
|
52
|
+
@environ ||= Environ.new
|
45
53
|
end
|
46
54
|
|
47
55
|
# @return [Array<Pin::Base>]
|
48
56
|
def document_symbols
|
49
57
|
@document_symbols ||= pins.select { |pin|
|
50
|
-
|
58
|
+
pin.path && !pin.path.empty?
|
51
59
|
}
|
52
60
|
end
|
53
61
|
|
@@ -77,11 +85,11 @@ module Solargraph
|
|
77
85
|
end
|
78
86
|
|
79
87
|
def locate_named_path_pin line, character
|
80
|
-
_locate_pin line, character, Pin::
|
88
|
+
_locate_pin line, character, Pin::Namespace, Pin::Method
|
81
89
|
end
|
82
90
|
|
83
91
|
def locate_block_pin line, character
|
84
|
-
_locate_pin line, character, Pin::
|
92
|
+
_locate_pin line, character, Pin::Namespace, Pin::Method, Pin::Block
|
85
93
|
end
|
86
94
|
|
87
95
|
# @param other_map [SourceMap]
|
@@ -139,13 +147,13 @@ module Solargraph
|
|
139
147
|
|
140
148
|
# @param line [Integer]
|
141
149
|
# @param character [Integer]
|
142
|
-
# @param
|
150
|
+
# @param klasses [Array<Class>]
|
143
151
|
# @return [Pin::Base]
|
144
|
-
def _locate_pin line, character, *
|
152
|
+
def _locate_pin line, character, *klasses
|
145
153
|
position = Position.new(line, character)
|
146
154
|
found = nil
|
147
155
|
pins.each do |pin|
|
148
|
-
found = pin if (
|
156
|
+
found = pin if (klasses.empty? || klasses.any? { |kls| pin.is_a?(kls) } ) && pin.location.range.contain?(position)
|
149
157
|
break if pin.location.range.start.line > line
|
150
158
|
end
|
151
159
|
# Assuming the root pin is always valid
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Solargraph
|
2
4
|
class SourceMap
|
3
5
|
# A static analysis tool for obtaining definitions, completions,
|
@@ -25,6 +27,7 @@ module Solargraph
|
|
25
27
|
return package_completions(api_map.get_symbols) if cursor.chain.literal? && cursor.chain.links.last.word == '<Symbol>'
|
26
28
|
return Completion.new([], cursor.range) if cursor.chain.literal? || cursor.comment?
|
27
29
|
result = []
|
30
|
+
result.concat complete_keyword_parameters
|
28
31
|
if cursor.chain.constant? || cursor.start_of_constant?
|
29
32
|
if cursor.chain.undefined?
|
30
33
|
type = cursor.chain.base.infer(api_map, context_pin, locals)
|
@@ -38,7 +41,7 @@ module Solargraph
|
|
38
41
|
type = ComplexType::UNDEFINED
|
39
42
|
end
|
40
43
|
end
|
41
|
-
result.concat api_map.get_constants(type.undefined? ? '' : type.namespace, cursor.start_of_constant? ? '' : context_pin.full_context.namespace)
|
44
|
+
result.concat api_map.get_constants(type.undefined? ? '' : type.namespace, cursor.start_of_constant? ? '' : context_pin.full_context.namespace, *gates)
|
42
45
|
else
|
43
46
|
type = cursor.chain.base.infer(api_map, block, locals)
|
44
47
|
result.concat api_map.get_complex_type_methods(type, block.binder.namespace, cursor.chain.links.length == 1)
|
@@ -51,7 +54,7 @@ module Solargraph
|
|
51
54
|
return package_completions(api_map.get_global_variable_pins)
|
52
55
|
end
|
53
56
|
result.concat locals
|
54
|
-
result.concat api_map.get_constants(
|
57
|
+
result.concat api_map.get_constants(context_pin.context.namespace, *gates)
|
55
58
|
result.concat api_map.get_methods(block.binder.namespace, scope: block.binder.scope, visibility: [:public, :private, :protected])
|
56
59
|
result.concat api_map.get_methods('Kernel')
|
57
60
|
result.concat ApiMap.keywords
|
@@ -88,6 +91,10 @@ module Solargraph
|
|
88
91
|
}.reverse
|
89
92
|
end
|
90
93
|
|
94
|
+
def gates
|
95
|
+
block.gates
|
96
|
+
end
|
97
|
+
|
91
98
|
private
|
92
99
|
|
93
100
|
# @return [ApiMap]
|
@@ -128,13 +135,38 @@ module Solargraph
|
|
128
135
|
result
|
129
136
|
end
|
130
137
|
|
138
|
+
# @return [Array<Pin::KeywordParam]
|
139
|
+
def complete_keyword_parameters
|
140
|
+
return [] unless cursor.argument? && cursor.chain.links.one? && cursor.word =~ /^[a-z0-9_]*:?$/
|
141
|
+
pins = signify
|
142
|
+
result = []
|
143
|
+
done = []
|
144
|
+
pins.each do |pin|
|
145
|
+
pin.parameter_names.each do |name|
|
146
|
+
next if done.include?(name)
|
147
|
+
done.push name
|
148
|
+
if pin.parameters.any? { |par| par.start_with?("#{name}:") }
|
149
|
+
result.push Pin::KeywordParam.new(pin.location, "#{name}:")
|
150
|
+
end
|
151
|
+
end
|
152
|
+
if !pin.parameters.empty? && pin.parameters.last.start_with?('**') || pin.parameters.last =~ /= *?\{\}$/
|
153
|
+
pin.docstring.tags(:param).each do |tag|
|
154
|
+
next if done.include?(tag.name)
|
155
|
+
done.push tag.name
|
156
|
+
result.push Pin::KeywordParam.new(pin.location, "#{tag.name}:")
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
result
|
161
|
+
end
|
162
|
+
|
131
163
|
# @param result [Array<Pin::Base>]
|
132
164
|
# @return [Completion]
|
133
165
|
def package_completions result
|
134
166
|
frag_start = cursor.start_of_word.to_s.downcase
|
135
167
|
filtered = result.uniq(&:name).select { |s|
|
136
168
|
s.name.downcase.start_with?(frag_start) &&
|
137
|
-
(s.
|
169
|
+
(!s.is_a?(Pin::BaseMethod) || s.name.match(/^[a-z0-9_]+(\!|\?|=)?$/i))
|
138
170
|
}
|
139
171
|
Completion.new(filtered, cursor.range)
|
140
172
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Solargraph
|
2
4
|
class SourceMap
|
3
5
|
module NodeProcessor
|
@@ -60,12 +62,12 @@ module Solargraph
|
|
60
62
|
end
|
61
63
|
|
62
64
|
def named_path_pin position
|
63
|
-
pins.select{|pin|
|
65
|
+
pins.select{|pin| pin.is_a?(Pin::Closure) && !pin.path.empty? && pin.location.range.contain?(position)}.last
|
64
66
|
end
|
65
67
|
|
66
68
|
# @todo Candidate for deprecation
|
67
69
|
def block_pin position
|
68
|
-
pins.select{|pin|
|
70
|
+
pins.select{|pin| pin.is_a?(Pin::Closure) && pin.location.range.contain?(position)}.last
|
69
71
|
end
|
70
72
|
|
71
73
|
# @todo Candidate for deprecation
|
@@ -80,7 +82,7 @@ module Solargraph
|
|
80
82
|
list = nil
|
81
83
|
args = []
|
82
84
|
node.children.each { |c|
|
83
|
-
if c.
|
85
|
+
if c.is_a?(AST::Node) and c.type == :args
|
84
86
|
list = c
|
85
87
|
break
|
86
88
|
end
|