solargraph 0.32.1 → 0.32.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (177) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +9 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +6 -0
  5. data/.travis.yml +25 -0
  6. data/EXAMPLES.md +76 -0
  7. data/Gemfile +3 -0
  8. data/LANGUAGE_SERVER.md +51 -0
  9. data/LICENSE +21 -0
  10. data/OVERVIEW.md +37 -0
  11. data/README.md +106 -0
  12. data/Rakefile +14 -0
  13. data/SERVER.md +95 -0
  14. data/bin/solargraph +0 -0
  15. data/bin/solargraph-runtime +5 -5
  16. data/lib/solargraph.rb +54 -54
  17. data/lib/solargraph/api_map.rb +659 -659
  18. data/lib/solargraph/api_map/cache.rb +49 -49
  19. data/lib/solargraph/api_map/source_to_yard.rb +67 -67
  20. data/lib/solargraph/api_map/store.rb +201 -201
  21. data/lib/solargraph/bundle.rb +24 -24
  22. data/lib/solargraph/complex_type.rb +150 -150
  23. data/lib/solargraph/complex_type/type_methods.rb +124 -124
  24. data/lib/solargraph/complex_type/unique_type.rb +44 -44
  25. data/lib/solargraph/core_fills.rb +37 -37
  26. data/lib/solargraph/diagnostics.rb +52 -52
  27. data/lib/solargraph/diagnostics/base.rb +20 -20
  28. data/lib/solargraph/diagnostics/require_not_found.rb +28 -28
  29. data/lib/solargraph/diagnostics/rubocop.rb +98 -98
  30. data/lib/solargraph/diagnostics/rubocop_helpers.rb +46 -46
  31. data/lib/solargraph/diagnostics/type_not_defined.rb +108 -108
  32. data/lib/solargraph/diagnostics/update_errors.rb +38 -38
  33. data/lib/solargraph/language_server/completion_item_kinds.rb +33 -33
  34. data/lib/solargraph/language_server/error_codes.rb +18 -18
  35. data/lib/solargraph/language_server/host.rb +684 -681
  36. data/lib/solargraph/language_server/host/cataloger.rb +54 -79
  37. data/lib/solargraph/language_server/host/diagnoser.rb +80 -80
  38. data/lib/solargraph/language_server/host/dispatch.rb +112 -113
  39. data/lib/solargraph/language_server/host/sources.rb +138 -138
  40. data/lib/solargraph/language_server/message.rb +90 -90
  41. data/lib/solargraph/language_server/message/base.rb +83 -83
  42. data/lib/solargraph/language_server/message/completion_item/resolve.rb +40 -40
  43. data/lib/solargraph/language_server/message/exit_notification.rb +11 -11
  44. data/lib/solargraph/language_server/message/extended.rb +19 -19
  45. data/lib/solargraph/language_server/message/extended/check_gem_version.rb +86 -86
  46. data/lib/solargraph/language_server/message/extended/document.rb +18 -18
  47. data/lib/solargraph/language_server/message/extended/document_gems.rb +30 -30
  48. data/lib/solargraph/language_server/message/extended/environment.rb +20 -20
  49. data/lib/solargraph/language_server/message/extended/search.rb +18 -18
  50. data/lib/solargraph/language_server/message/initialize.rb +141 -141
  51. data/lib/solargraph/language_server/message/initialized.rb +23 -23
  52. data/lib/solargraph/language_server/message/shutdown.rb +11 -11
  53. data/lib/solargraph/language_server/message/text_document.rb +25 -25
  54. data/lib/solargraph/language_server/message/text_document/completion.rb +51 -51
  55. data/lib/solargraph/language_server/message/text_document/definition.rb +18 -18
  56. data/lib/solargraph/language_server/message/text_document/did_change.rb +13 -13
  57. data/lib/solargraph/language_server/message/text_document/document_symbol.rb +21 -21
  58. data/lib/solargraph/language_server/message/text_document/folding_range.rb +24 -24
  59. data/lib/solargraph/language_server/message/text_document/formatting.rb +50 -50
  60. data/lib/solargraph/language_server/message/text_document/hover.rb +31 -31
  61. data/lib/solargraph/language_server/message/text_document/on_type_formatting.rb +32 -32
  62. data/lib/solargraph/language_server/message/text_document/prepare_rename.rb +9 -9
  63. data/lib/solargraph/language_server/message/text_document/references.rb +14 -14
  64. data/lib/solargraph/language_server/message/text_document/rename.rb +17 -17
  65. data/lib/solargraph/language_server/message/text_document/signature_help.rb +19 -19
  66. data/lib/solargraph/language_server/message/workspace.rb +12 -12
  67. data/lib/solargraph/language_server/message/workspace/did_change_configuration.rb +29 -29
  68. data/lib/solargraph/language_server/message/workspace/did_change_watched_files.rb +29 -27
  69. data/lib/solargraph/language_server/message/workspace/did_change_workspace_folders.rb +24 -24
  70. data/lib/solargraph/language_server/message/workspace/workspace_symbol.rb +21 -21
  71. data/lib/solargraph/language_server/request.rb +22 -22
  72. data/lib/solargraph/language_server/symbol_kinds.rb +34 -34
  73. data/lib/solargraph/language_server/transport.rb +11 -11
  74. data/lib/solargraph/language_server/transport/adapter.rb +60 -60
  75. data/lib/solargraph/language_server/transport/data_reader.rb +66 -66
  76. data/lib/solargraph/language_server/uri_helpers.rb +25 -25
  77. data/lib/solargraph/library.rb +421 -419
  78. data/lib/solargraph/live_map.rb +126 -126
  79. data/lib/solargraph/live_map/cache.rb +38 -38
  80. data/lib/solargraph/location.rb +31 -31
  81. data/lib/solargraph/logging.rb +25 -25
  82. data/lib/solargraph/page.rb +68 -68
  83. data/lib/solargraph/pin.rb +50 -50
  84. data/lib/solargraph/pin/attribute.rb +41 -41
  85. data/lib/solargraph/pin/base.rb +280 -280
  86. data/lib/solargraph/pin/base_method.rb +76 -76
  87. data/lib/solargraph/pin/base_variable.rb +72 -72
  88. data/lib/solargraph/pin/block.rb +32 -32
  89. data/lib/solargraph/pin/block_parameter.rb +103 -103
  90. data/lib/solargraph/pin/class_variable.rb +9 -9
  91. data/lib/solargraph/pin/constant.rb +30 -30
  92. data/lib/solargraph/pin/conversions.rb +79 -79
  93. data/lib/solargraph/pin/documenting.rb +41 -41
  94. data/lib/solargraph/pin/duck_method.rb +14 -14
  95. data/lib/solargraph/pin/global_variable.rb +9 -9
  96. data/lib/solargraph/pin/instance_variable.rb +9 -9
  97. data/lib/solargraph/pin/keyword.rb +17 -17
  98. data/lib/solargraph/pin/local_variable.rb +23 -23
  99. data/lib/solargraph/pin/localized.rb +22 -22
  100. data/lib/solargraph/pin/method.rb +126 -126
  101. data/lib/solargraph/pin/method_alias.rb +30 -30
  102. data/lib/solargraph/pin/method_parameter.rb +40 -40
  103. data/lib/solargraph/pin/namespace.rb +54 -54
  104. data/lib/solargraph/pin/plugin/method.rb +25 -25
  105. data/lib/solargraph/pin/proxy_type.rb +35 -35
  106. data/lib/solargraph/pin/reference.rb +22 -22
  107. data/lib/solargraph/pin/reference/extend.rb +11 -11
  108. data/lib/solargraph/pin/reference/include.rb +11 -11
  109. data/lib/solargraph/pin/reference/require.rb +15 -15
  110. data/lib/solargraph/pin/reference/superclass.rb +11 -11
  111. data/lib/solargraph/pin/symbol.rb +44 -44
  112. data/lib/solargraph/pin/yard_pin.rb +10 -10
  113. data/lib/solargraph/pin/yard_pin/constant.rb +14 -14
  114. data/lib/solargraph/pin/yard_pin/method.rb +35 -35
  115. data/lib/solargraph/pin/yard_pin/namespace.rb +19 -19
  116. data/lib/solargraph/pin/yard_pin/yard_mixin.rb +14 -14
  117. data/lib/solargraph/plugin.rb +8 -8
  118. data/lib/solargraph/plugin/base.rb +41 -41
  119. data/lib/solargraph/plugin/canceler.rb +11 -11
  120. data/lib/solargraph/plugin/process.rb +172 -172
  121. data/lib/solargraph/plugin/runtime.rb +134 -134
  122. data/lib/solargraph/position.rb +110 -110
  123. data/lib/solargraph/range.rb +83 -83
  124. data/lib/solargraph/server_methods.rb +14 -14
  125. data/lib/solargraph/shell.rb +102 -102
  126. data/lib/solargraph/source.rb +521 -521
  127. data/lib/solargraph/source/chain.rb +120 -120
  128. data/lib/solargraph/source/chain/call.rb +107 -107
  129. data/lib/solargraph/source/chain/class_variable.rb +11 -11
  130. data/lib/solargraph/source/chain/constant.rb +30 -30
  131. data/lib/solargraph/source/chain/global_variable.rb +11 -11
  132. data/lib/solargraph/source/chain/head.rb +33 -33
  133. data/lib/solargraph/source/chain/instance_variable.rb +11 -11
  134. data/lib/solargraph/source/chain/link.rb +33 -33
  135. data/lib/solargraph/source/chain/literal.rb +21 -21
  136. data/lib/solargraph/source/chain/variable.rb +11 -11
  137. data/lib/solargraph/source/change.rb +77 -77
  138. data/lib/solargraph/source/cursor.rb +157 -157
  139. data/lib/solargraph/source/node_chainer.rb +96 -96
  140. data/lib/solargraph/source/node_methods.rb +225 -225
  141. data/lib/solargraph/source/source_chainer.rb +183 -183
  142. data/lib/solargraph/source_map.rb +169 -169
  143. data/lib/solargraph/source_map/clip.rb +145 -145
  144. data/lib/solargraph/source_map/completion.rb +21 -21
  145. data/lib/solargraph/source_map/mapper.rb +149 -149
  146. data/lib/solargraph/source_map/node_processor.rb +78 -78
  147. data/lib/solargraph/source_map/node_processor/alias_node.rb +19 -19
  148. data/lib/solargraph/source_map/node_processor/args_node.rb +28 -28
  149. data/lib/solargraph/source_map/node_processor/base.rb +68 -68
  150. data/lib/solargraph/source_map/node_processor/begin_node.rb +11 -11
  151. data/lib/solargraph/source_map/node_processor/block_node.rb +14 -14
  152. data/lib/solargraph/source_map/node_processor/casgn_node.rb +14 -14
  153. data/lib/solargraph/source_map/node_processor/cvasgn_node.rb +14 -14
  154. data/lib/solargraph/source_map/node_processor/def_node.rb +54 -54
  155. data/lib/solargraph/source_map/node_processor/defs_node.rb +21 -21
  156. data/lib/solargraph/source_map/node_processor/gvasgn_node.rb +12 -12
  157. data/lib/solargraph/source_map/node_processor/ivasgn_node.rb +18 -18
  158. data/lib/solargraph/source_map/node_processor/lvasgn_node.rb +16 -16
  159. data/lib/solargraph/source_map/node_processor/namespace_node.rb +26 -26
  160. data/lib/solargraph/source_map/node_processor/orasgn_node.rb +12 -12
  161. data/lib/solargraph/source_map/node_processor/sclass_node.rb +11 -11
  162. data/lib/solargraph/source_map/node_processor/send_node.rb +162 -162
  163. data/lib/solargraph/source_map/node_processor/sym_node.rb +11 -11
  164. data/lib/solargraph/source_map/region.rb +58 -58
  165. data/lib/solargraph/version.rb +3 -3
  166. data/lib/solargraph/views/environment.erb +53 -53
  167. data/lib/solargraph/workspace.rb +183 -183
  168. data/lib/solargraph/workspace/config.rb +170 -170
  169. data/lib/solargraph/yard_map.rb +298 -298
  170. data/lib/solargraph/yard_map/cache.rb +17 -17
  171. data/lib/solargraph/yard_map/core_docs.rb +163 -163
  172. data/lib/solargraph/yard_map/core_gen.rb +76 -76
  173. data/lib/yard-coregen.rb +16 -16
  174. data/lib/yard-solargraph.rb +18 -18
  175. data/solargraph.gemspec +37 -0
  176. data/travis-bundler.rb +10 -0
  177. metadata +19 -6
