solargraph 0.33.2 → 0.34.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (191) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/README.md +1 -1
  4. data/lib/solargraph.rb +5 -0
  5. data/lib/solargraph/api_map.rb +36 -18
  6. data/lib/solargraph/api_map/cache.rb +2 -0
  7. data/lib/solargraph/api_map/source_to_yard.rb +14 -5
  8. data/lib/solargraph/api_map/store.rb +17 -19
  9. data/lib/solargraph/bundle.rb +2 -0
  10. data/lib/solargraph/complex_type.rb +18 -4
  11. data/lib/solargraph/complex_type/type_methods.rb +2 -0
  12. data/lib/solargraph/complex_type/unique_type.rb +2 -0
  13. data/lib/solargraph/convention.rb +38 -0
  14. data/lib/solargraph/convention/base.rb +28 -0
  15. data/lib/solargraph/convention/gemfile.rb +18 -0
  16. data/lib/solargraph/convention/gemspec.rb +25 -0
  17. data/lib/solargraph/convention/rspec.rb +23 -0
  18. data/lib/solargraph/core_fills.rb +66 -42
  19. data/lib/solargraph/diagnostics.rb +2 -0
  20. data/lib/solargraph/diagnostics/base.rb +2 -0
  21. data/lib/solargraph/diagnostics/require_not_found.rb +2 -0
  22. data/lib/solargraph/diagnostics/rubocop.rb +2 -0
  23. data/lib/solargraph/diagnostics/rubocop_helpers.rb +2 -0
  24. data/lib/solargraph/diagnostics/severities.rb +15 -13
  25. data/lib/solargraph/diagnostics/type_check.rb +2 -0
  26. data/lib/solargraph/diagnostics/update_errors.rb +2 -0
  27. data/lib/solargraph/documentor.rb +42 -0
  28. data/lib/solargraph/environ.rb +40 -0
  29. data/lib/solargraph/language_server.rb +19 -17
  30. data/lib/solargraph/language_server/completion_item_kinds.rb +2 -0
  31. data/lib/solargraph/language_server/error_codes.rb +2 -0
  32. data/lib/solargraph/language_server/host.rb +3 -1
  33. data/lib/solargraph/language_server/host/cataloger.rb +2 -0
  34. data/lib/solargraph/language_server/host/diagnoser.rb +2 -0
  35. data/lib/solargraph/language_server/host/dispatch.rb +2 -0
  36. data/lib/solargraph/language_server/host/sources.rb +2 -0
  37. data/lib/solargraph/language_server/message.rb +2 -0
  38. data/lib/solargraph/language_server/message/base.rb +2 -0
  39. data/lib/solargraph/language_server/message/cancel_request.rb +13 -11
  40. data/lib/solargraph/language_server/message/client.rb +11 -9
  41. data/lib/solargraph/language_server/message/client/register_capability.rb +15 -13
  42. data/lib/solargraph/language_server/message/completion_item.rb +11 -9
  43. data/lib/solargraph/language_server/message/completion_item/resolve.rb +2 -0
  44. data/lib/solargraph/language_server/message/exit_notification.rb +2 -0
  45. data/lib/solargraph/language_server/message/extended.rb +2 -0
  46. data/lib/solargraph/language_server/message/extended/check_gem_version.rb +2 -0
  47. data/lib/solargraph/language_server/message/extended/document.rb +2 -0
  48. data/lib/solargraph/language_server/message/extended/document_gems.rb +2 -0
  49. data/lib/solargraph/language_server/message/extended/download_core.rb +27 -25
  50. data/lib/solargraph/language_server/message/extended/environment.rb +5 -0
  51. data/lib/solargraph/language_server/message/extended/search.rb +2 -0
  52. data/lib/solargraph/language_server/message/initialize.rb +2 -0
  53. data/lib/solargraph/language_server/message/initialized.rb +2 -0
  54. data/lib/solargraph/language_server/message/method_not_found.rb +16 -14
  55. data/lib/solargraph/language_server/message/method_not_implemented.rb +14 -12
  56. data/lib/solargraph/language_server/message/shutdown.rb +2 -0
  57. data/lib/solargraph/language_server/message/text_document.rb +2 -0
  58. data/lib/solargraph/language_server/message/text_document/base.rb +19 -17
  59. data/lib/solargraph/language_server/message/text_document/code_action.rb +2 -0
  60. data/lib/solargraph/language_server/message/text_document/completion.rb +3 -1
  61. data/lib/solargraph/language_server/message/text_document/definition.rb +2 -0
  62. data/lib/solargraph/language_server/message/text_document/did_change.rb +2 -0
  63. data/lib/solargraph/language_server/message/text_document/did_close.rb +15 -13
  64. data/lib/solargraph/language_server/message/text_document/did_open.rb +15 -13
  65. data/lib/solargraph/language_server/message/text_document/did_save.rb +17 -15
  66. data/lib/solargraph/language_server/message/text_document/document_symbol.rb +2 -0
  67. data/lib/solargraph/language_server/message/text_document/folding_range.rb +2 -0
  68. data/lib/solargraph/language_server/message/text_document/formatting.rb +8 -1
  69. data/lib/solargraph/language_server/message/text_document/hover.rb +3 -1
  70. data/lib/solargraph/language_server/message/text_document/on_type_formatting.rb +2 -0
  71. data/lib/solargraph/language_server/message/text_document/prepare_rename.rb +2 -0
  72. data/lib/solargraph/language_server/message/text_document/references.rb +2 -0
  73. data/lib/solargraph/language_server/message/text_document/rename.rb +2 -0
  74. data/lib/solargraph/language_server/message/text_document/signature_help.rb +7 -1
  75. data/lib/solargraph/language_server/message/workspace.rb +2 -0
  76. data/lib/solargraph/language_server/message/workspace/did_change_configuration.rb +2 -0
  77. data/lib/solargraph/language_server/message/workspace/did_change_watched_files.rb +2 -0
  78. data/lib/solargraph/language_server/message/workspace/did_change_workspace_folders.rb +2 -0
  79. data/lib/solargraph/language_server/message/workspace/workspace_symbol.rb +2 -0
  80. data/lib/solargraph/language_server/message_types.rb +14 -12
  81. data/lib/solargraph/language_server/request.rb +2 -0
  82. data/lib/solargraph/language_server/symbol_kinds.rb +2 -0
  83. data/lib/solargraph/language_server/transport.rb +2 -0
  84. data/lib/solargraph/language_server/transport/adapter.rb +2 -0
  85. data/lib/solargraph/language_server/transport/data_reader.rb +3 -1
  86. data/lib/solargraph/language_server/uri_helpers.rb +2 -0
  87. data/lib/solargraph/library.rb +2 -0
  88. data/lib/solargraph/location.rb +2 -0
  89. data/lib/solargraph/logging.rb +2 -0
  90. data/lib/solargraph/page.rb +2 -0
  91. data/lib/solargraph/pin.rb +3 -20
  92. data/lib/solargraph/pin/attribute.rb +2 -4
  93. data/lib/solargraph/pin/base.rb +3 -5
  94. data/lib/solargraph/pin/base_method.rb +2 -4
  95. data/lib/solargraph/pin/base_variable.rb +2 -0
  96. data/lib/solargraph/pin/block.rb +2 -4
  97. data/lib/solargraph/pin/class_variable.rb +2 -3
  98. data/lib/solargraph/pin/closure.rb +9 -0
  99. data/lib/solargraph/pin/common.rb +3 -5
  100. data/lib/solargraph/pin/constant.rb +2 -4
  101. data/lib/solargraph/pin/conversions.rb +4 -2
  102. data/lib/solargraph/pin/documenting.rb +2 -0
  103. data/lib/solargraph/pin/duck_method.rb +2 -0
  104. data/lib/solargraph/pin/global_variable.rb +2 -3
  105. data/lib/solargraph/pin/instance_variable.rb +2 -4
  106. data/lib/solargraph/pin/keyword.rb +2 -4
  107. data/lib/solargraph/pin/keyword_param.rb +8 -0
  108. data/lib/solargraph/pin/local_variable.rb +2 -4
  109. data/lib/solargraph/pin/localized.rb +2 -0
  110. data/lib/solargraph/pin/method.rb +14 -4
  111. data/lib/solargraph/pin/method_alias.rb +2 -4
  112. data/lib/solargraph/pin/namespace.rb +22 -14
  113. data/lib/solargraph/pin/parameter.rb +4 -6
  114. data/lib/solargraph/pin/proxy_type.rb +2 -0
  115. data/lib/solargraph/pin/reference.rb +2 -0
  116. data/lib/solargraph/pin/reference/extend.rb +2 -3
  117. data/lib/solargraph/pin/reference/include.rb +2 -3
  118. data/lib/solargraph/pin/reference/override.rb +12 -3
  119. data/lib/solargraph/pin/reference/require.rb +2 -4
  120. data/lib/solargraph/pin/reference/superclass.rb +2 -3
  121. data/lib/solargraph/pin/singleton.rb +2 -0
  122. data/lib/solargraph/pin/symbol.rb +2 -4
  123. data/lib/solargraph/pin/yard_pin.rb +2 -0
  124. data/lib/solargraph/pin/yard_pin/constant.rb +7 -3
  125. data/lib/solargraph/pin/yard_pin/method.rb +12 -10
  126. data/lib/solargraph/pin/yard_pin/namespace.rb +9 -4
  127. data/lib/solargraph/pin/yard_pin/yard_mixin.rb +30 -3
  128. data/lib/solargraph/position.rb +2 -0
  129. data/lib/solargraph/range.rb +2 -0
  130. data/lib/solargraph/server_methods.rb +2 -0
  131. data/lib/solargraph/shell.rb +33 -2
  132. data/lib/solargraph/source.rb +2 -0
  133. data/lib/solargraph/source/chain.rb +2 -0
  134. data/lib/solargraph/source/chain/call.rb +63 -14
  135. data/lib/solargraph/source/chain/class_variable.rb +2 -0
  136. data/lib/solargraph/source/chain/constant.rb +18 -11
  137. data/lib/solargraph/source/chain/global_variable.rb +2 -0
  138. data/lib/solargraph/source/chain/head.rb +2 -0
  139. data/lib/solargraph/source/chain/instance_variable.rb +2 -0
  140. data/lib/solargraph/source/chain/link.rb +2 -0
  141. data/lib/solargraph/source/chain/literal.rb +2 -0
  142. data/lib/solargraph/source/chain/or.rb +2 -0
  143. data/lib/solargraph/source/chain/variable.rb +2 -0
  144. data/lib/solargraph/source/change.rb +2 -0
  145. data/lib/solargraph/source/cursor.rb +4 -1
  146. data/lib/solargraph/source/encoding_fixes.rb +2 -0
  147. data/lib/solargraph/source/flawed_builder.rb +15 -13
  148. data/lib/solargraph/source/node_chainer.rb +2 -0
  149. data/lib/solargraph/source/node_methods.rb +9 -5
  150. data/lib/solargraph/source/source_chainer.rb +2 -0
  151. data/lib/solargraph/source/updater.rb +52 -50
  152. data/lib/solargraph/source_map.rb +15 -7
  153. data/lib/solargraph/source_map/clip.rb +35 -3
  154. data/lib/solargraph/source_map/completion.rb +2 -0
  155. data/lib/solargraph/source_map/mapper.rb +2 -0
  156. data/lib/solargraph/source_map/node_processor.rb +2 -0
  157. data/lib/solargraph/source_map/node_processor/alias_node.rb +2 -0
  158. data/lib/solargraph/source_map/node_processor/args_node.rb +2 -0
  159. data/lib/solargraph/source_map/node_processor/base.rb +5 -3
  160. data/lib/solargraph/source_map/node_processor/begin_node.rb +2 -0
  161. data/lib/solargraph/source_map/node_processor/block_node.rb +2 -0
  162. data/lib/solargraph/source_map/node_processor/casgn_node.rb +2 -0
  163. data/lib/solargraph/source_map/node_processor/cvasgn_node.rb +2 -0
  164. data/lib/solargraph/source_map/node_processor/def_node.rb +2 -0
  165. data/lib/solargraph/source_map/node_processor/defs_node.rb +2 -0
  166. data/lib/solargraph/source_map/node_processor/gvasgn_node.rb +2 -0
  167. data/lib/solargraph/source_map/node_processor/ivasgn_node.rb +3 -1
  168. data/lib/solargraph/source_map/node_processor/lvasgn_node.rb +2 -0
  169. data/lib/solargraph/source_map/node_processor/namespace_node.rb +4 -1
  170. data/lib/solargraph/source_map/node_processor/orasgn_node.rb +2 -0
  171. data/lib/solargraph/source_map/node_processor/resbody_node.rb +2 -0
  172. data/lib/solargraph/source_map/node_processor/sclass_node.rb +2 -0
  173. data/lib/solargraph/source_map/node_processor/send_node.rb +11 -6
  174. data/lib/solargraph/source_map/node_processor/sym_node.rb +2 -0
  175. data/lib/solargraph/source_map/region.rb +2 -0
  176. data/lib/solargraph/type_checker.rb +35 -17
  177. data/lib/solargraph/type_checker/param_def.rb +2 -0
  178. data/lib/solargraph/type_checker/problem.rb +2 -0
  179. data/lib/solargraph/version.rb +3 -1
  180. data/lib/solargraph/views/document.erb +3 -3
  181. data/lib/solargraph/views/environment.erb +3 -0
  182. data/lib/solargraph/workspace.rb +5 -1
  183. data/lib/solargraph/workspace/config.rb +14 -0
  184. data/lib/solargraph/yard_map.rb +64 -5
  185. data/lib/solargraph/yard_map/cache.rb +2 -0
  186. data/lib/solargraph/yard_map/core_docs.rb +2 -0
  187. data/lib/solargraph/yard_map/core_gen.rb +2 -0
  188. data/lib/solargraph/yard_map/mapper.rb +15 -14
  189. data/lib/solargraph/yard_map/rdoc_to_yard.rb +129 -0
  190. data/lib/yard-solargraph.rb +8 -0
  191. 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,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Solargraph
