-
Notifications
You must be signed in to change notification settings - Fork 114
Expand file tree
/
Copy pathcheck.rs
More file actions
68 lines (59 loc) · 2.34 KB
/
check.rs
File metadata and controls
68 lines (59 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use pglt_analyse::RuleCategoriesBuilder;
use pglt_diagnostics::{Error, category};
use crate::execute::diagnostics::ResultExt;
use crate::execute::process_file::workspace_file::WorkspaceFile;
use crate::execute::process_file::{FileResult, FileStatus, Message, SharedTraversalOptions};
use std::path::Path;
use std::sync::atomic::Ordering;
/// Lints a single file and returns a [FileResult]
pub(crate) fn check_file<'ctx>(
ctx: &'ctx SharedTraversalOptions<'ctx, '_>,
path: &Path,
) -> FileResult {
let mut workspace_file = WorkspaceFile::new(ctx, path)?;
check_with_guard(ctx, &mut workspace_file)
}
pub(crate) fn check_with_guard<'ctx>(
ctx: &'ctx SharedTraversalOptions<'ctx, '_>,
workspace_file: &mut WorkspaceFile,
) -> FileResult {
tracing::info_span!("Processes check", path =? workspace_file.path.display()).in_scope(
move || {
let input = workspace_file.input()?;
let changed = false;
let (only, skip) = (Vec::new(), Vec::new());
let max_diagnostics = ctx.remaining_diagnostics.load(Ordering::Relaxed);
let pull_diagnostics_result = workspace_file
.guard()
.pull_diagnostics(
RuleCategoriesBuilder::default().all().build(),
max_diagnostics,
only,
skip,
)
.with_file_path_and_code(
workspace_file.path.display().to_string(),
category!("check"),
)?;
let no_diagnostics = pull_diagnostics_result.diagnostics.is_empty()
&& pull_diagnostics_result.skipped_diagnostics == 0;
if !no_diagnostics {
ctx.push_message(Message::Diagnostics {
name: workspace_file.path.display().to_string(),
content: input,
diagnostics: pull_diagnostics_result
.diagnostics
.into_iter()
.map(Error::from)
.collect(),
skipped_diagnostics: pull_diagnostics_result.skipped_diagnostics as u32,
});
}
if changed {
Ok(FileStatus::Changed)
} else {
Ok(FileStatus::Unchanged)
}
},
)
}