Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 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
19 changes: 16 additions & 3 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -212,16 +212,27 @@ jobs:
uses: oven-sh/setup-bun@v2
- name: Install JS dependencies
run: bun install
- name: Build backend-jsonrpc

- name: Build backend-jsonrpc (deprecated)
working-directory: packages/@postgrestools/backend-jsonrpc
run: bun run build
- name: Run backend-jsonrpc test
- name: Run backend-jsonrpc test (deprecated)
working-directory: packages/@postgrestools/backend-jsonrpc
run: bun run test
- name: Run cli test
- name: Run cli test (deprecated)
working-directory: packages/@postgrestools/postgrestools
run: bun run test

- name: Build backend-jsonrpc
working-directory: packages/@postgres-language-server/backend-jsonrpc
run: bun run build
- name: Run backend-jsonrpc test
working-directory: packages/@postgres-language-server/backend-jsonrpc
run: bun run test
- name: Run cli test
working-directory: packages/@postgres-language-server/cli
run: bun run test

codegen:
name: Check Codegen
runs-on: ubuntu-22.04
Expand Down Expand Up @@ -258,6 +269,8 @@ jobs:
run: cargo run -p xtask_codegen -- analyser
- name: Run the configuration codegen
run: cargo run -p xtask_codegen -- configuration
- name: Run the bindings codegen
run: cargo run -p xtask_codegen -- bindings
- name: Run the docs codegen
run: cargo run -p docs_codegen
- name: Check for git diff -- run "just ready" if you see an error
Expand Down
44 changes: 44 additions & 0 deletions bun.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,32 @@
"typescript": "^5",
},
},
"packages/@postgres-language-server/backend-jsonrpc": {
"name": "@postgres-language-server/backend-jsonrpc",
"optionalDependencies": {
"@postgres-language-server/cli-darwin-arm64": "<placeholder>",
"@postgres-language-server/cli-darwin-x64": "<placeholder>",
"@postgres-language-server/cli-linux-arm64": "<placeholder>",
"@postgres-language-server/cli-linux-x64": "<placeholder>",
"@postgres-language-server/cli-win32-arm64": "<placeholder>",
"@postgres-language-server/cli-win32-x64": "<placeholder>",
},
},
"packages/@postgres-language-server/cli": {
"name": "@postgres-language-server/cli",
"bin": {
"postgres-language-server": "bin/postgres-language-server",
},
"optionalDependencies": {
"@postgres-language-server/cli-aarch64-apple-darwin": "<placeholder>",
"@postgres-language-server/cli-aarch64-linux-gnu": "<placeholder>",
"@postgres-language-server/cli-aarch64-windows-msvc": "<placeholder>",
"@postgres-language-server/cli-x86_64-apple-darwin": "<placeholder>",
"@postgres-language-server/cli-x86_64-linux-gnu": "<placeholder>",
"@postgres-language-server/cli-x86_64-linux-musl": "<placeholder>",
"@postgres-language-server/cli-x86_64-windows-msvc": "<placeholder>",
},
},
"packages/@postgrestools/backend-jsonrpc": {
"name": "@postgrestools/backend-jsonrpc",
"optionalDependencies": {
Expand Down Expand Up @@ -57,6 +83,24 @@

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

"@postgres-language-server/backend-jsonrpc": ["@postgres-language-server/backend-jsonrpc@workspace:packages/@postgres-language-server/backend-jsonrpc"],

"@postgres-language-server/cli": ["@postgres-language-server/cli@workspace:packages/@postgres-language-server/cli"],

"@postgres-language-server/cli-aarch64-apple-darwin": ["@postgres-language-server/cli-aarch64-apple-darwin@0.17.1", "", { "os": "darwin", "cpu": "arm64" }, "sha512-0Umsb4yuHyI8D9oZkkpa6H4aZXMAAMLa7qbOrHRP9IMML4mKp5B9wkCiyvgd1ZKRP82UQBZnVjh53AGXky4Jdw=="],

"@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=="],

"@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=="],

"@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=="],

"@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=="],

"@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=="],

"@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=="],

"@postgrestools/backend-jsonrpc": ["@postgrestools/backend-jsonrpc@workspace:packages/@postgrestools/backend-jsonrpc"],

