Skip to content

Commit 9814aef

Browse files
committed
Address review comment
1 parent f17f375 commit 9814aef

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

rust/extractor/src/crate_graph.rs

+4-18
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use chalk_ir::IntTy;
66
use chalk_ir::Scalar;
77
use chalk_ir::UintTy;
88
use chalk_ir::{FloatTy, Safety};
9-
use codeql_extractor::trap::Location;
109
use itertools::Itertools;
1110
use ra_ap_base_db::CrateGraph;
1211
use ra_ap_base_db::CrateId;
@@ -78,29 +77,16 @@ pub fn extract_crate_graph(trap_provider: &trap::TrapFileProvider, db: &RootData
7877
continue;
7978
}
8079
let krate = &crate_graph[krate_id];
81-
let module = emit_module(
80+
let root_module = emit_module(
8281
&crate_graph,
8382
db,
8483
db.crate_def_map(krate_id).as_ref(),
8584
"crate",
8685
DefMap::ROOT,
8786
&mut trap,
8887
);
89-
let file_label = trap.emit_file(root_module_file).as_untyped();
90-
let location_label = codeql_extractor::extractor::location_label(
91-
&mut trap.writer,
92-
Location {
93-
file_label,
94-
start_line: 0,
95-
start_column: 0,
96-
end_line: 0,
97-
end_column: 0,
98-
},
99-
);
100-
trap.writer.add_tuple(
101-
"locatable_locations",
102-
vec![module.into(), location_label.into()],
103-
);
88+
let file_label = trap.emit_file(root_module_file);
89+
trap.emit_file_only_location(file_label, root_module);
10490

10591
let element = generated::Crate {
10692
id: trap::TrapId::Key(format!("{}:{hash}", root_module_file.display())),
@@ -109,7 +95,7 @@ pub fn extract_crate_graph(trap_provider: &trap::TrapFileProvider, db: &RootData
10995
.as_ref()
11096
.map(|x| x.canonical_name().to_string()),
11197
version: krate.version.to_owned(),
112-
module: Some(module),
98+
module: Some(root_module),
11399
cfg_options: krate
114100
.cfg_options
115101
.as_ref()

rust/extractor/src/trap.rs

+20
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,26 @@ impl TrapFile {
171171
);
172172
}
173173

174+
pub fn emit_file_only_location<E: TrapClass>(
175+
&mut self,
176+
file_label: Label<generated::File>,
177+
entity_label: Label<E>,
178+
) {
179+
let location_label = extractor::location_label(
180+
&mut self.writer,
181+
trap::Location {
182+
file_label: file_label.as_untyped(),
183+
start_line: 0,
184+
start_column: 0,
185+
end_line: 0,
186+
end_column: 0,
187+
},
188+
);
189+
self.writer.add_tuple(
190+
"locatable_locations",
191+
vec![entity_label.into(), location_label.into()],
192+
);
193+
}
174194
pub fn emit_diagnostic(
175195
&mut self,
176196
severity: DiagnosticSeverity,

0 commit comments

Comments
 (0)