rubydex 0.4.1 → 0.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +11 -0
  3. data/THIRD_PARTY_LICENSES.html +14 -427
  4. data/ext/rubydex/declaration.c +2 -6
  5. data/ext/rubydex/definition.c +2 -3
  6. data/ext/rubydex/extconf.rb +1 -0
  7. data/ext/rubydex/graph.c +2 -1
  8. data/ext/rubydex/query.c +3 -1
  9. data/ext/rubydex/reference.c +3 -3
  10. data/ext/rubydex/utils.c +13 -0
  11. data/ext/rubydex/utils.h +5 -0
  12. data/lib/rubydex/cli/command/dead_code.rb +59 -0
  13. data/lib/rubydex/mcp_server/tools/codebase_stats_tool.rb +1 -1
  14. data/lib/rubydex/mcp_server/tools/find_constant_references_tool.rb +4 -4
  15. data/lib/rubydex/mcp_server/tools/find_dead_code_candidates_tool.rb +33 -0
  16. data/lib/rubydex/mcp_server/tools/get_declaration_tool.rb +2 -2
  17. data/lib/rubydex/mcp_server/tools/get_descendants_tool.rb +4 -4
  18. data/lib/rubydex/mcp_server/tools/get_file_declarations_tool.rb +2 -2
  19. data/lib/rubydex/mcp_server/tools/search_declarations_tool.rb +6 -6
  20. data/lib/rubydex/mcp_server.rb +24 -12
  21. data/lib/rubydex/version.rb +1 -1
  22. data/rust/Cargo.lock +17 -11
  23. data/rust/Cargo.toml +5 -1
  24. data/rust/rubydex/Cargo.toml +3 -3
  25. data/rust/rubydex/src/compile_assertions.rs +2 -0
  26. data/rust/rubydex/src/config.rs +1 -1
  27. data/rust/rubydex/src/indexing/rbs_indexer.rs +4 -4
  28. data/rust/rubydex/src/indexing/ruby_indexer.rs +26 -18
  29. data/rust/rubydex/src/indexing/ruby_indexer_tests.rs +42 -2
  30. data/rust/rubydex/src/indexing.rs +6 -6
  31. data/rust/rubydex/src/listing.rs +12 -12
  32. data/rust/rubydex/src/model/built_in.rs +1 -1
  33. data/rust/rubydex/src/model/comment.rs +4 -4
  34. data/rust/rubydex/src/model/declaration.rs +25 -17
  35. data/rust/rubydex/src/model/document.rs +11 -11
  36. data/rust/rubydex/src/model/graph.rs +3 -3
  37. data/rust/rubydex/src/offset.rs +1 -13
  38. data/rust/rubydex/src/operation/ruby_builder.rs +29 -19
  39. data/rust/rubydex/src/query.rs +3 -2
  40. data/rust/rubydex/src/test_utils/graph_test.rs +2 -2
  41. data/rust/rubydex/src/test_utils/local_graph_test.rs +13 -6
  42. data/rust/rubydex-sys/Cargo.toml +7 -4
  43. data/rust/rubydex-sys/build.rs +1 -2
  44. data/rust/rubydex-sys/src/cypher_api.rs +8 -8
  45. data/rust/rubydex-sys/src/declaration_api.rs +11 -19
  46. data/rust/rubydex-sys/src/definition_api.rs +10 -17
  47. data/rust/rubydex-sys/src/diagnostic_api.rs +5 -7
  48. data/rust/rubydex-sys/src/graph_api.rs +96 -49
  49. data/rust/rubydex-sys/src/name_api.rs +193 -58
  50. data/rust/rubydex-sys/src/reference_api.rs +7 -10
  51. data/rust/rubydex-sys/src/utils.rs +49 -0
  52. metadata +191 -191
data/ext/rubydex/utils.c CHANGED
@@ -59,6 +59,19 @@ VALUE rdxi_owned_c_string_to_ruby(const char *string) {
59
59
  return value;
60
60
  }
61
61
 
62
+ // Convert a Rust-owned string with an explicit length to a Ruby string and release it with free_owned_string.
63
+ // Returns nil when the Rust side returned a null string.
64
+ VALUE rdxi_owned_string_to_ruby(OwnedString string) {
65
+ if (string.data == NULL) {
66
+ return Qnil;
67
+ }
68
+
69
+ VALUE value = rb_utf8_str_new(string.data, (long)string.length);
70
+ free_owned_string(string);
71
+
72
+ return value;
73
+ }
74
+
62
75
  // Coerce an optional String, Symbol, or nil to a C string, defaulting to `default_value` for nil.