"@postgrestools/cli-aarch64-apple-darwin": ["@postgrestools/cli-aarch64-apple-darwin@0.13.0", "", { "os": "darwin", "cpu": "arm64" }, "sha512-LqgpsiupuNR1m8rSqcMdwep1UsSG5z7RZ9MYHODBB0+AsN/e1YzcyutqGeKs+AfDBdKdv7QmSbpf7KruBYL+tg=="],
Expand Down
26 changes: 24 additions & 2 deletions crates/pgls_cli/src/commands/dblint.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use std::time::Instant;

use crate::cli_options::CliOptions;
use crate::reporter::Report;
use crate::{CliDiagnostic, CliSession, VcsIntegration};
use pgls_configuration::PartialConfiguration;
use pgls_diagnostics::Error;
use pgls_workspace::features::diagnostics::{PullDatabaseDiagnosticsParams, PullDiagnosticsResult};

pub fn dblint(
mut session: CliSession,
Expand All @@ -10,9 +14,27 @@ pub fn dblint(
) -> Result<(), CliDiagnostic> {
let configuration = session.prepare_with_config(cli_options, cli_configuration)?;
session.setup_workspace(configuration, VcsIntegration::Disabled)?;
let workspace = session.workspace();

let max_diagnostics = if cli_options.reporter.is_default() {
cli_options.max_diagnostics.into()
} else {
u32::MAX
};

let start = Instant::now();

let PullDiagnosticsResult {
diagnostics,
skipped_diagnostics,
} = workspace.pull_db_diagnostics(PullDatabaseDiagnosticsParams { max_diagnostics })?;

// TODO: Implement actual dblint logic here
let report = Report::new(vec![], std::time::Duration::new(0, 0), 0, None);
let report = Report::new(
diagnostics.into_iter().map(Error::from).collect(),
start.elapsed(),
skipped_diagnostics,
None,
);

session.report("dblint", cli_options, &report)
}
2 changes: 1 addition & 1 deletion crates/pgls_cli/src/execute/process_file/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub(crate) fn check_with_guard<'ctx>(
.into_iter()
.map(Error::from)
.collect(),
skipped_diagnostics: pull_diagnostics_result.skipped_diagnostics as u32,
skipped_diagnostics: pull_diagnostics_result.skipped_diagnostics,
});
}

