Skip to content

Commit 9952744

Browse files
authored
refactor: pull diagnostics (#585)
1 parent a9ac119 commit 9952744

File tree

31 files changed

+269
-168
lines changed

31 files changed

+269
-168
lines changed

.github/workflows/pull_request.yml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,16 +213,27 @@ jobs:
213213
uses: oven-sh/setup-bun@v2
214214
- name: Install JS dependencies
215215
run: bun install
216-
- name: Build backend-jsonrpc
216+
217+
- name: Build backend-jsonrpc (deprecated)
217218
working-directory: packages/@postgrestools/backend-jsonrpc
218219
run: bun run build
219-
- name: Run backend-jsonrpc test
220+
- name: Run backend-jsonrpc test (deprecated)
220221
working-directory: packages/@postgrestools/backend-jsonrpc
221222
run: bun run test
222-
- name: Run cli test
223+
- name: Run cli test (deprecated)
223224
working-directory: packages/@postgrestools/postgrestools
224225
run: bun run test
225226

227+
- name: Build backend-jsonrpc
228+
working-directory: packages/@postgres-language-server/backend-jsonrpc
229+
run: bun run build
230+
- name: Run backend-jsonrpc test
231+
working-directory: packages/@postgres-language-server/backend-jsonrpc
232+
run: bun run test
233+
- name: Run cli test
234+
working-directory: packages/@postgres-language-server/cli
235+
run: bun run test
236+
226237
codegen:
227238
name: Check Codegen
228239
runs-on: ubuntu-22.04
@@ -259,6 +270,8 @@ jobs:
259270
run: cargo run -p xtask_codegen -- analyser
260271
- name: Run the configuration codegen
261272
run: cargo run -p xtask_codegen -- configuration
273+
- name: Run the bindings codegen
274+
run: cargo run -p xtask_codegen -- bindings
262275
- name: Run the docs codegen
263276
run: cargo run -p docs_codegen
264277
- name: Check for git diff -- run "just ready" if you see an error

bun.lock

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,32 @@
1111
"typescript": "^5",
1212
},
1313
},
14+
"packages/@postgres-language-server/backend-jsonrpc": {
15+
"name": "@postgres-language-server/backend-jsonrpc",
16+
"optionalDependencies": {
17+
"@postgres-language-server/cli-darwin-arm64": "<placeholder>",
18+
"@postgres-language-server/cli-darwin-x64": "<placeholder>",
19+
"@postgres-language-server/cli-linux-arm64": "<placeholder>",
20+
"@postgres-language-server/cli-linux-x64": "<placeholder>",
21+
"@postgres-language-server/cli-win32-arm64": "<placeholder>",
22+
"@postgres-language-server/cli-win32-x64": "<placeholder>",
23+
},
24+
},
25+
"packages/@postgres-language-server/cli": {
26+
"name": "@postgres-language-server/cli",
27+
"bin": {
28+
"postgres-language-server": "bin/postgres-language-server",
29+
},
30+
"optionalDependencies": {
31+
"@postgres-language-server/cli-aarch64-apple-darwin": "<placeholder>",
32+
"@postgres-language-server/cli-aarch64-linux-gnu": "<placeholder>",
33+
"@postgres-language-server/cli-aarch64-windows-msvc": "<placeholder>",
34+
"@postgres-language-server/cli-x86_64-apple-darwin": "<placeholder>",
35+
"@postgres-language-server/cli-x86_64-linux-gnu": "<placeholder>",
36+
"@postgres-language-server/cli-x86_64-linux-musl": "<placeholder>",
37+
"@postgres-language-server/cli-x86_64-windows-msvc": "<placeholder>",
38+
},
39+
},
1440
"packages/@postgrestools/backend-jsonrpc": {
1541
"name": "@postgrestools/backend-jsonrpc",
1642
"optionalDependencies": {
@@ -57,6 +83,24 @@
5783

5884
"@biomejs/cli-win32-x64": ["@biomejs/cli-win32-x64@1.9.4", "", { "os": "win32", "cpu": "x64" }, "sha512-8Y5wMhVIPaWe6jw2H+KlEm4wP/f7EW3810ZLmDlrEEy5KvBsb9ECEfu/kMWD484ijfQ8+nIi0giMgu9g1UAuuA=="],
5985

86+
"@postgres-language-server/backend-jsonrpc": ["@postgres-language-server/backend-jsonrpc@workspace:packages/@postgres-language-server/backend-jsonrpc"],
87+
88+
"@postgres-language-server/cli": ["@postgres-language-server/cli@workspace:packages/@postgres-language-server/cli"],
89+
90+
"@postgres-language-server/cli-aarch64-apple-darwin": ["@postgres-language-server/cli-aarch64-apple-darwin@0.17.1", "", { "os": "darwin", "cpu": "arm64" }, "sha512-0Umsb4yuHyI8D9oZkkpa6H4aZXMAAMLa7qbOrHRP9IMML4mKp5B9wkCiyvgd1ZKRP82UQBZnVjh53AGXky4Jdw=="],
91+
92+
"@postgres-language-server/cli-aarch64-linux-gnu": ["@postgres-language-server/cli-aarch64-linux-gnu@0.17.1", "", { "os": "linux", "cpu": "arm64" }, "sha512-ye8IQLNLyJK4hR5tx8rKh1tEO1Sb+Dw574cbBG++K46LTZAdRq5/IQrNkIfDzFdgU+HMK3QYfm54cgudYeVVlQ=="],
93+
94+
"@postgres-language-server/cli-aarch64-windows-msvc": ["@postgres-language-server/cli-aarch64-windows-msvc@0.17.1", "", { "os": "win32", "cpu": "arm64" }, "sha512-FkOjgvN7+vq0RvwVD/effFjKgH1mrAVMnV+3eO9bdZ6jCXpPesGOyCvyhf59IzoqmvIMyEeKJzjOUcXxWPmdZg=="],
95+
96+
"@postgres-language-server/cli-x86_64-apple-darwin": ["@postgres-language-server/cli-x86_64-apple-darwin@0.17.1", "", { "os": "darwin", "cpu": "x64" }, "sha512-B79kZ9tz8fvGihv4W/cyCFzw5Wz95HlqF1hnNTBocJtf8Nvo9h6RDWoUEYliBjRp37gcdV945ZjV2RHHxdKMTw=="],
97+
98+
"@postgres-language-server/cli-x86_64-linux-gnu": ["@postgres-language-server/cli-x86_64-linux-gnu@0.17.1", "", { "os": "linux", "cpu": "x64" }, "sha512-lh5Lg/Cc18+232NRd1OZqdpJzuJMW6lrwkC6RKYiiTzxUfRq7uRV8qI0NNnp5cyKiyDO90cpQQ8fjepTaMzh9A=="],
99+
100+
"@postgres-language-server/cli-x86_64-linux-musl": ["@postgres-language-server/cli-x86_64-linux-musl@0.17.1", "", { "os": "linux", "cpu": "x64" }, "sha512-YH5Znq0urRUxtdsbyDu6Dcg5x9qhgDqTl7gCVY/LmVrPnHfP2I6gU/TJT21B5sDTSadjwZ73AbXimLmlwG6HPA=="],
101+
102+
"@postgres-language-server/cli-x86_64-windows-msvc": ["@postgres-language-server/cli-x86_64-windows-msvc@0.17.1", "", { "os": "win32", "cpu": "x64" }, "sha512-o2uIx0Vi3iEBFKKnz024JicgovJZWpM9G4WbQxf3r9IQlZPWvDXknlX7rNPQDnQTFRIUg8bpjZpjEvDFHMmuGg=="],
103+
60104
"@postgrestools/backend-jsonrpc": ["@postgrestools/backend-jsonrpc@workspace:packages/@postgrestools/backend-jsonrpc"],
61105

62106
"@postgrestools/cli-aarch64-apple-darwin": ["@postgrestools/cli-aarch64-apple-darwin@0.13.0", "", { "os": "darwin", "cpu": "arm64" }, "sha512-LqgpsiupuNR1m8rSqcMdwep1UsSG5z7RZ9MYHODBB0+AsN/e1YzcyutqGeKs+AfDBdKdv7QmSbpf7KruBYL+tg=="],

crates/pgls_analyse/src/categories.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,34 +91,34 @@ impl ActionCategory {
9191
match self {
9292
ActionCategory::QuickFix(tag) => {
9393
if tag.is_empty() {
94-
Cow::Borrowed("quickfix.pgt")
94+
Cow::Borrowed("quickfix.pgls")
9595
} else {
96-
Cow::Owned(format!("quickfix.pgt.{tag}"))
96+
Cow::Owned(format!("quickfix.pgls.{tag}"))
9797
}
9898
}
9999

100-
ActionCategory::Refactor(RefactorKind::None) => Cow::Borrowed("refactor.pgt"),
100+
ActionCategory::Refactor(RefactorKind::None) => Cow::Borrowed("refactor.pgls"),
101101
ActionCategory::Refactor(RefactorKind::Extract) => {
102-
Cow::Borrowed("refactor.extract.pgt")
102+
Cow::Borrowed("refactor.extract.pgls")
103103
}
104-
ActionCategory::Refactor(RefactorKind::Inline) => Cow::Borrowed("refactor.inline.pgt"),
104+
ActionCategory::Refactor(RefactorKind::Inline) => Cow::Borrowed("refactor.inline.pgls"),
105105
ActionCategory::Refactor(RefactorKind::Rewrite) => {
106-
Cow::Borrowed("refactor.rewrite.pgt")
106+
Cow::Borrowed("refactor.rewrite.pgls")
107107
}
108108
ActionCategory::Refactor(RefactorKind::Other(tag)) => {
109-
Cow::Owned(format!("refactor.{tag}.pgt"))
109+
Cow::Owned(format!("refactor.{tag}.pgls"))
110110
}
111111

112-
ActionCategory::Source(SourceActionKind::None) => Cow::Borrowed("source.pgt"),
113-
ActionCategory::Source(SourceActionKind::FixAll) => Cow::Borrowed("source.fixAll.pgt"),
112+
ActionCategory::Source(SourceActionKind::None) => Cow::Borrowed("source.pgls"),
113+
ActionCategory::Source(SourceActionKind::FixAll) => Cow::Borrowed("source.fixAll.pgls"),
114114
ActionCategory::Source(SourceActionKind::OrganizeImports) => {
115-
Cow::Borrowed("source.organizeImports.pgt")
115+
Cow::Borrowed("source.organizeImports.pgls")
116116
}
117117
ActionCategory::Source(SourceActionKind::Other(tag)) => {
118-
Cow::Owned(format!("source.{tag}.pgt"))
118+
Cow::Owned(format!("source.{tag}.pgls"))
119119
}
120120

121-
ActionCategory::Other(tag) => Cow::Owned(format!("{tag}.pgt")),
121+
ActionCategory::Other(tag) => Cow::Owned(format!("{tag}.pgls")),
122122
}
123123
}
124124
}

crates/pgls_cli/src/cli_options.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ pub struct CliOptions {
5858

5959
#[bpaf(
6060
env("PGT_LOG_LEVEL"),
61+
env("PGLS_LOG_LEVEL"),
6162
long("log-level"),
6263
argument("none|debug|info|warn|error"),
6364
fallback(LoggingLevel::default()),

crates/pgls_cli/src/commands/daemon.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -181,15 +181,15 @@ async fn start_lsp_proxy(
181181
/// The events received by the subscriber are filtered at the `info` level,
182182
/// then printed using the [HierarchicalLayer] layer, and the resulting text
183183
/// is written to log files rotated on a hourly basis (in
184-
/// `pgt-logs/server.log.yyyy-MM-dd-HH` files inside the system temporary
184+
/// `pgls-logs/server.log.yyyy-MM-dd-HH` files inside the system temporary
185185
/// directory)
186186
fn setup_tracing_subscriber(
187187
log_path: Option<PathBuf>,
188188
log_file_name_prefix: Option<String>,
189189
log_level: Option<String>,
190190
log_kind: Option<String>,
191191
) {
192-
let pgls_log_path = log_path.unwrap_or(pgls_fs::ensure_cache_dir().join("pgt-logs"));
192+
let pgls_log_path = log_path.unwrap_or(pgls_fs::ensure_cache_dir().join("pgls-logs"));
193193

194194
let appender_builder = tracing_appender::rolling::RollingFileAppender::builder();
195195

@@ -200,7 +200,7 @@ fn setup_tracing_subscriber(
200200
.build(pgls_log_path)
201201
.expect("Failed to start the logger for the daemon.");
202202

203-
let filter = PgtLoggingFilter::from(log_level);
203+
let filter = PgLSLoggingFilter::from(log_level);
204204

205205
let log_kind = log_kind.unwrap_or("hierarchical".into());
206206

@@ -241,16 +241,16 @@ pub fn default_pgls_log_path() -> PathBuf {
241241
.or_else(|| env.pgls_log_path.value())
242242
{
243243
Some(directory) => PathBuf::from(directory),
244-
None => pgls_fs::ensure_cache_dir().join("pgt-logs"),
244+
None => pgls_fs::ensure_cache_dir().join("pgls-logs"),
245245
}
246246
}
247247

248248
/// Tracing Filter with two rules:
249-
/// For all crates starting with pgt*, use `PGT_LOG_LEVEL` or CLI option or "info" as default
249+
/// For all crates starting with pgls*, use `PGLS_LOG_LEVEL` or CLI option or "info" as default
250250
/// For all other crates, use "info"
251-
struct PgtLoggingFilter(LevelFilter);
251+
struct PgLSLoggingFilter(LevelFilter);
252252

253-
impl From<Option<String>> for PgtLoggingFilter {
253+
impl From<Option<String>> for PgLSLoggingFilter {
254254
fn from(value: Option<String>) -> Self {
255255
Self(
256256
value
@@ -269,9 +269,9 @@ impl From<Option<String>> for PgtLoggingFilter {
269269
}
270270
}
271271

272-
impl PgtLoggingFilter {
272+
impl PgLSLoggingFilter {
273273
fn is_enabled(&self, meta: &Metadata<'_>) -> bool {
274-
let filter = if meta.target().starts_with("pgt") {
274+
let filter = if meta.target().starts_with("pgls") {
275275
self.0
276276
} else {
277277
LevelFilter::INFO
@@ -281,7 +281,7 @@ impl PgtLoggingFilter {
281281
}
282282
}
283283

284-
impl<S> Filter<S> for PgtLoggingFilter {
284+
impl<S> Filter<S> for PgLSLoggingFilter {
285285
fn enabled(&self, meta: &Metadata<'_>, _cx: &Context<'_, S>) -> bool {
286286
self.is_enabled(meta)
287287
}
Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
use std::time::Instant;
2+
13
use crate::cli_options::CliOptions;
24
use crate::reporter::Report;
35
use crate::{CliDiagnostic, CliSession, VcsIntegration};
46
use pgls_configuration::PartialConfiguration;
7+
use pgls_diagnostics::Error;
8+
use pgls_workspace::features::diagnostics::{PullDatabaseDiagnosticsParams, PullDiagnosticsResult};
59

610
pub fn dblint(
711
mut session: CliSession,
@@ -10,9 +14,27 @@ pub fn dblint(
1014
) -> Result<(), CliDiagnostic> {
1115
let configuration = session.prepare_with_config(cli_options, cli_configuration)?;
1216
session.setup_workspace(configuration, VcsIntegration::Disabled)?;
17+
let workspace = session.workspace();
18+
19+
let max_diagnostics = if cli_options.reporter.is_default() {
20+
cli_options.max_diagnostics.into()
21+
} else {
22+
u32::MAX
23+
};
24+
25+
let start = Instant::now();
26+
27+
let PullDiagnosticsResult {
28+
diagnostics,
29+
skipped_diagnostics,
30+
} = workspace.pull_db_diagnostics(PullDatabaseDiagnosticsParams { max_diagnostics })?;
1331

14-
// TODO: Implement actual dblint logic here
15-
let report = Report::new(vec![], std::time::Duration::new(0, 0), 0, None);
32+
let report = Report::new(
33+
diagnostics.into_iter().map(Error::from).collect(),
34+
start.elapsed(),
35+
skipped_diagnostics,
36+
None,
37+
);
1638

1739
session.report("dblint", cli_options, &report)
1840
}

crates/pgls_cli/src/commands/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ pub enum PgLSCommand {
9393
long("log-path"),
9494
argument("PATH"),
9595
hide_usage,
96-
fallback(pgls_fs::ensure_cache_dir().join("pgt-logs")),
96+
fallback(pgls_fs::ensure_cache_dir().join("pgls-logs")),
9797
)]
9898
log_path: PathBuf,
9999
/// Allows to set a custom file path to the configuration file,
@@ -136,7 +136,7 @@ pub enum PgLSCommand {
136136
long("log-path"),
137137
argument("PATH"),
138138
hide_usage,
139-
fallback(pgls_fs::ensure_cache_dir().join("pgt-logs")),
139+
fallback(pgls_fs::ensure_cache_dir().join("pgls-logs")),
140140
)]
141141
log_path: PathBuf,
142142
/// Allows to set a custom file path to the configuration file,
@@ -178,11 +178,11 @@ pub enum PgLSCommand {
178178
long("log-path"),
179179
argument("PATH"),
180180
hide_usage,
181-
fallback(pgls_fs::ensure_cache_dir().join("pgt-logs")),
181+
fallback(pgls_fs::ensure_cache_dir().join("pgls-logs")),
182182
)]
183183
log_path: PathBuf,
184184

185-
/// Allows to change the log level. Default is debug. This will only affect "pgt*" crates. All others are logged with info level.
185+
/// Allows to change the log level. Default is debug. This will only affect "pgls*" crates. All others are logged with info level.
186186
#[bpaf(
187187
env("PGT_LOG_LEVEL"),
188188
env("PGLS_LOG_LEVEL"),

crates/pgls_cli/src/execute/process_file/check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub(crate) fn check_with_guard<'ctx>(
5454
.into_iter()
5555
.map(Error::from)
5656
.collect(),
57-
skipped_diagnostics: pull_diagnostics_result.skipped_diagnostics as u32,
57+
skipped_diagnostics: pull_diagnostics_result.skipped_diagnostics,
5858
});
5959
}
6060

crates/pgls_cli/src/execute/walk.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub(crate) fn traverse(
5959

6060
let (duration, evaluated_paths, diagnostics) = thread::scope(|s| {
6161
let handler = thread::Builder::new()
62-
.name(String::from("pgt::console"))
62+
.name(String::from("pgls::console"))
6363
.spawn_scoped(s, || printer.run(receiver, recv_files))
6464
.expect("failed to spawn console thread");
6565

@@ -121,7 +121,7 @@ fn init_thread_pool() {
121121
static INIT_ONCE: Once = Once::new();
122122
INIT_ONCE.call_once(|| {
123123
rayon::ThreadPoolBuilder::new()
124-
.thread_name(|index| format!("pgt::worker_{index}"))
124+
.thread_name(|index| format!("pgls::worker_{index}"))
125125
.build_global()
126126
.expect("failed to initialize the global thread pool");
127127
});

crates/pgls_cli/src/logging.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@ impl Display for LoggingLevel {
9292

9393
/// Tracing filter enabling:
9494
/// - All spans and events at level info or higher
95-
/// - All spans and events at level debug in crates whose name starts with `pgt`
95+
/// - All spans and events at level debug in crates whose name starts with `pgls`
9696
struct LoggingFilter {
9797
level: LoggingLevel,
9898
}
9999

100-
/// Tracing filter used for spans emitted by `pgt*` crates
100+
/// Tracing filter used for spans emitted by `pgls*` crates
101101
const SELF_FILTER: LevelFilter = if cfg!(debug_assertions) {
102102
LevelFilter::TRACE
103103
} else {
@@ -106,7 +106,7 @@ const SELF_FILTER: LevelFilter = if cfg!(debug_assertions) {
106106

107107
impl LoggingFilter {
108108
fn is_enabled(&self, meta: &Metadata<'_>) -> bool {
109-
let filter = if meta.target().starts_with("pgt") {
109+
let filter = if meta.target().starts_with("pgls") {
110110
if let Some(level) = self.level.to_filter_level() {
111111
level
112112
} else {

0 commit comments

Comments
 (0)