rucoa 0.11.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +6 -3
  3. data/Gemfile.lock +3 -3
  4. data/README.md +4 -1
  5. data/lib/rucoa/configuration.rb +22 -12
  6. data/lib/rucoa/definition_store.rb +131 -131
  7. data/lib/rucoa/definitions/method_definition.rb +11 -11
  8. data/lib/rucoa/handler_concerns/configuration_requestable.rb +7 -7
  9. data/lib/rucoa/handler_concerns/diagnostics_publishable.rb +11 -11
  10. data/lib/rucoa/handler_concerns/text_document_position_parameters.rb +29 -0
  11. data/lib/rucoa/handler_concerns/text_document_uri_parameters.rb +21 -0
  12. data/lib/rucoa/handler_concerns.rb +2 -0
  13. data/lib/rucoa/handlers/base.rb +9 -9
  14. data/lib/rucoa/handlers/initialize_handler.rb +1 -0
  15. data/lib/rucoa/handlers/initialized_handler.rb +16 -16
  16. data/lib/rucoa/handlers/text_document_code_action_handler.rb +12 -12
  17. data/lib/rucoa/handlers/text_document_completion_handler.rb +85 -99
  18. data/lib/rucoa/handlers/text_document_definition_handler.rb +11 -30
  19. data/lib/rucoa/handlers/text_document_did_close_handler.rb +2 -8
  20. data/lib/rucoa/handlers/text_document_did_open_handler.rb +3 -7
  21. data/lib/rucoa/handlers/text_document_document_highlight_handler.rb +256 -0
  22. data/lib/rucoa/handlers/text_document_document_symbol_handler.rb +47 -76
  23. data/lib/rucoa/handlers/text_document_formatting_handler.rb +15 -23
  24. data/lib/rucoa/handlers/text_document_hover_handler.rb +24 -43
  25. data/lib/rucoa/handlers/text_document_range_formatting_handler.rb +17 -25
  26. data/lib/rucoa/handlers/text_document_selection_range_handler.rb +11 -19
  27. data/lib/rucoa/handlers/text_document_signature_help_handler.rb +17 -36
  28. data/lib/rucoa/handlers.rb +1 -0
  29. data/lib/rucoa/node_concerns/body.rb +1 -1
  30. data/lib/rucoa/node_concerns/qualified_name.rb +5 -5
  31. data/lib/rucoa/node_concerns/rescue.rb +21 -0
  32. data/lib/rucoa/node_concerns.rb +1 -0
  33. data/lib/rucoa/node_inspector.rb +5 -5
  34. data/lib/rucoa/nodes/base.rb +48 -48
  35. data/lib/rucoa/nodes/begin_node.rb +2 -0
  36. data/lib/rucoa/nodes/block_node.rb +24 -0
  37. data/lib/rucoa/nodes/case_node.rb +24 -0
  38. data/lib/rucoa/nodes/const_node.rb +26 -26
  39. data/lib/rucoa/nodes/def_node.rb +14 -13
  40. data/lib/rucoa/nodes/ensure_node.rb +19 -0
  41. data/lib/rucoa/nodes/for_node.rb +8 -0
  42. data/lib/rucoa/nodes/if_node.rb +32 -0
  43. data/lib/rucoa/nodes/resbody_node.rb +8 -0
  44. data/lib/rucoa/nodes/rescue_node.rb +17 -0
  45. data/lib/rucoa/nodes/send_node.rb +40 -0
  46. data/lib/rucoa/nodes/until_node.rb +8 -0
  47. data/lib/rucoa/nodes/when_node.rb +8 -0
  48. data/lib/rucoa/nodes/while_node.rb +8 -0
  49. data/lib/rucoa/nodes.rb +10 -1
  50. data/lib/rucoa/parser_builder.rb +16 -2
  51. data/lib/rucoa/range.rb +9 -3
  52. data/lib/rucoa/rbs/constant_definition_mapper.rb +5 -5
  53. data/lib/rucoa/rbs/method_definition_mapper.rb +18 -18
  54. data/lib/rucoa/rbs/module_definition_mapper.rb +13 -13
  55. data/lib/rucoa/rbs/ruby_definitions_loader.rb +5 -5
  56. data/lib/rucoa/rubocop/configuration_checker.rb +7 -7
  57. data/lib/rucoa/server.rb +24 -23
  58. data/lib/rucoa/source.rb +5 -5
  59. data/lib/rucoa/source_store.rb +8 -8
  60. data/lib/rucoa/version.rb +1 -1
  61. data/lib/rucoa/yard/definition_generators/method_definition_generator.rb +1 -1
  62. metadata +16 -3
  63. data/lib/rucoa/nodes/defs_node.rb +0 -33
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cec8d0284ecf97b03cd43de02d36c16263910dba3c5a1052f73df0bf0fd51f68
4
- data.tar.gz: b83c8aad102fbd510a0f7474394ab8cf91cd17976bbc365e188c276789815e9a
3
+ metadata.gz: a5097a136a7c60eb420569df3c2c115de4716e4e33c2db0ed14e402aca3b7a09
4
+ data.tar.gz: '0609d97e8b5167b1c0f1217a517c995f6c0ef13a6aef52f483e5c3cbe850e0c8'
5
5
  SHA512:
