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

Commit 4707ae9

Browse files
author
Rick Winfrey
committed
Update SourceInfo syntax_type and fully_qualified_name fields' type to ControlledOption
1 parent e28eb4a commit 4707ae9

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

stack-graphs/src/graph.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,7 +1337,7 @@ pub struct SourceInfo {
13371337
/// The location in its containing file of the source code that this node represents.
13381338
pub span: lsp_positions::Span,
13391339
/// The kind of syntax entity this node represents (e.g. `function`, `class`, `method`, etc.).
1340-
pub syntax_type: Option<Handle<InternedString>>,
1340+
pub syntax_type: ControlledOption<Handle<InternedString>>,
13411341
/// The full content of the line containing this node in its source file.
13421342
pub containing_line: ControlledOption<Handle<InternedString>>,
13431343
/// The location in its containing file of the source code that this node's definiens represents.
@@ -1347,7 +1347,7 @@ pub struct SourceInfo {
13471347
pub definiens_span: lsp_positions::Span,
13481348
/// The fully qualified name is a representation of the symbol that captures its name and its
13491349
/// embedded context (e.g. `foo.bar` for the symbol `bar` defined in the module `foo`).
1350-
pub fully_qualified_name: Option<Handle<InternedString>>,
1350+
pub fully_qualified_name: ControlledOption<Handle<InternedString>>,
13511351
}
13521352

13531353
impl StackGraph {
@@ -1568,14 +1568,16 @@ impl StackGraph {
15681568
span: source_info.span.clone(),
15691569
syntax_type: source_info
15701570
.syntax_type
1571-
.map(|st| self.add_string(&other[st])),
1571+
.into_option()
1572+
.map(|st| self.add_string(&other[st]))
1573+
.into(),
15721574
containing_line: source_info
15731575
.containing_line
15741576
.into_option()
15751577
.map(|cl| self.add_string(&other[cl]))
15761578
.into(),
15771579
definiens_span: source_info.definiens_span.clone(),
1578-
fully_qualified_name: None,
1580+
fully_qualified_name: ControlledOption::default(),
15791581
};
15801582
}
15811583
if let Some(debug_info) = other.node_debug_info(other_node) {

stack-graphs/src/serde/graph.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ impl StackGraph {
141141
syntax_type: source_info
142142
.syntax_type
143143
.as_ref()
144-
.map(|st| graph.add_string(&st)),
144+
.map(|st| graph.add_string(&st))
145+
.into(),
145146
..Default::default()
146147
};
147148
}
@@ -444,7 +445,7 @@ impl crate::graph::StackGraph {
444445
) -> Option<SourceInfo> {
445446
self.source_info(handle).map(|info| SourceInfo {
446447
span: info.span.clone(),
447-
syntax_type: info.syntax_type.map(|ty| self[ty].to_owned()),
448+
syntax_type: info.syntax_type.into_option().map(|ty| self[ty].to_owned()),
448449
})
449450
}
450451

stack-graphs/tests/it/test_graphs/simple.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// Please see the LICENSE-APACHE or LICENSE-MIT files in this distribution for license details.
66
// ------------------------------------------------------------------------------------------------
77

8+
use controlled_option::ControlledOption;
89
use lsp_positions::Offset;
910
use lsp_positions::Position;
1011
use lsp_positions::Span;
@@ -77,7 +78,7 @@ pub fn new() -> StackGraph {
7778
syntax_type: str_var.into(),
7879
containing_line: str_line0.into(),
7980
definiens_span: Span::default(),
80-
fully_qualified_name: None,
81+
fully_qualified_name: ControlledOption::default(),
8182
};
8283
*graph.source_info_mut(ref_x) = SourceInfo {
8384
span: Span {
@@ -105,7 +106,7 @@ pub fn new() -> StackGraph {
105106
syntax_type: str_var.into(),
106107
containing_line: str_line1.into(),
107108
definiens_span: Span::default(),
108-
fully_qualified_name: None,
109+
fully_qualified_name: ControlledOption::default(),
109110
};
110111

111112
let str_dsl_var = graph.add_string("dsl_var");

0 commit comments

Comments
 (0)