rubydex 0.4.1 → 0.4.3
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.
- checksums.yaml +4 -4
- data/README.md +11 -0
- data/THIRD_PARTY_LICENSES.html +14 -427
- data/ext/rubydex/extconf.rb +1 -0
- data/lib/rubydex/cli/command/dead_code.rb +59 -0
- data/lib/rubydex/mcp_server/tools/codebase_stats_tool.rb +1 -1
- data/lib/rubydex/mcp_server/tools/find_constant_references_tool.rb +4 -4
- data/lib/rubydex/mcp_server/tools/find_dead_code_candidates_tool.rb +33 -0
- data/lib/rubydex/mcp_server/tools/get_declaration_tool.rb +2 -2
- data/lib/rubydex/mcp_server/tools/get_descendants_tool.rb +4 -4
- data/lib/rubydex/mcp_server/tools/get_file_declarations_tool.rb +2 -2
- data/lib/rubydex/mcp_server/tools/search_declarations_tool.rb +6 -6
- data/lib/rubydex/mcp_server.rb +24 -12
- data/lib/rubydex/version.rb +1 -1
- data/rust/Cargo.lock +17 -11
- data/rust/Cargo.toml +3 -0
- data/rust/rubydex/Cargo.toml +2 -2
- data/rust/rubydex/src/compile_assertions.rs +2 -0
- data/rust/rubydex/src/config.rs +1 -1
- data/rust/rubydex/src/indexing/rbs_indexer.rs +4 -4
- data/rust/rubydex/src/indexing/ruby_indexer.rs +26 -18
- data/rust/rubydex/src/indexing/ruby_indexer_tests.rs +42 -2
- data/rust/rubydex/src/indexing.rs +6 -6
- data/rust/rubydex/src/listing.rs +12 -12
- data/rust/rubydex/src/model/built_in.rs +1 -1
- data/rust/rubydex/src/model/comment.rs +4 -4
- data/rust/rubydex/src/model/declaration.rs +25 -17
- data/rust/rubydex/src/model/document.rs +11 -11
- data/rust/rubydex/src/model/graph.rs +3 -3
- data/rust/rubydex/src/offset.rs +1 -13
- data/rust/rubydex/src/operation/ruby_builder.rs +29 -19
- data/rust/rubydex/src/query.rs +3 -2
- data/rust/rubydex/src/test_utils/graph_test.rs +2 -2
- data/rust/rubydex/src/test_utils/local_graph_test.rs +13 -6
- data/rust/rubydex-sys/Cargo.toml +6 -3
- data/rust/rubydex-sys/build.rs +1 -2
- data/rust/rubydex-sys/src/definition_api.rs +1 -1
- data/rust/rubydex-sys/src/graph_api.rs +96 -49
- data/rust/rubydex-sys/src/name_api.rs +193 -58
- metadata +191 -191
|
@@ -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
|
|
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:
|
|
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 "
|
|
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
|
|
11
|
-
limit: { type: "integer", description: "
|
|
12
|
-
offset: { type: "integer", description: "Number of
|
|
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
|
|
7
|
+
description "List Ruby declarations defined in an indexed file."
|
|
8
8
|
input_schema(
|
|
9
9
|
properties: {
|
|
10
|
-
file_path: { type: "string", description: "
|
|
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
|
|
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: "
|
|
11
|
-
kind: { type: "string", description: "
|
|
12
|
-
match_mode: { type: "string", description: '
|
|
13
|
-
limit: { type: "integer", description: "
|
|
14
|
-
offset: { type: "integer", description: "Number of results to skip
|
|
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
|
)
|
data/lib/rubydex/mcp_server.rb
CHANGED
|
@@ -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
|
-
|
|
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
|
|
148
|
+
join_or_kill_all(@workers + [@indexer])
|
|
154
149
|
@outgoing_queue.close unless @outgoing_queue.closed?
|
|
155
|
-
@outgoing_dispatcher
|
|
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
|
data/lib/rubydex/version.rb
CHANGED
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 = "
|
|
721
|
+
version = "2.0.0"
|
|
722
722
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
723
|
-
checksum = "
|
|
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 = "
|
|
732
|
+
version = "2.0.0"
|
|
733
733
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
734
|
-
checksum = "
|
|
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.
|
|
763
|
+
version = "0.4.3"
|
|
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.
|
|
792
|
+
version = "0.4.3"
|
|
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.
|
|
1335
|
+
version = "0.8.16"
|
|
1330
1336
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
1331
|
-
checksum = "
|
|
1337
|
+
checksum = "4d93c89cdc2d3a63c3ec48ffe926931bdc069eafa8e4402fe6d8f790c9d1e576"
|
|
1332
1338
|
|
|
1333
1339
|
[[package]]
|
|
1334
1340
|
name = "yoke"
|
data/rust/Cargo.toml
CHANGED
data/rust/rubydex/Cargo.toml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "rubydex"
|
|
3
|
-
version =
|
|
3
|
+
version.workspace = true
|
|
4
4
|
edition = "2024"
|
|
5
5
|
rust-version = "1.89.0"
|
|
6
6
|
license = "MIT"
|
|
@@ -32,7 +32,7 @@ test_utils = ["dep:tempfile"]
|
|
|
32
32
|
|
|
33
33
|
[dependencies]
|
|
34
34
|
cypher-parser = "0.8.1"
|
|
35
|
-
ruby-prism = "
|
|
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
|
}
|
data/rust/rubydex/src/config.rs
CHANGED
|
@@ -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
|
-
|
|
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:
|
|
37
|
-
let uri_id = UriId::from(
|
|
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..].
|
|
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".
|
|
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:
|
|
97
|
-
let uri_id = UriId::from(
|
|
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
|
|
1393
|
-
Some((Self::location_to_string(&
|
|
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().
|
|
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().
|
|
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().
|
|
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.
|
|
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
|
-
|
|
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(), &
|
|
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(), &
|
|
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.
|
|
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.
|
|
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.
|
|
2411
|
+
Self::location_to_string(&symbol_node.content_loc())
|
|
2404
2412
|
} else {
|
|
2405
2413
|
Self::location_to_string(&node.old_name().location())
|
|
2406
2414
|
};
|
|
@@ -900,7 +900,7 @@ mod class_and_module_tests {
|
|
|
900
900
|
assert_def_name_eq!(&context, def, "Baz");
|
|
901
901
|
assert_def_name_offset_eq!(&context, def, "3:11-3:14");
|
|
902
902
|
assert!(def.superclass_ref().is_none());
|
|
903
|
-
|
|
903
|
+
assert_eq!(def.members(), []);
|
|
904
904
|
|
|
905
905
|
assert_definition_at!(&context, "2:3-4:6", Class, |parent_nesting| {
|
|
906
906
|
assert_eq!(parent_nesting.id(), def.lexical_nesting_id().unwrap());
|
|
@@ -948,7 +948,7 @@ mod class_and_module_tests {
|
|
|
948
948
|
assert_def_name_eq!(&context, def, "Quuux");
|
|
949
949
|
assert_def_name_offset_eq!(&context, def, "3:13-3:18");
|
|
950
950
|
assert!(def.superclass_ref().is_none());
|
|
951
|
-
|
|
951
|
+
assert_eq!(def.members(), []);
|
|
952
952
|
|
|
953
953
|
assert_definition_at!(&context, "2:3-4:6", Class, |parent_nesting| {
|
|
954
954
|
assert_eq!(parent_nesting.id(), def.lexical_nesting_id().unwrap());
|
|
@@ -1250,6 +1250,46 @@ mod method_tests {
|
|
|
1250
1250
|
});
|
|
1251
1251
|
}
|
|
1252
1252
|
|
|
1253
|
+
#[test]
|
|
1254
|
+
fn index_def_node_with_no_block_parameter() {
|
|
1255
|
+
let context = index_source({
|
|
1256
|
+
"
|
|
1257
|
+
def foo(a, &nil); end
|
|
1258
|
+
"
|
|
1259
|
+
});
|
|
1260
|
+
|
|
1261
|
+
assert_no_local_diagnostics!(&context);
|
|
1262
|
+
|
|
1263
|
+
assert_definition_at!(&context, "1:1-1:22", Method, |def| {
|
|
1264
|
+
assert_simple_signature!(def, |params| {
|
|
1265
|
+
assert_eq!(params.len(), 1);
|
|
1266
|
+
assert_parameter!(¶ms[0], RequiredPositional, |param| {
|
|
1267
|
+
assert_string_eq!(context, param.str(), "a");
|
|
1268
|
+
});
|
|
1269
|
+
});
|
|
1270
|
+
});
|
|
1271
|
+
}
|
|
1272
|
+
|
|
1273
|
+
#[test]
|
|
1274
|
+
fn index_def_node_with_trailing_comma_in_parameters() {
|
|
1275
|
+
let context = index_source({
|
|
1276
|
+
"
|
|
1277
|
+
def foo(a,); end
|
|
1278
|
+
"
|
|
1279
|
+
});
|
|
1280
|
+
|
|
1281
|
+
assert_no_local_diagnostics!(&context);
|
|
1282
|
+
|
|
1283
|
+
assert_definition_at!(&context, "1:1-1:17", Method, |def| {
|
|
1284
|
+
assert_simple_signature!(def, |params| {
|
|
1285
|
+
assert_eq!(params.len(), 1);
|
|
1286
|
+
assert_parameter!(¶ms[0], RequiredPositional, |param| {
|
|
1287
|
+
assert_string_eq!(context, param.str(), "a");
|
|
1288
|
+
});
|
|
1289
|
+
});
|
|
1290
|
+
});
|
|
1291
|
+
}
|
|
1292
|
+
|
|
1253
1293
|
#[test]
|
|
1254
1294
|
fn index_nested_method_definitions() {
|
|
1255
1295
|
let context = index_source({
|
|
@@ -101,7 +101,7 @@ impl Job for IndexingJob {
|
|
|
101
101
|
};
|
|
102
102
|
|
|
103
103
|
let language = self.path.extension().map_or(LanguageId::Ruby, LanguageId::from);
|
|
104
|
-
let local_graph = build_local_graph(url.to_string(), &source, &language, self.backend);
|
|
104
|
+
let local_graph = build_local_graph(url.to_string().into(), &source, &language, self.backend);
|
|
105
105
|
|
|
106
106
|
self.local_graph_tx
|
|
107
107
|
.send(local_graph)
|
|
@@ -110,8 +110,8 @@ impl Job for IndexingJob {
|
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
/// Indexes a single source string in memory, dispatching to the appropriate indexer based on `language_id`.
|
|
113
|
-
pub fn index_source(graph: &mut Graph, uri:
|
|
114
|
-
let local_graph = build_local_graph(uri
|
|
113
|
+
pub fn index_source(graph: &mut Graph, uri: Box<str>, source: &str, language_id: &LanguageId) {
|
|
114
|
+
let local_graph = build_local_graph(uri, source, language_id, IndexerBackend::RubyIndexer);
|
|
115
115
|
graph.consume_document_changes(local_graph);
|
|
116
116
|
}
|
|
117
117
|
|
|
@@ -153,7 +153,7 @@ pub fn index_files(graph: &mut Graph, paths: Vec<PathBuf>, backend: IndexerBacke
|
|
|
153
153
|
|
|
154
154
|
/// Indexes a source string using the appropriate indexer for the given language.
|
|
155
155
|
#[must_use]
|
|
156
|
-
pub fn build_local_graph(uri:
|
|
156
|
+
pub fn build_local_graph(uri: Box<str>, source: &str, language: &LanguageId, backend: IndexerBackend) -> LocalGraph {
|
|
157
157
|
match language {
|
|
158
158
|
LanguageId::Ruby => match backend {
|
|
159
159
|
IndexerBackend::RubyIndexer => {
|
|
@@ -203,7 +203,7 @@ mod tests {
|
|
|
203
203
|
let mut graph = Graph::new();
|
|
204
204
|
let errors = index_files(&mut graph, vec![relative_to_pwd.clone()], IndexerBackend::RubyIndexer);
|
|
205
205
|
|
|
206
|
-
|
|
206
|
+
assert_eq!(errors.as_slice(), []);
|
|
207
207
|
assert_eq!(graph.documents().len(), 2);
|
|
208
208
|
}
|
|
209
209
|
|
|
@@ -228,7 +228,7 @@ mod tests {
|
|
|
228
228
|
assert_eq!(6, graph.definitions().len());
|
|
229
229
|
assert_eq!(2, graph.documents().len());
|
|
230
230
|
|
|
231
|
-
index_source(&mut graph,
|
|
231
|
+
index_source(&mut graph, uri.into(), "", &LanguageId::Ruby);
|
|
232
232
|
|
|
233
233
|
assert_eq!(5, graph.definitions().len());
|
|
234
234
|
assert_eq!(2, graph.documents().len());
|