6
- metadata.gz: 3042168fc7a78f71854f96d8367f9f4e1e0c62d4300b4feef36b6596e602b3c40c5150d1d6f0902ab5d7b1015179cdf10c2d1e6beabe68cbf3fa1114f6cdb00e
7
- data.tar.gz: 6721bdccd41cb883d6b6ab97a5a990b878e088a7832ccb6c42bcc642ff13f1ab3126d8893a43b47a29295caa0ff14ed4b59bdf5ab0ca95c14a4536dee11eb899
6
+ metadata.gz: c793f79584557be25e5584343d56d8ab94d195ddd0eadf32f96e0426e3db3749d0f4a502e9d682d7ed17f5926754bdfba9ea4620e60b323224d5d6a2b5802d12
7
+ data.tar.gz: 42c2e6927d684f63a541c22b2c3d56404acf126d48d665d4573b7def31c3e11a2ff92ce230441e9d2cfd5ee508174a0bcb1b965ab22d1a38156efeed1c6c1995
data/.rubocop.yml CHANGED
@@ -35,13 +35,16 @@ Security/MarshalLoad:
35
35
  Sevencop/AutoloadOrdered:
36
36
  Enabled: true
37
37
 
38
- Sevencop/HashLiteralOrder:
38
+ Sevencop/HashElementOrdered:
39
39
  Enabled: true
40
40
 
41
- Sevencop/MethodDefinitionKeywordArgumentsOrdered:
41
+ Sevencop/MethodDefinitionOrdered:
42
42
  Enabled: true
43
43
 
44
- Sevencop/MethodDefinitionMultilineArguments:
44
+ Sevencop/MethodDefinitionArgumentsMultiline:
45
+ Enabled: true
46
+
47
+ Sevencop/MethodDefinitionKeywordArgumentOrdered:
45
48
  Enabled: true
46
49
 
47
50
  Style/Documentation:
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rucoa (0.11.0)
4
+ rucoa (0.12.0)
5
5
  parser
6
6
  rbs
7
7
  rubocop
@@ -19,7 +19,7 @@ GEM
19
19
  rainbow (3.1.1)
20
20
  rake (13.0.6)
21
21
  rbs (2.6.0)
22
- regexp_parser (2.5.0)
22
+ regexp_parser (2.6.0)
23
23
  rexml (3.2.5)
24
24
  rspec (3.11.0)
25
25
  rspec-core (~> 3.11.0)
@@ -54,7 +54,7 @@ GEM
54
54
  rubocop-rspec (2.13.2)
55
55
  rubocop (~> 1.33)
56
56
  ruby-progressbar (1.11.0)
57
- sevencop (0.13.0)
57
+ sevencop (0.15.0)
58
58
  rubocop
59
59
  unicode-display_width (2.3.0)
60
60
  webrick (1.7.0)
data/README.md CHANGED
@@ -66,6 +66,10 @@ Provides completion items for constant names and method names.
66
66
 
67
67
  Provides "Go to Definition" command to jump to the definition.
68
68
 
69
+ ### Highlight
70
+
71
+ Highlights corresponding keywords.
72
+
69
73
  ### Hover
70
74
 
71
75
  Shows documentation for the symbol under the cursor.
