Skip to content

feat: pull diagnostics #153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions crates/pg_cli/src/changed.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use crate::CliDiagnostic;
use pg_configuration::PartialConfiguration;
use pg_fs::FileSystem;
use pg_workspace_new::DynRef;
use std::ffi::OsString;

pub(crate) fn get_changed_files(
fs: &DynRef<'_, dyn FileSystem>,
configuration: &PartialConfiguration,
since: Option<&str>,
) -> Result<Vec<OsString>, CliDiagnostic> {
let default_branch = configuration
.vcs
.as_ref()
.and_then(|v| v.default_branch.as_ref());

let base = match (since, default_branch) {
(Some(since), Some(_)) => since,
(Some(since), None) => since,
(None, Some(branch)) => branch,
(None, None) => return Err(CliDiagnostic::incompatible_end_configuration("The `--changed` flag was set, but couldn't determine the base to compare against. Either set configuration.vcs.default_branch or use the --since argument.")),
};

let changed_files = fs.get_changed_files(base)?;

let filtered_changed_files = changed_files.iter().map(OsString::from).collect::<Vec<_>>();

Ok(filtered_changed_files)
}

pub(crate) fn get_staged_files(
fs: &DynRef<'_, dyn FileSystem>,
) -> Result<Vec<OsString>, CliDiagnostic> {
let staged_files = fs.get_staged_files()?;

let filtered_staged_files = staged_files.iter().map(OsString::from).collect::<Vec<_>>();

Ok(filtered_staged_files)
}
77 changes: 77 additions & 0 deletions crates/pg_cli/src/commands/check.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// use super::{determine_fix_file_mode, FixFileModeOptions, LoadEditorConfig};
use crate::cli_options::CliOptions;
// use crate::commands::{get_files_to_process_with_cli_options, CommandRunner};
use crate::{CliDiagnostic, Execution, TraversalMode};
use pg_configuration::PartialConfiguration;
use pg_console::Console;
// use biome_deserialize::Merge;
use pg_fs::FileSystem;
use pg_workspace_new::{configuration::LoadedConfiguration, DynRef, Workspace, WorkspaceError};
use std::ffi::OsString;

use super::{determine_fix_file_mode, get_files_to_process_with_cli_options, CommandRunner};

pub(crate) struct CheckCommandPayload {
pub(crate) write: bool,
pub(crate) fix: bool,
pub(crate) unsafe_: bool,
pub(crate) configuration: Option<PartialConfiguration>,
pub(crate) paths: Vec<OsString>,
pub(crate) stdin_file_path: Option<String>,
pub(crate) staged: bool,
pub(crate) changed: bool,
pub(crate) since: Option<String>,
}

impl CommandRunner for CheckCommandPayload {
const COMMAND_NAME: &'static str = "check";

fn merge_configuration(
&mut self,
loaded_configuration: LoadedConfiguration,
fs: &DynRef<'_, dyn FileSystem>,
console: &mut dyn Console,
) -> Result<PartialConfiguration, WorkspaceError> {
let LoadedConfiguration { configuration, .. } = loaded_configuration;

Ok(configuration)
}

fn get_files_to_process(
&self,
fs: &DynRef<'_, dyn FileSystem>,
configuration: &PartialConfiguration,
) -> Result<Vec<OsString>, CliDiagnostic> {
let paths = get_files_to_process_with_cli_options(
self.since.as_deref(),
self.changed,
self.staged,
fs,
configuration,
)?
.unwrap_or(self.paths.clone());

Ok(paths)
}

fn get_stdin_file_path(&self) -> Option<&str> {
self.stdin_file_path.as_deref()
}

fn should_write(&self) -> bool {
self.write || self.fix
}

fn get_execution(
&self,
cli_options: &CliOptions,
console: &mut dyn Console,
_workspace: &dyn Workspace,
) -> Result<Execution, CliDiagnostic> {
Ok(Execution::new(TraversalMode::Check {
stdin: self.get_stdin(console)?,
vcs_targeted: (self.staged, self.changed).into(),
})
.set_report(cli_options))
}
}
8 changes: 4 additions & 4 deletions crates/pg_cli/src/commands/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,13 @@ pub(crate) fn read_most_recent_log_file(
/// `pglsp-logs/server.log.yyyy-MM-dd-HH` files inside the system temporary
/// directory)
fn setup_tracing_subscriber(log_path: Option<PathBuf>, log_file_name_prefix: Option<String>) {
let biome_log_path = log_path.unwrap_or(pg_fs::ensure_cache_dir().join("pglsp-logs"));
let pglsp_log_path = log_path.unwrap_or(pg_fs::ensure_cache_dir().join("pglsp-logs"));
let appender_builder = tracing_appender::rolling::RollingFileAppender::builder();
let file_appender = appender_builder
.filename_prefix(log_file_name_prefix.unwrap_or(String::from("server.log")))
.max_log_files(7)
.rotation(Rotation::HOURLY)
.build(biome_log_path)
.build(pglsp_log_path)
.expect("Failed to start the logger for the daemon.");

registry()
Expand Down Expand Up @@ -241,7 +241,7 @@ pub fn default_pglsp_log_path() -> PathBuf {
/// - All spans and events at level debug in crates whose name starts with `biome`
struct LoggingFilter;

/// Tracing filter used for spans emitted by `biome*` crates
/// Tracing filter used for spans emitted by `pglsp*` crates
const SELF_FILTER: LevelFilter = if cfg!(debug_assertions) {
LevelFilter::TRACE
} else {
Expand All @@ -250,7 +250,7 @@ const SELF_FILTER: LevelFilter = if cfg!(debug_assertions) {

impl LoggingFilter {
fn is_enabled(&self, meta: &Metadata<'_>) -> bool {
let filter = if meta.target().starts_with("biome") {
let filter = if meta.target().starts_with("pglsp") {
SELF_FILTER
} else {
LevelFilter::INFO
Expand Down
Loading
Loading