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

Commit 2f513a8

Browse files
author
Rick Winfrey
authored
Merge pull request #281 from github/fully-qualified-name
Add `fully_qualified_name` field to `SourceInfo`
2 parents 4834331 + 4707ae9 commit 2f513a8

File tree

7 files changed

+23
-5
lines changed

7 files changed

+23
-5
lines changed

stack-graphs/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- New `Defines` and `Refers` assertions test for the presence of definitions and references, respectively, without resolution.
1313
- A method `StackGraph::get_file` to look up an existing file.
14+
- A field named `fully_qualified_name` was added to `SourceInfo`.
1415

1516
### Changed
1617

stack-graphs/include/stack-graphs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,9 @@ struct sg_source_info {
259259
// If you need one of these to make the type checker happy, but you don't have one, just use
260260
// sg_span::default(), as this will correspond to the all-0s spans which mean "no definiens".
261261
struct sg_span definiens_span;
262+
// The fully qualified name is a representation of the symbol that captures its name and its
263+
// embedded context (e.g. `foo.bar` for the symbol `bar` defined in the module `foo`).
264+
sg_string_handle fully_qualified_name;
262265
};
263266

264267
// An array of all of the source information in a stack graph. Source information is associated

stack-graphs/src/c.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,12 +627,14 @@ pub struct sg_source_info {
627627
pub syntax_type: sg_string_handle,
628628
/// The full content of the line containing this node in its source file.
629629
pub containing_line: sg_string_handle,
630-
631630
/// The location in its containing file of the source code that this node's definiens represents.
632631
/// This is used for things like the bodies of functions, rather than the RHSes of equations.
633632
/// If you need one of these to make the type checker happy, but you don't have one, just use
634633
/// sg_span::default(), as this will correspond to the all-0s spans which mean "no definiens".
635634
pub definiens_span: sg_span,
635+
/// The fully qualified name is a representation of the symbol that captures its name and its
636+
/// embedded context (e.g. `foo.bar` for the symbol `bar` defined in the module `foo`).
637+
pub fully_qualified_name: sg_string_handle,
636638
}
637639

638640
/// All of the position information that we have about a range of content in a source file

stack-graphs/src/graph.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,14 +1337,17 @@ 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.
13441344
/// This is used for things like the bodies of functions, rather than the RHSes of equations.
13451345
/// If you need one of these to make the type checker happy, but you don't have one, just use
13461346
/// lsp_positions::Span::default(), as this will correspond to the all-0s spans which mean "no definiens".
13471347
pub definiens_span: lsp_positions::Span,
1348+
/// The fully qualified name is a representation of the symbol that captures its name and its
1349+
/// embedded context (e.g. `foo.bar` for the symbol `bar` defined in the module `foo`).
1350+
pub fully_qualified_name: ControlledOption<Handle<InternedString>>,
13481351
}
13491352

13501353
impl StackGraph {
@@ -1565,13 +1568,16 @@ impl StackGraph {
15651568
span: source_info.span.clone(),
15661569
syntax_type: source_info
15671570
.syntax_type
1568-
.map(|st| self.add_string(&other[st])),
1571+
.into_option()
1572+
.map(|st| self.add_string(&other[st]))
1573+
.into(),
15691574
containing_line: source_info
15701575
.containing_line
15711576
.into_option()
15721577
.map(|cl| self.add_string(&other[cl]))
15731578
.into(),
15741579
definiens_span: source_info.definiens_span.clone(),
1580+
fully_qualified_name: ControlledOption::default(),
15751581
};
15761582
}
15771583
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/c/nodes.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,7 @@ fn can_create_source_info() {
674674

675675
let syntax_type = add_string(graph, "function");
676676
let containing_line = add_string(graph, "def foo():");
677+
let fully_qualified_name = add_string(graph, "bar.foo");
677678

678679
let mut infos = [sg_node_source_info {
679680
node: handles[1],
@@ -682,6 +683,7 @@ fn can_create_source_info() {
682683
syntax_type,
683684
containing_line,
684685
definiens_span: sg_span::default(),
686+
fully_qualified_name,
685687
},
686688
}];
687689
infos[0].source_info.span.start.line = 17;

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

Lines changed: 3 additions & 0 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,6 +78,7 @@ pub fn new() -> StackGraph {
7778
syntax_type: str_var.into(),
7879
containing_line: str_line0.into(),
7980
definiens_span: Span::default(),
81+
fully_qualified_name: ControlledOption::default(),
8082
};
8183
*graph.source_info_mut(ref_x) = SourceInfo {
8284
span: Span {
@@ -104,6 +106,7 @@ pub fn new() -> StackGraph {
104106
syntax_type: str_var.into(),
105107
containing_line: str_line1.into(),
106108
definiens_span: Span::default(),
109+
fully_qualified_name: ControlledOption::default(),
107110
};
108111

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

0 commit comments

Comments
 (0)