Skip to content
This repository was archived by the owner on Sep 9, 2025. It is now read-only.

Commit eab5048

Browse files
author
Hendrik van Antwerpen
authored
Merge pull request #180 from nerdypepper/impl-deser-simple
implement Deserialize for stack-graphs
2 parents ba57851 + 8ebe511 commit eab5048

File tree

16 files changed

+1197
-489
lines changed

16 files changed

+1197
-489
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
Douglas Creager <[email protected]>
22
Hendrik van Antwerpen <[email protected]>
3+

lsp-positions/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ default = ["tree-sitter"]
2323
memchr = "2.4"
2424
tree-sitter = { version=">= 0.19", optional=true }
2525
unicode-segmentation = { version="1.8" }
26+
serde = { version="1", optional=true, features=["derive"] }

lsp-positions/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ fn utf16_len(string: &str) -> usize {
4444
/// All of the position information that we have about a character in a source file
4545
#[repr(C)]
4646
#[derive(Clone, Debug, Default, Eq, Hash, PartialEq)]
47+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
4748
pub struct Position {
4849
/// The 0-indexed line number containing the character
4950
pub line: usize,
@@ -106,6 +107,7 @@ impl PartialOrd<tree_sitter::Point> for Position {
106107
/// All of the position information that we have about a range of content in a source file
107108
#[repr(C)]
108109
#[derive(Clone, Debug, Default, Eq, Hash, PartialEq)]
110+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
109111
pub struct Span {
110112
pub start: Position,
111113
pub end: Position,
@@ -141,6 +143,7 @@ impl PartialOrd for Span {
141143
///
142144
/// All offsets are 0-indexed.
143145
#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
146+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
144147
pub struct Offset {
145148
/// The number of UTF-8-encoded bytes appearing before this character in the string
146149
pub utf8_offset: usize,

stack-graphs/Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ edition = "2018"
1414

1515
[features]
1616
copious-debugging = []
17-
json = ["serde", "serde_json"]
17+
serde = ["dep:serde", "lsp-positions/serde"]
18+
json = ["serde", "serde_json", "lsp-positions/serde"]
1819

1920
[lib]
2021
# All of our tests are in the tests/it "integration" test executable.
@@ -29,7 +30,7 @@ fxhash = "0.2"
2930
itertools = "0.10"
3031
libc = "0.2"
3132
lsp-positions = { version="0.3", path="../lsp-positions" }
32-
serde = { version="1.0", optional=true }
33+
serde = { version="1.0", optional=true, features = ["derive"] }
3334
serde_json = { version="1.0", optional=true }
3435
smallvec = { version="1.6", features=["union"] }
3536
thiserror = { version="1.0" }
@@ -38,6 +39,7 @@ thiserror = { version="1.0" }
3839
itertools = "0.10"
3940
maplit = "1.0"
4041
pretty_assertions = "0.7"
42+
serde_json = { version="1.0" }
4143

4244
[package.metadata.docs.rs]
43-
all-features = true
45+
all-features = true

stack-graphs/src/graph.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,8 @@ pub struct NodeID {
429429
local_id: u32,
430430
}
431431

432-
const ROOT_NODE_ID: u32 = 1;
433-
const JUMP_TO_NODE_ID: u32 = 2;
432+
pub(crate) const ROOT_NODE_ID: u32 = 1;
433+
pub(crate) const JUMP_TO_NODE_ID: u32 = 2;
434434

435435
impl NodeID {
436436
/// Returns the ID of the singleton _root node_.

0 commit comments

Comments
 (0)