@@ -76,5 +80,4 @@ Shows method signature help when you start to type method arguments like `"100".
76
80
 
77
81
  ## Coming soon
78
82
 
79
- - Highlight
80
83
  - Semantic Tokens
@@ -36,6 +36,11 @@ module Rucoa
36
36
  disable_feature('formatting')
37
37
  end
38
38
 
39
+ # @return [void]
40
+ def disable_highlight
41
+ disable_feature('highlight')
42
+ end
43
+
39
44
  # @return [void]
40
45
  def disable_hover
41
46
  disable_feature('hover')
@@ -58,18 +63,6 @@ module Rucoa
58
63
  @settings['base']['debug'] = true
59
64
  end
60
65
 
61
- # @return [Boolean]
62
- # @example returns false if the configuration is empty
63
- # configuration = Rucoa::Configuration.new
64
- # expect(configuration).not_to be_enables_debug
65
- # @example returns true if the configuration enables debug
66
- # configuration = Rucoa::Configuration.new
67
- # configuration.update('base' => { 'debug' => true })
68
- # expect(configuration).to be_enables_debug
69
- def enables_debug?
70
- fetch('base', 'debug', default: false)
71
- end
72
-
73
66
  # @return [Boolean]
74
67
  # @example returns true if the configuration is empty
75
68
  # configuration = Rucoa::Configuration.new
@@ -87,6 +80,18 @@ module Rucoa
87
80
  enables_feature?('completion')
88
81
  end
89
82
 
83
+ # @return [Boolean]
84
+ # @example returns false if the configuration is empty
85
+ # configuration = Rucoa::Configuration.new
86
+ # expect(configuration).not_to be_enables_debug
87
+ # @example returns true if the configuration enables debug
88
+ # configuration = Rucoa::Configuration.new
89
+ # configuration.update('base' => { 'debug' => true })
90
+ # expect(configuration).to be_enables_debug
91
+ def enables_debug?
92
+ fetch('base', 'debug', default: false)
93
+ end
94
+
90
95
  # @return [Boolean]
91
96
  def enables_definition?
92
97
  enables_feature?('definition')
@@ -107,6 +112,11 @@ module Rucoa
107
112
  enables_feature?('formatting')
108
113
  end
109
114
 
115
+ # @return [Boolean]
116
+ def enables_highlight?
117
+ enables_feature?('highlight')
118
+ end
119
+
110
120
  # @return [Boolean]
111
121
  def enables_hover?
112
122
  enables_feature?('hover')
@@ -7,11 +7,6 @@ module Rucoa
7
7
  @qualified_names_by_uri = ::Hash.new { |hash, key| hash[key] = [] }
8
8
  end
9
9
 
10
- # @return [String]
11
- def inspect
12
- "#<#{self.class} definitions_count=#{@definition_by_qualified_name.count}>"
13
- end
14
-
15
10
  # @param definitions [Array<Rucoa::Definition::Base>]
16
11
  # @return [void]
17
12
  def bulk_add(definitions)
@@ -23,61 +18,12 @@ module Rucoa
23
18
  end
24
19
  end
25
20
 
26
- # @param source [Rucoa::Source]
27
- # @return [void]
28
- # @example resolves super class name from definitions
29
- # definition_store = Rucoa::DefinitionStore.new
30
- # foo = Rucoa::Source.new(
31
- # content: <<~RUBY,
32
- # module A
33
- # class Foo
34
- # end
35
- # end
36
- # RUBY
37
- # uri: 'file:///path/to/a/foo.rb',
38
- # )
39
- # definition_store.update_from(foo)
40
- # bar = Rucoa::Source.new(
41
- # content: <<~RUBY,
42
- # module A
43
- # class Bar < Foo
44
- # end
45
- # end
46
- # RUBY
47
- # uri: 'file:///path/to/a/bar.rb',
48
- # )
49
- # definition_store.update_from(bar)
50
- # definition = definition_store.find_definition_by_qualified_name('A::Bar')
51
- # expect(definition.super_class_qualified_name).to eq('A::Foo')
52
- # @example resolves included module names from definitions
53
- # definition_store = Rucoa::DefinitionStore.new
54
- # foo = Rucoa::Source.new(
55
- # content: <<~RUBY,
56
- # module A
57
- # module Foo
58
- # end
59
- # end
60
- # RUBY
61
- # uri: 'file:///path/to/a/foo.rb',
62
- # )
63
- # definition_store.update_from(foo)
64
- # bar = Rucoa::Source.new(
65
- # content: <<~RUBY,
66
- # module A
67
- # class Bar
68
- # include Foo
69
- # end
70
- # end
71
- # RUBY
72
- # uri: 'file:///path/to/a/bar.rb',
73
- # )
74
- # definition_store.update_from(bar)
75
- # definition = definition_store.find_definition_by_qualified_name('A::Bar')
76
- # expect(definition.included_module_qualified_names).to eq(%w[A::Foo])
77
- def update_from(source)
78
- delete_definitions_in(source)
79
- add_definitions_in(source)
80
- resolve_constants_in(source)
21
+ # @param namespace [String]
22
+ # @return [Array<Rucoa::Definitions::ConstantDefinition>] e.g. File::Separator, File::SEPARATOR, etc.
23
+ def constant_definitions_under(namespace)
24
+ constant_definitions.select do |constant_definition|
25
+ constant_definition.namespace == namespace
26
+ end
81
27
  end
82
28
 
83
29
  # @param qualified_name [String]
@@ -178,6 +124,11 @@ module Rucoa
178
124
  end
179
125
  end
180
126
 
127
+ # @return [String]
128
+ def inspect
129
+ "#<#{self.class} definitions_count=#{@definition_by_qualified_name.count}>"
130
+ end
131
+
181
132
  # @param type [String]
182
133
  # @return [Array<Rucoa::Definitions::MethodDefinition>]
183
134
  # @example supports simple instance method
@@ -266,6 +217,19 @@ module Rucoa
266
217
  end.uniq(&:method_name)
267
218
  end
268
219
 
220
+ # @todo Search ancestors.
221
+ # @param unqualified_name [Rucoa::UnqualifiedName]
222
+ # @return [String]
223
+ def resolve_constant(unqualified_name)
224
+ (
225
+ unqualified_name.module_nesting.map do |prefix|
226
+ "#{prefix}::#{unqualified_name.chained_name}"
227
+ end + [unqualified_name.chained_name]
228
+ ).find do |candidate|
229
+ find_definition_by_qualified_name(candidate)
230
+ end || unqualified_name.chained_name
231
+ end
232
+
269
233
  # @param type [String]
270
234
  # @return [Array<Rucoa::Definitions::MethodDefinition>]
271
235
  # @example supports simple singleton method
@@ -340,42 +304,76 @@ module Rucoa
340
304
  end.uniq(&:method_name)
341
305
  end
342
306
 
343
- # @param namespace [String]
344
- # @return [Array<Rucoa::Definitions::ConstantDefinition>] e.g. File::Separator, File::SEPARATOR, etc.
345
- def constant_definitions_under(namespace)
346
- constant_definitions.select do |constant_definition|
347
- constant_definition.namespace == namespace
348
- end
349
- end
350
-
351
- # @todo Search ancestors.
352
- # @param unqualified_name [Rucoa::UnqualifiedName]
353
- # @return [String]
354
- def resolve_constant(unqualified_name)
355
- (
356
- unqualified_name.module_nesting.map do |prefix|
357
- "#{prefix}::#{unqualified_name.chained_name}"
358
- end + [unqualified_name.chained_name]
359
- ).find do |candidate|
360
- find_definition_by_qualified_name(candidate)
361
- end || unqualified_name.chained_name
307
+ # @param source [Rucoa::Source]
308
+ # @return [void]
309
+ # @example resolves super class name from definitions
310
+ # definition_store = Rucoa::DefinitionStore.new
311
+ # foo = Rucoa::Source.new(
312
+ # content: <<~RUBY,
313
+ # module A
314
+ # class Foo
315
+ # end
316
+ # end
317
+ # RUBY
318
+ # uri: 'file:///path/to/a/foo.rb',
319
+ # )
320
+ # definition_store.update_from(foo)
321
+ # bar = Rucoa::Source.new(
322
+ # content: <<~RUBY,
323
+ # module A
324
+ # class Bar < Foo
325
+ # end
326
+ # end
327
+ # RUBY
328
+ # uri: 'file:///path/to/a/bar.rb',
329
+ # )
330
+ # definition_store.update_from(bar)
331
+ # definition = definition_store.find_definition_by_qualified_name('A::Bar')
332
+ # expect(definition.super_class_qualified_name).to eq('A::Foo')
333
+ # @example resolves included module names from definitions
334
+ # definition_store = Rucoa::DefinitionStore.new
335
+ # foo = Rucoa::Source.new(
336
+ # content: <<~RUBY,
337
+ # module A
338
+ # module Foo
339
+ # end
340
+ # end
341
+ # RUBY
342
+ # uri: 'file:///path/to/a/foo.rb',
343
+ # )
344
+ # definition_store.update_from(foo)
345
+ # bar = Rucoa::Source.new(
346
+ # content: <<~RUBY,
347
+ # module A
348
+ # class Bar
349
+ # include Foo
350
+ # end
351
+ # end
352
+ # RUBY
353
+ # uri: 'file:///path/to/a/bar.rb',
354
+ # )
355
+ # definition_store.update_from(bar)
356
+ # definition = definition_store.find_definition_by_qualified_name('A::Bar')
357
+ # expect(definition.included_module_qualified_names).to eq(%w[A::Foo])
358
+ def update_from(source)
359
+ delete_definitions_in(source)
360
+ add_definitions_in(source)
361
+ resolve_constants_in(source)
362
362
  end
363
363
 
364
364
  private
365
365
 
366
366
  # @param source [Rucoa::Source]
367
367
  # @return [void]
368
- def delete_definitions_in(source)
369
- @qualified_names_by_uri[source.uri].each do |qualified_name|
370
- @definition_by_qualified_name.delete(qualified_name)
368
+ def add_definitions_in(source)
369
+ source.definitions.group_by do |definition|
370
+ definition.location.uri
371
+ end.each do |uri, definitions|
372
+ @qualified_names_by_uri[uri] += definitions.map(&:qualified_name)
373
+ definitions.each do |definition|
374
+ @definition_by_qualified_name[definition.qualified_name] = definition
375
+ end
371
376
  end
372
- @qualified_names_by_uri.delete(source.uri)
373
- end
374
-
375
- # @param type [String]
376
- # @return [String, nil]
377
- def singleton_class_name_from(type)
378
- type[/singleton<([\w:]+)>/, 1]
379
377
  end
380
378
 
381
379
  # @param definition [Rucoa::Definitions::Class, Rucoa::Definitions::Module]
@@ -390,32 +388,9 @@ module Rucoa
390
388
  end
391
389
  end
392
390
 
393
- # @param definition [Rucoa::Definitions::Class, Rucoa::Definitions::Module]
394
- # @return [Array<Rucoa::Definitions::Class, Rucoa::Definitions::Module>] An array of prepended, itself, and included definitions
395
- def module_ancestors_of(definition)
396
- [
397
- *definition.prepended_module_qualified_names.filter_map do |qualified_name|
398
- find_definition_by_qualified_name(qualified_name)
399
- end.reverse,
400
- definition,
401
- *definition.included_module_qualified_names.filter_map do |qualified_name|
402
- find_definition_by_qualified_name(qualified_name)
403
- end.reverse
404
- ]
405
- end
406
-
407
- # @param definition [Rucoa::Definitions::Class]
408
- # @return [Array<Rucoa::Definitions::Class>] super "class"es (not including modules) in closest-first order
409
- def super_class_definitions_of(definition)
410
- result = []
411
- while (super_class_qualified_name = definition.super_class_qualified_name)
412
- super_definition = find_definition_by_qualified_name(super_class_qualified_name)
413
- break unless super_definition
414
-
415
- result << super_definition
416
- definition = super_definition
417
- end
418
- result
391
+ # @return [Array<Rucoa::Definition::ConstantDefinition>]
392
+ def constant_definitions
393
+ definitions.grep(Definitions::ConstantDefinition)
419
394
  end
420
395
 
421
396
  # @return [Array<Rucoa::Definitions::Base>]
@@ -423,27 +398,32 @@ module Rucoa
423
398
  @definition_by_qualified_name.values
424
399
  end
425
400
 
401
+ # @param source [Rucoa::Source]
402
+ # @return [void]
403
+ def delete_definitions_in(source)
404
+ @qualified_names_by_uri[source.uri].each do |qualified_name|
405
+ @definition_by_qualified_name.delete(qualified_name)
406
+ end
407
+ @qualified_names_by_uri.delete(source.uri)
408
+ end
409
+
426
410
  # @return [Array<Rucoa::Definition::MethodDefinition>]
427
411
  def method_definitions
428
412
  definitions.grep(Definitions::MethodDefinition)
429
413
  end
430
414
 
431
- # @return [Array<Rucoa::Definition::ConstantDefinition>]
432
- def constant_definitions
433
- definitions.grep(Definitions::ConstantDefinition)
434
- end
435
-
436
- # @param source [Rucoa::Source]
437
- # @return [void]
438
- def add_definitions_in(source)
439
- source.definitions.group_by do |definition|
440
- definition.location.uri
441
- end.each do |uri, definitions|
442
- @qualified_names_by_uri[uri] += definitions.map(&:qualified_name)
443
- definitions.each do |definition|
444
- @definition_by_qualified_name[definition.qualified_name] = definition
445
- end
446
- end
415
+ # @param definition [Rucoa::Definitions::Class, Rucoa::Definitions::Module]
416
+ # @return [Array<Rucoa::Definitions::Class, Rucoa::Definitions::Module>] An array of prepended, itself, and included definitions
417
+ def module_ancestors_of(definition)
418
+ [
419
+ *definition.prepended_module_qualified_names.filter_map do |qualified_name|
420
+ find_definition_by_qualified_name(qualified_name)
421
+ end.reverse,
422
+ definition,
423
+ *definition.included_module_qualified_names.filter_map do |qualified_name|
424
+ find_definition_by_qualified_name(qualified_name)
425
+ end.reverse
426
+ ]
447
427
  end
448
428
 
449
429
  # @param source [Rucoa::Source]
@@ -471,5 +451,25 @@ module Rucoa
471
451
  definition.prepended_module_unqualified_names = []
472
452
  end
473
453
  end
454
+
455
+ # @param type [String]
456
+ # @return [String, nil]
457
+ def singleton_class_name_from(type)
458
+ type[/singleton<([\w:]+)>/, 1]
459
+ end
460
+
461
+ # @param definition [Rucoa::Definitions::Class]
462
+ # @return [Array<Rucoa::Definitions::Class>] super "class"es (not including modules) in closest-first order
463
+ def super_class_definitions_of(definition)
464
+ result = []
465
+ while (super_class_qualified_name = definition.super_class_qualified_name)
466
+ super_definition = find_definition_by_qualified_name(super_class_qualified_name)
467
+ break unless super_definition
468
+
469
+ result << super_definition
470
+ definition = super_definition
471
+ end
472
+ result
473
+ end
474
474
  end
475
475
  end
@@ -30,6 +30,17 @@ module Rucoa
30
30
  @types = types
31
31
  end
32
32
 
33
+ # @return [Boolean]
34
+ def instance_method?
35
+ @kind == :instance
36
+ end
37
+
38
+ # @todo
39
+ # @return [Array<Rucoa::Definitions::MethodParameter>]
40
+ def parameters
41
+ []
42
+ end
43
+
33
44
  # @return [String]
34
45
  # @example returns qualified name of method
35
46
  # definition = Rucoa::Source.new(
@@ -52,12 +63,6 @@ module Rucoa
52
63
  ].join
53
64
  end
54
65
 
55
- # @todo
56
- # @return [Array<Rucoa::Definitions::MethodParameter>]
57
- def parameters
58
- []
59
- end
60
-
61
66
  # @return [Array<String>]
62
67
  # @example returns return types
63
68
  # definition = Rucoa::Source.new(
@@ -105,11 +110,6 @@ module Rucoa
105
110
  end
106
111
  end
107
112
 
108
- # @return [Boolean]
109
- def instance_method?
110
- @kind == :instance
111
- end
112
-
113
113
  # @return [Boolean]
114
114
  def singleton_method?
115
115
  !instance_method?
@@ -7,6 +7,13 @@ module Rucoa
7
7
 
8
8
  private
9
9
 
10
+ # @return [void]
11
+ def publish_diagnostics_on_each_source
12
+ source_store.each_uri do |uri|
13
+ publish_diagnostics_on(uri)
14
+ end
15
+ end
16
+
10
17
  # @return [void]
11
18
  def request_workspace_configuration
12
19
  write(
@@ -23,13 +30,6 @@ module Rucoa
23
30
  publish_diagnostics_on_each_source
24
31
  end
25
32
  end
26
-
27
- # @return [void]
28
- def publish_diagnostics_on_each_source
29
- source_store.each_uri do |uri|
30
- publish_diagnostics_on(uri)
31
- end
32
- end
33
33
  end
34
34
  end
35
35
  end
@@ -5,17 +5,6 @@ module Rucoa
5
5
  module DiagnosticsPublishable
6
6
  private
7
7
 
8
- # @param uri [String]
9
- # @return [Array<Hash>]
10
- def diagnostics_on(uri)
11
- return [] unless configuration.enables_diagnostics?
12
-
13
- DiagnosticProvider.call(
14
- source: source_store.get(uri),
15
- uri: uri
16
- )
17
- end
18
-
19
8
  # @param uri [String]
20
9
  # @return [void]
21
10
  def clear_diagnostics_on(uri)
@@ -28,6 +17,17 @@ module Rucoa
28
17
  )
29
18
  end
30
19
 
20
+ # @param uri [String]
21
+ # @return [Array<Hash>]
22
+ def diagnostics_on(uri)
23
+ return [] unless configuration.enables_diagnostics?
24
+
25
+ DiagnosticProvider.call(
26
+ source: source_store.get(uri),
27
+ uri: uri
28
+ )
29
+ end
30
+
31
31
  # @param uri [String]
32
32
  # @return [void]
33
33
  def publish_diagnostics_on(uri)
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rucoa
4
+ module HandlerConcerns
5
+ module TextDocumentPositionParameters
6
+ private
7
+
8
+ # @return [Rucoa::Nodes::Base, nil]
9
+ def node
10
+ return unless position
11
+ return unless source
12
+
13
+ @node ||= source.node_at(position)
14
+ end
15
+
16
+ # @return [String, nil]
17
+ def parameter_position
18
+ @parameter_position ||= request.dig('params', 'position')
19
+ end
20
+
21
+ # @return [Rucoa::Position, nil]
22
+ def position
23
+ return unless parameter_position
24
+
25
+ @position ||= Position.from_vscode_position(parameter_position)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rucoa
4
+ module HandlerConcerns
5
+ module TextDocumentUriParameters
6
+ private
7
+
8
+ # @return [String, nil]
9
+ def parameter_uri
10
+ @parameter_uri ||= request.dig('params', 'textDocument', 'uri')
11
+ end
12
+
13
+ # @return [Rucoa::Source, nil]
14
+ def source
15
+ return unless parameter_uri
16
+
17
+ @source ||= source_store.get(parameter_uri)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -4,5 +4,7 @@ module Rucoa
4
4
  module HandlerConcerns
5
5
  autoload :ConfigurationRequestable, 'rucoa/handler_concerns/configuration_requestable'
6
6
  autoload :DiagnosticsPublishable, 'rucoa/handler_concerns/diagnostics_publishable'
7
+ autoload :TextDocumentPositionParameters, 'rucoa/handler_concerns/text_document_position_parameters'
8
+ autoload :TextDocumentUriParameters, 'rucoa/handler_concerns/text_document_uri_parameters'
7
9
  end
8
10
  end
@@ -41,15 +41,6 @@ module Rucoa
41
41
  # @return [Rucoa::Server]
42
42
  attr_reader :server
43
43
 
44
- # @param message [Hash]
45
- # @return [void]
46
- def respond(message)
47
- write(
48
- id: request['id'],
49
- result: message
50
- )
51
- end
52
-
53
44
  # @return [Rucoa::Configuration]
54
45
  def configuration
55
46
  @server.configuration
@@ -60,6 +51,15 @@ module Rucoa
60
51
  @server.definition_store
61
52
  end
62
53
 
54
+ # @param message [Hash]
55
+ # @return [void]
56
+ def respond(message)
57
+ write(
58
+ id: request['id'],
59
+ result: message
60
+ )
61
+ end
62
+
63
63
  # @return [Rucoa::SourceStore]
64
64
  def source_store
65
65
  @server.source_store
@@ -15,6 +15,7 @@ module Rucoa
15
15
  },
16
16
  definitionProvider: true,
17
17
  documentFormattingProvider: true,
18
+ documentHighlightProvider: true,
18
19
  documentRangeFormattingProvider: true,
19
20
  documentSymbolProvider: true,
20
21
  hoverProvider: true,