ruby-lsp-rake 0.1.3 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6bdcde0bdc4ebc43f2cf72c1644ff98491d779e076beaaa7aa2fbf164dc3d979
4
- data.tar.gz: ff5f37d8872ada12e8ffd0cbdc9eef136059d4018551135eda1fe50930d01372
3
+ metadata.gz: 5cdf5ce3b286b6f1824bcff07f386aff744fee063debf045a33f0a104ccb9a58
4
+ data.tar.gz: 0f61d107e42ac8412f3f4ac53425c6d8dc0e4c90e11bcab050ee8a1aaa80719c
5
5
  SHA512:
6
- metadata.gz: 8ca6d230be2bac1c0aba848922adc32307a546d7023f710a103bcd9c040c14ed6fa1062c7a75e2cea8c3ea6285c86b2f19c1c23d8247d2915087322d5eeda833
7
- data.tar.gz: 85f04c0bc96f657718961cad0f449751d8d96e13c28a6ae9978df499406f9e8c55e9d45811c1737cf7012fc5855e0201bffcf4fc15cd09aeff67c670180d961c
6
+ metadata.gz: 44d24d9356c0893323402638a91d564562c66728233445901c32c0502aa6fbfa95ff5ed1cf6b6f94d80031e4f180a2b2b578e96080dd68f9c9c53f14e5b02358
7
+ data.tar.gz: 98bb06c07335e47d6064101ed3761299215b3f25a5c090006931a257a74e3eb1ba4f5fbf7ad7f916779cafaf49b786fc266756abe14666de1a4140c16a9397f2
data/Rakefile CHANGED
@@ -17,3 +17,25 @@ namespace :srb do
17
17
  sh "bundle exec srb tc"
18
18
  end
19
19
  end
20
+
21
+ task aaa: %i[bbb ccc:ddd eee:fff]
22
+
23
+ task :bbb do
24
+ puts :bbb
25
+ end
26
+
27
+ namespace :ccc do
28
+ task ddd: :eee do
29
+ puts "ccc:ddd"
30
+ end
31
+
32
+ task :eee do
33
+ puts "ccc:eee"
34
+ end
35
+ end
36
+
37
+ namespace :eee do
38
+ task :fff do
39
+ puts "eee:fff"
40
+ end
41
+ end
Binary file
@@ -4,7 +4,7 @@
4
4
  module Ruby
5
5
  module Lsp
6
6
  module Rake
7
- VERSION = "0.1.3"
7
+ VERSION = "0.1.5"
8
8
  end
9
9
  end
10
10
  end
@@ -8,21 +8,34 @@ require_relative "hover"
8
8
  module RubyLsp
9
9
  module Rake
10
10
  class Addon < ::RubyLsp::Addon # rubocop:disable Style/Documentation
11
- def activate(global_state, _message_queue)
11
+ extend T::Sig
12
+
13
+ sig { override.params(global_state: GlobalState, outgoing_queue: Thread::Queue).void }
14
+ def activate(global_state, outgoing_queue) # rubocop:disable Lint/UnusedMethodArgument
12
15
  @index = global_state.index
13
- @index.configuration.apply_config({ "included_patterns" => ["**/Rakefile"] })
16
+ @index.configuration.apply_config({ "included_patterns" => ["**/Rakefile", "lib/../Rakefile"] })
14
17
  end
15
18
 
19
+ sig { override.void }
16
20
  def deactivate; end
17
21
 
22
+ sig { override.returns(String) }
18
23
  def name
19
24
  "A Ruby LSP addon that adds extra editor functionality for Rake"
20
25
  end
21
26
 
27
+ sig { override.returns(String) }
22
28
  def version
23
29
  ::Ruby::Lsp::Rake::VERSION
24
30
  end
25
31
 
32
+ sig do
33
+ override.params(
34
+ response_builder: ResponseBuilders::Hover,
35
+ node_context: NodeContext,
36
+ dispatcher: Prism::Dispatcher
37
+ ).void
38
+ end
26
39
  def create_hover_listener(response_builder, node_context, dispatcher)
27
40
  Hover.new(response_builder, node_context, dispatcher, @index)
28
41
  end
@@ -4,8 +4,17 @@
4
4
  module RubyLsp
5
5
  module Rake
6
6
  class Hover # rubocop:disable Style/Documentation
7
+ extend T::Sig
7
8
  include Requests::Support::Common
8
9
 
10
+ sig do
11
+ override.params(
12
+ response_builder: ResponseBuilders::Hover,
13
+ node_context: NodeContext,
14
+ dispatcher: Prism::Dispatcher,
15
+ index: RubyIndexer::Index
16
+ ).void
17
+ end
9
18
  def initialize(response_builder, node_context, dispatcher, index)
10
19
  @response_builder = response_builder
11
20
  @node_context = node_context
@@ -13,14 +22,17 @@ module RubyLsp
13
22
  @index = index
14
23
  end
15
24
 
