rubydex 0.1.0.beta11 → 0.1.0.beta13
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/LICENSE.txt +23 -23
- data/README.md +125 -125
- data/THIRD_PARTY_LICENSES.html +2018 -945
- data/exe/rdx +47 -47
- data/ext/rubydex/declaration.c +453 -388
- data/ext/rubydex/declaration.h +23 -23
- data/ext/rubydex/definition.c +284 -197
- data/ext/rubydex/definition.h +28 -28
- data/ext/rubydex/diagnostic.c +6 -6
- data/ext/rubydex/diagnostic.h +11 -11
- data/ext/rubydex/document.c +97 -98
- data/ext/rubydex/document.h +10 -10
- data/ext/rubydex/extconf.rb +146 -127
- data/ext/rubydex/graph.c +701 -512
- data/ext/rubydex/graph.h +10 -10
- data/ext/rubydex/handle.h +44 -44
- data/ext/rubydex/location.c +22 -22
- data/ext/rubydex/location.h +15 -15
- data/ext/rubydex/reference.c +123 -104
- data/ext/rubydex/reference.h +15 -16
- data/ext/rubydex/rubydex.c +22 -22
- data/ext/rubydex/utils.c +108 -86
- data/ext/rubydex/utils.h +34 -28
- data/lib/rubydex/comment.rb +17 -17
- data/lib/rubydex/declaration.rb +11 -0
- data/lib/rubydex/diagnostic.rb +21 -21
- data/lib/rubydex/failures.rb +15 -15
- data/lib/rubydex/graph.rb +98 -92
- data/lib/rubydex/keyword.rb +17 -0
- data/lib/rubydex/keyword_parameter.rb +13 -0
- data/lib/rubydex/location.rb +90 -90
- data/lib/rubydex/mixin.rb +22 -0
- data/lib/rubydex/version.rb +5 -5
- data/lib/rubydex.rb +24 -20
- data/rbi/rubydex.rbi +425 -310
- data/rust/Cargo.lock +1851 -1851
- data/rust/Cargo.toml +29 -29
- data/rust/about.toml +10 -10
- data/rust/{about.hbs → about_templates/about.hbs} +81 -78
- data/rust/about_templates/mingw_licenses.hbs +1071 -0
- data/rust/rubydex/Cargo.toml +42 -42
- data/rust/rubydex/src/compile_assertions.rs +13 -13
- data/rust/rubydex/src/diagnostic.rs +110 -109
- data/rust/rubydex/src/errors.rs +28 -28
- data/rust/rubydex/src/indexing/local_graph.rs +224 -224
- data/rust/rubydex/src/indexing/rbs_indexer.rs +1551 -1554
- data/rust/rubydex/src/indexing/ruby_indexer.rs +2329 -6753
- data/rust/rubydex/src/indexing/ruby_indexer_tests.rs +4962 -0
- data/rust/rubydex/src/indexing.rs +210 -210
- data/rust/rubydex/src/integrity.rs +279 -278
- data/rust/rubydex/src/job_queue.rs +199 -205
- data/rust/rubydex/src/lib.rs +17 -17
- data/rust/rubydex/src/listing.rs +371 -272
- data/rust/rubydex/src/main.rs +160 -160
- data/rust/rubydex/src/model/built_in.rs +83 -0
- data/rust/rubydex/src/model/comment.rs +24 -24
- data/rust/rubydex/src/model/declaration.rs +679 -588
- data/rust/rubydex/src/model/definitions.rs +1682 -1602
- data/rust/rubydex/src/model/document.rs +222 -252
- data/rust/rubydex/src/model/encoding.rs +22 -22
- data/rust/rubydex/src/model/graph.rs +3782 -3556
- data/rust/rubydex/src/model/id.rs +110 -110
- data/rust/rubydex/src/model/identity_maps.rs +58 -58
- data/rust/rubydex/src/model/ids.rs +60 -38
- data/rust/rubydex/src/model/keywords.rs +256 -256
- data/rust/rubydex/src/model/name.rs +298 -298
- data/rust/rubydex/src/model/references.rs +111 -111
- data/rust/rubydex/src/model/string_ref.rs +50 -50
- data/rust/rubydex/src/model/visibility.rs +41 -41
- data/rust/rubydex/src/model.rs +15 -14
- data/rust/rubydex/src/offset.rs +147 -147
- data/rust/rubydex/src/position.rs +6 -6
- data/rust/rubydex/src/query.rs +1841 -1700
- data/rust/rubydex/src/resolution.rs +1852 -5895
- data/rust/rubydex/src/resolution_tests.rs +4701 -0
- data/rust/rubydex/src/stats/memory.rs +71 -71
- data/rust/rubydex/src/stats/orphan_report.rs +264 -263
- data/rust/rubydex/src/stats/timer.rs +127 -127
- data/rust/rubydex/src/stats.rs +11 -11
- data/rust/rubydex/src/test_utils/context.rs +226 -226
- data/rust/rubydex/src/test_utils/graph_test.rs +730 -679
- data/rust/rubydex/src/test_utils/local_graph_test.rs +602 -602
- data/rust/rubydex/src/test_utils.rs +52 -52
- data/rust/rubydex/src/visualization/dot.rs +192 -176
- data/rust/rubydex/src/visualization.rs +6 -6
- data/rust/rubydex/tests/cli.rs +185 -167
- data/rust/rubydex-mcp/Cargo.toml +28 -28
- data/rust/rubydex-mcp/src/main.rs +48 -48
- data/rust/rubydex-mcp/src/server.rs +1145 -1145
- data/rust/rubydex-mcp/src/tools.rs +49 -49
- data/rust/rubydex-mcp/tests/mcp.rs +302 -302
- data/rust/rubydex-sys/Cargo.toml +20 -20
- data/rust/rubydex-sys/build.rs +14 -14
- data/rust/rubydex-sys/cbindgen.toml +12 -12
- data/rust/rubydex-sys/src/declaration_api.rs +485 -469
- data/rust/rubydex-sys/src/definition_api.rs +443 -352
- data/rust/rubydex-sys/src/diagnostic_api.rs +99 -99
- data/rust/rubydex-sys/src/document_api.rs +85 -54
- data/rust/rubydex-sys/src/graph_api.rs +1017 -700
- data/rust/rubydex-sys/src/lib.rs +79 -9
- data/rust/rubydex-sys/src/location_api.rs +79 -79
- data/rust/rubydex-sys/src/name_api.rs +187 -135
- data/rust/rubydex-sys/src/reference_api.rs +267 -195
- data/rust/rubydex-sys/src/utils.rs +70 -70
- data/rust/rustfmt.toml +2 -2
- metadata +16 -9
- data/lib/rubydex/librubydex_sys.so +0 -0
data/rust/rubydex/src/offset.rs
CHANGED
|
@@ -1,147 +1,147 @@
|
|
|
1
|
-
//! Offset handling for byte-based file positions.
|
|
2
|
-
//!
|
|
3
|
-
//! This module provides the [`Offset`] struct which represents a span of bytes
|
|
4
|
-
//! within a file. It can be used to track positions in source code and convert
|
|
5
|
-
//! between byte offsets and line/column positions.
|
|
6
|
-
|
|
7
|
-
use crate::model::document::Document;
|
|
8
|
-
|
|
9
|
-
/// Represents a byte offset range within a specific file.
|
|
10
|
-
///
|
|
11
|
-
/// An `Offset` tracks a contiguous span of bytes from `start` to `end` within a file. This is useful for
|
|
12
|
-
/// representing the location of tokens, AST nodes, or other text spans in source code.
|
|
13
|
-
#[derive(Debug, Clone, PartialEq, Eq, Hash, Ord, PartialOrd)]
|
|
14
|
-
pub struct Offset {
|
|
15
|
-
/// The starting byte offset (inclusive)
|
|
16
|
-
start: u32,
|
|
17
|
-
/// The ending byte offset (exclusive)
|
|
18
|
-
end: u32,
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
impl Offset {
|
|
22
|
-
/// Creates a new `Offset` with the specified file ID and byte range.
|
|
23
|
-
///
|
|
24
|
-
/// # Arguments
|
|
25
|
-
///
|
|
26
|
-
/// * `start` - The starting byte position (inclusive)
|
|
27
|
-
/// * `end` - The ending byte position (exclusive)
|
|
28
|
-
#[must_use]
|
|
29
|
-
pub const fn new(start: u32, end: u32) -> Self {
|
|
30
|
-
Self { start, end }
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/// # Panics
|
|
34
|
-
///
|
|
35
|
-
/// This function can panic if the Prism location offsets do not fit into a u32
|
|
36
|
-
#[must_use]
|
|
37
|
-
pub fn from_prism_location(location: &ruby_prism::Location) -> Self {
|
|
38
|
-
Self::new(
|
|
39
|
-
location
|
|
40
|
-
.start_offset()
|
|
41
|
-
.try_into()
|
|
42
|
-
.expect("Expected usize `start` to fit in `u32`"),
|
|
43
|
-
location
|
|
44
|
-
.end_offset()
|
|
45
|
-
.try_into()
|
|
46
|
-
.expect("Expected usize `end` to fit in `u32`"),
|
|
47
|
-
)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/// # Panics
|
|
51
|
-
///
|
|
52
|
-
/// This function can panic if the RBS location offsets don't fit into u32
|
|
53
|
-
#[must_use]
|
|
54
|
-
pub fn from_rbs_location(location: &ruby_rbs::node::RBSLocationRange) -> Self {
|
|
55
|
-
Self::new(
|
|
56
|
-
location
|
|
57
|
-
.start()
|
|
58
|
-
.try_into()
|
|
59
|
-
.expect("RBS location start offset should fit into u32"),
|
|
60
|
-
location
|
|
61
|
-
.end()
|
|
62
|
-
.try_into()
|
|
63
|
-
.expect("RBS location end offset should fit into u32"),
|
|
64
|
-
)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
#[must_use]
|
|
68
|
-
pub fn start(&self) -> u32 {
|
|
69
|
-
self.start
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
#[must_use]
|
|
73
|
-
pub fn end(&self) -> u32 {
|
|
74
|
-
self.end
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/// Converts an offset to a display range like `1:1-1:5`
|
|
78
|
-
#[must_use]
|
|
79
|
-
pub fn to_display_range(&self, document: &Document) -> String {
|
|
80
|
-
let loc = self.to_location(document).to_presentation();
|
|
81
|
-
format!(
|
|
82
|
-
"{}:{}-{}:{}",
|
|
83
|
-
loc.start_line(),
|
|
84
|
-
loc.start_col(),
|
|
85
|
-
loc.end_line(),
|
|
86
|
-
loc.end_col()
|
|
87
|
-
)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/// Converts this offset to a 0-indexed [`Location`] with start and end line/column numbers.
|
|
91
|
-
#[must_use]
|
|
92
|
-
pub fn to_location(&self, document: &Document) -> Location {
|
|
93
|
-
let line_index = document.line_index();
|
|
94
|
-
let start = line_index.line_col(self.start().into());
|
|
95
|
-
let end = line_index.line_col(self.end().into());
|
|
96
|
-
Location {
|
|
97
|
-
start_line: start.line,
|
|
98
|
-
start_col: start.col,
|
|
99
|
-
end_line: end.line,
|
|
100
|
-
end_col: end.col,
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/// A resolved location within a file, with start and end line/column positions.
|
|
106
|
-
/// Values are 0-indexed by default. Use [`to_presentation`](Location::to_presentation)
|
|
107
|
-
/// for 1-indexed values suitable for display.
|
|
108
|
-
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
109
|
-
pub struct Location {
|
|
110
|
-
start_line: u32,
|
|
111
|
-
start_col: u32,
|
|
112
|
-
end_line: u32,
|
|
113
|
-
end_col: u32,
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
impl Location {
|
|
117
|
-
#[must_use]
|
|
118
|
-
pub fn start_line(&self) -> u32 {
|
|
119
|
-
self.start_line
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
#[must_use]
|
|
123
|
-
pub fn start_col(&self) -> u32 {
|
|
124
|
-
self.start_col
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
#[must_use]
|
|
128
|
-
pub fn end_line(&self) -> u32 {
|
|
129
|
-
self.end_line
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
#[must_use]
|
|
133
|
-
pub fn end_col(&self) -> u32 {
|
|
134
|
-
self.end_col
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/// Returns a new `Location` with 1-indexed values for display purposes.
|
|
138
|
-
#[must_use]
|
|
139
|
-
pub fn to_presentation(&self) -> Self {
|
|
140
|
-
Self {
|
|
141
|
-
start_line: self.start_line + 1,
|
|
142
|
-
start_col: self.start_col + 1,
|
|
143
|
-
end_line: self.end_line + 1,
|
|
144
|
-
end_col: self.end_col + 1,
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
1
|
+
//! Offset handling for byte-based file positions.
|
|
2
|
+
//!
|
|
3
|
+
//! This module provides the [`Offset`] struct which represents a span of bytes
|
|
4
|
+
//! within a file. It can be used to track positions in source code and convert
|
|
5
|
+
//! between byte offsets and line/column positions.
|
|
6
|
+
|
|
7
|
+
use crate::model::document::Document;
|
|
8
|
+
|
|
9
|
+
/// Represents a byte offset range within a specific file.
|
|
10
|
+
///
|
|
11
|
+
/// An `Offset` tracks a contiguous span of bytes from `start` to `end` within a file. This is useful for
|
|
12
|
+
/// representing the location of tokens, AST nodes, or other text spans in source code.
|
|
13
|
+
#[derive(Debug, Clone, PartialEq, Eq, Hash, Ord, PartialOrd)]
|
|
14
|
+
pub struct Offset {
|
|
15
|
+
/// The starting byte offset (inclusive)
|
|
16
|
+
start: u32,
|
|
17
|
+
/// The ending byte offset (exclusive)
|
|
18
|
+
end: u32,
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
impl Offset {
|
|
22
|
+
/// Creates a new `Offset` with the specified file ID and byte range.
|
|
23
|
+
///
|
|
24
|
+
/// # Arguments
|
|
25
|
+
///
|
|
26
|
+
/// * `start` - The starting byte position (inclusive)
|
|
27
|
+
/// * `end` - The ending byte position (exclusive)
|
|
28
|
+
#[must_use]
|
|
29
|
+
pub const fn new(start: u32, end: u32) -> Self {
|
|
30
|
+
Self { start, end }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/// # Panics
|
|
34
|
+
///
|
|
35
|
+
/// This function can panic if the Prism location offsets do not fit into a u32
|
|
36
|
+
#[must_use]
|
|
37
|
+
pub fn from_prism_location(location: &ruby_prism::Location) -> Self {
|
|
38
|
+
Self::new(
|
|
39
|
+
location
|
|
40
|
+
.start_offset()
|
|
41
|
+
.try_into()
|
|
42
|
+
.expect("Expected usize `start` to fit in `u32`"),
|
|
43
|
+
location
|
|
44
|
+
.end_offset()
|
|
45
|
+
.try_into()
|
|
46
|
+
.expect("Expected usize `end` to fit in `u32`"),
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/// # Panics
|
|
51
|
+
///
|
|
52
|
+
/// This function can panic if the RBS location offsets don't fit into u32
|
|
53
|
+
#[must_use]
|
|
54
|
+
pub fn from_rbs_location(location: &ruby_rbs::node::RBSLocationRange) -> Self {
|
|
55
|
+
Self::new(
|
|
56
|
+
location
|
|
57
|
+
.start()
|
|
58
|
+
.try_into()
|
|
59
|
+
.expect("RBS location start offset should fit into u32"),
|
|
60
|
+
location
|
|
61
|
+
.end()
|
|
62
|
+
.try_into()
|
|
63
|
+
.expect("RBS location end offset should fit into u32"),
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
#[must_use]
|
|
68
|
+
pub fn start(&self) -> u32 {
|
|
69
|
+
self.start
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
#[must_use]
|
|
73
|
+
pub fn end(&self) -> u32 {
|
|
74
|
+
self.end
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/// Converts an offset to a display range like `1:1-1:5`
|
|
78
|
+
#[must_use]
|
|
79
|
+
pub fn to_display_range(&self, document: &Document) -> String {
|
|
80
|
+
let loc = self.to_location(document).to_presentation();
|
|
81
|
+
format!(
|
|
82
|
+
"{}:{}-{}:{}",
|
|
83
|
+
loc.start_line(),
|
|
84
|
+
loc.start_col(),
|
|
85
|
+
loc.end_line(),
|
|
86
|
+
loc.end_col()
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/// Converts this offset to a 0-indexed [`Location`] with start and end line/column numbers.
|
|
91
|
+
#[must_use]
|
|
92
|
+
pub fn to_location(&self, document: &Document) -> Location {
|
|
93
|
+
let line_index = document.line_index();
|
|
94
|
+
let start = line_index.line_col(self.start().into());
|
|
95
|
+
let end = line_index.line_col(self.end().into());
|
|
96
|
+
Location {
|
|
97
|
+
start_line: start.line,
|
|
98
|
+
start_col: start.col,
|
|
99
|
+
end_line: end.line,
|
|
100
|
+
end_col: end.col,
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/// A resolved location within a file, with start and end line/column positions.
|
|
106
|
+
/// Values are 0-indexed by default. Use [`to_presentation`](Location::to_presentation)
|
|
107
|
+
/// for 1-indexed values suitable for display.
|
|
108
|
+
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
109
|
+
pub struct Location {
|
|
110
|
+
start_line: u32,
|
|
111
|
+
start_col: u32,
|
|
112
|
+
end_line: u32,
|
|
113
|
+
end_col: u32,
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
impl Location {
|
|
117
|
+
#[must_use]
|
|
118
|
+
pub fn start_line(&self) -> u32 {
|
|
119
|
+
self.start_line
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
#[must_use]
|
|
123
|
+
pub fn start_col(&self) -> u32 {
|
|
124
|
+
self.start_col
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
#[must_use]
|
|
128
|
+
pub fn end_line(&self) -> u32 {
|
|
129
|
+
self.end_line
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
#[must_use]
|
|
133
|
+
pub fn end_col(&self) -> u32 {
|
|
134
|
+
self.end_col
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/// Returns a new `Location` with 1-indexed values for display purposes.
|
|
138
|
+
#[must_use]
|
|
139
|
+
pub fn to_presentation(&self) -> Self {
|
|
140
|
+
Self {
|
|
141
|
+
start_line: self.start_line + 1,
|
|
142
|
+
start_col: self.start_col + 1,
|
|
143
|
+
end_line: self.end_line + 1,
|
|
144
|
+
end_col: self.end_col + 1,
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
use line_index::LineCol;
|
|
2
|
-
|
|
3
|
-
/// A position composed of line and columns. Note that all values are zero indexed and columns are based on the LSP
|
|
4
|
-
/// specification, meaning that they are always based in code units and can be retrieved for the 3 supported encodings
|
|
5
|
-
/// (Utf8, Utf16, Utf32)
|
|
6
|
-
pub type Position = LineCol;
|
|
1
|
+
use line_index::LineCol;
|
|
2
|
+
|
|
3
|
+
/// A position composed of line and columns. Note that all values are zero indexed and columns are based on the LSP
|
|
4
|
+
/// specification, meaning that they are always based in code units and can be retrieved for the 3 supported encodings
|
|
5
|
+
/// (Utf8, Utf16, Utf32)
|
|
6
|
+
pub type Position = LineCol;
|