63
76
  const char *rdxi_symbol_or_string_cstr(VALUE value, const char *default_value) {
64
77
  if (NIL_P(value)) {
data/ext/rubydex/utils.h CHANGED
@@ -2,6 +2,7 @@
2
2
  #define RUBYDEX_UTILS_H
3
3
 
4
4
  #include "ruby.h"
5
+ #include "rustbindings.h"
5
6
 
6
7
  // Convert a Ruby array of strings into a double char pointer so that we can pass that to Rust.
7
8
  // This copies the data so it must be freed with rdxi_free_str_array
@@ -17,6 +18,10 @@ void rdxi_check_array_of_strings(VALUE array);
17
18
  // Returns nil when the Rust side returned NULL.
18
19
  VALUE rdxi_owned_c_string_to_ruby(const char *string);
19
20
 
21
+ // Convert a Rust-owned string with an explicit length to a Ruby string and release it with free_owned_string. Unlike
22
+ // a C string, it may contain NUL bytes. Returns nil when the Rust side returned a null string.
23
+ VALUE rdxi_owned_string_to_ruby(OwnedString string);
24
+
20
25
  // Coerce an optional String, Symbol, or nil to a C string, returning `default_value` when the value
21
26
  // is nil. A non-nil value must be a String or Symbol, otherwise a `TypeError` is raised. The
22
27
  // returned pointer is owned by the Ruby VALUE and is only valid while it stays live.
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rubydex/cli/command"
4
+
5
+ module Rubydex
6
+ module CLI
7
+ # `rdx dead_code` — lists dead code candidates in the current workspace.
8
+ class Command
9
+ class DeadCode < Command
10
+ command "dead_code"
11
+ summary "List dead code candidates in the current workspace"
12
+
13
+ #: -> void
14
+ def run
15
+ parse_options!
16
+ abort_with_usage("unexpected argument: #{argv.first}") unless argv.empty?
17
+
18
+ require "rubydex/linter/helpers/path_helpers"
19
+
20
+ $stderr.puts("Looking for potentially dead code...")
21
+ graph = build_graph($stderr, workspace_path: current_workspace_path)
22
+ candidates = graph.dead_code_candidates.sort_by(&:name)
23
+
24
+ candidates.each do |candidate|
25
+ puts(candidate.name)
26
+ candidate.definitions.map(&:location).sort.each do |location|
27
+ display = location.to_display
28
+ path = Rubydex::Linter::Helpers::PathHelpers.display_path(display, workspace: graph.workspace_path)
29
+ puts(" #{path}:#{display.start_line},#{display.start_column}-#{display.end_line},#{display.end_column}")
30
+ end
31
+ puts
32
+ end
33
+
34
+ print_summary(graph.documents.count, candidates.length)
35
+ end
36
+
37
+ private
38
+
39
+ #: (Integer file_count, Integer candidate_count) -> void
40
+ def print_summary(file_count, candidate_count)
41
+ if candidate_count.zero?
42
+ puts("#{file_count} #{pluralize("file", file_count)} inspected, no dead code candidates found")
43
+ return
44
+ end
45
+
46
+ puts(
47
+ "#{file_count} #{pluralize("file", file_count)} inspected, " \
48
+ "#{candidate_count} dead code #{pluralize("candidate", candidate_count)} found",
49
+ )
50
+ end
51
+
52
+ #: (String word, Integer count) -> String
53
+ def pluralize(word, count)
54
+ count == 1 ? word : "#{word}s"
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -4,7 +4,7 @@ module Rubydex
4
4
  module MCPServer
5
5
  class CodebaseStatsTool < BaseTool
6
6
  tool_name "codebase_stats"
7
- description "Get an overview of the indexed Ruby codebase: total file count, declaration counts, and breakdown by kind (classes, modules, methods, constants). Use this to understand codebase size and composition, or to verify that indexing completed successfully."
7
+ description "Count indexed files, declarations, definitions, and references, with declarations grouped by kind."
8
8
  input_schema(properties: {})
9
9
 
10
10
  #: -> Tool::Response
@@ -4,12 +4,12 @@ module Rubydex
4
4
  module MCPServer
5
5
  class FindConstantReferencesTool < BaseTool
6
6
  tool_name "find_constant_references"
7
- description "Find all resolved references to a Ruby class, module, or constant across the codebase. Returns file paths, line numbers, and columns for each usage. Results are paginated: the response includes `total`. If `total` exceeds the number of returned results, use `offset` to fetch subsequent pages."
7
+ description "Locate resolved references to a Ruby class, module, or constant."
8
8
  input_schema(
9
9
  properties: {
10
- name: { type: "string", description: "Fully qualified name of the class, module, or constant to find references for" },
11
- limit: { type: "integer", description: "Maximum number of references to return (default 50, max 200)" },
12
- offset: { type: "integer", description: "Number of references to skip for pagination (default 0)" },
10
+ name: { type: "string", description: "Fully qualified class, module, or constant name" },
11
+ limit: { type: "integer", description: "Page size (default 50, capped at 200)" },
12
+ offset: { type: "integer", description: "Number of results to skip (default 0)" },
13
13
  },
14
14
  required: ["name"],
15
15
  )
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rubydex
4
+ module MCPServer
5
+ class FindDeadCodeCandidatesTool < BaseTool
6
+ tool_name "find_dead_code_candidates"
7
+ description "Find Ruby classes, modules, and constants with no detected references, including dependency code. Dynamic usage through DSLs or metaprogramming may not be detected."
8
+ input_schema(
9
+ properties: {
10
+ limit: { type: "integer", description: "Page size (default 50, capped at 100)" },
11
+ offset: { type: "integer", description: "Number of results to skip (default 0)" },
12
+ },
13
+ )
14
+
15
+ #: (?limit: Integer, ?offset: Integer) -> Tool::Response
16
+ def call(limit: nil, offset: nil)
17
+ declarations = @graph.dead_code_candidates.sort_by(&:name)
18
+ page, total = paginate(declarations, offset, limit, 100)
19
+ candidates = page.map do |declaration|
20
+ {
21
+ name: declaration.name,
22
+ kind: declaration_kind(declaration),
23
+ locations: declaration.definitions.sort_by(&:location).map do |definition|
24
+ display_location(definition.location)
25
+ end,
26
+ }
27
+ end
28
+
29
+ response(candidates: candidates, total: total)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -4,10 +4,10 @@ module Rubydex
4
4
  module MCPServer
5
5
  class GetDeclarationTool < BaseTool
6
6
  tool_name "get_declaration"
7
- description 'Get complete information about a Ruby class, module, method, or constant by its exact fully qualified name. Returns file locations, documentation comments, ancestor chain, and members with locations. FQN format: "Foo::Bar" for classes/modules/constants, "Foo::Bar#method_name" for instance methods, "Foo::Bar::<Bar>" for singleton classes, and "Foo::Bar::<Bar>#method_name" for class methods.'
7
+ description "Get a Ruby declaration's definition locations, documentation, ancestors, and members."
8
8
  input_schema(
9
9
  properties: {
10
- name: { type: "string", description: "Fully qualified name of the declaration (e.g. 'Foo::Bar', 'Foo::Bar#baz')" },
10
+ name: { type: "string", description: 'Exact fully qualified name: "Foo::Bar", "Foo::Bar#method_name()" (instance method), "Foo::Bar::<Bar>" (singleton class), or "Foo::Bar::<Bar>#method_name()" (class method)' },
11
11
  },
12
12
  required: ["name"],
13
13
  )
@@ -4,12 +4,12 @@ module Rubydex
4
4
  module MCPServer
5
5
  class GetDescendantsTool < BaseTool
6
6
  tool_name "get_descendants"
7
- description "Returns all known descendants for the given namespace including itself and all transitive descendants. Can be used to understand how a module/class is used across the codebase. Results are paginated: the response includes `total`. If `total` exceeds the number of returned results, use `offset` to fetch subsequent pages."
7
+ description "List a class or module and its known descendants, including transitive descendants."
8
8
  input_schema(
9
9
  properties: {
10
- name: { type: "string", description: "Fully qualified name of the class or module" },
11
- limit: { type: "integer", description: "Maximum number of descendants to return (default 50, max 500)" },
12
- offset: { type: "integer", description: "Number of descendants to skip for pagination (default 0)" },
10
+ name: { type: "string", description: "Fully qualified class or module name" },
11
+ limit: { type: "integer", description: "Page size (default 50, capped at 500)" },
12
+ offset: { type: "integer", description: "Number of results to skip (default 0)" },
13
13
  },
14
14
  required: ["name"],
15
15
  )
@@ -4,10 +4,10 @@ module Rubydex
4
4
  module MCPServer
5
5
  class GetFileDeclarationsTool < BaseTool
6
6
  tool_name "get_file_declarations"
7
- description "List all Ruby classes, modules, methods, and constants defined in a specific file. Returns a structural overview with names, kinds, and line numbers. Use this to understand a file's structure before reading it, or to see what a file contributes to the codebase. Accepts relative or absolute paths."
7
+ description "List Ruby declarations defined in an indexed file."
8
8
  input_schema(
9
9
  properties: {
10
- file_path: { type: "string", description: "File path (relative or absolute) to list declarations for" },
10
+ file_path: { type: "string", description: "Absolute path or path relative to the workspace root" },
11
11
  },
12
12
  required: ["file_path"],
13
13
  )
@@ -4,14 +4,14 @@ module Rubydex
4
4
  module MCPServer
5
5
  class SearchDeclarationsTool < BaseTool
6
6
  tool_name "search_declarations"
7
- description 'Search for Ruby classes, modules, methods, or constants by name. Use this INSTEAD OF Grep when you know part of a Ruby identifier name and want to find its definition. Returns fully qualified names, kinds, and file locations. Use the `kind` filter ("Class", "Module", "Method", "Constant") to narrow results. Set `match_mode` to "exact" for precise substring matching or "fuzzy" for LSP-style workspace symbol search (default). Results are paginated: the response includes `total` (the full count of matches). If `total` exceeds the number of returned results, use `offset` to fetch subsequent pages.'
7
+ description "Find definitions of Ruby classes, modules, methods, or constants by full or partial name."
8
8
  input_schema(
9
9
  properties: {
10
- query: { type: "string", description: "Search query to match against declaration names" },
11
- kind: { type: "string", description: "Filter by declaration kind: Class, Module, Method, Constant, etc." },
12
- match_mode: { type: "string", description: 'Matching mode: "fuzzy" (default) for LSP-style workspace symbol search, or "exact" for precise substring matching' },
13
- limit: { type: "integer", description: "Maximum number of results to return (default 50, max 100)" },
14
- offset: { type: "integer", description: "Number of results to skip for pagination (default 0)" },
10
+ query: { type: "string", description: "Text to match against fully qualified names. An empty string matches all declarations." },
11
+ kind: { type: "string", description: "Case-insensitive declaration kind, such as Class, Module, Method, or Constant" },
12
+ match_mode: { type: "string", description: '"fuzzy" (default) matches characters in order, ignoring ASCII case. "exact" matches a case-sensitive substring.' },
13
+ limit: { type: "integer", description: "Page size (default 50, capped at 100)" },
14
+ offset: { type: "integer", description: "Number of results to skip (default 0)" },
15
15
  },
16
16
  required: ["query"],
17
17
  )
@@ -10,19 +10,13 @@ Dir[File.join(__dir__, "mcp_server", "tools", "*_tool.rb")].sort.each { |file| r
10
10
  module Rubydex
11
11
  module MCPServer
12
12
  SERVER_INSTRUCTIONS = <<~TEXT
13
- Rubydex provides semantic Ruby code intelligence.
14
-
15
- Use these tools for Ruby source files (.rb, .rbi, .rbs) when you need structural information about declarations, locations, hierarchy, references, or codebase composition.
16
-
17
- Use text search instead for literal strings, comments, log messages, non-Ruby files, or content search rather than structural queries.
18
-
19
- Fully qualified name format: "Foo::Bar" for classes/modules/constants, "Foo::Bar#method_name" for instance methods.
20
-
21
- Pagination: tools that may return a high number of results include `total` for pagination. When `total` exceeds the number of returned items, use `offset` to fetch the next page.
13
+ Tools query a static index of workspace code, available bundle dependencies, and available Ruby core and standard-library RBS definitions.
14
+ The index is built at server startup and does not track file changes; restart the server to refresh it.
22
15
  TEXT
23
16
 
24
17
  class Server
25
18
  WORKER_COUNT = 4
19
+ SHUTDOWN_JOIN_TIMEOUT = 2
26
20
 
27
21
  #: (root_path: String, ?transport: StdioTransport) -> void
28
22
  def initialize(root_path:, transport: nil)
@@ -34,13 +28,14 @@ module Rubydex
34
28
  @outgoing_queue = Thread::Queue.new
35
29
  @workers = []
36
30
  @outgoing_dispatcher = nil
31
+ @indexer = nil
37
32
  end
38
33
 
39
34
  attr_reader :root_path
40
35
 
41
36
  #: -> Thread
42
37
  def spawn_indexer
43
- Thread.new do
38
+ @indexer = Thread.new do
44
39
  @graph.index_workspace
45
40
  @graph.resolve
46
41
  @index_finished = true
@@ -150,9 +145,26 @@ module Rubydex
150
145
  #: -> void
151
146
  def run_shutdown
152
147
  @incoming_queue.close unless @incoming_queue.closed?
153
- @workers.each(&:join)
148
+ join_or_kill_all(@workers + [@indexer])
154
149
  @outgoing_queue.close unless @outgoing_queue.closed?
155
- @outgoing_dispatcher&.join
150
+ join_or_kill_all([@outgoing_dispatcher])
151
+ end
152
+
153
+ #: (Array[Thread?]) -> void
154
+ def join_or_kill_all(threads)
155
+ live_threads = threads.compact.select(&:alive?)
156
+ return if live_threads.empty?
157
+
158
+ deadline = Process.clock_gettime(Process::CLOCK_MONOTONIC) + SHUTDOWN_JOIN_TIMEOUT
159
+ live_threads.each do |thread|
160
+ remaining = deadline - Process.clock_gettime(Process::CLOCK_MONOTONIC)
161
+ break if remaining <= 0
162
+
163
+ thread.join(remaining)
164
+ end
165
+
166
+ live_threads.select(&:alive?).each(&:kill)
167
+ live_threads.select(&:alive?).each(&:join)
156
168
  end
157
169
 
158
170
  #: -> Thread
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rubydex
4
- VERSION = "0.4.1"
4
+ VERSION = "0.4.4"
5
5
  end
data/rust/Cargo.lock CHANGED
@@ -99,7 +99,7 @@ dependencies = [
99
99
  "quote",
100
100
  "regex",
101
101
  "rustc-hash",
102
- "shlex",
102
+ "shlex 1.3.0",
103
103
  "syn",
104
104
  ]
105
105
 
@@ -151,7 +151,7 @@ version = "1.2.30"
151
151
  source = "registry+https://github.com/rust-lang/crates.io-index"
152
152
  checksum = "deec109607ca693028562ed836a5f1c4b8bd77755c4e132fc5ce11b0b6211ae7"
153
153
  dependencies = [
154
- "shlex",
154
+ "shlex 1.3.0",
155
155
  ]
156
156
 
157
157
  [[package]]
@@ -718,9 +718,9 @@ checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
718
718
 
719
719
  [[package]]
720
720
  name = "ruby-prism"
721
- version = "1.9.0"
721
+ version = "2.0.0"
722
722
  source = "registry+https://github.com/rust-lang/crates.io-index"
723
- checksum = "3b302f00359d0b5423a600314935ca5f994484e15da2db5345631d28c6e029d6"
723
+ checksum = "e292a6139b28657899a18778d281cd4829d5e46ccc060edc1d0cdcd6b1fae774"
724
724
  dependencies = [
725
725
  "ruby-prism-sys",
726
726
  "serde",
@@ -729,12 +729,12 @@ dependencies = [
729
729
 
730
730
  [[package]]
731
731
  name = "ruby-prism-sys"
732
- version = "1.9.0"
732
+ version = "2.0.0"
733
733
  source = "registry+https://github.com/rust-lang/crates.io-index"
734
- checksum = "9f85fd9571455bdca2b3bf0b2f543cd13ac39d5de0026a8eb2deb94ffd264f00"
734
+ checksum = "0080aa6a022c43438c9f33533e2da926407776e96583be67d7864c4037fb84b3"
735
735
  dependencies = [
736
- "bindgen",
737
736
  "cc",
737
+ "shlex 2.0.1",
738
738
  ]
739
739
 
740
740
  [[package]]
@@ -760,7 +760,7 @@ dependencies = [
760
760
 
761
761
  [[package]]
762
762
  name = "rubydex"
763
- version = "0.2.6"
763
+ version = "0.4.4"
764
764
  dependencies = [
765
765
  "assert_cmd",
766
766
  "bitflags",
@@ -789,7 +789,7 @@ dependencies = [
789
789
 
790
790
  [[package]]
791
791
  name = "rubydex-sys"
792
- version = "0.2.6"
792
+ version = "0.4.4"
793
793
  dependencies = [
794
794
  "cbindgen",
795
795
  "libc",
@@ -902,6 +902,12 @@ version = "1.3.0"
902
902
  source = "registry+https://github.com/rust-lang/crates.io-index"
903
903
  checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
904
904
 
905
+ [[package]]
906
+ name = "shlex"
907
+ version = "2.0.1"
908
+ source = "registry+https://github.com/rust-lang/crates.io-index"
909
+ checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
910
+
905
911
  [[package]]
906
912
  name = "smallvec"
907
913
  version = "1.15.1"
@@ -1326,9 +1332,9 @@ checksum = "ea2f10b9bb0928dfb1b42b65e1f9e36f7f54dbdf08457afefb38afcdec4fa2bb"
1326
1332
 
1327
1333
  [[package]]
1328
1334
  name = "xxhash-rust"
1329
- version = "0.8.15"
1335
+ version = "0.8.16"
1330
1336
  source = "registry+https://github.com/rust-lang/crates.io-index"
1331
- checksum = "fdd20c5420375476fbd4394763288da7eb0cc0b8c11deed431a91562af7335d3"
1337
+ checksum = "4d93c89cdc2d3a63c3ec48ffe926931bdc069eafa8e4402fe6d8f790c9d1e576"
1332
1338
 
1333
1339
  [[package]]
1334
1340
  name = "yoke"
data/rust/Cargo.toml CHANGED
@@ -6,6 +6,10 @@ members = [
6
6
 
7
7
  resolver = "3"
8
8
 
9
+ [workspace.package]
10
+ version = "0.4.4"
11
+ rust-version = "1.99.1"
12
+
9
13
  [profile.release]
10
14
  lto = true
11
15
  opt-level = 3
@@ -25,4 +29,4 @@ complexity = "deny"
25
29
  style = "deny"
26
30
  pedantic = "warn"
27
31
 
28
- ptr-as-ptr = { level = "deny", priority = 1 }
32
+ ptr_as_ptr = { level = "deny", priority = 1 }
@@ -1,8 +1,8 @@
1
1
  [package]
2
2
  name = "rubydex"
3
- version = "0.2.6"
3
+ version.workspace = true
4
4
  edition = "2024"
5
- rust-version = "1.89.0"
5
+ rust-version.workspace = true
6
6
  license = "MIT"
7
7
  description = "High-performance Ruby code indexing and static analysis library."
8
8
  homepage = "https://github.com/Shopify/rubydex"
@@ -32,7 +32,7 @@ test_utils = ["dep:tempfile"]
32
32
 
33
33
  [dependencies]
34
34
  cypher-parser = "0.8.1"
35
- ruby-prism = "1.9.0"
35
+ ruby-prism = "2.0.0"
36
36
  ruby-rbs = "0.3"
37
37
  url = "2.5.4"
38
38
  xxhash-rust = { version = "0.8.15", features = ["xxh3"] }
@@ -3,11 +3,13 @@
3
3
  macro_rules! assert_mem_size {
4
4
  ($struct:ident, $size:expr) => {
5
5
  // Check struct name on this assert! error
6
+ #[cfg(target_pointer_width = "64")]
6
7
  const _: () = assert!(
7
8
  std::mem::size_of::<$struct>() == $size,
8
9
  concat!("Incorrect size for `", stringify!($struct), "`")
9
10
  );
10
11
  // Check actual size on this array error
12
+ #[cfg(target_pointer_width = "64")]
11
13
  const _: [(); $size] = [(); std::mem::size_of::<$struct>()];
12
14
  };
13
15
  }
@@ -433,7 +433,7 @@ mod tests {
433
433
 
434
434
  let other = rules.iter().find(|rule| rule.name() == "Other").unwrap();
435
435
  assert!(!other.enabled());
436
- assert!(other.exclude_patterns().is_empty());
436
+ assert_eq!(other.exclude_patterns(), []);
437
437
  assert_eq!(other.severity(), None);
438
438
  }
439
439
 
@@ -33,8 +33,8 @@ pub struct RBSIndexer<'a> {
33
33
 
34
34
  impl<'a> RBSIndexer<'a> {
35
35
  #[must_use]
36
- pub fn new(uri: String, source: &'a str) -> Self {
37
- let uri_id = UriId::from(&uri);
36
+ pub fn new(uri: Box<str>, source: &'a str) -> Self {
37
+ let uri_id = UriId::from(&*uri);
38
38
  let local_graph = LocalGraph::new(uri_id, Document::new(uri, source));
39
39
 
40
40
  Self {
@@ -197,7 +197,7 @@ impl<'a> RBSIndexer<'a> {
197
197
  // Skip past indentation to the comment text
198
198
  current_offset += line_indent as u32;
199
199
 
200
- let line_text = line[line_indent..].to_string();
200
+ let line_text: Box<str> = line[line_indent..].into();
201
201
  let line_bytes = line_text.len() as u32;
202
202
  let offset = Offset::new(current_offset, current_offset + line_bytes);
203
203
  comments.push(Comment::new(offset, line_text));
@@ -1454,7 +1454,7 @@ mod tests {
1454
1454
  fn split_multiline_comments_crlf() {
1455
1455
  // Build the indexer directly to bypass normalize_indentation, which strips \r
1456
1456
  let source = "# First line\r\n# Second line\r\nclass Foo\r\nend\r\n";
1457
- let mut indexer = RBSIndexer::new("file:///foo.rbs".to_string(), source);
1457
+ let mut indexer = RBSIndexer::new("file:///foo.rbs".into(), source);
1458
1458
  indexer.index();
1459
1459
  let context = LocalGraphTest::from_local_graph("file:///foo.rbs", source, indexer.local_graph());
1460
1460
 
@@ -93,8 +93,8 @@ pub struct RubyIndexer<'a> {
93
93
 
94
94
  impl<'a> RubyIndexer<'a> {
95
95
  #[must_use]
96
- pub fn new(uri: String, source: &'a str) -> Self {
97
- let uri_id = UriId::from(&uri);
96
+ pub fn new(uri: Box<str>, source: &'a str) -> Self {
97
+ let uri_id = UriId::from(&*uri);
98
98
  let local_graph = LocalGraph::new(uri_id, Document::new(uri, source));
99
99
 
100
100
  Self {
@@ -120,7 +120,7 @@ impl<'a> RubyIndexer<'a> {
120
120
  self.local_graph.add_diagnostic(
121
121
  Rule::ParseError,
122
122
  Offset::from_prism_location(&error.location()),
123
- error.message().to_string(),
123
+ String::from_utf8_lossy(error.message()).to_string(),
124
124
  );
125
125
  }
126
126
 
@@ -128,7 +128,7 @@ impl<'a> RubyIndexer<'a> {
128
128
  self.local_graph.add_diagnostic(
129
129
  Rule::ParseWarning,
130
130
  Offset::from_prism_location(&warning.location()),
131
- warning.message().to_string(),
131
+ String::from_utf8_lossy(warning.message()).to_string(),
132
132
  );
133
133
  }
134
134
 
@@ -313,7 +313,9 @@ impl<'a> RubyIndexer<'a> {
313
313
  }
314
314
  }
315
315
 
316
- if let Some(block) = parameters_list.block() {
316
+ if let Some(block) = parameters_list.block()
317
+ && let Some(block) = block.as_block_parameter_node()
318
+ {
317
319
  let location = block.name_loc().unwrap_or_else(|| block.location());
318
320
  let str_id = self.local_graph.intern_string(Self::location_to_string(&location));
319
321
 
@@ -1389,8 +1391,8 @@ impl<'a> RubyIndexer<'a> {
1389
1391
  match arg {
1390
1392
  ruby_prism::Node::SymbolNode { .. } => {
1391
1393
  let symbol = arg.as_symbol_node().unwrap();
1392
- let value_loc = symbol.value_loc()?;
1393
- Some((Self::location_to_string(&value_loc), value_loc))
1394
+ let content_loc = symbol.content_loc();
1395
+ Some((Self::location_to_string(&content_loc), content_loc))
1394
1396
  }
1395
1397
  ruby_prism::Node::StringNode { .. } => {
1396
1398
  let string = arg.as_string_node().unwrap();
@@ -1522,7 +1524,7 @@ impl CommentGroup {
1522
1524
  // Accepts the next line if it is continuous
1523
1525
  fn accepts(&self, next: &ruby_prism::Comment, source: &str) -> bool {
1524
1526
  let current_end_offset = self.end_offset;
1525
- let next_line_start_offset = next.location().start_offset();
1527
+ let next_line_start_offset = next.location().start() as usize;
1526
1528
 
1527
1529
  let between = &source.as_bytes()[current_end_offset..next_line_start_offset];
1528
1530
  if !between.iter().all(|&b| b.is_ascii_whitespace()) {
@@ -1538,7 +1540,7 @@ impl CommentGroup {
1538
1540
  // 1. still move the group end offset to the end of the magic comment
1539
1541
  // 2. not add the comment to the comments array
1540
1542
  fn add_comment(&mut self, comment: &ruby_prism::Comment) {
1541
- self.end_offset = comment.location().end_offset();
1543
+ self.end_offset = comment.location().end() as usize;
1542
1544
  let text = String::from_utf8_lossy(comment.location().as_slice()).to_string();
1543
1545
 
1544
1546
  if text.lines().any(|line| line.starts_with("# @deprecated")) {
@@ -1547,7 +1549,7 @@ impl CommentGroup {
1547
1549
 
1548
1550
  self.comments.push(Comment::new(
1549
1551
  Offset::from_prism_location(&comment.location()),
1550
- text.trim().to_string(),
1552
+ text.trim().into(),
1551
1553
  ));
1552
1554
  }
1553
1555
 
@@ -1984,12 +1986,18 @@ impl Visit<'_> for RubyIndexer<'_> {
1984
1986
  });
1985
1987
  };
1986
1988
 
1987
- let message_loc = node.message_loc();
1989
+ let message_loc = if node.name().as_slice().is_empty() {
1990
+ // Incomplete calls like `Foo.` have no message. We still index them using the call operator location, so
1991
+ // that the receiver's singleton class gets created, which completion depends on
1992
+ node.call_operator_loc()
1993
+ } else {
1994
+ node.message_loc()
1995
+ };
1988
1996
 
1989
- if message_loc.is_none() {
1997
+ let Some(message_loc) = message_loc else {
1990
1998
  // No message, we can't index this node
1991
1999
  return;
1992
- }
2000
+ };
1993
2001
 
1994
2002
  let message = String::from_utf8_lossy(node.name().as_slice()).to_string();
1995
2003
 
@@ -2217,11 +2225,11 @@ impl Visit<'_> for RubyIndexer<'_> {
2217
2225
  self.visit(&receiver);
2218
2226
  }
2219
2227
 
2220
- self.index_method_reference(message.clone(), &node.message_loc().unwrap(), method_receiver);
2228
+ self.index_method_reference(message.clone(), &message_loc, method_receiver);
2221
2229
 
2222
2230
  match message.as_str() {
2223
2231
  ">" | "<" | ">=" | "<=" => {
2224
- self.index_method_reference("<=>".to_string(), &node.message_loc().unwrap(), method_receiver);
2232
+ self.index_method_reference("<=>".to_string(), &message_loc, method_receiver);
2225
2233
  }
2226
2234
  _ => {}
2227
2235
  }
@@ -2382,7 +2390,7 @@ impl Visit<'_> for RubyIndexer<'_> {
2382
2390
  match expression {
2383
2391
  ruby_prism::Node::SymbolNode { .. } => {
2384
2392
  let symbol = expression.as_symbol_node().unwrap();
2385
- let name = Self::location_to_string(&symbol.value_loc().unwrap());
2393
+ let name = Self::location_to_string(&symbol.content_loc());
2386
2394
  self.index_method_reference(name, &node.location(), None);
2387
2395
  }
2388
2396
  _ => {
@@ -2394,13 +2402,13 @@ impl Visit<'_> for RubyIndexer<'_> {
2394
2402
 
2395
2403
  fn visit_alias_method_node(&mut self, node: &ruby_prism::AliasMethodNode<'_>) {
2396
2404
  let mut new_name = if let Some(symbol_node) = node.new_name().as_symbol_node() {
2397
- Self::location_to_string(&symbol_node.value_loc().unwrap())
2405
+ Self::location_to_string(&symbol_node.content_loc())
2398
2406
  } else {
2399
2407
  Self::location_to_string(&node.new_name().location())
2400
2408
  };
2401
2409
 
2402
2410
  let mut old_name = if let Some(symbol_node) = node.old_name().as_symbol_node() {
2403
- Self::location_to_string(&symbol_node.value_loc().unwrap())
2411
+ Self::location_to_string(&symbol_node.content_loc())
2404
2412
  } else {
2405
2413
  Self::location_to_string(&node.old_name().location())
2406
2414
  };