@@ -1,44 +1,44 @@
1
- module Solargraph
2
- class ComplexType
3
- # An individual type signature. A complex type can consist of multiple
4
- # unique types.
5
- #
6
- class UniqueType
7
- include TypeMethods
8
-
9
- # Create a UniqueType with the specified name and an optional substring.
10
- # The substring is the parameter section of a parametrized type, e.g.,
11
- # for the type `Array<String>`, the name is `Array` and the substring is
12
- # `<String>`.
13
- #
14
- # @param name [String] The name of the type
15
- # @param substring [String] The substring of the type
16
- def initialize name, substring = ''
17
- if name.start_with?('::')
18
- @name = name[2..-1]
19
- @rooted = true
20
- else
21
- @name = name
22
- @rooted = false
23
- end
24
- @substring = substring
25
- @tag = @name + substring
26
- @key_types = []
27
- @subtypes = []
28
- return unless parameters?
29
- subs = ComplexType.parse(substring[1..-2], partial: true)
30
- if hash_parameters?
31
- raise ComplexTypeError, "Bad hash type" unless !subs.is_a?(ComplexType) and subs.length == 2 and !subs[0].is_a?(ComplexType) and !subs[1].is_a?(ComplexType)
32
- @key_types.concat subs[0]
33
- @subtypes.concat subs[1]
34
- else
35
- @subtypes.concat subs
36
- end
37
- end
38
-
39
- def to_s
40
- tag
41
- end
42
- end
43
- end
44
- end
1
+ module Solargraph
2
+ class ComplexType
3
+ # An individual type signature. A complex type can consist of multiple
4
+ # unique types.
5
+ #
6
+ class UniqueType
7
+ include TypeMethods
8
+
9
+ # Create a UniqueType with the specified name and an optional substring.
10
+ # The substring is the parameter section of a parametrized type, e.g.,
11
+ # for the type `Array<String>`, the name is `Array` and the substring is
12
+ # `<String>`.
13
+ #
14
+ # @param name [String] The name of the type
15
+ # @param substring [String] The substring of the type
16
+ def initialize name, substring = ''
17
+ if name.start_with?('::')
18
+ @name = name[2..-1]
19
+ @rooted = true
20
+ else
21
+ @name = name
22
+ @rooted = false
23
+ end
24
+ @substring = substring
25
+ @tag = @name + substring
26
+ @key_types = []
27
+ @subtypes = []
28
+ return unless parameters?
29
+ subs = ComplexType.parse(substring[1..-2], partial: true)
30
+ if hash_parameters?
31
+ raise ComplexTypeError, "Bad hash type" unless !subs.is_a?(ComplexType) and subs.length == 2 and !subs[0].is_a?(ComplexType) and !subs[1].is_a?(ComplexType)
32
+ @key_types.concat subs[0]
33
+ @subtypes.concat subs[1]
34
+ else
35
+ @subtypes.concat subs
36
+ end
37
+ end
38
+
39
+ def to_s
40
+ tag
41
+ end
42
+ end
43
+ end
44
+ end
@@ -1,37 +1,37 @@
1
- module Solargraph
2
- module CoreFills
3
- KEYWORDS = [
4
- '__ENCODING__', '__LINE__', '__FILE__', 'BEGIN', 'END', 'alias', 'and',
5
- 'begin', 'break', 'case', 'class', 'def', 'defined?', 'do', 'else',
6
- 'elsif', 'end', 'ensure', 'false', 'for', 'if', 'in', 'module', 'next',
7
- 'nil', 'not', 'or', 'redo', 'rescue', 'retry', 'return', 'self', 'super',
8
- 'then', 'true', 'undef', 'unless', 'until', 'when', 'while', 'yield'
9
- ].freeze
10
-
11
- METHODS_RETURNING_SELF = %w[
12
- Array#select Array#reject Array#keep_if Array#delete_if
13
- Enumerable#select
14
- Object#clone Object#dup Object#freeze Object#taint Object#untaint Object#tap
15
- String#freeze
16
- ].freeze
17
-
18
- METHODS_RETURNING_SUBTYPES = %w[
19
- Array#[] Array#first Array#last
20
- ].freeze
21
-
22
- METHODS_WITH_YIELDPARAM_SELF = %w[
23
- Object#tap
24
- ].freeze
25
-
26
- METHODS_WITH_YIELDPARAM_SUBTYPES = %w[
27
- Array#each Array#map Array#any? Array#all? Array#index
28
- Enumerable#each_entry Enumerable#map Enumerable#any? Enumerable#all?
29
- Set#each
30
- ].freeze
31
-
32
- CUSTOM_RETURN_TYPES = {
33
- 'String#split' => 'Array<String>',
34
- 'String#lines' => 'Array<String>'
35
- }.freeze
36
- end
37
- end
1
+ module Solargraph
2
+ module CoreFills
3
+ KEYWORDS = [
4
+ '__ENCODING__', '__LINE__', '__FILE__', 'BEGIN', 'END', 'alias', 'and',
5
+ 'begin', 'break', 'case', 'class', 'def', 'defined?', 'do', 'else',
6
+ 'elsif', 'end', 'ensure', 'false', 'for', 'if', 'in', 'module', 'next',
7
+ 'nil', 'not', 'or', 'redo', 'rescue', 'retry', 'return', 'self', 'super',
8
+ 'then', 'true', 'undef', 'unless', 'until', 'when', 'while', 'yield'
9
+ ].freeze
10
+
11
+ METHODS_RETURNING_SELF = %w[
12
+ Array#select Array#reject Array#keep_if Array#delete_if
13
+ Enumerable#select
14
+ Object#clone Object#dup Object#freeze Object#taint Object#untaint Object#tap
15
+ String#freeze
16
+ ].freeze
17
+
18
+ METHODS_RETURNING_SUBTYPES = %w[
19
+ Array#[] Array#first Array#last
20
+ ].freeze
21
+
22
+ METHODS_WITH_YIELDPARAM_SELF = %w[
23
+ Object#tap
24
+ ].freeze
25
+
26
+ METHODS_WITH_YIELDPARAM_SUBTYPES = %w[
27
+ Array#each Array#map Array#any? Array#all? Array#index
28
+ Enumerable#each_entry Enumerable#map Enumerable#any? Enumerable#all?
29
+ Set#each
30
+ ].freeze
31
+
32
+ CUSTOM_RETURN_TYPES = {
33
+ 'String#split' => 'Array<String>',
34
+ 'String#lines' => 'Array<String>'
35
+ }.freeze
36
+ end
37
+ end
@@ -1,52 +1,52 @@
1
- module Solargraph
2
- # The Diagnostics library provides reporters for analyzing problems in code
3
- # and providing the results to language server clients.
4
- #
5
- module Diagnostics
6
- autoload :Base, 'solargraph/diagnostics/base'
7
- autoload :Severities, 'solargraph/diagnostics/severities'
8
- autoload :Rubocop, 'solargraph/diagnostics/rubocop'
9
- autoload :RubocopHelpers, 'solargraph/diagnostics/rubocop_helpers'
10
- autoload :RequireNotFound, 'solargraph/diagnostics/require_not_found'
11
- autoload :TypeNotDefined, 'solargraph/diagnostics/type_not_defined'
12
- autoload :UpdateErrors, 'solargraph/diagnostics/update_errors'
13
-
14
- class << self
15
- # Add a reporter with a name to identify it in .solargraph.yml files.
16
- #
17
- # @param name [String] The name
18
- # @param klass [Class<Solargraph::Diagnostics::Base>] The class implementation
19
- # @return [void]
20
- def register name, klass
21
- reporter_hash[name] = klass
22
- end
23
-
24
- # Get an array of reporter names.
25
- #
26
- # @return [Array<String>]
27
- def reporters
28
- reporter_hash.keys
29
- end
30
-
31
- # Find a reporter by name.
32
- #
33
- # @param name [String] The name with which the reporter was registered
34
- # @return [Class<Solargraph::Diagnostics::Base>]
35
- def reporter name
36
- reporter_hash[name]
37
- end
38
-
39
- private
40
-
41
- # @return [Hash]
42
- def reporter_hash
43
- @reporter_hash ||= {}
44
- end
45
- end
46
-
47
- register 'rubocop', Rubocop
48
- register 'require_not_found', RequireNotFound
49
- register 'type_not_defined', TypeNotDefined
50
- register 'update_errors', UpdateErrors
51
- end
52
- end
1
+ module Solargraph
2
+ # The Diagnostics library provides reporters for analyzing problems in code
3
+ # and providing the results to language server clients.
4
+ #
5
+ module Diagnostics
6
+ autoload :Base, 'solargraph/diagnostics/base'
7
+ autoload :Severities, 'solargraph/diagnostics/severities'
8
+ autoload :Rubocop, 'solargraph/diagnostics/rubocop'
9
+ autoload :RubocopHelpers, 'solargraph/diagnostics/rubocop_helpers'
10
+ autoload :RequireNotFound, 'solargraph/diagnostics/require_not_found'
11
+ autoload :TypeNotDefined, 'solargraph/diagnostics/type_not_defined'
12
+ autoload :UpdateErrors, 'solargraph/diagnostics/update_errors'
13
+
14
+ class << self
15
+ # Add a reporter with a name to identify it in .solargraph.yml files.
16
+ #
17
+ # @param name [String] The name
18
+ # @param klass [Class<Solargraph::Diagnostics::Base>] The class implementation
19
+ # @return [void]
20
+ def register name, klass
21
+ reporter_hash[name] = klass
22
+ end
23
+
24
+ # Get an array of reporter names.
25
+ #
26
+ # @return [Array<String>]
27
+ def reporters
28
+ reporter_hash.keys
29
+ end
30
+
31
+ # Find a reporter by name.
32
+ #
33
+ # @param name [String] The name with which the reporter was registered
34
+ # @return [Class<Solargraph::Diagnostics::Base>]
35
+ def reporter name
36
+ reporter_hash[name]
37
+ end
38
+
39
+ private
40
+
41
+ # @return [Hash]
42
+ def reporter_hash
43
+ @reporter_hash ||= {}
44
+ end
45
+ end
46
+
47
+ register 'rubocop', Rubocop
48
+ register 'require_not_found', RequireNotFound
49
+ register 'type_not_defined', TypeNotDefined
50
+ register 'update_errors', UpdateErrors
51
+ end
52
+ end
@@ -1,20 +1,20 @@
1
- module Solargraph
2
- module Diagnostics
3
- # The base class for diagnostics reporters.
4
- #
5
- class Base
6
- # Perform a diagnosis on a Source within the context of an ApiMap.
7
- # The result is an array of hash objects that conform to the LSP's
8
- # Diagnostic specification.
9
- #
10
- # Subclasses should override this method.
11
- #
12
- # @param source [Solargraph::Source]
13
- # @param api_map [Solargraph::ApiMap]
14
- # @return [Array<Hash>]
15
- def diagnose source, api_map
16
- []
17
- end
18
- end
19
- end
20
- end
1
+ module Solargraph
2
+ module Diagnostics
3
+ # The base class for diagnostics reporters.
4
+ #
5
+ class Base
6
+ # Perform a diagnosis on a Source within the context of an ApiMap.
7
+ # The result is an array of hash objects that conform to the LSP's
8
+ # Diagnostic specification.
9
+ #
10
+ # Subclasses should override this method.
11
+ #
12
+ # @param source [Solargraph::Source]
13
+ # @param api_map [Solargraph::ApiMap]
14
+ # @return [Array<Hash>]
15
+ def diagnose source, api_map
16
+ []
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,28 +1,28 @@
1
- module Solargraph
2
- module Diagnostics
3
- # RequireNotFound reports required paths that could not be resolved to
4
- # either a file in the workspace or a gem.
5
- #
6
- class RequireNotFound < Base
7
- def diagnose source, api_map
8
- return [] unless source.parsed? && source.synchronized?
9
- result = []
10
- refs = {}
11
- map = api_map.source_map(source.filename)
12
- map.requires.each do |ref|
13
- refs[ref.name] = ref
14
- end
15
- api_map.unresolved_requires.each do |r|
16
- next unless refs.has_key?(r)
17
- result.push(
18
- range: refs[r].location.range.to_hash,
19
- severity: Diagnostics::Severities::WARNING,
20
- source: 'Solargraph',
21
- message: "Required path #{r} could not be resolved."
22
- )
23
- end
24
- result
25
- end
26
- end
27
- end
28
- end
1
+ module Solargraph
2
+ module Diagnostics
3
+ # RequireNotFound reports required paths that could not be resolved to
4
+ # either a file in the workspace or a gem.
5
+ #
6
+ class RequireNotFound < Base
7
+ def diagnose source, api_map
8
+ return [] unless source.parsed? && source.synchronized?
9
+ result = []
10
+ refs = {}
11
+ map = api_map.source_map(source.filename)
12
+ map.requires.each do |ref|
13
+ refs[ref.name] = ref
14
+ end
15
+ api_map.unresolved_requires.each do |r|
16
+ next unless refs.has_key?(r)
17
+ result.push(
18
+ range: refs[r].location.range.to_hash,
19
+ severity: Diagnostics::Severities::WARNING,
20
+ source: 'Solargraph',
21
+ message: "Required path #{r} could not be resolved."
22
+ )
23
+ end
24
+ result
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,98 +1,98 @@
1
- require 'rubocop'
2
- require 'stringio'
3
-
4
- module Solargraph
5
- module Diagnostics
6
- # This reporter provides linting through RuboCop.
7
- #
8
- class Rubocop < Base
9
- include RubocopHelpers
10
-
11
- # Conversion of RuboCop severity names to LSP constants
12
- SEVERITIES = {
13
- 'refactor' => Severities::HINT,
14
- 'convention' => Severities::INFORMATION,
15
- 'warning' => Severities::WARNING,
16
- 'error' => Severities::ERROR,
17
- 'fatal' => Severities::ERROR
18
- }
19
-
20
- # @param source [Solargraph::Source]
21
- # @param _api_map [Solargraph::ApiMap]
22
- # @return [Array<Hash>]
23
- def diagnose source, _api_map
24
- options, paths = generate_options(source.filename, source.code)
25
- runner = RuboCop::Runner.new(options, RuboCop::ConfigStore.new)
26
- result = redirect_stdout{ runner.run(paths) }
27
- make_array JSON.parse(result)
28
- rescue RuboCop::ValidationError, RuboCop::ConfigNotFoundError => e
29
- raise DiagnosticsError, "Error in RuboCop configuration: #{e.message}"
30
- rescue JSON::ParserError
31
- raise DiagnosticsError, 'RuboCop returned invalid data'
32
- end
33
-
34
- private
35
-
36
- # @todo This is a smelly way to redirect output, but the RuboCop specs do
37
- # the same thing.
38
- # @return [String]
39
- def redirect_stdout
40
- redir = StringIO.new
41
- $stdout = redir
42
- yield if block_given?
43
- $stdout = STDOUT
44
- redir.string
45
- end
46
-
47
- # @param resp [Hash]
48
- # @return [Array<Hash>]
49
- def make_array resp
50
- diagnostics = []
51
- resp['files'].each do |file|
52
- file['offenses'].each do |off|
53
- diagnostics.push offense_to_diagnostic(off)
54
- end
55
- end
56
- diagnostics
57
- end
58
-
59
- # Convert a RuboCop offense to an LSP diagnostic
60
- #
61
- # @param off [Hash] Offense received from Rubocop
62
- # @return [Hash] LSP diagnostic
63
- def offense_to_diagnostic off
64
- {
65
- range: offense_range(off).to_hash,
66
- # 1 = Error, 2 = Warning, 3 = Information, 4 = Hint
67
- severity: SEVERITIES[off['severity']],
68
- source: off['cop_name'],
69
- message: off['message'].gsub(/^#{off['cop_name']}\:/, '')
70
- }
71
- end
72
-
73
- # @param off [Hash]
74
- # @return [Range]
75
- def offense_range off
76
- Range.new(offense_start_position(off), offense_ending_position(off))
77
- end
78
-
79
- # @param off [Hash]
80
- # @return [Position]
81
- def offense_start_position off
82
- Position.new(off['location']['start_line'] - 1, off['location']['start_column'] - 1)
83
- end
84
-
85
- # @param off [Hash]
86
- # @return [Position]
87
- def offense_ending_position off
88
- if off['location']['start_line'] != off['location']['last_line']
89
- Position.new(off['location']['start_line'], 0)
90
- else
91
- Position.new(
92
- off['location']['start_line'] - 1, off['location']['last_column']
93
- )
94
- end
95
- end
96
- end
97
- end
98
- end
1
+ require 'rubocop'
2
+ require 'stringio'
3
+
4
+ module Solargraph
5
+ module Diagnostics
6
+ # This reporter provides linting through RuboCop.
7
+ #
8
+ class Rubocop < Base
9
+ include RubocopHelpers
10
+
11
+ # Conversion of RuboCop severity names to LSP constants
12
+ SEVERITIES = {
13
+ 'refactor' => Severities::HINT,
14
+ 'convention' => Severities::INFORMATION,
15
+ 'warning' => Severities::WARNING,
16
+ 'error' => Severities::ERROR,
17
+ 'fatal' => Severities::ERROR
18
+ }
19
+
20
+ # @param source [Solargraph::Source]
21
+ # @param _api_map [Solargraph::ApiMap]
22
+ # @return [Array<Hash>]
23
+ def diagnose source, _api_map
24
+ options, paths = generate_options(source.filename, source.code)
25
+ runner = RuboCop::Runner.new(options, RuboCop::ConfigStore.new)
26
+ result = redirect_stdout{ runner.run(paths) }
27
+ make_array JSON.parse(result)
28
+ rescue RuboCop::ValidationError, RuboCop::ConfigNotFoundError => e
29
+ raise DiagnosticsError, "Error in RuboCop configuration: #{e.message}"
30
+ rescue JSON::ParserError
31
+ raise DiagnosticsError, 'RuboCop returned invalid data'
32
+ end
33
+
34
+ private
35
+
36
+ # @todo This is a smelly way to redirect output, but the RuboCop specs do
37
+ # the same thing.
38
+ # @return [String]
39
+ def redirect_stdout
40
+ redir = StringIO.new
41
+ $stdout = redir
42
+ yield if block_given?
43
+ $stdout = STDOUT
44
+ redir.string
45
+ end
46
+
47
+ # @param resp [Hash]
48
+ # @return [Array<Hash>]
49
+ def make_array resp
50
+ diagnostics = []
51
+ resp['files'].each do |file|
52
+ file['offenses'].each do |off|
53
+ diagnostics.push offense_to_diagnostic(off)
54
+ end
55
+ end
56
+ diagnostics
57
+ end
58
+
59
+ # Convert a RuboCop offense to an LSP diagnostic
60
+ #
61
+ # @param off [Hash] Offense received from Rubocop
62
+ # @return [Hash] LSP diagnostic
63
+ def offense_to_diagnostic off
64
+ {
65
+ range: offense_range(off).to_hash,
66
+ # 1 = Error, 2 = Warning, 3 = Information, 4 = Hint
67
+ severity: SEVERITIES[off['severity']],
68
+ source: off['cop_name'],
69
+ message: off['message'].gsub(/^#{off['cop_name']}\:/, '')
70
+ }
71
+ end
72
+
73
+ # @param off [Hash]
74
+ # @return [Range]
75
+ def offense_range off
76
+ Range.new(offense_start_position(off), offense_ending_position(off))
77
+ end
78
+
79
+ # @param off [Hash]
80
+ # @return [Position]
81
+ def offense_start_position off
82
+ Position.new(off['location']['start_line'] - 1, off['location']['start_column'] - 1)
83
+ end
84
+
85
+ # @param off [Hash]
86
+ # @return [Position]
87
+ def offense_ending_position off
88
+ if off['location']['start_line'] != off['location']['last_line']
89
+ Position.new(off['location']['start_line'], 0)
90
+ else
91
+ Position.new(
92
+ off['location']['start_line'] - 1, off['location']['last_column']
93
+ )
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end