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

Commit 34ec1a6

Browse files
oppiliappanHendrik van Antwerpen
authored andcommitted
add intermediary data structures for ser/de
- StackGraph::apply_filter converts a StackGraph into a serde-friendly intermediate data-structure - this data structure can be used to serialize json with serde_json::to_value - this data structure can be used deserialize json with serde_json::from_value - an auxilliary function called reconstruct is introduced, but not implemented. it proposes the type-signature to convert the intermediary structure back to a StackGraph
1 parent e335b50 commit 34ec1a6

File tree

4 files changed

+369
-37
lines changed

4 files changed

+369
-37
lines changed

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: 5 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,
@@ -52,9 +53,11 @@ pub struct Position {
5253
pub column: Offset,
5354
/// The UTF-8 byte indexes (within the file) of the start and end of the line containing the
5455
/// character
56+
#[cfg_attr(feature = "serde", serde(skip))]
5557
pub containing_line: Range<usize>,
5658
/// The UTF-8 byte indexes (within the file) of the start and end of the line containing the
5759
/// character, with any leading and trailing whitespace removed
60+
#[cfg_attr(feature = "serde", serde(skip))]
5861
pub trimmed_line: Range<usize>,
5962
}
6063

@@ -106,6 +109,7 @@ impl PartialOrd<tree_sitter::Point> for Position {
106109
/// All of the position information that we have about a range of content in a source file
107110
#[repr(C)]
108111
#[derive(Clone, Debug, Default, Eq, Hash, PartialEq)]
112+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
109113
pub struct Span {
110114
pub start: Position,
111115
pub end: Position,
@@ -141,6 +145,7 @@ impl PartialOrd for Span {
141145
///
142146
/// All offsets are 0-indexed.
143147
#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
148+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
144149
pub struct Offset {
145150
/// The number of UTF-8-encoded bytes appearing before this character in the string
146151
pub utf8_offset: usize,

stack-graphs/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ edition = "2018"
1414

1515
[features]
1616
copious-debugging = []
17-
json = ["serde", "serde_json"]
17+
json = ["serde", "serde_json", "lsp-positions/serde"]
1818

1919
[lib]
2020
# All of our tests are in the tests/it "integration" test executable.

0 commit comments

Comments
 (0)