mirror of
https://github.com/github/codeql.git
synced 2026-04-28 10:15:14 +02:00
Rust: add flag to turn off extractor path resolution
This commit is contained in:
@@ -57,6 +57,7 @@ pub struct Config {
|
||||
pub qltest: bool,
|
||||
pub qltest_cargo_check: bool,
|
||||
pub qltest_dependencies: Vec<String>,
|
||||
pub skip_path_resolution: bool,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use crate::diagnostics::{emit_extraction_diagnostics, ExtractionStep};
|
||||
use crate::rust_analyzer::path_to_file_id;
|
||||
use crate::translate::ResolvePaths;
|
||||
use crate::trap::TrapId;
|
||||
use anyhow::Context;
|
||||
use archive::Archiver;
|
||||
@@ -43,7 +44,7 @@ impl<'a> Extractor<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
fn extract(&mut self, rust_analyzer: &rust_analyzer::RustAnalyzer, file: &std::path::Path) {
|
||||
fn extract(&mut self, rust_analyzer: &RustAnalyzer, file: &Path, resolve_paths: ResolvePaths) {
|
||||
self.archiver.archive(file);
|
||||
|
||||
let before_parse = Instant::now();
|
||||
@@ -66,6 +67,7 @@ impl<'a> Extractor<'a> {
|
||||
label,
|
||||
line_index,
|
||||
semantics_info.as_ref().ok(),
|
||||
resolve_paths,
|
||||
);
|
||||
|
||||
for err in errors {
|
||||
@@ -102,12 +104,17 @@ impl<'a> Extractor<'a> {
|
||||
file: &Path,
|
||||
semantics: &Semantics<'_, RootDatabase>,
|
||||
vfs: &Vfs,
|
||||
resolve_paths: ResolvePaths,
|
||||
) {
|
||||
self.extract(&RustAnalyzer::new(vfs, semantics), file);
|
||||
self.extract(&RustAnalyzer::new(vfs, semantics), file, resolve_paths);
|
||||
}
|
||||
|
||||
pub fn extract_without_semantics(&mut self, file: &Path, reason: &str) {
|
||||
self.extract(&RustAnalyzer::WithoutSemantics { reason }, file);
|
||||
self.extract(
|
||||
&RustAnalyzer::WithoutSemantics { reason },
|
||||
file,
|
||||
ResolvePaths::No,
|
||||
);
|
||||
}
|
||||
|
||||
pub fn load_manifest(
|
||||
@@ -236,12 +243,19 @@ fn main() -> anyhow::Result<()> {
|
||||
extractor.extract_without_semantics(file, "no manifest found");
|
||||
}
|
||||
let cargo_config = cfg.to_cargo_config(&cwd()?);
|
||||
let resolve_paths = if cfg.skip_path_resolution {
|
||||
ResolvePaths::No
|
||||
} else {
|
||||
ResolvePaths::Yes
|
||||
};
|
||||
for (manifest, files) in map.values().filter(|(_, files)| !files.is_empty()) {
|
||||
if let Some((ref db, ref vfs)) = extractor.load_manifest(manifest, &cargo_config) {
|
||||
let semantics = Semantics::new(db);
|
||||
for file in files {
|
||||
match extractor.load_source(file, &semantics, vfs) {
|
||||
Ok(()) => extractor.extract_with_semantics(file, &semantics, vfs),
|
||||
Ok(()) => {
|
||||
extractor.extract_with_semantics(file, &semantics, vfs, resolve_paths)
|
||||
}
|
||||
Err(reason) => extractor.extract_without_semantics(file, &reason),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2,4 +2,4 @@ mod base;
|
||||
mod generated;
|
||||
mod mappings;
|
||||
|
||||
pub use base::Translator;
|
||||
pub use base::{ResolvePaths, Translator};
|
||||
|
||||
@@ -83,6 +83,12 @@ macro_rules! dispatch_to_tracing {
|
||||
};
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq)]
|
||||
pub enum ResolvePaths {
|
||||
Yes,
|
||||
No,
|
||||
}
|
||||
|
||||
pub struct Translator<'a> {
|
||||
pub trap: TrapFile,
|
||||
path: &'a str,
|
||||
@@ -90,6 +96,7 @@ pub struct Translator<'a> {
|
||||
line_index: LineIndex,
|
||||
file_id: Option<EditionedFileId>,
|
||||
pub semantics: Option<&'a Semantics<'a, RootDatabase>>,
|
||||
resolve_paths: ResolvePaths,
|
||||
}
|
||||
|
||||
const UNKNOWN_LOCATION: (LineCol, LineCol) =
|
||||
@@ -102,6 +109,7 @@ impl<'a> Translator<'a> {
|
||||
label: Label<generated::File>,
|
||||
line_index: LineIndex,
|
||||
semantic_info: Option<&FileSemanticInformation<'a>>,
|
||||
resolve_paths: ResolvePaths,
|
||||
) -> Translator<'a> {
|
||||
Translator {
|
||||
trap,
|
||||
@@ -110,6 +118,7 @@ impl<'a> Translator<'a> {
|
||||
line_index,
|
||||
file_id: semantic_info.map(|i| i.file_id),
|
||||
semantics: semantic_info.map(|i| i.semantics),
|
||||
resolve_paths,
|
||||
}
|
||||
}
|
||||
fn location(&self, range: TextRange) -> Option<(LineCol, LineCol)> {
|
||||
@@ -497,6 +506,9 @@ impl<'a> Translator<'a> {
|
||||
item: &T,
|
||||
label: Label<generated::Addressable>,
|
||||
) {
|
||||
if self.resolve_paths == ResolvePaths::No {
|
||||
return;
|
||||
}
|
||||
(|| {
|
||||
let sema = self.semantics.as_ref()?;
|
||||
let def = T::Hir::try_from_source(item, sema)?;
|
||||
@@ -517,6 +529,9 @@ impl<'a> Translator<'a> {
|
||||
item: &ast::Variant,
|
||||
label: Label<generated::Variant>,
|
||||
) {
|
||||
if self.resolve_paths == ResolvePaths::No {
|
||||
return;
|
||||
}
|
||||
(|| {
|
||||
let sema = self.semantics.as_ref()?;
|
||||
let def = sema.to_enum_variant_def(item)?;
|
||||
@@ -537,6 +552,9 @@ impl<'a> Translator<'a> {
|
||||
item: &impl PathAst,
|
||||
label: Label<generated::Resolvable>,
|
||||
) {
|
||||
if self.resolve_paths == ResolvePaths::No {
|
||||
return;
|
||||
}
|
||||
(|| {
|
||||
let path = item.path()?;
|
||||
let sema = self.semantics.as_ref()?;
|
||||
@@ -557,6 +575,9 @@ impl<'a> Translator<'a> {
|
||||
item: &ast::MethodCallExpr,
|
||||
label: Label<generated::MethodCallExpr>,
|
||||
) {
|
||||
if self.resolve_paths == ResolvePaths::No {
|
||||
return;
|
||||
}
|
||||
(|| {
|
||||
let sema = self.semantics.as_ref()?;
|
||||
let resolved = sema.resolve_method_call_fallback(item)?;
|
||||
|
||||
Reference in New Issue
Block a user