Expand Down
2 changes: 1 addition & 1 deletion crates/pgls_cli/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ impl WorkspaceTransport for SocketTransport {

self.pending_requests.insert(request.id, send);

let is_shutdown = request.method == "pgt/shutdown";
let is_shutdown = request.method == "pgls/shutdown";

let request = JsonRpcRequest {
jsonrpc: Cow::Borrowed("2.0"),
Expand Down
8 changes: 4 additions & 4 deletions crates/pgls_lsp/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,9 @@ type Sessions = Arc<Mutex<FxHashMap<SessionKey, SessionHandle>>>;
macro_rules! workspace_method {
( $builder:ident, $method:ident ) => {
$builder = $builder.custom_method(
concat!("pgt/", stringify!($method)),
concat!("pgls/", stringify!($method)),
|server: &LSPServer, params| {
let span = tracing::trace_span!(concat!("pgt/", stringify!($method)), params = ?params).or_current();
let span = tracing::trace_span!(concat!("pgls/", stringify!($method)), params = ?params).or_current();
tracing::info!("Received request: {}", stringify!($method));

let workspace = server.session.workspace.clone();
Expand Down Expand Up @@ -445,7 +445,7 @@ impl ServerFactory {
});

// "shutdown" is not part of the Workspace API
builder = builder.custom_method("pgt/shutdown", |server: &LSPServer, (): ()| {
builder = builder.custom_method("pgls/shutdown", |server: &LSPServer, (): ()| {
info!("Sending shutdown signal");
server.session.broadcast_shutdown();
ready(Ok(Some(())))
Expand All @@ -457,7 +457,7 @@ impl ServerFactory {
workspace_method!(builder, open_file);
workspace_method!(builder, change_file);
workspace_method!(builder, close_file);
workspace_method!(builder, pull_diagnostics);
workspace_method!(builder, pull_file_diagnostics);
workspace_method!(builder, get_completions);
workspace_method!(builder, register_project_folder);
workspace_method!(builder, unregister_project_folder);
Expand Down
18 changes: 9 additions & 9 deletions crates/pgls_lsp/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,15 +270,15 @@ impl Session {
let categories = RuleCategoriesBuilder::default().all();

let diagnostics: Vec<lsp_types::Diagnostic> = {
let result =
self.workspace
.pull_diagnostics(features::diagnostics::PullDiagnosticsParams {
path: pgls_path.clone(),
max_diagnostics: u64::MAX,
categories: categories.build(),
only: Vec::new(),
skip: Vec::new(),
})?;
let result = self.workspace.pull_file_diagnostics(
features::diagnostics::PullFileDiagnosticsParams {
path: pgls_path.clone(),
max_diagnostics: u32::MAX,
categories: categories.build(),
only: Vec::new(),
skip: Vec::new(),
},
)?;

result
.diagnostics
Expand Down
6 changes: 3 additions & 3 deletions crates/pgls_lsp/tests/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,11 +323,11 @@ impl Server {
.await
}

/// Basic implementation of the `pgt/shutdown` request for tests
/// Basic implementation of the `pgls/shutdown` request for tests
async fn pgls_shutdown(&mut self) -> Result<()> {
self.request::<_, ()>("pgt/shutdown", "_pgls_shutdown", ())
self.request::<_, ()>("pgls/shutdown", "_pgls_shutdown", ())
.await?
.context("pgt/shutdown returned None")?;
.context("pgls/shutdown returned None")?;
Ok(())
}
}
Expand Down
13 changes: 9 additions & 4 deletions crates/pgls_workspace/src/features/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use pgls_fs::PgLSPath;

#[derive(Debug, serde::Serialize, serde::Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct PullDiagnosticsParams {
pub struct PullFileDiagnosticsParams {
pub path: PgLSPath,
pub categories: RuleCategories,
pub max_diagnostics: u64,
pub max_diagnostics: u32,
pub only: Vec<RuleSelector>,
pub skip: Vec<RuleSelector>,
}
Expand All @@ -16,6 +16,11 @@ pub struct PullDiagnosticsParams {
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct PullDiagnosticsResult {
pub diagnostics: Vec<pgls_diagnostics::serde::Diagnostic>,
pub errors: usize,
pub skipped_diagnostics: u64,
pub skipped_diagnostics: u32,
}

#[derive(Debug, serde::Serialize, serde::Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct PullDatabaseDiagnosticsParams {
pub max_diagnostics: u32,
}
29 changes: 19 additions & 10 deletions crates/pgls_workspace/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ use crate::{
CodeActionsParams, CodeActionsResult, ExecuteStatementParams, ExecuteStatementResult,
},
completions::{CompletionsResult, GetCompletionsParams},
diagnostics::{PullDiagnosticsParams, PullDiagnosticsResult},
diagnostics::{
PullDatabaseDiagnosticsParams, PullDiagnosticsResult, PullFileDiagnosticsParams,
},
on_hover::{OnHoverParams, OnHoverResult},
},
};
Expand Down Expand Up @@ -98,9 +100,15 @@ pub struct UnregisterProjectFolderParams {

pub trait Workspace: Send + Sync + RefUnwindSafe {
/// Retrieves the list of diagnostics associated to a file
fn pull_diagnostics(
fn pull_file_diagnostics(
&self,
params: PullDiagnosticsParams,
params: PullFileDiagnosticsParams,
) -> Result<PullDiagnosticsResult, WorkspaceError>;

/// Retrieves the list of diagnostics associated to a database schema
fn pull_db_diagnostics(
&self,
params: PullDatabaseDiagnosticsParams,
) -> Result<PullDiagnosticsResult, WorkspaceError>;

/// Retrieves a list of available code_actions for a file/cursor_position
Expand Down Expand Up @@ -214,13 +222,14 @@ impl<'app, W: Workspace + ?Sized> FileGuard<'app, W> {
only: Vec<RuleSelector>,
skip: Vec<RuleSelector>,
) -> Result<PullDiagnosticsResult, WorkspaceError> {
self.workspace.pull_diagnostics(PullDiagnosticsParams {
path: self.path.clone(),
categories,
max_diagnostics: max_diagnostics.into(),
only,
skip,
})
self.workspace
.pull_file_diagnostics(PullFileDiagnosticsParams {
path: self.path.clone(),
categories,
max_diagnostics,
only,
skip,
})
}
}

Expand Down
Loading