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,126 +1,126 @@
1
- module Solargraph
2
- # The LiveMap allows extensions to add their own completion suggestions.
3
- #
4
- class LiveMap
5
- autoload :Cache, 'solargraph/live_map/cache'
6
-
7
- @@plugin_registry = {}
8
-
9
- # @return [Solargraph::ApiMap]
10
- attr_reader :api_map
11
-
12
- # @param api_map [Solargraph::ApiMap]
13
- def initialize api_map
14
- @api_map = api_map
15
- runners
16
- end
17
-
18
- def get_path_pin path
19
- cache.get_path_pin(path)
20
- end
21
-
22
- # @return [Array<Solargraph::Pin::Base>]
23
- def get_methods(namespace, root = '', scope = 'instance', with_private = false)
24
- fqns = api_map.qualify(namespace, root)
25
- params = {
26
- namespace: namespace, root: root, scope: scope, with_private: with_private
27
- }
28
- cached = cache.get_methods(params)
29
- return cached unless cached.nil?
30
- did_runtime = false
31
- result = []
32
- runners.each do |p|
33
- next if did_runtime and p.runtime?
34
- p.get_methods(namespace: namespace, root: root, scope: scope, with_private: with_private).each do |m|
35
- result.push Solargraph::Pin::Method.new(nil, namespace, m['name'], YARD::Docstring.new('(defined at runtime)'), scope.to_sym, nil, [])
36
- end
37
- did_runtime = true if p.runtime?
38
- end
39
- cache.set_methods(params, result)
40
- result
41
- end
42
-
43
- # @return [Array<Solargraph::Pin::Base>]
44
- def get_constants(namespace, root = '')
45
- cached = cache.get_constants(namespace, root)
46
- return cached unless cached.nil?
47
- did_runtime = false
48
- result = []
49
- runners.each do |p|
50
- next if did_runtime and p.runtime?
51
- result.concat p.get_constants(namespace, root)
52
- did_runtime = true if p.runtime?
53
- end
54
- suggestions = []
55
- result.uniq.each do |r|
56
- path = (r['namespace'].empty? ? '' : "#{r['namespace']}::") + r['name']
57
- kind = Pin::CONSTANT
58
- if r['class'] == 'Class'
59
- suggestions.push Pin::Namespace.new(nil, r['namespace'], r['name'], YARD::Docstring.new("(defined at runtime)"), :class, :public, nil)
60
- elsif r['class'] == 'Module'
61
- suggestions.push Pin::Namespace.new(nil, r['namespace'], r['name'], YARD::Docstring.new("(defined at runtime)"), :module, :public, nil)
62
- else
63
- suggestions.push Pin::Constant.new(nil, r['namespace'], r['name'], YARD::Docstring.new("(defined at runtime"), nil, nil, nil, :public)
64
- end
65
- end
66
- cache.set_constants(namespace, root, suggestions)
67
- suggestions
68
- end
69
-
70
- def get_fqns(namespace, root)
71
- did_runtime = false
72
- runners.each do |p|
73
- next if did_runtime and p.runtime?
74
- result = p.get_fqns(namespace, root)
75
- return result unless result.nil?
76
- did_runtime = true if p.runtime?
77
- end
78
- nil
79
- end
80
-
81
- def self.register name, klass
82
- raise ArgumentError.new("A Solargraph plugin named #{name} already exists") if @@plugin_registry.has_key?(name)
83
- @@plugin_registry[name] = klass
84
- end
85
-
86
- def refresh
87
- changed = false
88
- runners.each do |p|
89
- changed ||= p.refresh
90
- end
91
- if changed
92
- Solargraph::Logging.logger.debug "Resetting LiveMap cache"
93
- cache.clear
94
- get_constants('')
95
- get_methods('', '', 'class')
96
- get_methods('', '', 'instance')
97
- get_methods('Kernel', '', 'class')
98
- get_methods('Kernel', '', 'instance')
99
- end
100
- end
101
-
102
- private
103
-
104
- # @return [Solargraph::LiveMap::Cache]
105
- def cache
106
- @cache ||= Solargraph::LiveMap::Cache.new
107
- end
108
-
109
- # @return [Array<Solargraph::Plugin::Base>]
110
- def runners
111
- @runners ||= load_runners
112
- end
113
-
114
- # @return [Array<Solargraph::Plugin::Base>]
115
- def load_runners
116
- result = []
117
- api_map.workspace.config.plugins.each do |name|
118
- r = @@plugin_registry[name].new(api_map)
119
- result.push r
120
- end
121
- result
122
- end
123
- end
124
- end
125
-
126
- Solargraph::LiveMap.register 'runtime', Solargraph::Plugin::Runtime
1
+ module Solargraph
2
+ # The LiveMap allows extensions to add their own completion suggestions.
3
+ #
4
+ class LiveMap
5
+ autoload :Cache, 'solargraph/live_map/cache'
6
+
7
+ @@plugin_registry = {}
8
+
9
+ # @return [Solargraph::ApiMap]
10
+ attr_reader :api_map
11
+
12
+ # @param api_map [Solargraph::ApiMap]
13
+ def initialize api_map
14
+ @api_map = api_map
15
+ runners
16
+ end
17
+
18
+ def get_path_pin path
19
+ cache.get_path_pin(path)
20
+ end
21
+
22
+ # @return [Array<Solargraph::Pin::Base>]
23
+ def get_methods(namespace, root = '', scope = 'instance', with_private = false)
24
+ fqns = api_map.qualify(namespace, root)
25
+ params = {
26
+ namespace: namespace, root: root, scope: scope, with_private: with_private
27
+ }
28
+ cached = cache.get_methods(params)
29
+ return cached unless cached.nil?
30
+ did_runtime = false
31
+ result = []
32
+ runners.each do |p|
33
+ next if did_runtime and p.runtime?
34
+ p.get_methods(namespace: namespace, root: root, scope: scope, with_private: with_private).each do |m|
35
+ result.push Solargraph::Pin::Method.new(nil, namespace, m['name'], YARD::Docstring.new('(defined at runtime)'), scope.to_sym, nil, [])
36
+ end
37
+ did_runtime = true if p.runtime?
38
+ end
39
+ cache.set_methods(params, result)
40
+ result
41
+ end
42
+
43
+ # @return [Array<Solargraph::Pin::Base>]
44
+ def get_constants(namespace, root = '')
45
+ cached = cache.get_constants(namespace, root)
46
+ return cached unless cached.nil?
47
+ did_runtime = false
48
+ result = []
49
+ runners.each do |p|
50
+ next if did_runtime and p.runtime?
51
+ result.concat p.get_constants(namespace, root)
52
+ did_runtime = true if p.runtime?
53
+ end
54
+ suggestions = []
55
+ result.uniq.each do |r|
56
+ path = (r['namespace'].empty? ? '' : "#{r['namespace']}::") + r['name']
57
+ kind = Pin::CONSTANT
58
+ if r['class'] == 'Class'
59
+ suggestions.push Pin::Namespace.new(nil, r['namespace'], r['name'], YARD::Docstring.new("(defined at runtime)"), :class, :public, nil)
60
+ elsif r['class'] == 'Module'
61
+ suggestions.push Pin::Namespace.new(nil, r['namespace'], r['name'], YARD::Docstring.new("(defined at runtime)"), :module, :public, nil)
62
+ else
63
+ suggestions.push Pin::Constant.new(nil, r['namespace'], r['name'], YARD::Docstring.new("(defined at runtime"), nil, nil, nil, :public)
64
+ end
65
+ end
66
+ cache.set_constants(namespace, root, suggestions)
67
+ suggestions
68
+ end
69
+
70
+ def get_fqns(namespace, root)
71
+ did_runtime = false
72
+ runners.each do |p|
73
+ next if did_runtime and p.runtime?
74
+ result = p.get_fqns(namespace, root)
75
+ return result unless result.nil?
76
+ did_runtime = true if p.runtime?
77
+ end
78
+ nil
79
+ end
80
+
81
+ def self.register name, klass
82
+ raise ArgumentError.new("A Solargraph plugin named #{name} already exists") if @@plugin_registry.has_key?(name)
83
+ @@plugin_registry[name] = klass
84
+ end
85
+
86
+ def refresh
87
+ changed = false
88
+ runners.each do |p|
89
+ changed ||= p.refresh
90
+ end
91
+ if changed
92
+ Solargraph::Logging.logger.debug "Resetting LiveMap cache"
93
+ cache.clear
94
+ get_constants('')
95
+ get_methods('', '', 'class')
96
+ get_methods('', '', 'instance')
97
+ get_methods('Kernel', '', 'class')
98
+ get_methods('Kernel', '', 'instance')
99
+ end
100
+ end
101
+
102
+ private
103
+
104
+ # @return [Solargraph::LiveMap::Cache]
105
+ def cache
106
+ @cache ||= Solargraph::LiveMap::Cache.new
107
+ end
108
+
109
+ # @return [Array<Solargraph::Plugin::Base>]
110
+ def runners
111
+ @runners ||= load_runners
112
+ end
113
+
114
+ # @return [Array<Solargraph::Plugin::Base>]
115
+ def load_runners
116
+ result = []
117
+ api_map.workspace.config.plugins.each do |name|
118
+ r = @@plugin_registry[name].new(api_map)
119
+ result.push r
120
+ end
121
+ result
122
+ end
123
+ end
124
+ end
125
+
126
+ Solargraph::LiveMap.register 'runtime', Solargraph::Plugin::Runtime
@@ -1,38 +1,38 @@
1
- module Solargraph
2
- class LiveMap
3
- class Cache
4
- def initialize
5
- @method_cache = {}
6
- @constant_cache = {}
7
- @path_cache = {}
8
- end
9
-
10
- def get_methods options
11
- @method_cache[options]
12
- end
13
-
14
- def set_methods options, values
15
- @method_cache[options] = values
16
- values.each { |pin| @path_cache[pin.path] = pin }
17
- end
18
-
19
- def get_constants namespace, root
20
- @constant_cache[[namespace, root]]
21
- end
22
-
23
- def set_constants namespace, root, values
24
- @constant_cache[[namespace, root]] = values
25
- end
26
-
27
- def get_path_pin path
28
- @path_cache[path]
29
- end
30
-
31
- def clear
32
- @method_cache.clear
33
- @constant_cache.clear
34
- @path_cache.clear
35
- end
36
- end
37
- end
38
- end
1
+ module Solargraph
2
+ class LiveMap
3
+ class Cache
4
+ def initialize
5
+ @method_cache = {}
6
+ @constant_cache = {}
7
+ @path_cache = {}
8
+ end
9
+
10
+ def get_methods options
11
+ @method_cache[options]
12
+ end
13
+
14
+ def set_methods options, values
15
+ @method_cache[options] = values
16
+ values.each { |pin| @path_cache[pin.path] = pin }
17
+ end
18
+
19
+ def get_constants namespace, root
20
+ @constant_cache[[namespace, root]]
21
+ end
22
+
23
+ def set_constants namespace, root, values
24
+ @constant_cache[[namespace, root]] = values
25
+ end
26
+
27
+ def get_path_pin path
28
+ @path_cache[path]
29
+ end
30
+
31
+ def clear
32
+ @method_cache.clear
33
+ @constant_cache.clear
34
+ @path_cache.clear
35
+ end
36
+ end
37
+ end
38
+ end
@@ -1,31 +1,31 @@
1
- module Solargraph
2
- # A section of text identified by its filename and range.
3
- #
4
- class Location
5
- # @return [String]
6
- attr_reader :filename
7
-
8
- # @return [Solargraph::Range]
9
- attr_reader :range
10
-
11
- # @param filename [String]
12
- # @param range [Solargraph::Range]
13
- def initialize filename, range
14
- @filename = filename
15
- @range = range
16
- end
17
-
18
- # @return [Hash]
19
- def to_hash
20
- {
21
- filename: filename,
22
- range: range.to_hash
23
- }
24
- end
25
-
26
- def == other
27
- return false unless other.is_a?(Location)
28
- filename == other.filename and range == other.range
29
- end
30
- end
31
- end
1
+ module Solargraph
2
+ # A section of text identified by its filename and range.
3
+ #
4
+ class Location
5
+ # @return [String]
6
+ attr_reader :filename
7
+
8
+ # @return [Solargraph::Range]
9
+ attr_reader :range
10
+
11
+ # @param filename [String]
12
+ # @param range [Solargraph::Range]
13
+ def initialize filename, range
14
+ @filename = filename
15
+ @range = range
16
+ end
17
+
18
+ # @return [Hash]
19
+ def to_hash
20
+ {
21
+ filename: filename,
22
+ range: range.to_hash
23
+ }
24
+ end
25
+
26
+ def == other
27
+ return false unless other.is_a?(Location)
28
+ filename == other.filename and range == other.range
29
+ end
30
+ end
31
+ end
@@ -1,25 +1,25 @@
1
- require 'logger'
2
-
3
- module Solargraph
4
- module Logging
5
- DEFAULT_LOG_LEVEL = Logger::WARN
6
-
7
- LOG_LEVELS = {
8
- 'warn' => Logger::WARN,
9
- 'info' => Logger::INFO,
10
- 'debug' => Logger::DEBUG
11
- }
12
-
13
- @@logger = Logger.new(STDERR, level: DEFAULT_LOG_LEVEL)
14
- @@logger.formatter = proc do |severity, datetime, progname, msg|
15
- "[#{severity}] #{msg}\n"
16
- end
17
-
18
- module_function
19
-
20
- # @return [Logger]
21
- def logger
22
- @@logger
23
- end
24
- end
25
- end
1
+ require 'logger'
2
+
3
+ module Solargraph
4
+ module Logging
5
+ DEFAULT_LOG_LEVEL = Logger::WARN
6
+
7
+ LOG_LEVELS = {
8
+ 'warn' => Logger::WARN,
9
+ 'info' => Logger::INFO,
10
+ 'debug' => Logger::DEBUG
11
+ }
12
+
13
+ @@logger = Logger.new(STDERR, level: DEFAULT_LOG_LEVEL)
14
+ @@logger.formatter = proc do |severity, datetime, progname, msg|
15
+ "[#{severity}] #{msg}\n"
16
+ end
17
+
18
+ module_function
19
+
20
+ # @return [Logger]
21
+ def logger
22
+ @@logger
23
+ end
24
+ end
25
+ end
@@ -1,68 +1,68 @@
1
- require 'ostruct'
2
- require 'tilt'
3
- require 'kramdown'
4
- require 'htmlentities'
5
- require 'cgi'
6
-
7
- module Solargraph
8
- class Page
9
- class Binder < OpenStruct
10
- def initialize locals, render_method
11
- super(locals)
12
- define_singleton_method :render do |template, layout: false, locals: {}|
13
- render_method.call(template, layout: layout, locals: locals)
14
- end
15
- define_singleton_method :erb do |template, layout: false, locals: {}|
16
- render_method.call(template, layout: layout, locals: locals)
17
- end
18
- end
19
-
20
- def htmlify text
21
- Kramdown::Document.new(
22
- text.to_s.lines.map{|l| l.gsub(/^ /, "\t")}.join,
23
- input: 'GFM',
24
- entity_output: :symbolic,
25
- syntax_highlighter_opts: {
26
- block: {
27
- line_numbers: false
28
- },
29
- default_lang: :ruby
30
- },
31
- ).to_html
32
- end
33
-
34
- def ruby_to_html code
35
- code
36
- end
37
- end
38
- private_constant :Binder
39
-
40
- def initialize directory = VIEWS_PATH
41
- directory = VIEWS_PATH if directory.nil? or !File.directory?(directory)
42
- directories = [directory]
43
- directories.push VIEWS_PATH if directory != VIEWS_PATH
44
- @render_method = proc { |template, layout: false, locals: {}|
45
- binder = Binder.new(locals, @render_method)
46
- if layout
47
- Tilt::ERBTemplate.new(Page.select_template(directories, 'layout')).render(binder) do
48
- Tilt::ERBTemplate.new(Page.select_template(directories, template)).render(binder)
49
- end
50
- else
51
- Tilt::ERBTemplate.new(Page.select_template(directories, template)).render(binder)
52
- end
53
- }
54
- end
55
-
56
- def render template, layout: true, locals: {}
57
- @render_method.call(template, layout: layout, locals: locals)
58
- end
59
-
60
- def self.select_template directories, name
61
- directories.each do |dir|
62
- path = File.join(dir, "#{name}.erb")
63
- return path if File.file?(path)
64
- end
65
- raise FileNotFoundError, "Template not found: #{name}"
66
- end
67
- end
68
- end
1
+ require 'ostruct'
2
+ require 'tilt'
3
+ require 'kramdown'
4
+ require 'htmlentities'
5
+ require 'cgi'
6
+
7
+ module Solargraph
8
+ class Page
9
+ class Binder < OpenStruct
10
+ def initialize locals, render_method
11
+ super(locals)
12
+ define_singleton_method :render do |template, layout: false, locals: {}|
13
+ render_method.call(template, layout: layout, locals: locals)
14
+ end
15
+ define_singleton_method :erb do |template, layout: false, locals: {}|
16
+ render_method.call(template, layout: layout, locals: locals)
17
+ end
18
+ end
19
+
20
+ def htmlify text
21
+ Kramdown::Document.new(
22
+ text.to_s.lines.map{|l| l.gsub(/^ /, "\t")}.join,
23
+ input: 'GFM',
24
+ entity_output: :symbolic,
25
+ syntax_highlighter_opts: {
26
+ block: {
27
+ line_numbers: false
28
+ },
29
+ default_lang: :ruby
30
+ },
31
+ ).to_html
32
+ end
33
+
34
+ def ruby_to_html code
35
+ code
36
+ end
37
+ end
38
+ private_constant :Binder
39
+
40
+ def initialize directory = VIEWS_PATH
41
+ directory = VIEWS_PATH if directory.nil? or !File.directory?(directory)
42
+ directories = [directory]
43
+ directories.push VIEWS_PATH if directory != VIEWS_PATH
44
+ @render_method = proc { |template, layout: false, locals: {}|
45
+ binder = Binder.new(locals, @render_method)
46
+ if layout
47
+ Tilt::ERBTemplate.new(Page.select_template(directories, 'layout')).render(binder) do
48
+ Tilt::ERBTemplate.new(Page.select_template(directories, template)).render(binder)
49
+ end
50
+ else
51
+ Tilt::ERBTemplate.new(Page.select_template(directories, template)).render(binder)
52
+ end
53
+ }
54
+ end
55
+
56
+ def render template, layout: true, locals: {}
57
+ @render_method.call(template, layout: layout, locals: locals)
58
+ end
59
+
60
+ def self.select_template directories, name
61
+ directories.each do |dir|
62
+ path = File.join(dir, "#{name}.erb")
63
+ return path if File.file?(path)
64
+ end
65
+ raise FileNotFoundError, "Template not found: #{name}"
66
+ end
67
+ end
68
+ end