From dd3f66ecd64cc373793d8149142224c5fdc2408a Mon Sep 17 00:00:00 2001 From: psteinroe Date: Sat, 4 Jan 2025 11:51:40 -0100 Subject: [PATCH 01/23] fix: justfile --- justfile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/justfile b/justfile index 3cd149ade..dd5100d9c 100644 --- a/justfile +++ b/justfile @@ -140,7 +140,10 @@ clear-branches: git branch --merged | egrep -v "(^\\*|main)" | xargs git branch -d reset-git: - git checkout main && git pull && pnpm run clear-branches + git checkout main + git pull + just clear-branches merge-main: - git fetch origin main:main && git merge main + git fetch origin main:main + git merge main From f9cb457d523ce71c9a2b7fad3171b0542bb86bb4 Mon Sep 17 00:00:00 2001 From: psteinroe Date: Sat, 4 Jan 2025 12:05:11 -0100 Subject: [PATCH 02/23] feat: improve ci --- .github/actions/free-disk-space/action.yml | 16 ++ .github/workflows/ci.yml | 197 +++++++++++++++++---- 2 files changed, 180 insertions(+), 33 deletions(-) create mode 100644 .github/actions/free-disk-space/action.yml diff --git a/.github/actions/free-disk-space/action.yml b/.github/actions/free-disk-space/action.yml new file mode 100644 index 000000000..c55bf403b --- /dev/null +++ b/.github/actions/free-disk-space/action.yml @@ -0,0 +1,16 @@ +name: Free Disk Space +description: Free up disk space on the runner +runs: + using: composite + steps: + - name: Free Disk Space (Ubuntu) + if: runner.os == 'Linux' + uses: jlumbroso/free-disk-space@main + with: + # We need to reclaim some space, but uninstalling everyting takes + # too long. So we'll just remove some of the larger packages. + # https://github.com/jlumbroso/free-disk-space/pull/26 + android: true + dotnet: true + haskell: true + large-packages: false diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 691d6716e..290bca1d9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,6 +3,14 @@ name: CI on: workflow_dispatch: pull_request: + # paths: # Only run when changes are made to rust code or root Cargo + # - "crates/**" + # - "fuzz/**" + # - "xtask/**" + # - "Cargo.toml" + # - "Cargo.lock" + # - "rust-toolchain.toml" + # - "rustfmt.toml" concurrency: group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }} @@ -10,48 +18,171 @@ concurrency: env: RUSTFLAGS: --deny warnings + RUST_LOG: info + RUST_BACKTRACE: 1 + RUSTUP_WINDOWS_PATH_ADD_BIN: 1 jobs: - ci: - name: CI - timeout-minutes: 10 + format: + name: Format runs-on: ubuntu-latest + steps: + - name: Checkout PR branch + uses: actions/checkout@v4 + - name: Free Disk Space + uses: ./.github/actions/free-disk-space + - name: Install toolchain + uses: moonrepo/setup-rust@v1 + with: + components: rustfmt + bins: taplo-cli + cache-base: main + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Run format + run: | + cargo fmt --all --check + taplo format --check - services: - postgres: - image: postgres:latest + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - name: Checkout PR Branch + uses: actions/checkout@v4 + - name: Free Disk Space + uses: ./.github/actions/free-disk-space + - name: Install toolchain + uses: moonrepo/setup-rust@v1 + with: + components: clippy + cache-base: main env: - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres - POSTGRES_DB: postgres - ports: - - 5432:5432 + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Run clippy + run: | + cargo lint + cargo run -p rules_check - env: - DATABASE_URL: postgresql://postgres:postgres@localhost:5432/postgres + check-dependencies: + name: Check Dependencies + runs-on: ubuntu-latest + steps: + - name: Checkout PR Branch + uses: actions/checkout@v4 + - name: Free Disk Space + uses: ./.github/actions/free-disk-space + - name: Install toolchain + run: rustup toolchain install nightly + - name: Install udeps + run: cargo install cargo-udeps --locked + - name: Detect unused dependencies using udeps + run: cargo +nightly udeps --all-targets + test: + name: Test + runs-on: ${{ matrix.os }} + strategy: + matrix: + include: + - os: windows-latest + - os: ubuntu-latest steps: - - name: 🏗 Setup repository - uses: actions/checkout@v3 + - name: Checkout PR branch + uses: actions/checkout@v4 + - name: Free Disk Space + uses: ./.github/actions/free-disk-space + - name: Install toolchain + uses: moonrepo/setup-rust@v1 with: - submodules: true + cache-base: main + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Run tests + run: cargo test --workspace - - name: 🏗 Setup monorepo - uses: ./.github/actions/setup-monorepo + codegen: + name: Codegen + runs-on: ubuntu-latest + steps: + - name: Checkout PR branch + uses: actions/checkout@v4 + - name: Free Disk Space + uses: ./.github/actions/free-disk-space + - name: Install toolchain + uses: moonrepo/setup-rust@v1 with: - github-token: ${{ secrets.GITHUB_TOKEN }} - - - name: Run test migrations - run: psql -f test-db/seed.sql postgresql://postgres:postgres@localhost:5432/postgres - - - name: 📦 Build - id: build - run: RUSTFLAGS="-A dead_code" cargo build - - - name: ⚡️ Check - id: check - run: RUSTFLAGS="-A dead_code" cargo check + cache-base: main + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Run the analyser codegen + run: cargo codegen analyser + - name: Run the configuration codegen + run: cargo codegen-configuration + - name: Check for git diff + run: | + if [[ `git status --porcelain` ]]; then + git status + git diff + exit 1 + fi - - name: 🦺 Test - id: test - run: RUSTFLAGS="-A dead_code" cargo test + # ci: + # name: CI + # timeout-minutes: 10 + # runs-on: ubuntu-latest + # + # services: + # postgres: + # image: postgres:latest + # env: + # POSTGRES_USER: postgres + # POSTGRES_PASSWORD: postgres + # POSTGRES_DB: postgres + # ports: + # - 5432:5432 + # + # env: + # DATABASE_URL: postgresql://postgres:postgres@localhost:5432/postgres + # + # steps: + # - name: 🏗 Setup repository + # uses: actions/checkout@v4 + # with: + # submodules: true + # + # - name: Free Disk Space + # uses: ./.github/actions/free-disk-space + # + # - name: Install toolchain + # uses: moonrepo/setup-rust@e013866c4215f77c925f42f60257dec7dd18836e # v1.2.1 + # with: + # components: rustfmt + # bins: taplo-cli + # cache-base: main + # env: + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # - name: Run format + # run: | + # cargo fmt --all --check + # taplo format --check + # + # - name: 🏗 Setup monorepo + # uses: ./.github/actions/setup-monorepo + # with: + # github-token: ${{ secrets.GITHUB_TOKEN }} + # + # - name: Run test migrations + # run: psql -f test-db/seed.sql postgresql://postgres:postgres@localhost:5432/postgres + # + # - name: 📦 Build + # id: build + # run: RUSTFLAGS="-A dead_code" cargo build + # + # - name: ⚡️ Check + # id: check + # run: RUSTFLAGS="-A dead_code" cargo check + # + # - name: 🦺 Test + # id: test + # run: RUSTFLAGS="-A dead_code" cargo test From dd0995e20a0854922901a47aee8043c4b97f3559 Mon Sep 17 00:00:00 2001 From: psteinroe Date: Sat, 4 Jan 2025 12:13:39 -0100 Subject: [PATCH 03/23] fix: ci --- .github/workflows/ci.yml | 15 ++++++++++++--- justfile | 2 ++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 290bca1d9..489455578 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -61,7 +61,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Run clippy run: | - cargo lint + cargo clippy cargo run -p rules_check check-dependencies: @@ -82,6 +82,15 @@ jobs: test: name: Test runs-on: ${{ matrix.os }} + services: + postgres: + image: postgres:latest + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: postgres + ports: + - 5432:5432 strategy: matrix: include: @@ -116,9 +125,9 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Run the analyser codegen - run: cargo codegen analyser + run: cargo run -p xtask_codegen -- analyser - name: Run the configuration codegen - run: cargo codegen-configuration + run: cargo run -p xtask_codegen -- configuration - name: Check for git diff run: | if [[ `git status --porcelain` ]]; then diff --git a/justfile b/justfile index dd5100d9c..aafa199fd 100644 --- a/justfile +++ b/justfile @@ -104,9 +104,11 @@ test-doc: # Alias for `cargo clippy`, it runs clippy on the whole codebase lint: cargo clippy + cargo run -p rules_check lint-fix: cargo clippy --fix + cargo run -p rules_check # When you finished coding, run this command to run the same commands in the CI. # ready: From 3c58c966c4c4942963f0865157dbf9f3cb5512df Mon Sep 17 00:00:00 2001 From: psteinroe Date: Sat, 4 Jan 2025 12:34:48 -0100 Subject: [PATCH 04/23] fix: ci --- .github/workflows/ci.yml | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 489455578..ecf32cebc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -82,15 +82,6 @@ jobs: test: name: Test runs-on: ${{ matrix.os }} - services: - postgres: - image: postgres:latest - env: - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres - POSTGRES_DB: postgres - ports: - - 5432:5432 strategy: matrix: include: @@ -107,6 +98,11 @@ jobs: cache-base: main env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + # running containers via `services` only works on linux + # https://github.com/actions/runner/issues/1866 + - name: Setup postgres + uses: ikalnytskyi/action-setup-postgres@v7 - name: Run tests run: cargo test --workspace From 5fd00d144cc5a5bbc2ab346b4b6253042bde6acc Mon Sep 17 00:00:00 2001 From: psteinroe Date: Sat, 4 Jan 2025 12:39:23 -0100 Subject: [PATCH 05/23] fix: ci --- .github/workflows/{ci.yml => pull_request.yml} | 11 ++++++++++- crates/pg_console/src/utils.rs | 1 - 2 files changed, 10 insertions(+), 2 deletions(-) rename .github/workflows/{ci.yml => pull_request.yml} (95%) diff --git a/.github/workflows/ci.yml b/.github/workflows/pull_request.yml similarity index 95% rename from .github/workflows/ci.yml rename to .github/workflows/pull_request.yml index ecf32cebc..200a48d7b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/pull_request.yml @@ -1,4 +1,4 @@ -name: CI +name: Pull Request on: workflow_dispatch: @@ -109,6 +109,15 @@ jobs: codegen: name: Codegen runs-on: ubuntu-latest + services: + postgres: + image: postgres:latest + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: postgres + ports: + - 5432:5432 steps: - name: Checkout PR branch uses: actions/checkout@v4 diff --git a/crates/pg_console/src/utils.rs b/crates/pg_console/src/utils.rs index 6524b3dae..d56e0139f 100644 --- a/crates/pg_console/src/utils.rs +++ b/crates/pg_console/src/utils.rs @@ -3,7 +3,6 @@ use crate::{markup, Markup}; use std::io; /// It displays a type that implements [std::fmt::Display] - pub struct DebugDisplay(pub T); impl Display for DebugDisplay From e793edee9ec768ed04666678962341a12e769b00 Mon Sep 17 00:00:00 2001 From: psteinroe Date: Sat, 4 Jan 2025 12:41:14 -0100 Subject: [PATCH 06/23] fix: ci --- .github/workflows/pull_request.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 200a48d7b..c48e5cc05 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -90,6 +90,8 @@ jobs: steps: - name: Checkout PR branch uses: actions/checkout@v4 + with: + submodules: true - name: Free Disk Space uses: ./.github/actions/free-disk-space - name: Install toolchain From 134c9b9fb35837732151d5c8a6e78c071c94312d Mon Sep 17 00:00:00 2001 From: psteinroe Date: Sat, 4 Jan 2025 12:44:51 -0100 Subject: [PATCH 07/23] fix: ci --- crates/pg_completions/src/context.rs | 24 +++++++-------- crates/pg_completions/src/test_helper.rs | 6 ++-- crates/pg_lsp/src/db_connection.rs | 2 +- crates/pg_lsp/src/session.rs | 3 +- crates/pg_schema_cache/src/columns.rs | 30 +++++++++---------- .../src/workspace/server/pg_query.rs | 3 +- 6 files changed, 32 insertions(+), 36 deletions(-) diff --git a/crates/pg_completions/src/context.rs b/crates/pg_completions/src/context.rs index 79354cf6d..912a7cec1 100644 --- a/crates/pg_completions/src/context.rs +++ b/crates/pg_completions/src/context.rs @@ -29,7 +29,7 @@ impl TryFrom<&str> for ClauseType { panic!("{}", message); } - return Err(message); + Err(message) } } } @@ -215,7 +215,7 @@ mod tests { let params = crate::CompletionParams { position: (position as u32).into(), - text: text, + text, tree: Some(&tree), schema: &pg_schema_cache::SchemaCache::new(), }; @@ -247,7 +247,7 @@ mod tests { let tree = get_tree(text.as_str()); let params = crate::CompletionParams { position: (position as u32).into(), - text: text, + text, tree: Some(&tree), schema: &pg_schema_cache::SchemaCache::new(), }; @@ -281,7 +281,7 @@ mod tests { let tree = get_tree(text.as_str()); let params = crate::CompletionParams { position: (position as u32).into(), - text: text, + text, tree: Some(&tree), schema: &pg_schema_cache::SchemaCache::new(), }; @@ -306,14 +306,14 @@ mod tests { let params = crate::CompletionParams { position: (position as u32).into(), - text: text, + text, tree: Some(&tree), schema: &pg_schema_cache::SchemaCache::new(), }; let ctx = CompletionContext::new(¶ms); - let node = ctx.ts_node.map(|n| n.clone()).unwrap(); + let node = ctx.ts_node.unwrap(); assert_eq!(ctx.get_ts_node_content(node), Some("select")); @@ -334,14 +334,14 @@ mod tests { let params = crate::CompletionParams { position: (position as u32).into(), - text: text, + text, tree: Some(&tree), schema: &pg_schema_cache::SchemaCache::new(), }; let ctx = CompletionContext::new(¶ms); - let node = ctx.ts_node.map(|n| n.clone()).unwrap(); + let node = ctx.ts_node.unwrap(); assert_eq!(ctx.get_ts_node_content(node), Some("from")); assert_eq!( @@ -360,14 +360,14 @@ mod tests { let params = crate::CompletionParams { position: (position as u32).into(), - text: text, + text, tree: Some(&tree), schema: &pg_schema_cache::SchemaCache::new(), }; let ctx = CompletionContext::new(¶ms); - let node = ctx.ts_node.map(|n| n.clone()).unwrap(); + let node = ctx.ts_node.unwrap(); assert_eq!(ctx.get_ts_node_content(node), Some("")); assert_eq!(ctx.wrapping_clause_type, None); @@ -385,14 +385,14 @@ mod tests { let params = crate::CompletionParams { position: (position as u32).into(), - text: text, + text, tree: Some(&tree), schema: &pg_schema_cache::SchemaCache::new(), }; let ctx = CompletionContext::new(¶ms); - let node = ctx.ts_node.map(|n| n.clone()).unwrap(); + let node = ctx.ts_node.unwrap(); assert_eq!(ctx.get_ts_node_content(node), Some("fro")); assert_eq!(ctx.wrapping_clause_type, Some(ClauseType::Select)); diff --git a/crates/pg_completions/src/test_helper.rs b/crates/pg_completions/src/test_helper.rs index 08a3af2e8..8aa20a273 100644 --- a/crates/pg_completions/src/test_helper.rs +++ b/crates/pg_completions/src/test_helper.rs @@ -34,10 +34,8 @@ pub(crate) async fn get_test_deps( pub(crate) fn get_text_and_position(sql: &str) -> (usize, String) { // the cursor is to the left of the `CURSOR_POS` let position = sql - .find(|c| c == CURSOR_POS) - .expect("Please insert the CURSOR_POS into your query.") - .checked_sub(1) - .unwrap_or(0); + .find(CURSOR_POS) + .expect("Please insert the CURSOR_POS into your query.").saturating_sub(1); let text = sql.replace(CURSOR_POS, ""); diff --git a/crates/pg_lsp/src/db_connection.rs b/crates/pg_lsp/src/db_connection.rs index 38286ea5d..4e0bdb728 100644 --- a/crates/pg_lsp/src/db_connection.rs +++ b/crates/pg_lsp/src/db_connection.rs @@ -40,7 +40,7 @@ impl DbConnection { res = listener.recv() => { match res { Ok(not) => { - if not.payload().to_string() == "reload schema" { + if not.payload() == "reload schema" { let schema_cache = SchemaCache::load(&cloned_pool).await.unwrap(); ide.write().await.set_schema_cache(schema_cache); }; diff --git a/crates/pg_lsp/src/session.rs b/crates/pg_lsp/src/session.rs index 4e4dcfd93..e94fd0c53 100644 --- a/crates/pg_lsp/src/session.rs +++ b/crates/pg_lsp/src/session.rs @@ -248,8 +248,7 @@ impl Session { tree: ide .tree_sitter .tree(&stmt) - .as_ref() - .and_then(|t| Some(t.as_ref())), + .as_ref().map(|t| t.as_ref()), schema: &schema_cache, }) .into_iter() diff --git a/crates/pg_schema_cache/src/columns.rs b/crates/pg_schema_cache/src/columns.rs index 1ff4a412e..a8d88eae0 100644 --- a/crates/pg_schema_cache/src/columns.rs +++ b/crates/pg_schema_cache/src/columns.rs @@ -148,27 +148,27 @@ mod tests { user_id_col.default_expr, Some("nextval('users_id_seq'::regclass)".into()) ); - assert_eq!(user_id_col.is_nullable, false); - assert_eq!(user_id_col.is_primary_key, true); - assert_eq!(user_id_col.is_unique, true); + assert!(!user_id_col.is_nullable); + assert!(user_id_col.is_primary_key); + assert!(user_id_col.is_unique); assert_eq!(user_id_col.varchar_length, None); let user_name_col = cache.find_col("name", "users", None).unwrap(); assert_eq!(user_name_col.class_kind, ColumnClassKind::OrdinaryTable); assert_eq!(user_name_col.comment, None); assert_eq!(user_name_col.default_expr, None); - assert_eq!(user_name_col.is_nullable, false); - assert_eq!(user_name_col.is_primary_key, false); - assert_eq!(user_name_col.is_unique, false); + assert!(!user_name_col.is_nullable); + assert!(!user_name_col.is_primary_key); + assert!(!user_name_col.is_unique); assert_eq!(user_name_col.varchar_length, Some(255)); let user_is_veg_col = cache.find_col("is_vegetarian", "users", None).unwrap(); assert_eq!(user_is_veg_col.class_kind, ColumnClassKind::OrdinaryTable); assert_eq!(user_is_veg_col.comment, None); assert_eq!(user_is_veg_col.default_expr, Some("false".into())); - assert_eq!(user_is_veg_col.is_nullable, true); - assert_eq!(user_is_veg_col.is_primary_key, false); - assert_eq!(user_is_veg_col.is_unique, false); + assert!(user_is_veg_col.is_nullable); + assert!(!user_is_veg_col.is_primary_key); + assert!(!user_is_veg_col.is_unique); assert_eq!(user_is_veg_col.varchar_length, None); let user_middle_name_col = cache.find_col("middle_name", "users", None).unwrap(); @@ -178,9 +178,9 @@ mod tests { ); assert_eq!(user_middle_name_col.comment, None); assert_eq!(user_middle_name_col.default_expr, None); - assert_eq!(user_middle_name_col.is_nullable, true); - assert_eq!(user_middle_name_col.is_primary_key, false); - assert_eq!(user_middle_name_col.is_unique, false); + assert!(user_middle_name_col.is_nullable); + assert!(!user_middle_name_col.is_primary_key); + assert!(!user_middle_name_col.is_unique); assert_eq!(user_middle_name_col.varchar_length, Some(255)); let properties_owner_id_col = cache @@ -194,9 +194,9 @@ mod tests { properties_owner_id_col.comment, Some("users might own many houses".into()) ); - assert_eq!(properties_owner_id_col.is_nullable, true); - assert_eq!(properties_owner_id_col.is_primary_key, false); - assert_eq!(properties_owner_id_col.is_unique, false); + assert!(properties_owner_id_col.is_nullable); + assert!(!properties_owner_id_col.is_primary_key); + assert!(!properties_owner_id_col.is_unique); assert_eq!(properties_owner_id_col.varchar_length, None); } } diff --git a/crates/pg_workspace_new/src/workspace/server/pg_query.rs b/crates/pg_workspace_new/src/workspace/server/pg_query.rs index e14e0a270..cbdf8bf0c 100644 --- a/crates/pg_workspace_new/src/workspace/server/pg_query.rs +++ b/crates/pg_workspace_new/src/workspace/server/pg_query.rs @@ -1,9 +1,8 @@ use std::sync::Arc; use dashmap::DashMap; -use pg_diagnostics::{serde::Diagnostic as SDiagnostic, Diagnostic, MessageAndDescription}; +use pg_diagnostics::serde::Diagnostic as SDiagnostic; use pg_query_ext::diagnostics::*; -use text_size::TextRange; use super::{ change::ChangedStatement, From d162213fc99e7ee97efbd80177ccfe7f0b80b9a6 Mon Sep 17 00:00:00 2001 From: psteinroe Date: Sat, 4 Jan 2025 12:45:30 -0100 Subject: [PATCH 08/23] fix: ci --- .github/workflows/pull_request.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index c48e5cc05..866502ee9 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -123,6 +123,8 @@ jobs: steps: - name: Checkout PR branch uses: actions/checkout@v4 + with: + submodules: true - name: Free Disk Space uses: ./.github/actions/free-disk-space - name: Install toolchain From 36bfd2dea217c8cca143a0a01d226a40d781d35b Mon Sep 17 00:00:00 2001 From: psteinroe Date: Sat, 4 Jan 2025 12:46:39 -0100 Subject: [PATCH 09/23] fix: ci --- crates/pg_completions/src/test_helper.rs | 3 ++- crates/pg_lsp/src/session.rs | 5 +---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/crates/pg_completions/src/test_helper.rs b/crates/pg_completions/src/test_helper.rs index 8aa20a273..4c29d1e7a 100644 --- a/crates/pg_completions/src/test_helper.rs +++ b/crates/pg_completions/src/test_helper.rs @@ -35,7 +35,8 @@ pub(crate) fn get_text_and_position(sql: &str) -> (usize, String) { // the cursor is to the left of the `CURSOR_POS` let position = sql .find(CURSOR_POS) - .expect("Please insert the CURSOR_POS into your query.").saturating_sub(1); + .expect("Please insert the CURSOR_POS into your query.") + .saturating_sub(1); let text = sql.replace(CURSOR_POS, ""); diff --git a/crates/pg_lsp/src/session.rs b/crates/pg_lsp/src/session.rs index e94fd0c53..16d99459a 100644 --- a/crates/pg_lsp/src/session.rs +++ b/crates/pg_lsp/src/session.rs @@ -245,10 +245,7 @@ impl Session { let completion_items: Vec = pg_completions::complete(CompletionParams { position: offset - range.start() - TextSize::from(1), text: stmt.text.clone(), - tree: ide - .tree_sitter - .tree(&stmt) - .as_ref().map(|t| t.as_ref()), + tree: ide.tree_sitter.tree(&stmt).as_ref().map(|t| t.as_ref()), schema: &schema_cache, }) .into_iter() From 4b4a59aa371efbcb0ab00bc052be6447cc7f5308 Mon Sep 17 00:00:00 2001 From: psteinroe Date: Sat, 4 Jan 2025 12:57:03 -0100 Subject: [PATCH 10/23] fix: ci --- .github/workflows/pull_request.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 866502ee9..b6e99c167 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -17,7 +17,7 @@ concurrency: cancel-in-progress: true env: - RUSTFLAGS: --deny warnings + RUSTFLAGS: --deny warnings -A dead_code RUST_LOG: info RUST_BACKTRACE: 1 RUSTUP_WINDOWS_PATH_ADD_BIN: 1 From bcd2b67fb38165dccdcbdf83b4ea65f993512e1f Mon Sep 17 00:00:00 2001 From: psteinroe Date: Sat, 4 Jan 2025 12:58:49 -0100 Subject: [PATCH 11/23] fix: ci --- crates/pg_diagnostics/src/display/backtrace.rs | 4 ++-- crates/pg_diagnostics/src/display/frame.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/pg_diagnostics/src/display/backtrace.rs b/crates/pg_diagnostics/src/display/backtrace.rs index c5ba1a1ee..bae7d979c 100644 --- a/crates/pg_diagnostics/src/display/backtrace.rs +++ b/crates/pg_diagnostics/src/display/backtrace.rs @@ -148,7 +148,7 @@ impl NativeBacktrace { frame.symbols().iter().any(|symbol| { symbol .addr() - .map_or(false, |addr| addr as usize == self.top_frame) + .is_some_and(|addr| addr as usize == self.top_frame) }) }); @@ -162,7 +162,7 @@ impl NativeBacktrace { frame.symbols().iter().any(|symbol| { symbol .addr() - .map_or(false, |addr| addr as usize == self.bottom_frame) + .is_some_and(|addr| addr as usize == self.bottom_frame) }) }); diff --git a/crates/pg_diagnostics/src/display/frame.rs b/crates/pg_diagnostics/src/display/frame.rs index 8013148e9..8719cc0df 100644 --- a/crates/pg_diagnostics/src/display/frame.rs +++ b/crates/pg_diagnostics/src/display/frame.rs @@ -411,7 +411,7 @@ pub(super) fn print_invisibles( let next_char_is_whitespace = iter .peek() - .map_or(false, |(_, char)| char.is_ascii_whitespace()); + .is_some_and(|(_, char)| char.is_ascii_whitespace()); if prev_char_was_whitespace || next_char_is_whitespace { show_invisible = false; @@ -436,7 +436,7 @@ pub(super) fn print_invisibles( // If we are a carriage return next to a \n then don't show the character as visible if options.ignore_trailing_carriage_return && char == '\r' { - let next_char_is_line_feed = iter.peek().map_or(false, |(_, char)| *char == '\n'); + let next_char_is_line_feed = iter.peek().is_some_and(|(_, char)| *char == '\n'); if next_char_is_line_feed { continue; } From 3e329c37b646b5ee073064137650d64ae3a6026b Mon Sep 17 00:00:00 2001 From: psteinroe Date: Sat, 4 Jan 2025 13:02:28 -0100 Subject: [PATCH 12/23] fix: ci --- .github/workflows/pull_request.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index b6e99c167..3e8c8df02 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -47,6 +47,15 @@ jobs: lint: name: Lint runs-on: ubuntu-latest + services: + postgres: + image: postgres:latest + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: postgres + ports: + - 5432:5432 steps: - name: Checkout PR Branch uses: actions/checkout@v4 From bb31d16c6e6cf232b13e199f609bc7feec66ba5a Mon Sep 17 00:00:00 2001 From: psteinroe Date: Sat, 4 Jan 2025 13:04:21 -0100 Subject: [PATCH 13/23] fix: ci --- .github/workflows/pull_request.yml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 3e8c8df02..66ccec779 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -44,8 +44,21 @@ jobs: cargo fmt --all --check taplo format --check + actionlint: + name: Lint GitHib Actions + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Download actionlint + id: get_actionlint + run: bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash) + shell: bash + - name: Check workflow files + run: ${{ steps.get_actionlint.outputs.executable }} -color + shell: bash + lint: - name: Lint + name: Lint Project runs-on: ubuntu-latest services: postgres: From b874e4eb2f819c3f61a69a0166289135e67ab103 Mon Sep 17 00:00:00 2001 From: psteinroe Date: Sat, 4 Jan 2025 13:07:20 -0100 Subject: [PATCH 14/23] fix: ci --- .github/workflows/pull_request.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 66ccec779..b732068fb 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -161,7 +161,7 @@ jobs: run: cargo run -p xtask_codegen -- configuration - name: Check for git diff run: | - if [[ `git status --porcelain` ]]; then + if [[ $(git status --porcelain) ]]; then git status git diff exit 1 From 4a702a736f2c9e3147b4381a2d39f19665292aa7 Mon Sep 17 00:00:00 2001 From: psteinroe Date: Sat, 4 Jan 2025 13:07:45 -0100 Subject: [PATCH 15/23] fix: ci --- .github/workflows/pull_request.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index b732068fb..2318d9f51 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -45,7 +45,7 @@ jobs: taplo format --check actionlint: - name: Lint GitHib Actions + name: Lint GitHub Actions runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 From c2f42c6c5915aaa8bcfb9fb3928269d99c0670ce Mon Sep 17 00:00:00 2001 From: psteinroe Date: Sat, 4 Jan 2025 13:12:03 -0100 Subject: [PATCH 16/23] fix: ci --- crates/pg_schema_cache/src/schema_cache.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/pg_schema_cache/src/schema_cache.rs b/crates/pg_schema_cache/src/schema_cache.rs index 6deac6f11..8d73e6319 100644 --- a/crates/pg_schema_cache/src/schema_cache.rs +++ b/crates/pg_schema_cache/src/schema_cache.rs @@ -66,7 +66,7 @@ impl SchemaCache { self.columns.iter().find(|c| { c.name.as_str() == name && c.table_name.as_str() == table - && schema.map_or(true, |s| s == c.schema_name.as_str()) + && schema.is_none_or(|s| s == c.schema_name.as_str()) }) } From 826c8a287d3ac39eb110ae41cc34f5bab7f1f173 Mon Sep 17 00:00:00 2001 From: psteinroe Date: Sat, 4 Jan 2025 13:17:15 -0100 Subject: [PATCH 17/23] fix: ci --- .github/workflows/pull_request.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 2318d9f51..a2d2e0d82 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -72,6 +72,8 @@ jobs: steps: - name: Checkout PR Branch uses: actions/checkout@v4 + with: + submodules: true - name: Free Disk Space uses: ./.github/actions/free-disk-space - name: Install toolchain @@ -92,6 +94,8 @@ jobs: steps: - name: Checkout PR Branch uses: actions/checkout@v4 + with: + submodules: true - name: Free Disk Space uses: ./.github/actions/free-disk-space - name: Install toolchain From d1805b50f45f734e9fed67689e044a63358fd75b Mon Sep 17 00:00:00 2001 From: psteinroe Date: Sat, 4 Jan 2025 13:19:02 -0100 Subject: [PATCH 18/23] fix: ci --- .github/workflows/pull_request.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index a2d2e0d82..50208ebe2 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -17,7 +17,7 @@ concurrency: cancel-in-progress: true env: - RUSTFLAGS: --deny warnings -A dead_code + RUSTFLAGS: -A dead_code RUST_LOG: info RUST_BACKTRACE: 1 RUSTUP_WINDOWS_PATH_ADD_BIN: 1 From 580eb3df771dc86bb3dfe30c6ddca4d62771b8ce Mon Sep 17 00:00:00 2001 From: psteinroe Date: Sat, 4 Jan 2025 13:19:18 -0100 Subject: [PATCH 19/23] fix: ci --- .github/workflows/pull_request.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 50208ebe2..c832b7236 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -135,7 +135,7 @@ jobs: run: cargo test --workspace codegen: - name: Codegen + name: Check Codegen runs-on: ubuntu-latest services: postgres: From 7a9fc56fb17f7df5d41bdee281c1c8cdcaad33f3 Mon Sep 17 00:00:00 2001 From: psteinroe Date: Sat, 4 Jan 2025 13:48:23 -0100 Subject: [PATCH 20/23] fix: ci --- .github/workflows/pull_request.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index c832b7236..f33817711 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -91,6 +91,15 @@ jobs: check-dependencies: name: Check Dependencies runs-on: ubuntu-latest + services: + postgres: + image: postgres:latest + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: postgres + ports: + - 5432:5432 steps: - name: Checkout PR Branch uses: actions/checkout@v4 @@ -111,7 +120,8 @@ jobs: strategy: matrix: include: - - os: windows-latest + # reactive once we upgrade to the latest version of pg_query that is windows-compatible + # - os: windows-latest - os: ubuntu-latest steps: - name: Checkout PR branch From 2340558c896c5700db9a0362d501f6b9dcba83b4 Mon Sep 17 00:00:00 2001 From: psteinroe Date: Mon, 6 Jan 2025 10:19:18 -0100 Subject: [PATCH 21/23] fix: ci --- .github/workflows/pull_request.yml | 50 +++++++++++++++--------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index f33817711..74a0e0cd9 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -88,31 +88,31 @@ jobs: cargo clippy cargo run -p rules_check - check-dependencies: - name: Check Dependencies - runs-on: ubuntu-latest - services: - postgres: - image: postgres:latest - env: - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres - POSTGRES_DB: postgres - ports: - - 5432:5432 - steps: - - name: Checkout PR Branch - uses: actions/checkout@v4 - with: - submodules: true - - name: Free Disk Space - uses: ./.github/actions/free-disk-space - - name: Install toolchain - run: rustup toolchain install nightly - - name: Install udeps - run: cargo install cargo-udeps --locked - - name: Detect unused dependencies using udeps - run: cargo +nightly udeps --all-targets + # check-dependencies: + # name: Check Dependencies + # runs-on: ubuntu-latest + # services: + # postgres: + # image: postgres:latest + # env: + # POSTGRES_USER: postgres + # POSTGRES_PASSWORD: postgres + # POSTGRES_DB: postgres + # ports: + # - 5432:5432 + # steps: + # - name: Checkout PR Branch + # uses: actions/checkout@v4 + # with: + # submodules: true + # - name: Free Disk Space + # uses: ./.github/actions/free-disk-space + # - name: Install toolchain + # run: rustup toolchain install nightly + # - name: Install udeps + # run: cargo install cargo-udeps --locked + # - name: Detect unused dependencies using udeps + # run: cargo +nightly udeps --all-targets test: name: Test From eae8aee207e35874bf6917b419e688211248086b Mon Sep 17 00:00:00 2001 From: psteinroe Date: Mon, 6 Jan 2025 10:20:06 -0100 Subject: [PATCH 22/23] fix: ci --- .github/actions/setup-monorepo/action.yml | 21 ------- .github/workflows/pull_request.yml | 76 +++-------------------- 2 files changed, 8 insertions(+), 89 deletions(-) delete mode 100644 .github/actions/setup-monorepo/action.yml diff --git a/.github/actions/setup-monorepo/action.yml b/.github/actions/setup-monorepo/action.yml deleted file mode 100644 index c697b3d89..000000000 --- a/.github/actions/setup-monorepo/action.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: Setup Monorepo -description: Prepare and install everything for the monorepo - -inputs: - github-token: - description: The GitHub token - - toolchain: - description: Toolchain name to use - default: nightly - -runs: - using: composite - steps: - - name: 🏗 Setup Toolchain - uses: dtolnay/rust-toolchain@master - with: - toolchain: ${{ inputs.toolchain }} - - - name: 🔒 Cache - uses: swatinem/rust-cache@v2 diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 74a0e0cd9..9e2084916 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -3,14 +3,14 @@ name: Pull Request on: workflow_dispatch: pull_request: - # paths: # Only run when changes are made to rust code or root Cargo - # - "crates/**" - # - "fuzz/**" - # - "xtask/**" - # - "Cargo.toml" - # - "Cargo.lock" - # - "rust-toolchain.toml" - # - "rustfmt.toml" + paths: # Only run when changes are made to rust code or root Cargo + - "crates/**" + - "fuzz/**" + - "xtask/**" + - "Cargo.toml" + - "Cargo.lock" + - "rust-toolchain.toml" + - "rustfmt.toml" concurrency: group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }} @@ -180,63 +180,3 @@ jobs: git diff exit 1 fi - - # ci: - # name: CI - # timeout-minutes: 10 - # runs-on: ubuntu-latest - # - # services: - # postgres: - # image: postgres:latest - # env: - # POSTGRES_USER: postgres - # POSTGRES_PASSWORD: postgres - # POSTGRES_DB: postgres - # ports: - # - 5432:5432 - # - # env: - # DATABASE_URL: postgresql://postgres:postgres@localhost:5432/postgres - # - # steps: - # - name: 🏗 Setup repository - # uses: actions/checkout@v4 - # with: - # submodules: true - # - # - name: Free Disk Space - # uses: ./.github/actions/free-disk-space - # - # - name: Install toolchain - # uses: moonrepo/setup-rust@e013866c4215f77c925f42f60257dec7dd18836e # v1.2.1 - # with: - # components: rustfmt - # bins: taplo-cli - # cache-base: main - # env: - # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # - name: Run format - # run: | - # cargo fmt --all --check - # taplo format --check - # - # - name: 🏗 Setup monorepo - # uses: ./.github/actions/setup-monorepo - # with: - # github-token: ${{ secrets.GITHUB_TOKEN }} - # - # - name: Run test migrations - # run: psql -f test-db/seed.sql postgresql://postgres:postgres@localhost:5432/postgres - # - # - name: 📦 Build - # id: build - # run: RUSTFLAGS="-A dead_code" cargo build - # - # - name: ⚡️ Check - # id: check - # run: RUSTFLAGS="-A dead_code" cargo check - # - # - name: 🦺 Test - # id: test - # run: RUSTFLAGS="-A dead_code" cargo test From 32c832203cb1a15da57dcacafcabb2ecb135bb49 Mon Sep 17 00:00:00 2001 From: psteinroe Date: Mon, 6 Jan 2025 10:20:38 -0100 Subject: [PATCH 23/23] fix: ci --- .github/workflows/pull_request.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 9e2084916..b75489f74 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -5,6 +5,7 @@ on: pull_request: paths: # Only run when changes are made to rust code or root Cargo - "crates/**" + - "lib/**" - "fuzz/**" - "xtask/**" - "Cargo.toml"