25
+ sig { params(node: Prism::StringNode).void }
16
26
  def on_string_node_enter(node)
17
27
  handle_prerequisite(node)
18
28
  end
19
29
 
30
+ sig { params(node: Prism::SymbolNode).void }
20
31
  def on_symbol_node_enter(node)
21
32
  handle_prerequisite(node)
22
33
  end
23
34
 
35
+ sig { params(node: T.any(Prism::StringNode, Prism::SymbolNode)).void }
24
36
  def handle_prerequisite(node) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
25
37
  call_node_name = @node_context.call_node&.name
26
38
  return unless call_node_name == :task
@@ -32,13 +44,40 @@ module RubyLsp
32
44
  node.value
33
45
  end
34
46
 
35
- task_name = "task_#{name}"
47
+ arg = @node_context.call_node&.arguments&.arguments&.first
48
+ case arg
49
+ when Prism::KeywordHashNode
50
+ kh = arg.child_nodes.first
51
+ case kh
52
+ when Prism::AssocNode
53
+ v = kh.value
54
+ case v
55
+ when Prism::StringNode
56
+ return unless name == v.content
57
+ when Prism::SymbolNode
58
+ return unless name == v.value
59
+ when Prism::ArrayNode
60
+ return unless v.elements.find do |node|
61
+ name == case node
62
+ when Prism::StringNode
63
+ node.content
64
+ when Prism::SymbolNode
65
+ node.value
66
+ end
67
+ end
68
+ end
69
+ end
70
+ else
71
+ return
72
+ end
73
+
74
+ task_name = "task:#{name}"
36
75
  return unless @index.indexed? task_name
37
76
 
38
77
  # refer to: https://github.com/Shopify/ruby-lsp/blob/896617a0c5f7a22ebe12912a481bf1b59db14c12/lib/ruby_lsp/requests/support/common.rb#L83
39
78
  content = +""
40
79
  entries = @index[task_name]
41
- links = entries.map do |entry|
80
+ links = entries&.map do |entry|
42
81
  loc = entry.location
43
82
  uri = T.unsafe(URI::Generic).from_path(
44
83
  path: entry.file_path,
@@ -48,7 +87,7 @@ module RubyLsp
48
87
  "[#{entry.file_name}](#{uri})"
49
88
  end
50
89
  @response_builder.push("```\nrake #{name}\n```", category: :title)
51
- @response_builder.push("Definitions: #{links.join(" | ")}", category: :links)
90
+ @response_builder.push("Definitions: #{links&.join(" | ")}", category: :links)
52
91
  @response_builder.push(content, category: :documentation)
53
92
  end
54
93
  end
@@ -4,13 +4,21 @@
4
4
  module RubyLsp
5
5
  module Rake
6
6
  class IndexingEnhancement < RubyIndexer::Enhancement # rubocop:disable Style/Documentation
7
- @last_desc = nil
7
+ extend T::Sig
8
8
 
9
+ sig { params(listener: RubyIndexer::DeclarationListener).void }
10
+ def initialize(listener)
11
+ super(listener)
12
+ @namespace_stack = []
13
+ @last_desc = nil
14
+ end
15
+
16
+ sig { override.params(node: Prism::CallNode).void }
9
17
  def on_call_node_enter(node) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
10
18
  @last_desc = nil unless node.name == :task
11
19
 
12
20
  return unless @listener.current_owner.nil?
13
- return unless node.name == :task || node.name == :desc
21
+ return unless node.name == :task || node.name == :desc || node.name == :namespace
14
22
 
15
23
  arguments = node.arguments&.arguments
16
24
  return unless arguments
@@ -37,23 +45,36 @@ module RubyLsp
37
45
 
38
46
  return if name.nil?
39
47
 
48
+ if node.name == :namespace
49
+ @namespace_stack << name
50
+ return
51
+ end
52
+
40
53
  if node.name == :desc
41
54
  @last_desc = name
42
55
  return
43
56
  end
44
57
 
45
- location = node.location
46
- @listener.add_method(
47
- "task_#{name}",
48
- location,
49
- [],
50
- comments: @last_desc
51
- )
58
+ ary = [*@namespace_stack, name]
59
+ (1..(ary.size)).each do |i|
60
+ @listener.add_method(
61
+ "task:#{ary[-i..].join(":")}",
62
+ node.location,
63
+ [],
64
+ comments: @last_desc
65
+ )
66
+ end
52
67
 
53
68
  @last_desc = nil
54
69
  end
55
70
 
56
- def on_call_node_leave(node); end
71
+ sig { override.params(node: Prism::CallNode).void }
72
+ def on_call_node_leave(node)
73
+ return unless @listener.current_owner.nil?
74
+ return unless node.name == :namespace
75
+
76
+ @namespace_stack.pop
77
+ end
57
78
  end
58
79
  end
59
80
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-lsp-rake
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Koji NAKAMURA
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-12-12 00:00:00.000000000 Z
11
+ date: 2024-12-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-lsp