Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions crates/pglt_analyse/src/categories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,38 +74,34 @@ impl ActionCategory {
match self {
ActionCategory::QuickFix(tag) => {
if tag.is_empty() {
Cow::Borrowed("quickfix.pglsp")
Cow::Borrowed("quickfix.pglt")
} else {
Cow::Owned(format!("quickfix.pglsp.{tag}"))
Cow::Owned(format!("quickfix.pglt.{tag}"))
}
}

ActionCategory::Refactor(RefactorKind::None) => Cow::Borrowed("refactor.pglsp"),
ActionCategory::Refactor(RefactorKind::None) => Cow::Borrowed("refactor.pglt"),
ActionCategory::Refactor(RefactorKind::Extract) => {
Cow::Borrowed("refactor.extract.pglsp")
}
ActionCategory::Refactor(RefactorKind::Inline) => {
Cow::Borrowed("refactor.inline.pglsp")
Cow::Borrowed("refactor.extract.pglt")
}
ActionCategory::Refactor(RefactorKind::Inline) => Cow::Borrowed("refactor.inline.pglt"),
ActionCategory::Refactor(RefactorKind::Rewrite) => {
Cow::Borrowed("refactor.rewrite.pglsp")
Cow::Borrowed("refactor.rewrite.pglt")
}
ActionCategory::Refactor(RefactorKind::Other(tag)) => {
Cow::Owned(format!("refactor.{tag}.pglsp"))
Cow::Owned(format!("refactor.{tag}.pglt"))
}

ActionCategory::Source(SourceActionKind::None) => Cow::Borrowed("source.pglsp"),
ActionCategory::Source(SourceActionKind::FixAll) => {
Cow::Borrowed("source.fixAll.pglsp")
}
ActionCategory::Source(SourceActionKind::None) => Cow::Borrowed("source.pglt"),
ActionCategory::Source(SourceActionKind::FixAll) => Cow::Borrowed("source.fixAll.pglt"),
ActionCategory::Source(SourceActionKind::OrganizeImports) => {
Cow::Borrowed("source.organizeImports.pglsp")
Cow::Borrowed("source.organizeImports.pglt")
}
ActionCategory::Source(SourceActionKind::Other(tag)) => {
Cow::Owned(format!("source.{tag}.pglsp"))
Cow::Owned(format!("source.{tag}.pglt"))
}

ActionCategory::Other(tag) => Cow::Owned(format!("{tag}.pglsp")),
ActionCategory::Other(tag) => Cow::Owned(format!("{tag}.pglt")),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/pglt_analyse/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl AnalyserRules {
/// A set of information useful to the analyser infrastructure
#[derive(Debug, Default)]
pub struct AnalyserOptions {
/// A data structured derived from the [`pglsp.toml`] file
/// A data structured derived from the [`pglt.toml`] file
pub rules: AnalyserRules,
}

Expand Down
6 changes: 3 additions & 3 deletions crates/pglt_analyser/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Let's assume that the rule we implement support the following options:
- `threshold`: an integer between 0 and 255;
- `behaviorExceptions`: an array of strings.

We would like to set the options in the `pglsp.toml` configuration file:
We would like to set the options in the `pglt.toml` configuration file:

```toml
[linter.rules.safety.myRule]
Expand Down Expand Up @@ -132,9 +132,9 @@ We currently require implementing _serde_'s traits `Deserialize`/`Serialize`.

Also, we use other `serde` macros to adjust the JSON configuration:

- `rename_all = "snake_case"`: it renames all fields in camel-case, so they are in line with the naming style of the `pglsp.toml`.
- `rename_all = "snake_case"`: it renames all fields in camel-case, so they are in line with the naming style of the `pglt.toml`.
- `deny_unknown_fields`: it raises an error if the configuration contains extraneous fields.
- `default`: it uses the `Default` value when the field is missing from `pglsp.toml`. This macro makes the field optional.
- `default`: it uses the `Default` value when the field is missing from `pglt.toml`. This macro makes the field optional.

You can simply use a derive macros:

Expand Down
14 changes: 7 additions & 7 deletions crates/pglt_base_db/src/change.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,13 +292,13 @@ mod tests {
use text_size::{TextRange, TextSize};

use crate::{change::Change, document::StatementRef, Document, DocumentChange};
use pglt_fs::PgLspPath;
use pglt_fs::PgLTPath;

#[test]
fn test_document_apply_changes() {
let input = "select id from users;\nselect * from contacts;";

let mut d = Document::new(PgLspPath::new("test.sql"), Some(input.to_string()));
let mut d = Document::new(PgLTPath::new("test.sql"), Some(input.to_string()));

assert_eq!(d.statement_ranges.len(), 2);

Expand All @@ -317,15 +317,15 @@ mod tests {
assert_eq!(
changed[0].statement().to_owned(),
StatementRef {
document_url: PgLspPath::new("test.sql"),
document_url: PgLTPath::new("test.sql"),
text: "select id from users;".to_string(),
idx: 0
}
);
assert_eq!(
changed[1].statement().to_owned(),
StatementRef {
document_url: PgLspPath::new("test.sql"),
document_url: PgLTPath::new("test.sql"),
text: "select * from contacts;".to_string(),
idx: 1
}
Expand All @@ -350,7 +350,7 @@ mod tests {
fn test_document_apply_changes_at_end_of_statement() {
let input = "select id from\nselect * from contacts;";

let mut d = Document::new(PgLspPath::new("test.sql"), Some(input.to_string()));
let mut d = Document::new(PgLTPath::new("test.sql"), Some(input.to_string()));

assert_eq!(d.statement_ranges.len(), 2);

Expand Down Expand Up @@ -393,7 +393,7 @@ mod tests {

#[test]
fn test_document_apply_changes_replacement() {
let path = PgLspPath::new("test.sql");
let path = PgLTPath::new("test.sql");

let mut doc = Document::new(path, None);

Expand Down Expand Up @@ -508,7 +508,7 @@ mod tests {
fn test_document_apply_changes_within_statement() {
let input = "select id from users;\nselect * from contacts;";

let mut d = Document::new(PgLspPath::new("test.sql"), Some(input.to_string()));
let mut d = Document::new(PgLTPath::new("test.sql"), Some(input.to_string()));

assert_eq!(d.statement_ranges.len(), 2);

Expand Down
12 changes: 6 additions & 6 deletions crates/pglt_base_db/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ use std::{hash::Hash, hash::Hasher, ops::RangeBounds};
use line_index::LineIndex;
use text_size::{TextRange, TextSize};

use pglt_fs::PgLspPath;
use pglt_fs::PgLTPath;

extern crate test;

/// Represents a sql source file, and contains a list of statements represented by their ranges
pub struct Document {
/// The url of the document
pub url: PgLspPath,
pub url: PgLTPath,
/// The text of the document
pub text: String,
/// The version of the document
Expand All @@ -33,15 +33,15 @@ impl Hash for Document {
/// Note that the ref must include all information needed to uniquely identify the statement, so that it can be used as a key in a hashmap.
#[derive(Debug, Hash, PartialEq, Eq, Clone)]
pub struct StatementRef {
pub document_url: PgLspPath,
pub document_url: PgLTPath,
// TODO use string interner for text
pub text: String,
pub idx: usize,
}

impl Document {
/// Create a new document
pub fn new(url: PgLspPath, text: Option<String>) -> Document {
pub fn new(url: PgLTPath, text: Option<String>) -> Document {
Document {
version: 0,
line_index: LineIndex::new(text.as_ref().unwrap_or(&"".to_string())),
Expand Down Expand Up @@ -162,14 +162,14 @@ impl Document {
#[cfg(test)]
mod tests {

use pglt_fs::PgLspPath;
use pglt_fs::PgLTPath;
use text_size::{TextRange, TextSize};

use crate::Document;

#[test]
fn test_statements_at_range() {
let url = PgLspPath::new("test.sql");
let url = PgLTPath::new("test.sql");

let doc = Document::new(
url,
Expand Down
2 changes: 1 addition & 1 deletion crates/pglt_cli/src/cli_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub struct CliOptions {
#[bpaf(long("verbose"), switch, fallback(false))]
pub verbose: bool,

/// Set the file path to the configuration file, or the directory path to find `pglsp.toml`.
/// Set the file path to the configuration file, or the directory path to find `pglt.toml`.
/// If used, it disables the default configuration file resolution.
#[bpaf(long("config-path"), argument("PATH"), optional)]
pub config_path: Option<String>,
Expand Down
10 changes: 5 additions & 5 deletions crates/pglt_cli/src/commands/clean.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use crate::commands::daemon::default_pglsp_log_path;
use crate::commands::daemon::default_pglt_log_path;
use crate::{CliDiagnostic, CliSession};
use pglt_flags::pglsp_env;
use pglt_flags::pglt_env;
use std::fs::{create_dir, remove_dir_all};
use std::path::PathBuf;

/// Runs the clean command
pub fn clean(_cli_session: CliSession) -> Result<(), CliDiagnostic> {
let logs_path = pglsp_env()
.pglsp_log_path
let logs_path = pglt_env()
.pglt_log_path
.value()
.map_or(default_pglsp_log_path(), PathBuf::from);
.map_or(default_pglt_log_path(), PathBuf::from);
remove_dir_all(logs_path.clone()).and_then(|_| create_dir(logs_path))?;
Ok(())
}
20 changes: 10 additions & 10 deletions crates/pglt_cli/src/commands/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ pub(crate) fn read_most_recent_log_file(
log_path: Option<PathBuf>,
log_file_name_prefix: String,
) -> io::Result<Option<String>> {
let pglsp_log_path = log_path.unwrap_or(default_pglsp_log_path());
let pglt_log_path = log_path.unwrap_or(default_pglt_log_path());

let most_recent = fs::read_dir(pglsp_log_path)?
let most_recent = fs::read_dir(pglt_log_path)?
.flatten()
.filter(|file| file.file_type().is_ok_and(|ty| ty.is_file()))
.filter_map(|file| {
Expand All @@ -203,16 +203,16 @@ pub(crate) fn read_most_recent_log_file(
/// The events received by the subscriber are filtered at the `info` level,
/// then printed using the [HierarchicalLayer] layer, and the resulting text
/// is written to log files rotated on a hourly basis (in
/// `pglsp-logs/server.log.yyyy-MM-dd-HH` files inside the system temporary
/// `pglt-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 pglsp_log_path = log_path.unwrap_or(pglt_fs::ensure_cache_dir().join("pglsp-logs"));
let pglt_log_path = log_path.unwrap_or(pglt_fs::ensure_cache_dir().join("pglt-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(pglsp_log_path)
.build(pglt_log_path)
.expect("Failed to start the logger for the daemon.");

registry()
Expand All @@ -229,19 +229,19 @@ fn setup_tracing_subscriber(log_path: Option<PathBuf>, log_file_name_prefix: Opt
.init();
}

pub fn default_pglsp_log_path() -> PathBuf {
pub fn default_pglt_log_path() -> PathBuf {
match env::var_os("PGLSP_LOG_PATH") {
Some(directory) => PathBuf::from(directory),
None => pglt_fs::ensure_cache_dir().join("pglsp-logs"),
None => pglt_fs::ensure_cache_dir().join("pglt-logs"),
}
}

/// Tracing filter enabling:
/// - All spans and events at level info or higher
/// - All spans and events at level debug in crates whose name starts with `pglsp`
/// - All spans and events at level debug in crates whose name starts with `pglt`
struct LoggingFilter;

/// Tracing filter used for spans emitted by `pglsp*` crates
/// Tracing filter used for spans emitted by `pglt*` 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("pglsp") {
let filter = if meta.target().starts_with("pglt") {
SELF_FILTER
} else {
LevelFilter::INFO
Expand Down
2 changes: 1 addition & 1 deletion crates/pglt_cli/src/commands/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use pglt_workspace::configuration::create_config;
pub(crate) fn init(mut session: CliSession) -> Result<(), CliDiagnostic> {
let fs = &mut session.app.fs;
create_config(fs, PartialConfiguration::init())?;
let file_created = ConfigName::pglsp_toml();
let file_created = ConfigName::pglt_toml();
session.app.console.log(markup! {
"
Welcome to the Postgres Language Server! Let's get you started...
Expand Down
18 changes: 9 additions & 9 deletions crates/pglt_cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub(crate) mod version;

#[derive(Debug, Clone, Bpaf)]
#[bpaf(options, version(VERSION))]
/// PgLsp official CLI. Use it to check the health of your project or run it to check single files.
/// PgLT official CLI. Use it to check the health of your project or run it to check single files.
pub enum PgltCommand {
/// Shows the version information and quit.
#[bpaf(command)]
Expand Down Expand Up @@ -58,7 +58,7 @@ pub enum PgltCommand {
changed: bool,

/// Use this to specify the base branch to compare against when you're using the --changed
/// flag and the `defaultBranch` is not set in your `pglsp.toml`
/// flag and the `defaultBranch` is not set in your `pglt.toml`
#[bpaf(long("since"), argument("REF"))]
since: Option<String>,

Expand Down Expand Up @@ -87,11 +87,11 @@ pub enum PgltCommand {
long("log-path"),
argument("PATH"),
hide_usage,
fallback(pglt_fs::ensure_cache_dir().join("pglsp-logs")),
fallback(pglt_fs::ensure_cache_dir().join("pglt-logs")),
)]
log_path: PathBuf,
/// Allows to set a custom file path to the configuration file,
/// or a custom directory path to find `pglsp.toml`
/// or a custom directory path to find `pglt.toml`
#[bpaf(env("PGLSP_LOG_PREFIX_NAME"), long("config-path"), argument("PATH"))]
config_path: Option<PathBuf>,
},
Expand Down Expand Up @@ -123,11 +123,11 @@ pub enum PgltCommand {
long("log-path"),
argument("PATH"),
hide_usage,
fallback(pglt_fs::ensure_cache_dir().join("pglsp-logs")),
fallback(pglt_fs::ensure_cache_dir().join("pglt-logs")),
)]
log_path: PathBuf,
/// Allows to set a custom file path to the configuration file,
/// or a custom directory path to find `pglsp.toml`
/// or a custom directory path to find `pglt.toml`
#[bpaf(env("PGLSP_CONFIG_PATH"), long("config-path"), argument("PATH"))]
config_path: Option<PathBuf>,
/// Bogus argument to make the command work with vscode-languageclient
Expand Down Expand Up @@ -157,14 +157,14 @@ pub enum PgltCommand {
long("log-path"),
argument("PATH"),
hide_usage,
fallback(pglt_fs::ensure_cache_dir().join("pglsp-logs")),
fallback(pglt_fs::ensure_cache_dir().join("pglt-logs")),
)]
log_path: PathBuf,

#[bpaf(long("stop-on-disconnect"), hide_usage)]
stop_on_disconnect: bool,
/// Allows to set a custom file path to the configuration file,
/// or a custom directory path to find `pglsp.toml`
/// or a custom directory path to find `pglt.toml`
#[bpaf(env("PGLSP_CONFIG_PATH"), long("config-path"), argument("PATH"))]
config_path: Option<PathBuf>,
},
Expand Down Expand Up @@ -197,7 +197,7 @@ impl PgltCommand {
}
// We want force colors in CI, to give e better UX experience
// Unless users explicitly set the colors flag
// if matches!(self, PgLspCommand::Ci { .. }) && cli_options.colors.is_none() {
// if matches!(self, PgLTCommand::Ci { .. }) && cli_options.colors.is_none() {
// return Some(&ColorsArg::Force);
// }
// Normal behaviors
Expand Down
Loading