2
4
  class Source
3
5
  module EncodingFixes
@@ -1,13 +1,15 @@
1
- module Solargraph
2
- class Source
3
- # A custom builder for source parsers that ignores character encoding
4
- # issues in literal strings.
5
- #
6
- class FlawedBuilder < Parser::Builders::Default
7
- def string_value(token)
8
- value(token)
9
- end
10
- end
11
- private_constant :FlawedBuilder
12
- end
13
- end
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
  # A factory for generating chains from nodes.
@@ -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.kind_of?(AST::Node)
18
+ if node.is_a?(AST::Node)
17
19
  node.children.each { |n|
18
- if n.kind_of?(AST::Node)
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.kind_of?(AST::Node) and node.type == :const
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.kind_of?(AST::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.kind_of?(AST::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,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Solargraph
2
4
  class Source
3
5
  # Information about a location in a source, including the location's word
@@ -1,50 +1,52 @@
1
- module Solargraph
2
- class Source
3
- # Updaters contain changes to be applied to a source. The source applies
4
- # the update via the Source#synchronize method.
5
- #
6
- class Updater
7
- # @return [String]
8
- attr_reader :filename
9
-
10
- # @return [Integer]
11
- attr_reader :version
12
-
13
- # @return [Array<Change>]
14
- attr_reader :changes
15
-
16
- # @param filename [String] The file to update.
17
- # @param version [Integer] A version number associated with this update.
18
- # @param changes [Array<Solargraph::Source::Change>] The changes.
19
- def initialize filename, version, changes
20
- @filename = filename
21
- @version = version
22
- @changes = changes
23
- @input = nil
24
- @did_nullify = nil
25
- @output = nil
26
- end
27
-
28
- # @return [String]
29
- def write text, nullable = false
30
- can_nullify = (nullable and changes.length == 1)
31
- return @output if @input == text and can_nullify == @did_nullify
32
- @input = text
33
- @output = text
34
- @did_nullify = can_nullify
35
- changes.each do |ch|
36
- @output = ch.write(@output, can_nullify)
37
- end
38
- @output
39
- end
40
-
41
- # @return [String]
42
- def repair text
43
- changes.each do |ch|
44
- text = ch.repair(text)
45
- end
46
- text
47
- end
48
- end
49
- end
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.kind == Pin::REQUIRE_REFERENCE}
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
- [Pin::ATTRIBUTE, Pin::CONSTANT, Pin::METHOD, Pin::NAMESPACE].include?(pin.kind) and !pin.path.empty?
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::NAMESPACE, Pin::METHOD
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::NAMESPACE, Pin::METHOD, Pin::BLOCK
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 kinds [Array<Symbol>]
150
+ # @param klasses [Array<Class>]
143
151
  # @return [Pin::Base]
144
- def _locate_pin line, character, *kinds
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 (kinds.empty? || kinds.include?(pin.kind)) && pin.location.range.contain?(position)
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('', context_pin.context.namespace)
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.kind != Pin::METHOD || s.name.match(/^[a-z0-9_]+(\!|\?|=)?$/i))
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
  # The result of a completion request containing the pins that describe
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Solargraph
2
4
  class SourceMap
3
5
  # The Mapper generates pins and other data for SourceMaps.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Solargraph
2
4
  class SourceMap
3
5
  # The processor classes used by SourceMap::Mapper to generate pins from
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Solargraph
2
4
  class SourceMap
3
5
  module NodeProcessor
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Solargraph
2
4
  class SourceMap
3
5
  module NodeProcessor
@@ -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| [Pin::NAMESPACE, Pin::METHOD].include?(pin.kind) && pin.location.range.contain?(position)}.last
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| [Pin::BLOCK, Pin::NAMESPACE, Pin::METHOD].include?(pin.kind) && pin.location.range.contain?(position)}.last
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.kind_of?(AST::Node) and c.type == :args
85
+ if c.is_a?(AST::Node) and c.type == :args
84
86
  list = c
85
87
  break
86
88
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Solargraph
2
4
  class SourceMap
3
5
  module NodeProcessor