diff --git a/STACKED_PR_PLAN.md b/STACKED_PR_PLAN.md deleted file mode 100644 index 6a4a7cace..000000000 --- a/STACKED_PR_PLAN.md +++ /dev/null @@ -1,186 +0,0 @@ -# Stacked PR Plan for PR 629 - -## Overview -PR 629 "feat: keyword completion in SELECT clauses" will be split into the following stacked PRs. - -## PRs - -### PR 1: refactor(grammar): update conflicts and remove unused keywords -**Files:** -- `crates/pgls_treesitter_grammar/grammar.js` -- `crates/pgls_treesitter_grammar/src/grammar.json` (generated) -- `crates/pgls_treesitter_grammar/src/node-types.json` (generated) -- `crates/pgls_treesitter_grammar/src/parser.c` (generated) - -**Changes:** -- Remove unused keywords (`unload`, `overwrite`, `change`, `modify`) -- Update grammar conflicts (join rules, object_reference) -- Regenerate parser files - -**Status:** [x] complete - https://github.com/supabase-community/postgres-language-server/pull/654 - ---- - -### PR 2: docs(grammar): add grammar guidelines -**Files:** -- `crates/pgls_treesitter_grammar/GRAMMAR_GUIDELINES.md` - -**Changes:** -- Add documentation for grammar contributions -- Explain identifier types, partial grammars, and `@end` markers - -**Status:** [x] complete - https://github.com/supabase-community/postgres-language-server/pull/655 - ---- - -### PR 3: feat(grammar): add benchmarks -**Files:** -- `crates/pgls_treesitter_grammar/Cargo.toml` -- `crates/pgls_treesitter_grammar/benches/lookahead_iter.rs` -- `crates/pgls_treesitter_grammar/benches/parsing.rs` -- `crates/pgls_treesitter_grammar/benches/parsing_with_existing_tree.rs` -- `Cargo.lock` - -**Changes:** -- Add criterion and clap dependencies -- Add parsing benchmarks -- Add lookahead iterator benchmark - -**Status:** [x] complete - https://github.com/supabase-community/postgres-language-server/pull/656 - ---- - -### PR 4: feat(treesitter): add helper module with navigation utilities -**Files:** -- `crates/pgls_treesitter/src/helper.rs` -- `crates/pgls_treesitter/src/lib.rs` - -**Changes:** -- Add `goto_node_at_position`, `goto_previous_leaf`, `goto_closest_unfinished_parent_clause` -- Add `previous_sibling_completed`, `last_children_completed` -- Add `SINGLE_TOKEN_RULES` constant -- Export functions from lib.rs - -**Status:** [x] complete - https://github.com/supabase-community/postgres-language-server/pull/657 - ---- - -### PR 5: feat(treesitter): add keyword and clause tracking to context -**Files:** -- `crates/pgls_treesitter/src/context/mod.rs` - -**Changes:** -- Add `possible_keywords_at_position`, `previous_clause`, `current_clause` fields -- Add methods to gather keyword possibilities using lookahead iterator -- Fix `GrantStatement` enum mapping (was incorrectly `RevokeStatement`) - -**Status:** [x] complete - https://github.com/supabase-community/postgres-language-server/pull/658 - ---- - -### PR 6: fix(completions): sanitization edge cases -**Files:** -- `crates/pgls_completions/src/sanitization.rs` - -**Changes:** -- Use `saturating_sub` to avoid panic on position 0 -- Prevent underflow in cursor position checks - -**Status:** [x] complete - https://github.com/supabase-community/postgres-language-server/pull/659 - ---- - -### PR 7: feat(completions): add keyword completion provider -**Files:** -- `crates/pgls_completions/src/providers/keywords.rs` -- `crates/pgls_completions/src/providers/mod.rs` -- `crates/pgls_completions/src/complete.rs` -- `crates/pgls_completions/src/item.rs` -- `crates/pgls_completions/src/relevance.rs` -- `crates/pgls_completions/src/relevance/filtering.rs` -- `crates/pgls_completions/src/relevance/scoring.rs` -- `crates/pgls_completions/src/builder.rs` -- `crates/pgls_lsp/src/handlers/completions.rs` - -**Changes:** -- Add `SqlKeyword` struct with keyword list -- Add `complete_keywords` function -- Add `Keyword` variant to `CompletionItemKind` -- Add filtering logic with speculative parsing -- Add keyword scoring (-10 to deprioritize) -- Update builder to pass shared tree for filtering - -**Status:** [x] complete - https://github.com/supabase-community/postgres-language-server/pull/661 - ---- - -### PR 8: style(grammar): formatting and trailing commas -**Files:** -- `crates/pgls_treesitter_grammar/grammar.js` -- `crates/pgls_treesitter_grammar/src/grammar.json` (generated) -- `crates/pgls_treesitter_grammar/src/node-types.json` (generated) -- `crates/pgls_treesitter_grammar/src/parser.c` (generated) -- `crates/pgls_treesitter_grammar/Cargo.toml` - -**Changes:** -- Add trailing commas to grammar.js -- Reorder dependencies in Cargo.toml - -**Status:** [ ] pending - ---- - -### PR 9: refactor(test_utils): add field names to tree printing -**Files:** -- `crates/pgls_test_utils/src/lib.rs` -- `crates/pgls_test_utils/src/bin/tree_print.rs` -- `crates/pgls_treesitter_grammar/tests/grammar_tests.rs` - -**Changes:** -- Update print_ts_tree signature to include field names -- Update grammar tests to use new signature - -**Status:** [ ] pending - ---- - -### PR 10: fix(treesitter): fix helper and context edge cases -**Files:** -- `crates/pgls_treesitter/src/helper.rs` -- `crates/pgls_treesitter/src/context/mod.rs` -- `crates/pgls_completions/src/providers/columns.rs` (typo fix only) - -**Changes:** -- Fix `previous_sibling_completed` to return true when no sibling -- Fix `delete` -> `delete_statement` clause mapping -- Fix typo "speciifcation" -> "specification" - -**Status:** [ ] pending - ---- - -### PR 11: test(completions): update snapshots and enable tests -**Files:** -- All snapshot files in `crates/pgls_completions/src/snapshots/` -- All snapshot files in `crates/pgls_treesitter_grammar/tests/snapshots/` -- `crates/pgls_completions/src/providers/columns.rs` (remove #[ignore]) -- `crates/pgls_completions/src/providers/keywords.rs` (remove #[ignore]) -- `crates/pgls_completions/src/providers/roles.rs` -- `crates/pgls_completions/src/providers/tables.rs` -- `crates/pgls_completions/src/relevance/filtering.rs` (remove #[ignore]) -- `crates/pgls_treesitter/src/context/mod.rs` (remove #[ignore]) -- `crates/pgls_completions/src/test_helper.rs` - -**Changes:** -- Update all snapshots for keyword completions and field names -- Remove #[ignore] attributes from tests -- Update test helper - -**Status:** [x] complete - https://github.com/supabase-community/postgres-language-server/pull/660 (needs splitting) - ---- - -## Notes -- PRs 1-6 are independent infrastructure changes -- PR 7 is the main feature PR -- PRs 8-11 split the original PR 8 into smaller chunks diff --git a/crates/pgls_completions/src/providers/columns.rs b/crates/pgls_completions/src/providers/columns.rs index 69328bf4e..d0908d0e0 100644 --- a/crates/pgls_completions/src/providers/columns.rs +++ b/crates/pgls_completions/src/providers/columns.rs @@ -93,7 +93,6 @@ mod tests { } #[sqlx::test(migrator = "pgls_test_utils::MIGRATIONS")] - #[ignore = "will be reintroduced after stacked keyword-completion PRs merge"] async fn shows_multiple_columns_if_no_relation_specified(pool: PgPool) { let setup = r#" create schema private; @@ -125,7 +124,6 @@ mod tests { } #[sqlx::test(migrator = "pgls_test_utils::MIGRATIONS")] - #[ignore = "will be reintroduced after stacked keyword-completion PRs merge"] async fn suggests_relevant_columns_without_letters(pool: PgPool) { let setup = r#" create table users ( @@ -213,7 +211,6 @@ mod tests { } #[sqlx::test(migrator = "pgls_test_utils::MIGRATIONS")] - #[ignore = "will be reintroduced after stacked keyword-completion PRs merge"] async fn filters_out_by_aliases_in_join_on(pool: PgPool) { let setup = r#" create schema auth; @@ -281,7 +278,6 @@ mod tests { } #[sqlx::test(migrator = "pgls_test_utils::MIGRATIONS")] - #[ignore = "will be reintroduced after stacked keyword-completion PRs merge"] async fn does_not_complete_cols_in_join_clauses(pool: PgPool) { let setup = r#" create schema auth; @@ -310,7 +306,6 @@ mod tests { } #[sqlx::test(migrator = "pgls_test_utils::MIGRATIONS")] - #[ignore = "will be reintroduced after stacked keyword-completion PRs merge"] async fn completes_in_join_on_clause(pool: PgPool) { let setup = r#" create schema auth; @@ -385,7 +380,6 @@ mod tests { } #[sqlx::test(migrator = "pgls_test_utils::MIGRATIONS")] - #[ignore = "will be reintroduced after stacked keyword-completion PRs merge"] async fn suggests_columns_in_insert_clause(pool: PgPool) { let setup = r#" create table instruments ( @@ -423,7 +417,6 @@ mod tests { } #[sqlx::test(migrator = "pgls_test_utils::MIGRATIONS")] - #[ignore = "will be reintroduced after stacked keyword-completion PRs merge"] async fn suggests_columns_in_where_clause(pool: PgPool) { let setup = r#" create table instruments ( @@ -447,7 +440,7 @@ mod tests { "select name from instruments i join others o on i.z = o.a ", ) .type_sql("where o.<1>a = <2>i.z and <3>i.id > 5;") - .comment("should respect alias speciifcation") + .comment("should respect alias specification") .comment("should not prioritize suggest columns or schemas (right side of binary expression)") .comment("should prioritize columns that aren't already mentioned"), ) @@ -456,7 +449,6 @@ mod tests { } #[sqlx::test(migrator = "pgls_test_utils::MIGRATIONS")] - #[ignore = "will be reintroduced after stacked keyword-completion PRs merge"] async fn suggests_columns_in_alter_table_and_drop_table(pool: PgPool) { let setup = r#" create table instruments ( @@ -531,7 +523,6 @@ mod tests { } #[sqlx::test(migrator = "pgls_test_utils::MIGRATIONS")] - #[ignore = "will be reintroduced after stacked keyword-completion PRs merge"] async fn completes_quoted_columns(pool: PgPool) { let setup = r#" create schema if not exists private; @@ -553,7 +544,6 @@ mod tests { } #[sqlx::test(migrator = "pgls_test_utils::MIGRATIONS")] - #[ignore = "will be reintroduced after stacked keyword-completion PRs merge"] async fn completes_quoted_columns_with_aliases(pool: PgPool) { let setup = r#" create schema if not exists private; diff --git a/crates/pgls_completions/src/providers/keywords.rs b/crates/pgls_completions/src/providers/keywords.rs index 20353e778..64ee188ee 100644 --- a/crates/pgls_completions/src/providers/keywords.rs +++ b/crates/pgls_completions/src/providers/keywords.rs @@ -535,7 +535,6 @@ mod tests { } #[sqlx::test] - #[ignore = "will be reintroduced after stacked keyword-completion PRs merge"] async fn completes_after_from_clause(pool: PgPool) { let setup = r#" create table public.users ( @@ -598,7 +597,6 @@ mod tests { } #[sqlx::test] - #[ignore = "will be reintroduced after stacked keyword-completion PRs merge"] async fn completes_from_keyword(pool: PgPool) { let setup = r#" create table public.users ( @@ -622,7 +620,6 @@ mod tests { } #[sqlx::test] - #[ignore = "will be reintroduced after stacked keyword-completion PRs merge"] async fn completes_from_keyword_after_aliases(pool: PgPool) { let setup = r#" create table public.users ( @@ -668,7 +665,6 @@ mod tests { } #[sqlx::test] - #[ignore = "will be reintroduced after stacked keyword-completion PRs merge"] async fn completes_keywords_after_column_aliases(pool: PgPool) { let setup = r#" create table public.users ( @@ -784,7 +780,6 @@ mod tests { } #[sqlx::test] - #[ignore = "will be reintroduced after stacked keyword-completion PRs merge"] async fn completes_join_after_alias(pool: PgPool) { let setup = r#" create table public.users ( diff --git a/crates/pgls_completions/src/providers/roles.rs b/crates/pgls_completions/src/providers/roles.rs index 4e8c7f17a..bbe7f40ef 100644 --- a/crates/pgls_completions/src/providers/roles.rs +++ b/crates/pgls_completions/src/providers/roles.rs @@ -34,7 +34,9 @@ pub fn complete_roles<'a>( mod tests { use sqlx::{Executor, PgPool}; - use crate::test_helper::{CompletionAssertion, assert_complete_results}; + use crate::test_helper::{ + CompletionAssertion, TestCompletionsCase, TestCompletionsSuite, assert_complete_results, + }; use pgls_test_utils::QueryWithCursorPosition; @@ -89,34 +91,44 @@ mod tests { } #[sqlx::test(migrator = "pgls_test_utils::MIGRATIONS")] - async fn works_in_set_statement(pool: PgPool) { - pool.execute(SETUP).await.unwrap(); - - assert_complete_results( - format!("set role {}", QueryWithCursorPosition::cursor_marker()).as_str(), - expected_roles(), - None, - &pool, - ) - .await; + async fn works_in_set_role_statement(pool: PgPool) { + TestCompletionsSuite::new(&pool, Some(SETUP)) + .with_case(TestCompletionsCase::new().type_sql("set role anon;")) + .snapshot("works_in_set_role_statement") + .await; + } - assert_complete_results( - format!( - "set session authorization {}", - QueryWithCursorPosition::cursor_marker() + #[sqlx::test(migrator = "pgls_test_utils::MIGRATIONS")] + async fn works_in_session_authorization_statement(pool: PgPool) { + TestCompletionsSuite::new(&pool, Some(SETUP)) + .with_case( + TestCompletionsCase::new().type_sql("set session authorization authenticated;"), ) - .as_str(), - expected_roles(), - None, - &pool, - ) - .await; + .snapshot("works_in_session_authorization_statement") + .await; } #[sqlx::test(migrator = "pgls_test_utils::MIGRATIONS")] - async fn works_in_policies(pool: PgPool) { + async fn works_in_policy_restrictive(pool: PgPool) { pool.execute(SETUP).await.unwrap(); + let mut expected = vec![ + CompletionAssertion::LabelAndKind( + "current_role".into(), + crate::CompletionItemKind::Keyword, + ), + CompletionAssertion::LabelAndKind( + "current_user".into(), + crate::CompletionItemKind::Keyword, + ), + CompletionAssertion::LabelAndKind("public".into(), crate::CompletionItemKind::Keyword), + CompletionAssertion::LabelAndKind( + "session_user".into(), + crate::CompletionItemKind::Keyword, + ), + ]; + expected.append(&mut expected_roles()); + assert_complete_results( format!( r#"create policy "my cool policy" on public.users @@ -127,11 +139,33 @@ mod tests { QueryWithCursorPosition::cursor_marker() ) .as_str(), - expected_roles(), + expected, None, &pool, ) .await; + } + + #[sqlx::test(migrator = "pgls_test_utils::MIGRATIONS")] + async fn works_in_policy_select(pool: PgPool) { + pool.execute(SETUP).await.unwrap(); + + let mut expected = vec![ + CompletionAssertion::LabelAndKind( + "current_role".into(), + crate::CompletionItemKind::Keyword, + ), + CompletionAssertion::LabelAndKind( + "current_user".into(), + crate::CompletionItemKind::Keyword, + ), + CompletionAssertion::LabelAndKind("public".into(), crate::CompletionItemKind::Keyword), + CompletionAssertion::LabelAndKind( + "session_user".into(), + crate::CompletionItemKind::Keyword, + ), + ]; + expected.append(&mut expected_roles()); assert_complete_results( format!( @@ -141,7 +175,7 @@ mod tests { QueryWithCursorPosition::cursor_marker() ) .as_str(), - expected_roles(), + expected, None, &pool, ) @@ -149,9 +183,26 @@ mod tests { } #[sqlx::test(migrator = "pgls_test_utils::MIGRATIONS")] - async fn works_in_grant_statements(pool: PgPool) { + async fn works_in_grant_on_table_to(pool: PgPool) { pool.execute(SETUP).await.unwrap(); + let mut expected = vec![ + CompletionAssertion::LabelAndKind( + "current_role".into(), + crate::CompletionItemKind::Keyword, + ), + CompletionAssertion::LabelAndKind( + "current_user".into(), + crate::CompletionItemKind::Keyword, + ), + CompletionAssertion::LabelAndKind("public".into(), crate::CompletionItemKind::Keyword), + CompletionAssertion::LabelAndKind( + "session_user".into(), + crate::CompletionItemKind::Keyword, + ), + ]; + expected.append(&mut expected_roles()); + assert_complete_results( format!( r#"grant select @@ -160,11 +211,33 @@ mod tests { QueryWithCursorPosition::cursor_marker() ) .as_str(), - expected_roles(), + expected, None, &pool, ) .await; + } + + #[sqlx::test(migrator = "pgls_test_utils::MIGRATIONS")] + async fn works_in_grant_on_table_to_multiple(pool: PgPool) { + pool.execute(SETUP).await.unwrap(); + + let mut expected = vec![ + CompletionAssertion::LabelAndKind( + "current_role".into(), + crate::CompletionItemKind::Keyword, + ), + CompletionAssertion::LabelAndKind( + "current_user".into(), + crate::CompletionItemKind::Keyword, + ), + CompletionAssertion::LabelAndKind("public".into(), crate::CompletionItemKind::Keyword), + CompletionAssertion::LabelAndKind( + "session_user".into(), + crate::CompletionItemKind::Keyword, + ), + ]; + expected.append(&mut expected_roles()); assert_complete_results( format!( @@ -174,11 +247,16 @@ mod tests { QueryWithCursorPosition::cursor_marker() ) .as_str(), - expected_roles(), + expected, None, &pool, ) .await; + } + + #[sqlx::test(migrator = "pgls_test_utils::MIGRATIONS")] + async fn works_in_grant_role_to(pool: PgPool) { + pool.execute(SETUP).await.unwrap(); assert_complete_results( format!( @@ -194,38 +272,138 @@ mod tests { } #[sqlx::test(migrator = "pgls_test_utils::MIGRATIONS")] - async fn works_in_revoke_statements(pool: PgPool) { + async fn works_in_revoke_role(pool: PgPool) { pool.execute(SETUP).await.unwrap(); - let queries = vec![ + assert_complete_results( format!( "revoke {} from owner", QueryWithCursorPosition::cursor_marker() - ), + ) + .as_str(), + expected_roles(), + None, + &pool, + ) + .await; + } + + #[sqlx::test(migrator = "pgls_test_utils::MIGRATIONS")] + async fn works_in_revoke_admin_option_for(pool: PgPool) { + pool.execute(SETUP).await.unwrap(); + + assert_complete_results( format!( "revoke admin option for {} from owner", QueryWithCursorPosition::cursor_marker() + ) + .as_str(), + expected_roles(), + None, + &pool, + ) + .await; + } + + #[sqlx::test(migrator = "pgls_test_utils::MIGRATIONS")] + async fn works_in_revoke_from(pool: PgPool) { + pool.execute(SETUP).await.unwrap(); + + let mut expected = vec![ + CompletionAssertion::LabelAndKind( + "current_role".into(), + crate::CompletionItemKind::Keyword, + ), + CompletionAssertion::LabelAndKind( + "current_user".into(), + crate::CompletionItemKind::Keyword, + ), + CompletionAssertion::LabelAndKind("public".into(), crate::CompletionItemKind::Keyword), + CompletionAssertion::LabelAndKind( + "session_user".into(), + crate::CompletionItemKind::Keyword, ), + ]; + expected.append(&mut expected_roles()); + + assert_complete_results( format!( "revoke owner from {}", QueryWithCursorPosition::cursor_marker() - ), + ) + .as_str(), + expected, + None, + &pool, + ) + .await; + } + + #[sqlx::test(migrator = "pgls_test_utils::MIGRATIONS")] + async fn works_in_revoke_all_on_schema_from_granted_by(pool: PgPool) { + pool.execute(SETUP).await.unwrap(); + + assert_complete_results( format!( "revoke all on schema public from {} granted by", QueryWithCursorPosition::cursor_marker() - ), + ) + .as_str(), + expected_roles(), + None, + &pool, + ) + .await; + } + + #[sqlx::test(migrator = "pgls_test_utils::MIGRATIONS")] + async fn works_in_revoke_all_on_schema_from_multiple(pool: PgPool) { + pool.execute(SETUP).await.unwrap(); + + assert_complete_results( format!( "revoke all on schema public from owner, {}", QueryWithCursorPosition::cursor_marker() + ) + .as_str(), + expected_roles(), + None, + &pool, + ) + .await; + } + + #[sqlx::test(migrator = "pgls_test_utils::MIGRATIONS")] + async fn works_in_revoke_all_on_table_from_multiple(pool: PgPool) { + pool.execute(SETUP).await.unwrap(); + + let mut expected = vec![ + CompletionAssertion::LabelAndKind( + "current_role".into(), + crate::CompletionItemKind::Keyword, ), - format!( - "revoke all on table users from owner, {}", - QueryWithCursorPosition::cursor_marker() + CompletionAssertion::LabelAndKind( + "current_user".into(), + crate::CompletionItemKind::Keyword, + ), + CompletionAssertion::LabelAndKind("public".into(), crate::CompletionItemKind::Keyword), + CompletionAssertion::LabelAndKind( + "session_user".into(), + crate::CompletionItemKind::Keyword, ), ]; + expected.append(&mut expected_roles()); - for query in queries { - assert_complete_results(query.as_str(), expected_roles(), None, &pool).await; - } + assert_complete_results( + format!( + "revoke all on table users from owner, {}", + QueryWithCursorPosition::cursor_marker() + ) + .as_str(), + expected, + None, + &pool, + ) + .await; } } diff --git a/crates/pgls_completions/src/providers/tables.rs b/crates/pgls_completions/src/providers/tables.rs index 2068577fb..d5003c58d 100644 --- a/crates/pgls_completions/src/providers/tables.rs +++ b/crates/pgls_completions/src/providers/tables.rs @@ -64,8 +64,8 @@ mod tests { use crate::{ CompletionItem, CompletionItemKind, complete, test_helper::{ - CompletionAssertion, assert_complete_results, assert_no_complete_results, - get_test_deps, get_test_params, + CompletionAssertion, TestCompletionsCase, TestCompletionsSuite, + assert_complete_results, assert_no_complete_results, get_test_deps, get_test_params, }, }; @@ -268,70 +268,13 @@ mod tests { ); "#; - pool.execute(setup).await.unwrap(); - - assert_complete_results( - format!("update {}", QueryWithCursorPosition::cursor_marker()).as_str(), - vec![CompletionAssertion::LabelAndKind( - "coos".into(), - CompletionItemKind::Table, - )], - None, - &pool, - ) - .await; - - assert_complete_results( - format!("update public.{}", QueryWithCursorPosition::cursor_marker()).as_str(), - vec![CompletionAssertion::LabelAndKind( - "coos".into(), - CompletionItemKind::Table, - )], - None, - &pool, - ) - .await; - - assert_no_complete_results( - format!( - "update public.coos {}", - QueryWithCursorPosition::cursor_marker() - ) - .as_str(), - None, - &pool, - ) - .await; - - assert_complete_results( - format!( - "update coos set {}", - QueryWithCursorPosition::cursor_marker() + TestCompletionsSuite::new(&pool, Some(setup)) + .with_case( + TestCompletionsCase::new() + .type_sql("update public.coos set name = 'cool' where id = 5;"), ) - .as_str(), - vec![ - CompletionAssertion::Label("id".into()), - CompletionAssertion::Label("name".into()), - ], - None, - &pool, - ) - .await; - - assert_complete_results( - format!( - "update coos set name = 'cool' where {}", - QueryWithCursorPosition::cursor_marker() - ) - .as_str(), - vec![ - CompletionAssertion::Label("id".into()), - CompletionAssertion::Label("name".into()), - ], - None, - &pool, - ) - .await; + .snapshot("suggests_tables_in_update") + .await; } #[sqlx::test(migrator = "pgls_test_utils::MIGRATIONS")] @@ -411,31 +354,18 @@ mod tests { ); "#; - assert_complete_results( - format!( - "select * from auth.users u join {}", - QueryWithCursorPosition::cursor_marker() + TestCompletionsSuite::new(&pool, Some(setup)) + .with_case( + TestCompletionsCase::new() + .inside_static_statement("select * from auth.users u ") + .type_sql("join"), ) - .as_str(), - vec![ - CompletionAssertion::LabelAndKind("auth".into(), CompletionItemKind::Schema), - CompletionAssertion::LabelAndKind( - "information_schema".into(), - CompletionItemKind::Schema, - ), - CompletionAssertion::LabelAndKind("pg_catalog".into(), CompletionItemKind::Schema), - CompletionAssertion::LabelAndKind("pg_toast".into(), CompletionItemKind::Schema), - CompletionAssertion::LabelAndKind("posts".into(), CompletionItemKind::Table), // self-join - CompletionAssertion::LabelAndKind("users".into(), CompletionItemKind::Table), - ], - Some(setup), - &pool, - ) - .await; + .snapshot("suggests_tables_in_join") + .await; } #[sqlx::test(migrator = "pgls_test_utils::MIGRATIONS")] - async fn suggests_tables_in_alter_and_drop_statements(pool: PgPool) { + async fn suggests_tables_in_drop_statements(pool: PgPool) { let setup = r#" create schema auth; @@ -454,63 +384,36 @@ mod tests { ); "#; - pool.execute(setup).await.unwrap(); + TestCompletionsSuite::new(&pool, Some(setup)) + .with_case(TestCompletionsCase::new().type_sql("drop table if exists auth.posts")) + .snapshot("suggests_tables_in_drop_statements") + .await; + } - assert_complete_results( - format!("alter table {}", QueryWithCursorPosition::cursor_marker()).as_str(), - vec![ - CompletionAssertion::LabelAndKind("auth".into(), CompletionItemKind::Schema), - CompletionAssertion::LabelAndKind("posts".into(), CompletionItemKind::Table), - CompletionAssertion::LabelAndKind("users".into(), CompletionItemKind::Table), - ], - None, - &pool, - ) - .await; + #[sqlx::test(migrator = "pgls_test_utils::MIGRATIONS")] + async fn suggests_tables_in_alter_statements(pool: PgPool) { + let setup = r#" + create schema auth; - assert_complete_results( - format!( - "alter table if exists {}", - QueryWithCursorPosition::cursor_marker() - ) - .as_str(), - vec![ - CompletionAssertion::LabelAndKind("auth".into(), CompletionItemKind::Schema), - CompletionAssertion::LabelAndKind("posts".into(), CompletionItemKind::Table), - CompletionAssertion::LabelAndKind("users".into(), CompletionItemKind::Table), - ], - None, - &pool, - ) - .await; + create table auth.users ( + uid serial primary key, + name text not null, + email text unique not null + ); - assert_complete_results( - format!("drop table {}", QueryWithCursorPosition::cursor_marker()).as_str(), - vec![ - CompletionAssertion::LabelAndKind("auth".into(), CompletionItemKind::Schema), - CompletionAssertion::LabelAndKind("posts".into(), CompletionItemKind::Table), - CompletionAssertion::LabelAndKind("users".into(), CompletionItemKind::Table), - ], - None, - &pool, - ) - .await; + create table auth.posts ( + pid serial primary key, + user_id int not null references auth.users(uid), + title text not null, + content text, + created_at timestamp default now() + ); + "#; - assert_complete_results( - format!( - "drop table if exists {}", - QueryWithCursorPosition::cursor_marker() - ) - .as_str(), - vec![ - CompletionAssertion::LabelAndKind("auth".into(), CompletionItemKind::Schema), - CompletionAssertion::LabelAndKind("posts".into(), CompletionItemKind::Table), // self-join - CompletionAssertion::LabelAndKind("users".into(), CompletionItemKind::Table), - ], - None, - &pool, - ) - .await; + TestCompletionsSuite::new(&pool, Some(setup)) + .with_case(TestCompletionsCase::new().type_sql("alter table if exists auth.posts")) + .snapshot("suggests_tables_in_alter_statements") + .await; } #[sqlx::test(migrator = "pgls_test_utils::MIGRATIONS")] diff --git a/crates/pgls_completions/src/relevance/filtering.rs b/crates/pgls_completions/src/relevance/filtering.rs index 16299140f..35adbce44 100644 --- a/crates/pgls_completions/src/relevance/filtering.rs +++ b/crates/pgls_completions/src/relevance/filtering.rs @@ -616,7 +616,6 @@ mod tests { use pgls_test_utils::QueryWithCursorPosition; #[sqlx::test(migrator = "pgls_test_utils::MIGRATIONS")] - #[ignore = "will be reintroduced after stacked keyword-completion PRs merge"] async fn completion_after_asterisk(pool: PgPool) { let setup = r#" create table users ( diff --git a/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__after_from_clause.snap b/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__after_from_clause.snap new file mode 100644 index 000000000..504a4e958 --- /dev/null +++ b/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__after_from_clause.snap @@ -0,0 +1,87 @@ +--- +source: crates/pgls_completions/src/test_helper.rs +expression: final_snapshot +--- +***Setup*** + +create table public.users ( + id serial primary key, + email varchar(255) +); + + +-------------- + +select email from users | + +Results: +cross - cross (Keyword) +full - full (Keyword) +group - group (Keyword) +inner - inner (Keyword) +join - join (Keyword) + +-------------- + +select email from users w| + +Results: +where - where (Keyword) +window - window (Keyword) + +-------------- + +select email from users where | + +Results: +email - public.users.email (Column) +id - public.users.id (Column) +abbrev - pg_catalog.pg_timezone_abbrevs.abbrev (Column) +action_condition - information_schema.triggers.action_condition (Column) +action_order - information_schema.triggers.action_order (Column) + +-------------- + +select email from users where i| + +Results: +id - public.users.id (Column) +email - public.users.email (Column) +ident - pg_catalog.pg_backend_memory_contexts.ident (Column) +identity_cycle - information_schema.columns.identity_cycle (Column) +identity_generation - information_schema.columns.identity_generation (Column) + +-------------- + +select email from users where id | + +Results: +group - group (Keyword) +limit - limit (Keyword) +order - order (Keyword) +window - window (Keyword) + +-------------- + +select email from users where id = | + +Results: +email - public.users.email (Column) +id - public.users.id (Column) +abbrev - pg_catalog.pg_timezone_abbrevs.abbrev (Column) +action_condition - information_schema.triggers.action_condition (Column) +action_order - information_schema.triggers.action_order (Column) + +-------------- + +select email from users where id = 1| +select email from users where id = 1; | + +Results: +insert - insert (Keyword) +reset - reset (Keyword) +select - select (Keyword) +set - set (Keyword) +truncate - truncate (Keyword) + +-------------- diff --git a/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__completes_in_join_on_clause.snap b/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__completes_in_join_on_clause.snap index 73e340190..cc9cca2db 100644 --- a/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__completes_in_join_on_clause.snap +++ b/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__completes_in_join_on_clause.snap @@ -56,6 +56,16 @@ user_id - auth.posts.user_id (Column) -------------- select u.id, auth.posts.content from auth.users u join auth.posts p on p.user_id | + +Results: +cross - cross (Keyword) +full - full (Keyword) +group - group (Keyword) +inner - inner (Keyword) +join - join (Keyword) + +-------------- + select u.id, auth.posts.content from auth.users u join auth.posts p on p.user_id = | Results: @@ -86,3 +96,12 @@ uid - auth.users.uid (Column) -------------- select u.id, auth.posts.content from auth.users u join auth.posts p on p.user_id = u.uid; | + +Results: +insert - insert (Keyword) +reset - reset (Keyword) +select - select (Keyword) +set - set (Keyword) +truncate - truncate (Keyword) + +-------------- diff --git a/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__completes_join_kw.snap b/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__completes_join_kw.snap new file mode 100644 index 000000000..dfad07c11 --- /dev/null +++ b/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__completes_join_kw.snap @@ -0,0 +1,16 @@ +--- +source: crates/pgls_completions/src/test_helper.rs +expression: final_snapshot +--- +***Setup*** + +create table public.users ( + id serial primary key, + email varchar(255) +); + + +-------------- + +select email from users left | +select email from users left j | diff --git a/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__completes_quoted_columns.snap b/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__completes_quoted_columns.snap index 8ef51386a..490bec446 100644 --- a/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__completes_quoted_columns.snap +++ b/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__completes_quoted_columns.snap @@ -17,6 +17,15 @@ create table private.users ( -------------- s| + +Results: +select - select (Keyword) +set - set (Keyword) +insert - insert (Keyword) +reset - reset (Keyword) + +-------------- + select | Results: @@ -62,7 +71,19 @@ encoding - pg_catalog.pg_database.encoding (Column) -------------- select "email" | + +Results: +from - from (Keyword) + +-------------- + select "email" f| + +Results: +from - from (Keyword) + +-------------- + select "email" from | Results: @@ -116,3 +137,12 @@ users - private.users (Table) select "email" from "private".u| select "email" from "private".users; | + +Results: +insert - insert (Keyword) +reset - reset (Keyword) +select - select (Keyword) +set - set (Keyword) +truncate - truncate (Keyword) + +-------------- diff --git a/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__completes_quoted_columns_with_aliases.snap b/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__completes_quoted_columns_with_aliases.snap index a21fe79fe..580ca1614 100644 --- a/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__completes_quoted_columns_with_aliases.snap +++ b/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__completes_quoted_columns_with_aliases.snap @@ -24,6 +24,15 @@ create table public.names ( ***Case 1:*** s| + +Results: +select - select (Keyword) +set - set (Keyword) +insert - insert (Keyword) +reset - reset (Keyword) + +-------------- + select | Results: @@ -73,7 +82,19 @@ select "pr"."| select "pr"."|" select "pr"."e|" select "pr"."email" | + +Results: +from - from (Keyword) + +-------------- + select "pr"."email" f| + +Results: +from - from (Keyword) + +-------------- + select "pr"."email" from | Results: @@ -111,11 +132,31 @@ users - private.users (Table) -------------- select "pr"."email" from private.users | + +Results: +cross - cross (Keyword) +full - full (Keyword) +group - group (Keyword) +inner - inner (Keyword) +join - join (Keyword) + +-------------- + select "pr"."email" from private.users "| select "pr"."email" from private.users "|" select "pr"."email" from private.users "p|" select "pr"."email" from private.users "pr" | +Results: +cross - cross (Keyword) +full - full (Keyword) +group - group (Keyword) +inner - inner (Keyword) +join - join (Keyword) + +-------------- + + diff --git a/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__does_not_complete_cols_in_join_clauses.snap b/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__does_not_complete_cols_in_join_clauses.snap index 629e98bc6..3a6dd9965 100644 --- a/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__does_not_complete_cols_in_join_clauses.snap +++ b/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__does_not_complete_cols_in_join_clauses.snap @@ -24,6 +24,15 @@ create table auth.posts ( -------------- s| + +Results: +select - select (Keyword) +set - set (Keyword) +insert - insert (Keyword) +reset - reset (Keyword) + +-------------- + select | Results: @@ -51,7 +60,19 @@ pid - auth.posts.pid (Column) select u.uid, p.| select u.uid, p.c| select u.uid, p.content | + +Results: +from - from (Keyword) + +-------------- + select u.uid, p.content f| + +Results: +from - from (Keyword) + +-------------- + select u.uid, p.content from | **Schema suggestions should be prioritized, since we want to push users to specify them.** @@ -94,8 +115,34 @@ users - auth.users (Table) -------------- select u.uid, p.content from auth.users | + +Results: +cross - cross (Keyword) +full - full (Keyword) +group - group (Keyword) +inner - inner (Keyword) +join - join (Keyword) + +-------------- + select u.uid, p.content from auth.users u | + +Results: +cross - cross (Keyword) +full - full (Keyword) +group - group (Keyword) +inner - inner (Keyword) +join - join (Keyword) + +-------------- + select u.uid, p.content from auth.users u j| + +Results: +join - join (Keyword) + +-------------- + select u.uid, p.content from auth.users u join | Results: @@ -134,8 +181,28 @@ posts - auth.posts (Table) -------------- select u.uid, p.content from auth.users u join auth.posts | + +Results: +on - on (Keyword) +using - using (Keyword) + +-------------- + select u.uid, p.content from auth.users u join auth.posts p | + +Results: +on - on (Keyword) +using - using (Keyword) + +-------------- + select u.uid, p.content from auth.users u join auth.posts p o| + +Results: +on - on (Keyword) + +-------------- + select u.uid, p.content from auth.users u join auth.posts p on | Results: @@ -164,6 +231,16 @@ uid - auth.users.uid (Column) -------------- select u.uid, p.content from auth.users u join auth.posts p on u.uid | + +Results: +cross - cross (Keyword) +full - full (Keyword) +group - group (Keyword) +inner - inner (Keyword) +join - join (Keyword) + +-------------- + select u.uid, p.content from auth.users u join auth.posts p on u.uid = | Results: @@ -194,3 +271,12 @@ user_id - auth.posts.user_id (Column) -------------- select u.uid, p.content from auth.users u join auth.posts p on u.uid = p.user_id | + +Results: +cross - cross (Keyword) +full - full (Keyword) +group - group (Keyword) +inner - inner (Keyword) +join - join (Keyword) + +-------------- diff --git a/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__filters_out_by_aliases_in_join_on.snap b/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__filters_out_by_aliases_in_join_on.snap index 37c635810..7d0f26a33 100644 --- a/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__filters_out_by_aliases_in_join_on.snap +++ b/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__filters_out_by_aliases_in_join_on.snap @@ -24,7 +24,20 @@ create table auth.posts ( -------------- select u.id, p.content from auth.users u join auth.posts p | + +Results: +on - on (Keyword) +using - using (Keyword) + +-------------- + select u.id, p.content from auth.users u join auth.posts p o| + +Results: +on - on (Keyword) + +-------------- + select u.id, p.content from auth.users u join auth.posts p on | **Should prefer primary indices here.** @@ -55,6 +68,16 @@ email - auth.users.email (Column) -------------- select u.id, p.content from auth.users u join auth.posts p on u.id | + +Results: +cross - cross (Keyword) +full - full (Keyword) +group - group (Keyword) +inner - inner (Keyword) +join - join (Keyword) + +-------------- + select u.id, p.content from auth.users u join auth.posts p on u.id = | Results: @@ -86,3 +109,12 @@ user_id - auth.posts.user_id (Column) -------------- select u.id, p.content from auth.users u join auth.posts p on u.id = p.user_id | + +Results: +cross - cross (Keyword) +full - full (Keyword) +group - group (Keyword) +inner - inner (Keyword) +join - join (Keyword) + +-------------- diff --git a/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__ignores_cols_in_from_clause.snap b/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__ignores_cols_in_from_clause.snap index a6c1b9f57..3c16b91c7 100644 --- a/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__ignores_cols_in_from_clause.snap +++ b/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__ignores_cols_in_from_clause.snap @@ -56,3 +56,12 @@ users - private.users (Table) -------------- select * from private.users | + +Results: +cross - cross (Keyword) +full - full (Keyword) +group - group (Keyword) +inner - inner (Keyword) +join - join (Keyword) + +-------------- diff --git a/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__prefers_not_mentioned_columns.snap b/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__prefers_not_mentioned_columns.snap index 9ccf98a9a..ab52b99cd 100644 --- a/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__prefers_not_mentioned_columns.snap +++ b/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__prefers_not_mentioned_columns.snap @@ -116,8 +116,8 @@ Results: c - public.two.c (Column) cache_size - pg_catalog.pg_sequences.cache_size (Column) calls - pg_catalog.pg_stat_user_functions.calls (Column) +cast - cast (Keyword) castcontext - pg_catalog.pg_cast.castcontext (Column) -castfunc - pg_catalog.pg_cast.castfunc (Column) -------------- @@ -268,8 +268,8 @@ Results: c - public.two.c (Column) cache_size - pg_catalog.pg_sequences.cache_size (Column) calls - pg_catalog.pg_stat_user_functions.calls (Column) +cast - cast (Keyword) castcontext - pg_catalog.pg_cast.castcontext (Column) -castfunc - pg_catalog.pg_cast.castfunc (Column) -------------- diff --git a/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__shows_multiple_columns_if_no_relation_specified.snap b/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__shows_multiple_columns_if_no_relation_specified.snap index 463bca8f4..6defa0825 100644 --- a/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__shows_multiple_columns_if_no_relation_specified.snap +++ b/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__shows_multiple_columns_if_no_relation_specified.snap @@ -25,6 +25,15 @@ create table private.audio_books ( -------------- s| + +Results: +select - select (Keyword) +set - set (Keyword) +insert - insert (Keyword) +reset - reset (Keyword) + +-------------- + select | **Should suggest all columns with n first** @@ -44,9 +53,14 @@ Results: name - public.users.name (Column) narrator - public.audio_books.narrator (Column) narrator_id - private.audio_books.narrator_id (Column) +null - null (Keyword) name - Schema: pg_catalog.name (Function) -nameconcatoid - Schema: pg_catalog.nameconcatoid (Function) -------------- select narrator_id | + +Results: +from - from (Keyword) + +-------------- diff --git a/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__suggests_columns_in_alter_table_and_drop_table.snap b/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__suggests_columns_in_alter_table_and_drop_table.snap index 76dc39d7e..11ff82787 100644 --- a/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__suggests_columns_in_alter_table_and_drop_table.snap +++ b/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__suggests_columns_in_alter_table_and_drop_table.snap @@ -17,6 +17,13 @@ create table instruments ( ***Case 1:*** a| + +Results: +truncate - truncate (Keyword) +update - update (Keyword) + +-------------- + alter | alter t| alter table | @@ -95,6 +102,13 @@ alter table instruments drop column name | ***Case 2:*** a| + +Results: +truncate - truncate (Keyword) +update - update (Keyword) + +-------------- + alter | alter t| alter table | @@ -197,6 +211,13 @@ alter table instruments drop column if exists name | ***Case 3:*** a| + +Results: +truncate - truncate (Keyword) +update - update (Keyword) + +-------------- + alter | alter t| alter table | @@ -230,7 +251,7 @@ created_at - public.instruments.created_at (Column) id - public.instruments.id (Column) name - public.instruments.name (Column) z - public.instruments.z (Column) -abbrev - pg_catalog.pg_timezone_abbrevs.abbrev (Column) +column - column (Keyword) -------------- @@ -238,10 +259,10 @@ alter table instruments alter c| Results: created_at - public.instruments.created_at (Column) +column - column (Keyword) cache_size - pg_catalog.pg_sequences.cache_size (Column) calls - pg_catalog.pg_stat_user_functions.calls (Column) castcontext - pg_catalog.pg_cast.castcontext (Column) -castfunc - pg_catalog.pg_cast.castfunc (Column) -------------- @@ -289,6 +310,13 @@ instruments - public.instruments (Table) ***Case 4:*** a| + +Results: +truncate - truncate (Keyword) +update - update (Keyword) + +-------------- + alter | alter t| alter table | @@ -322,7 +350,7 @@ created_at - public.instruments.created_at (Column) id - public.instruments.id (Column) name - public.instruments.name (Column) z - public.instruments.z (Column) -abbrev - pg_catalog.pg_timezone_abbrevs.abbrev (Column) +column - column (Keyword) -------------- @@ -330,10 +358,10 @@ alter table instruments alter n| Results: name - public.instruments.name (Column) +column - column (Keyword) n_dead_tup - pg_catalog.pg_stat_all_tables.n_dead_tup (Column) n_distinct - pg_catalog.pg_stats.n_distinct (Column) n_ins_since_vacuum - pg_catalog.pg_stat_all_tables.n_ins_since_vacuum (Column) -n_live_tup - pg_catalog.pg_stat_all_tables.n_live_tup (Column) -------------- @@ -359,6 +387,13 @@ instruments - public.instruments (Table) ***Case 5:*** a| + +Results: +truncate - truncate (Keyword) +update - update (Keyword) + +-------------- + alter | alter t| alter table | @@ -408,7 +443,7 @@ created_at - public.instruments.created_at (Column) id - public.instruments.id (Column) name - public.instruments.name (Column) z - public.instruments.z (Column) -abbrev - pg_catalog.pg_timezone_abbrevs.abbrev (Column) +column - column (Keyword) -------------- @@ -416,10 +451,10 @@ alter table public.instruments alter c| Results: created_at - public.instruments.created_at (Column) +column - column (Keyword) cache_size - pg_catalog.pg_sequences.cache_size (Column) calls - pg_catalog.pg_stat_user_functions.calls (Column) castcontext - pg_catalog.pg_cast.castcontext (Column) -castfunc - pg_catalog.pg_cast.castfunc (Column) -------------- @@ -453,6 +488,13 @@ alter table public.instruments alter column name | ***Case 6:*** a| + +Results: +truncate - truncate (Keyword) +update - update (Keyword) + +-------------- + alter | alter t| alter table | @@ -486,7 +528,7 @@ created_at - public.instruments.created_at (Column) id - public.instruments.id (Column) name - public.instruments.name (Column) z - public.instruments.z (Column) -abbrev - pg_catalog.pg_timezone_abbrevs.abbrev (Column) +column - column (Keyword) -------------- @@ -494,10 +536,10 @@ alter table instruments alter n| Results: name - public.instruments.name (Column) +column - column (Keyword) n_dead_tup - pg_catalog.pg_stat_all_tables.n_dead_tup (Column) n_distinct - pg_catalog.pg_stats.n_distinct (Column) n_ins_since_vacuum - pg_catalog.pg_stat_all_tables.n_ins_since_vacuum (Column) -n_live_tup - pg_catalog.pg_stat_all_tables.n_live_tup (Column) -------------- @@ -509,6 +551,13 @@ alter table instruments alter name | ***Case 7:*** a| + +Results: +truncate - truncate (Keyword) +update - update (Keyword) + +-------------- + alter | alter t| alter table | @@ -542,7 +591,7 @@ created_at - public.instruments.created_at (Column) id - public.instruments.id (Column) name - public.instruments.name (Column) z - public.instruments.z (Column) -abbrev - pg_catalog.pg_timezone_abbrevs.abbrev (Column) +column - column (Keyword) -------------- @@ -550,15 +599,27 @@ alter table instruments rename n| Results: name - public.instruments.name (Column) +column - column (Keyword) n_dead_tup - pg_catalog.pg_stat_all_tables.n_dead_tup (Column) n_distinct - pg_catalog.pg_stats.n_distinct (Column) n_ins_since_vacuum - pg_catalog.pg_stat_all_tables.n_ins_since_vacuum (Column) -n_live_tup - pg_catalog.pg_stat_all_tables.n_live_tup (Column) -------------- alter table instruments rename name | + +Results: +to - to (Keyword) + +-------------- + alter table instruments rename name t| + +Results: +to - to (Keyword) + +-------------- + alter table instruments rename name to | alter table instruments rename name to n| alter table instruments rename name to new_col | @@ -569,6 +630,13 @@ alter table instruments rename name to new_col | ***Case 8:*** a| + +Results: +truncate - truncate (Keyword) +update - update (Keyword) + +-------------- + alter | alter t| alter table | @@ -618,7 +686,7 @@ created_at - public.instruments.created_at (Column) id - public.instruments.id (Column) name - public.instruments.name (Column) z - public.instruments.z (Column) -abbrev - pg_catalog.pg_timezone_abbrevs.abbrev (Column) +column - column (Keyword) -------------- @@ -626,10 +694,10 @@ alter table public.instruments rename c| Results: created_at - public.instruments.created_at (Column) +column - column (Keyword) cache_size - pg_catalog.pg_sequences.cache_size (Column) calls - pg_catalog.pg_stat_user_functions.calls (Column) castcontext - pg_catalog.pg_cast.castcontext (Column) -castfunc - pg_catalog.pg_cast.castfunc (Column) -------------- @@ -656,7 +724,19 @@ n_live_tup - pg_catalog.pg_stat_all_tables.n_live_tup (Column) -------------- alter table public.instruments rename column name | + +Results: +to - to (Keyword) + +-------------- + alter table public.instruments rename column name t| + +Results: +to - to (Keyword) + +-------------- + alter table public.instruments rename column name to | alter table public.instruments rename column name to n| alter table public.instruments rename column name to new_col | diff --git a/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__suggests_columns_in_insert_clause.snap b/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__suggests_columns_in_insert_clause.snap index 0d300f984..0323de0f3 100644 --- a/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__suggests_columns_in_insert_clause.snap +++ b/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__suggests_columns_in_insert_clause.snap @@ -22,8 +22,26 @@ create table others ( ***Case 1:*** i| + +Results: +insert - insert (Keyword) + +-------------- + insert | + +Results: +into - into (Keyword) + +-------------- + insert i| + +Results: +into - into (Keyword) + +-------------- + insert into | Results: @@ -47,6 +65,13 @@ pg_catalog.pg_ident_file_mappings - pg_catalog.pg_ident_file_mappings (Table) -------------- insert into instruments | + +Results: +select - select (Keyword) +values - values (Keyword) + +-------------- + insert into instruments (| insert into instruments (|) @@ -54,8 +79,8 @@ Results: id - public.instruments.id (Column) name - public.instruments.name (Column) z - public.instruments.z (Column) +select - select (Keyword) a - public.others.a (Column) -b - public.others.b (Column) -------------- @@ -93,7 +118,20 @@ n_live_tup - pg_catalog.pg_stat_all_tables.n_live_tup (Column) -------------- insert into instruments (id, name) | + +Results: +select - select (Keyword) +values - values (Keyword) + +-------------- + insert into instruments (id, name) v| + +Results: +values - values (Keyword) + +-------------- + insert into instruments (id, name) values | insert into instruments (id, name) values (| insert into instruments (id, name) values (|) @@ -102,8 +140,8 @@ Results: z - public.instruments.z (Column) id - public.instruments.id (Column) name - public.instruments.name (Column) +default - default (Keyword) a - public.others.a (Column) -b - public.others.b (Column) -------------- @@ -114,22 +152,50 @@ Results: z - public.instruments.z (Column) id - public.instruments.id (Column) name - public.instruments.name (Column) +default - default (Keyword) a - public.others.a (Column) -b - public.others.b (Column) -------------- insert into instruments (id, name) values (1, '|) insert into instruments (id, name) values (1, 'my_bass'); | +Results: +insert - insert (Keyword) +reset - reset (Keyword) +select - select (Keyword) +set - set (Keyword) +truncate - truncate (Keyword) + +-------------- + + ***Case 2:*** i| + +Results: +insert - insert (Keyword) + +-------------- + insert | + +Results: +into - into (Keyword) + +-------------- + insert i| + +Results: +into - into (Keyword) + +-------------- + insert into | Results: @@ -153,6 +219,13 @@ pg_catalog.pg_ident_file_mappings - pg_catalog.pg_ident_file_mappings (Table) -------------- insert into instruments | + +Results: +select - select (Keyword) +values - values (Keyword) + +-------------- + insert into instruments (| insert into instruments (|) @@ -160,8 +233,8 @@ Results: id - public.instruments.id (Column) name - public.instruments.name (Column) z - public.instruments.z (Column) +select - select (Keyword) a - public.others.a (Column) -b - public.others.b (Column) -------------- @@ -221,7 +294,20 @@ n_live_tup - pg_catalog.pg_stat_all_tables.n_live_tup (Column) -------------- insert into instruments ("id", "name") | + +Results: +select - select (Keyword) +values - values (Keyword) + +-------------- + insert into instruments ("id", "name") v| + +Results: +values - values (Keyword) + +-------------- + insert into instruments ("id", "name") values | insert into instruments ("id", "name") values (| insert into instruments ("id", "name") values (|) @@ -230,8 +316,8 @@ Results: id - public.instruments.id (Column) name - public.instruments.name (Column) z - public.instruments.z (Column) +default - default (Keyword) a - public.others.a (Column) -b - public.others.b (Column) -------------- @@ -242,14 +328,24 @@ Results: id - public.instruments.id (Column) name - public.instruments.name (Column) z - public.instruments.z (Column) +default - default (Keyword) a - public.others.a (Column) -b - public.others.b (Column) -------------- insert into instruments ("id", "name") values (1, '|) insert into instruments ("id", "name") values (1, 'my_bass'); | +Results: +insert - insert (Keyword) +reset - reset (Keyword) +select - select (Keyword) +set - set (Keyword) +truncate - truncate (Keyword) + +-------------- + + diff --git a/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__suggests_columns_in_where_clause.snap b/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__suggests_columns_in_where_clause.snap index a291aad9e..a4f591bc0 100644 --- a/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__suggests_columns_in_where_clause.snap +++ b/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__suggests_columns_in_where_clause.snap @@ -21,7 +21,24 @@ create table others ( -------------- select name from instruments i join others o on i.z = o.a | + +Results: +cross - cross (Keyword) +full - full (Keyword) +group - group (Keyword) +inner - inner (Keyword) +join - join (Keyword) + +-------------- + select name from instruments i join others o on i.z = o.a w| + +Results: +where - where (Keyword) +window - window (Keyword) + +-------------- + select name from instruments i join others o on i.z = o.a where | Results: @@ -34,7 +51,7 @@ i.id - public.instruments.id (Column) -------------- select name from instruments i join others o on i.z = o.a where o.| -**should respect alias speciifcation** +**should respect alias specification** Results: a - public.others.a (Column) @@ -44,15 +61,24 @@ c - public.others.c (Column) -------------- select name from instruments i join others o on i.z = o.a where o.a | + +Results: +group - group (Keyword) +limit - limit (Keyword) +order - order (Keyword) +window - window (Keyword) + +-------------- + select name from instruments i join others o on i.z = o.a where o.a = | **should not prioritize suggest columns or schemas (right side of binary expression)** Results: -instruments - public.instruments (Table) -others - public.others (Table) -_sqlx_migrations - public._sqlx_migrations (Table) -information_schema - information_schema (Schema) -pg_catalog - pg_catalog (Schema) +o.b - public.others.b (Column) +o.c - public.others.c (Column) +i.created_at - public.instruments.created_at (Column) +i.id - public.instruments.id (Column) +i.name - public.instruments.name (Column) -------------- @@ -67,6 +93,15 @@ z - public.instruments.z (Column) -------------- select name from instruments i join others o on i.z = o.a where o.a = i.z | + +Results: +group - group (Keyword) +limit - limit (Keyword) +order - order (Keyword) +window - window (Keyword) + +-------------- + select name from instruments i join others o on i.z = o.a where o.a = i.z a| select name from instruments i join others o on i.z = o.a where o.a = i.z and | **should prioritize columns that aren't already mentioned** @@ -98,16 +133,34 @@ id - public.instruments.id (Column) -------------- select name from instruments i join others o on i.z = o.a where o.a = i.z and i.id | + +Results: +group - group (Keyword) +limit - limit (Keyword) +order - order (Keyword) +window - window (Keyword) + +-------------- + select name from instruments i join others o on i.z = o.a where o.a = i.z and i.id > | Results: -instruments - public.instruments (Table) -others - public.others (Table) -_sqlx_migrations - public._sqlx_migrations (Table) -information_schema - information_schema (Schema) -pg_catalog - pg_catalog (Schema) +o.b - public.others.b (Column) +o.c - public.others.c (Column) +i.created_at - public.instruments.created_at (Column) +i.name - public.instruments.name (Column) +i.z - public.instruments.z (Column) -------------- select name from instruments i join others o on i.z = o.a where o.a = i.z and i.id > 5| select name from instruments i join others o on i.z = o.a where o.a = i.z and i.id > 5; | + +Results: +insert - insert (Keyword) +reset - reset (Keyword) +select - select (Keyword) +set - set (Keyword) +truncate - truncate (Keyword) + +-------------- diff --git a/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__suggests_columns_policy_using_clause.snap b/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__suggests_columns_policy_using_clause.snap index d3db86856..d7441a1ef 100644 --- a/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__suggests_columns_policy_using_clause.snap +++ b/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__suggests_columns_policy_using_clause.snap @@ -31,10 +31,10 @@ create policy "my_pol" on public.instruments for select using (i|) Results: id - public.instruments.id (Column) +interval - interval (Keyword) ident - pg_catalog.pg_backend_memory_contexts.ident (Column) identity_cycle - information_schema.columns.identity_cycle (Column) identity_generation - information_schema.columns.identity_generation (Column) -identity_increment - information_schema.columns.identity_increment (Column) -------------- @@ -67,10 +67,10 @@ create policy "my_pol" on public.instruments for select using (id = 1 and c|) Results: created_at - public.instruments.created_at (Column) +cast - cast (Keyword) cache_size - pg_catalog.pg_sequences.cache_size (Column) calls - pg_catalog.pg_stat_user_functions.calls (Column) castcontext - pg_catalog.pg_cast.castcontext (Column) -castfunc - pg_catalog.pg_cast.castfunc (Column) -------------- @@ -99,10 +99,10 @@ create policy "my_pol" on public.instruments for insert with check (i|) Results: id - public.instruments.id (Column) +interval - interval (Keyword) ident - pg_catalog.pg_backend_memory_contexts.ident (Column) identity_cycle - information_schema.columns.identity_cycle (Column) identity_generation - information_schema.columns.identity_generation (Column) -identity_increment - information_schema.columns.identity_increment (Column) -------------- @@ -135,10 +135,10 @@ create policy "my_pol" on public.instruments for insert with check (id = 1 and c Results: created_at - public.instruments.created_at (Column) +cast - cast (Keyword) cache_size - pg_catalog.pg_sequences.cache_size (Column) calls - pg_catalog.pg_stat_user_functions.calls (Column) castcontext - pg_catalog.pg_cast.castcontext (Column) -castfunc - pg_catalog.pg_cast.castfunc (Column) -------------- diff --git a/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__suggests_relevant_columns_without_letters.snap b/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__suggests_relevant_columns_without_letters.snap index 758932c93..4ee4242ae 100644 --- a/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__suggests_relevant_columns_without_letters.snap +++ b/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__suggests_relevant_columns_without_letters.snap @@ -15,6 +15,15 @@ create table users ( -------------- s| + +Results: +select - select (Keyword) +set - set (Keyword) +insert - insert (Keyword) +reset - reset (Keyword) + +-------------- + select | Results: @@ -30,15 +39,27 @@ select n| Results: name - public.users.name (Column) +null - null (Keyword) +name - Schema: pg_catalog.name (Function) nameconcatoid - Schema: pg_catalog.nameconcatoid (Function) nameeq - Schema: pg_catalog.nameeq (Function) -nameeqtext - Schema: pg_catalog.nameeqtext (Function) -namege - Schema: pg_catalog.namege (Function) -------------- select name | + +Results: +from - from (Keyword) + +-------------- + select name f| + +Results: +from - from (Keyword) + +-------------- + select name from | Results: @@ -62,3 +83,12 @@ information_schema.user_defined_types - information_schema.user_defined_types (T -------------- select name from users | + +Results: +cross - cross (Keyword) +full - full (Keyword) +group - group (Keyword) +inner - inner (Keyword) +join - join (Keyword) + +-------------- diff --git a/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__suggests_tables_in_alter_statements.snap b/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__suggests_tables_in_alter_statements.snap new file mode 100644 index 000000000..308c56e34 --- /dev/null +++ b/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__suggests_tables_in_alter_statements.snap @@ -0,0 +1,103 @@ +--- +source: crates/pgls_completions/src/test_helper.rs +expression: final_snapshot +--- +***Setup*** + +create schema auth; + +create table auth.users ( + uid serial primary key, + name text not null, + email text unique not null +); + +create table auth.posts ( + pid serial primary key, + user_id int not null references auth.users(uid), + title text not null, + content text, + created_at timestamp default now() +); + + +-------------- + +a| + +Results: +truncate - truncate (Keyword) +update - update (Keyword) + +-------------- + +alter | +alter t| +alter table | + +Results: +auth - auth (Schema) +auth.posts - auth.posts (Table) +auth.users - auth.users (Table) +_sqlx_migrations - public._sqlx_migrations (Table) +information_schema - information_schema (Schema) + +-------------- + +alter table i| + +Results: +information_schema - information_schema (Schema) +information_schema.information_schema_catalog_name - information_schema.information_schema_catalog_name (Table) +public - public (Schema) +pg_catalog.pg_ident_file_mappings - pg_catalog.pg_ident_file_mappings (Table) +pg_catalog.pg_index - pg_catalog.pg_index (Table) + +-------------- + +alter table if | +alter table if e| + +Results: +exists - exists (Keyword) + +-------------- + +alter table if exists | + +Results: +auth - auth (Schema) +auth.posts - auth.posts (Table) +auth.users - auth.users (Table) +_sqlx_migrations - public._sqlx_migrations (Table) +information_schema - information_schema (Schema) + +-------------- + +alter table if exists a| + +Results: +auth - auth (Schema) +information_schema.administrable_role_authorizations - information_schema.administrable_role_authorizations (Table) +information_schema.applicable_roles - information_schema.applicable_roles (Table) +information_schema.attributes - information_schema.attributes (Table) +information_schema.collation_character_set_applicability - information_schema.collation_character_set_applicability (Table) + +-------------- + +alter table if exists auth.| + +Results: +posts - auth.posts (Table) +users - auth.users (Table) + +-------------- + +alter table if exists auth.p| + +Results: +posts - auth.posts (Table) + +-------------- + +alter table if exists auth.posts | diff --git a/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__suggests_tables_in_drop_statements.snap b/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__suggests_tables_in_drop_statements.snap new file mode 100644 index 000000000..14e8d3ef3 --- /dev/null +++ b/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__suggests_tables_in_drop_statements.snap @@ -0,0 +1,102 @@ +--- +source: crates/pgls_completions/src/test_helper.rs +expression: final_snapshot +--- +***Setup*** + +create schema auth; + +create table auth.users ( + uid serial primary key, + name text not null, + email text unique not null +); + +create table auth.posts ( + pid serial primary key, + user_id int not null references auth.users(uid), + title text not null, + content text, + created_at timestamp default now() +); + + +-------------- + +d| + +Results: +update - update (Keyword) + +-------------- + +drop | +drop t| +drop table | + +Results: +auth - auth (Schema) +auth.posts - auth.posts (Table) +auth.users - auth.users (Table) +_sqlx_migrations - public._sqlx_migrations (Table) +information_schema - information_schema (Schema) + +-------------- + +drop table i| + +Results: +information_schema - information_schema (Schema) +information_schema.information_schema_catalog_name - information_schema.information_schema_catalog_name (Table) +public - public (Schema) +pg_catalog.pg_ident_file_mappings - pg_catalog.pg_ident_file_mappings (Table) +pg_catalog.pg_index - pg_catalog.pg_index (Table) + +-------------- + +drop table if | +drop table if e| +drop table if exists | + +Results: +auth - auth (Schema) +auth.posts - auth.posts (Table) +auth.users - auth.users (Table) +_sqlx_migrations - public._sqlx_migrations (Table) +information_schema - information_schema (Schema) + +-------------- + +drop table if exists a| + +Results: +auth - auth (Schema) +information_schema.administrable_role_authorizations - information_schema.administrable_role_authorizations (Table) +information_schema.applicable_roles - information_schema.applicable_roles (Table) +information_schema.attributes - information_schema.attributes (Table) +information_schema.collation_character_set_applicability - information_schema.collation_character_set_applicability (Table) + +-------------- + +drop table if exists auth.| + +Results: +posts - auth.posts (Table) +users - auth.users (Table) + +-------------- + +drop table if exists auth.p| + +Results: +posts - auth.posts (Table) + +-------------- + +drop table if exists auth.posts | + +Results: +cascade - cascade (Keyword) +restrict - restrict (Keyword) + +-------------- diff --git a/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__suggests_tables_in_join.snap b/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__suggests_tables_in_join.snap new file mode 100644 index 000000000..136d848e8 --- /dev/null +++ b/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__suggests_tables_in_join.snap @@ -0,0 +1,53 @@ +--- +source: crates/pgls_completions/src/test_helper.rs +expression: final_snapshot +--- +***Setup*** + +create schema auth; + +create table auth.users ( + uid serial primary key, + name text not null, + email text unique not null +); + +create table auth.posts ( + pid serial primary key, + user_id int not null references auth.users(uid), + title text not null, + content text, + created_at timestamp default now() +); + + +-------------- + +select * from auth.users u | + +Results: +cross - cross (Keyword) +full - full (Keyword) +group - group (Keyword) +inner - inner (Keyword) +join - join (Keyword) + +-------------- + +select * from auth.users u j| + +Results: +join - join (Keyword) + +-------------- + +select * from auth.users u join | + +Results: +auth - auth (Schema) +information_schema - information_schema (Schema) +pg_catalog - pg_catalog (Schema) +pg_toast - pg_toast (Schema) +auth.posts - auth.posts (Table) + +-------------- diff --git a/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__suggests_tables_in_update.snap b/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__suggests_tables_in_update.snap new file mode 100644 index 000000000..fe3282315 --- /dev/null +++ b/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__suggests_tables_in_update.snap @@ -0,0 +1,155 @@ +--- +source: crates/pgls_completions/src/test_helper.rs +expression: final_snapshot +--- +***Setup*** + +create table coos ( + id serial primary key, + name text +); + + +-------------- + +u| + +Results: +update - update (Keyword) +truncate - truncate (Keyword) + +-------------- + +update | + +Results: +coos - public.coos (Table) +_sqlx_migrations - public._sqlx_migrations (Table) +information_schema - information_schema (Schema) +pg_catalog - pg_catalog (Schema) +pg_toast - pg_toast (Schema) + +-------------- + +update p| + +Results: +public - public (Schema) +pg_catalog - pg_catalog (Schema) +pg_toast - pg_toast (Schema) +information_schema.parameters - information_schema.parameters (Table) +pg_catalog.pg_aggregate - pg_catalog.pg_aggregate (Table) + +-------------- + +update public.| + +Results: +coos - public.coos (Table) +_sqlx_migrations - public._sqlx_migrations (Table) + +-------------- + +update public.c| + +Results: +coos - public.coos (Table) + +-------------- + +update public.coos | + +Results: +set - set (Keyword) + +-------------- + +update public.coos s| + +Results: +set - set (Keyword) + +-------------- + +update public.coos set | + +Results: +id - public.coos.id (Column) +name - public.coos.name (Column) +information_schema - information_schema (Schema) +pg_catalog - pg_catalog (Schema) +pg_toast - pg_toast (Schema) + +-------------- + +update public.coos set n| + +Results: +name - public.coos.name (Column) +information_schema - information_schema (Schema) +n_dead_tup - pg_catalog.pg_stat_all_tables.n_dead_tup (Column) +n_distinct - pg_catalog.pg_stats.n_distinct (Column) +n_ins_since_vacuum - pg_catalog.pg_stat_all_tables.n_ins_since_vacuum (Column) + +-------------- + +update public.coos set name | +update public.coos set name = | + +Results: +coos - public.coos (Table) +id - public.coos.id (Column) +name - public.coos.name (Column) +_sqlx_migrations - public._sqlx_migrations (Table) +information_schema - information_schema (Schema) + +-------------- + +update public.coos set name = '| +update public.coos set name = 'cool' | +update public.coos set name = 'cool' w| +update public.coos set name = 'cool' where | + +Results: +id - public.coos.id (Column) +name - public.coos.name (Column) +abbrev - pg_catalog.pg_timezone_abbrevs.abbrev (Column) +action_condition - information_schema.triggers.action_condition (Column) +action_order - information_schema.triggers.action_order (Column) + +-------------- + +update public.coos set name = 'cool' where i| + +Results: +id - public.coos.id (Column) +ident - pg_catalog.pg_backend_memory_contexts.ident (Column) +identity_cycle - information_schema.columns.identity_cycle (Column) +identity_generation - information_schema.columns.identity_generation (Column) +identity_increment - information_schema.columns.identity_increment (Column) + +-------------- + +update public.coos set name = 'cool' where id | +update public.coos set name = 'cool' where id = | + +Results: +name - public.coos.name (Column) +id - public.coos.id (Column) +abbrev - pg_catalog.pg_timezone_abbrevs.abbrev (Column) +action_condition - information_schema.triggers.action_condition (Column) +action_order - information_schema.triggers.action_order (Column) + +-------------- + +update public.coos set name = 'cool' where id = 5| +update public.coos set name = 'cool' where id = 5; | + +Results: +insert - insert (Keyword) +reset - reset (Keyword) +select - select (Keyword) +set - set (Keyword) +truncate - truncate (Keyword) + +-------------- diff --git a/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__works_in_session_authorization_statement.snap b/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__works_in_session_authorization_statement.snap new file mode 100644 index 000000000..fca7a55b5 --- /dev/null +++ b/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__works_in_session_authorization_statement.snap @@ -0,0 +1,61 @@ +--- +source: crates/pgls_completions/src/test_helper.rs +expression: final_snapshot +--- +***Setup*** + +create table users ( + id serial primary key, + email varchar, + address text +); + + +-------------- + +s| + +Results: +select - select (Keyword) +set - set (Keyword) +insert - insert (Keyword) +reset - reset (Keyword) + +-------------- + +set | +set s| +set session | +set session a| +set session authorization | + +Results: +anon - anon (Role) +authenticated - authenticated (Role) +owner - owner (Role) +service_role - service_role (Role) +test_login - test_login (Role) + +-------------- + +set session authorization a| + +Results: +anon - anon (Role) +authenticated - authenticated (Role) +pg_read_all_data - pg_read_all_data (Role) +pg_read_all_settings - pg_read_all_settings (Role) +pg_read_all_stats - pg_read_all_stats (Role) + +-------------- + +set session authorization authenticated; | + +Results: +insert - insert (Keyword) +reset - reset (Keyword) +select - select (Keyword) +set - set (Keyword) +truncate - truncate (Keyword) + +-------------- diff --git a/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__works_in_set_role_statement.snap b/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__works_in_set_role_statement.snap new file mode 100644 index 000000000..43ee1a56e --- /dev/null +++ b/crates/pgls_completions/src/snapshots/pgls_completions__test_helper__works_in_set_role_statement.snap @@ -0,0 +1,59 @@ +--- +source: crates/pgls_completions/src/test_helper.rs +expression: final_snapshot +--- +***Setup*** + +create table users ( + id serial primary key, + email varchar, + address text +); + + +-------------- + +s| + +Results: +select - select (Keyword) +set - set (Keyword) +insert - insert (Keyword) +reset - reset (Keyword) + +-------------- + +set | +set r| +set role | + +Results: +anon - anon (Role) +authenticated - authenticated (Role) +owner - owner (Role) +service_role - service_role (Role) +test_login - test_login (Role) + +-------------- + +set role a| + +Results: +anon - anon (Role) +authenticated - authenticated (Role) +pg_read_all_data - pg_read_all_data (Role) +pg_read_all_settings - pg_read_all_settings (Role) +pg_read_all_stats - pg_read_all_stats (Role) + +-------------- + +set role anon; | + +Results: +insert - insert (Keyword) +reset - reset (Keyword) +select - select (Keyword) +set - set (Keyword) +truncate - truncate (Keyword) + +-------------- diff --git a/crates/pgls_completions/src/test_helper.rs b/crates/pgls_completions/src/test_helper.rs index 7613f2815..8c59860ba 100644 --- a/crates/pgls_completions/src/test_helper.rs +++ b/crates/pgls_completions/src/test_helper.rs @@ -181,9 +181,10 @@ pub(crate) async fn assert_complete_results( assert!( items.len() >= existing.len(), - "Not enough items returned. Expected at least {} items, but got {}", + "Not enough items returned. Expected at least {} items, but got {}. query: {}", existing.len(), - items.len() + items.len(), + query ); for item in &items { @@ -555,7 +556,9 @@ impl TestCompletionsCase { write!(writer, " - ").unwrap(); match item.kind { - CompletionItemKind::Schema | CompletionItemKind::Role => {} + CompletionItemKind::Schema + | CompletionItemKind::Role + | CompletionItemKind::Keyword => {} _ => { write!(writer, "{}.", item.description).unwrap(); } diff --git a/crates/pgls_test_utils/src/lib.rs b/crates/pgls_test_utils/src/lib.rs index 0ad731929..8fcc58a4c 100644 --- a/crates/pgls_test_utils/src/lib.rs +++ b/crates/pgls_test_utils/src/lib.rs @@ -73,9 +73,7 @@ fn print_ts_tree_recur( node.start_position().column, node.end_position().column, node_text, - field_name - .map(|n| format!(" (@{})", n)) - .unwrap_or("".into()) + field_name.map(|n| format!(" (@{n})")).unwrap_or("".into()) ) .as_str(), ); diff --git a/crates/pgls_treesitter/src/context/mod.rs b/crates/pgls_treesitter/src/context/mod.rs index a536cc9a8..54e80f15d 100644 --- a/crates/pgls_treesitter/src/context/mod.rs +++ b/crates/pgls_treesitter/src/context/mod.rs @@ -384,7 +384,7 @@ impl<'a> TreesitterContext<'a> { "where" => Some(WrappingClause::Where), "update" => Some(WrappingClause::Update), "select" => Some(WrappingClause::Select), - "delete" => Some(WrappingClause::Delete), + "delete_statement" => Some(WrappingClause::Delete), "from" => Some(WrappingClause::From), "drop_table" => Some(WrappingClause::DropTable), "alter_role" => Some(WrappingClause::AlterRole), @@ -579,7 +579,6 @@ mod tests { } #[test] - #[ignore = "will be reintroduced after stacked keyword-completion PRs merge"] fn identifies_clauses() { let test_cases = vec![ ( diff --git a/crates/pgls_treesitter/src/helper.rs b/crates/pgls_treesitter/src/helper.rs index 3119a2b4c..4689cb3ac 100644 --- a/crates/pgls_treesitter/src/helper.rs +++ b/crates/pgls_treesitter/src/helper.rs @@ -1,6 +1,6 @@ use tree_sitter::{Node, Tree}; -pub static SINGLE_TOKEN_RULES: &[&'static str] = &[ +pub static SINGLE_TOKEN_RULES: &[&str] = &[ "any_identifier", "column_identifier", "schema_identifier", @@ -97,7 +97,7 @@ pub fn previous_sibling_completed(node: tree_sitter::Node) -> bool { is_finished && last_children_completed(prev) } else { - false + true } } diff --git a/crates/pgls_treesitter_grammar/benches/parsing.rs b/crates/pgls_treesitter_grammar/benches/parsing.rs index 7d753e17d..be2ce68fd 100644 --- a/crates/pgls_treesitter_grammar/benches/parsing.rs +++ b/crates/pgls_treesitter_grammar/benches/parsing.rs @@ -3,7 +3,7 @@ use criterion::{Criterion, black_box, criterion_group, criterion_main}; pub fn criterion_benchmark(c: &mut Criterion) { // takes about 3 microseconds on MacBook Pro M2 with 16GB Memory c.bench_function("parsing > small sql", |b| { - let content = format!("select * from users;"); + let content = "select * from users;".to_string(); b.iter(|| { let mut parser = tree_sitter::Parser::new(); @@ -17,8 +17,7 @@ pub fn criterion_benchmark(c: &mut Criterion) { // takes about 38 microseconds on MacBook Pro M2 with 16GB Memory c.bench_function("parsing > mid sql", |b| { - let content = format!( - r#"select + let content = r#"select n.oid :: int8 as "id!", n.nspname as name, u.rolname as "owner!" @@ -33,7 +32,7 @@ where ) and not pg_catalog.starts_with(n.nspname, 'pg_temp_') and not pg_catalog.starts_with(n.nspname, 'pg_toast_temp_');"# - ); + .to_string(); b.iter(|| { let mut parser = tree_sitter::Parser::new(); @@ -47,8 +46,7 @@ where // takes about 137 microseconds on MacBook Pro M2 with 16GB Memory c.bench_function("parsing > large sql", |b| { - let content = format!( - r#"with + let content = r#"with available_tables as ( select c.relname as table_name, @@ -104,7 +102,7 @@ where -- system columns, such as `cmax` or `tableoid`, have negative `attnum`s atts.attnum >= 0; "# - ); + .to_string(); b.iter(|| { let mut parser = tree_sitter::Parser::new(); diff --git a/crates/pgls_treesitter_grammar/benches/parsing_with_existing_tree.rs b/crates/pgls_treesitter_grammar/benches/parsing_with_existing_tree.rs index 6b696ccdd..5687185e1 100644 --- a/crates/pgls_treesitter_grammar/benches/parsing_with_existing_tree.rs +++ b/crates/pgls_treesitter_grammar/benches/parsing_with_existing_tree.rs @@ -4,7 +4,7 @@ use tree_sitter::{InputEdit, Point, StreamingIterator}; pub fn criterion_benchmark(c: &mut Criterion) { // takes about 3 microseconds on MacBook Pro M2 with 16GB Memory c.bench_function("parsing with existing tree > small sql", |b| { - let content = format!("select * from users;"); + let content = "select * from users;".to_string(); let mut parser = tree_sitter::Parser::new(); parser @@ -89,8 +89,7 @@ pub fn criterion_benchmark(c: &mut Criterion) { // takes about 12 microseconds on MacBook Pro M2 with 16GB Memory c.bench_function("parsing with existing tree > mid sql", |b| { - let content = format!( - r#" + let content = r#" select n.oid :: int8 as "id!", n.nspname as name, @@ -107,7 +106,7 @@ where and not pg_catalog.starts_with(n.nspname, 'pg_temp_') and not pg_catalog.starts_with(n.nspname, 'pg_toast_temp_'); "# - ); + .to_string(); let mut parser = tree_sitter::Parser::new(); parser @@ -188,8 +187,7 @@ where // takes about 12 microseconds on MacBook Pro M2 with 16GB Memory c.bench_function("parsing with existing tree > large sql", |b| { - let content = format!( - r#" + let content = r#" with available_tables as ( select c.relname as table_name, @@ -245,7 +243,7 @@ where -- system columns, such as `cmax` or `tableoid`, have negative `attnum`s atts.attnum >= 0; "# - ); + .to_string(); let mut parser = tree_sitter::Parser::new(); parser diff --git a/crates/pgls_treesitter_grammar/tests/snapshots/grammar_tests__test_1.snap b/crates/pgls_treesitter_grammar/tests/snapshots/grammar_tests__test_1.snap index 601cec9c0..43ffd3a50 100644 --- a/crates/pgls_treesitter_grammar/tests/snapshots/grammar_tests__test_1.snap +++ b/crates/pgls_treesitter_grammar/tests/snapshots/grammar_tests__test_1.snap @@ -8,15 +8,15 @@ program [0..25] 'select * from auth.users;' statement [0..24] 'select * from auth.users' select [0..8] 'select *' keyword_select [0..6] 'select' - select_expression [7..8] '*' - term [7..8] '*' - all_fields [7..8] '*' + select_expression [7..8] '*' (@end) + term [7..8] '*' (@end) + all_fields [7..8] '*' (@end) * [7..8] '*' from [9..24] 'from auth.users' keyword_from [9..13] 'from' - relation [14..24] 'auth.users' - table_reference [14..24] 'auth.users' - schema_identifier [14..18] 'auth' + relation [14..24] 'auth.users' (@end) + table_reference [14..24] 'auth.users' (@end) + schema_identifier [14..18] 'auth' (@table_reference_1of2) . [18..19] '.' - table_identifier [19..24] 'users' + table_identifier [19..24] 'users' (@table_reference_2of2) ; [24..25] ';' diff --git a/crates/pgls_treesitter_grammar/tests/snapshots/grammar_tests__test_2_sql1.snap b/crates/pgls_treesitter_grammar/tests/snapshots/grammar_tests__test_2_sql1.snap index 27b564708..a25f91f10 100644 --- a/crates/pgls_treesitter_grammar/tests/snapshots/grammar_tests__test_2_sql1.snap +++ b/crates/pgls_treesitter_grammar/tests/snapshots/grammar_tests__test_2_sql1.snap @@ -9,14 +9,14 @@ program [0..44] 'update auth.users set email = 'my@mail.com';' update [0..43] 'update auth.users set email = 'my@mail.com'' keyword_update [0..6] 'update' relation [7..17] 'auth.users' - table_reference [7..17] 'auth.users' - schema_identifier [7..11] 'auth' + table_reference [7..17] 'auth.users' (@end) + schema_identifier [7..11] 'auth' (@table_reference_1of2) . [11..12] '.' - table_identifier [12..17] 'users' + table_identifier [12..17] 'users' (@table_reference_2of2) keyword_set [18..21] 'set' assignment [22..43] 'email = 'my@mail.com'' - column_reference [22..27] 'email' - any_identifier [22..27] 'email' + column_reference [22..27] 'email' (@left) + any_identifier [22..27] 'email' (@column_reference_1of1) = [28..29] '=' - literal [30..43] ''my@mail.com'' + literal [30..43] ''my@mail.com'' (@right) ; [43..44] ';' diff --git a/crates/pgls_treesitter_grammar/tests/snapshots/grammar_tests__test_2_sql2.snap b/crates/pgls_treesitter_grammar/tests/snapshots/grammar_tests__test_2_sql2.snap index e3c5bf26b..bbe72f15e 100644 --- a/crates/pgls_treesitter_grammar/tests/snapshots/grammar_tests__test_2_sql2.snap +++ b/crates/pgls_treesitter_grammar/tests/snapshots/grammar_tests__test_2_sql2.snap @@ -9,16 +9,16 @@ program [0..50] 'update auth.users set users.email = 'my@mail.com';' update [0..49] 'update auth.users set users.email = 'my@mail.com'' keyword_update [0..6] 'update' relation [7..17] 'auth.users' - table_reference [7..17] 'auth.users' - schema_identifier [7..11] 'auth' + table_reference [7..17] 'auth.users' (@end) + schema_identifier [7..11] 'auth' (@table_reference_1of2) . [11..12] '.' - table_identifier [12..17] 'users' + table_identifier [12..17] 'users' (@table_reference_2of2) keyword_set [18..21] 'set' assignment [22..49] 'users.email = 'my@mail.com'' - column_reference [22..33] 'users.email' - any_identifier [22..27] 'users' + column_reference [22..33] 'users.email' (@left) + any_identifier [22..27] 'users' (@column_reference_1of2) . [27..28] '.' - any_identifier [28..33] 'email' + any_identifier [28..33] 'email' (@column_reference_2of2) = [34..35] '=' - literal [36..49] ''my@mail.com'' + literal [36..49] ''my@mail.com'' (@right) ; [49..50] ';' diff --git a/crates/pgls_treesitter_grammar/tests/snapshots/grammar_tests__test_2_sql3.snap b/crates/pgls_treesitter_grammar/tests/snapshots/grammar_tests__test_2_sql3.snap index 4b3c8759e..51d4ee0ef 100644 --- a/crates/pgls_treesitter_grammar/tests/snapshots/grammar_tests__test_2_sql3.snap +++ b/crates/pgls_treesitter_grammar/tests/snapshots/grammar_tests__test_2_sql3.snap @@ -9,18 +9,18 @@ program [0..55] 'update auth.users set auth.users.email = 'my@mail.com';' update [0..54] 'update auth.users set auth.users.email = 'my@mail.com'' keyword_update [0..6] 'update' relation [7..17] 'auth.users' - table_reference [7..17] 'auth.users' - schema_identifier [7..11] 'auth' + table_reference [7..17] 'auth.users' (@end) + schema_identifier [7..11] 'auth' (@table_reference_1of2) . [11..12] '.' - table_identifier [12..17] 'users' + table_identifier [12..17] 'users' (@table_reference_2of2) keyword_set [18..21] 'set' assignment [22..54] 'auth.users.email = 'my@mail.com'' - column_reference [22..38] 'auth.users.email' - schema_identifier [22..26] 'auth' + column_reference [22..38] 'auth.users.email' (@left) + schema_identifier [22..26] 'auth' (@column_reference_1of3) . [26..27] '.' - table_identifier [27..32] 'users' + table_identifier [27..32] 'users' (@column_reference_2of3) . [32..33] '.' - column_identifier [33..38] 'email' + column_identifier [33..38] 'email' (@column_reference_3of3) = [39..40] '=' - literal [41..54] ''my@mail.com'' + literal [41..54] ''my@mail.com'' (@right) ; [54..55] ';' diff --git a/crates/pgls_treesitter_grammar/tests/snapshots/grammar_tests__test_3.snap b/crates/pgls_treesitter_grammar/tests/snapshots/grammar_tests__test_3.snap index 0bbd1a28f..ac87ceea9 100644 --- a/crates/pgls_treesitter_grammar/tests/snapshots/grammar_tests__test_3.snap +++ b/crates/pgls_treesitter_grammar/tests/snapshots/grammar_tests__test_3.snap @@ -18,57 +18,57 @@ program [0..25] 'select u.id, u.email, cs.user_settings, cs.client_id from auth. statement [0..24] 'select u.id, u.email, cs.user_settings, cs.client_id from auth.users u join public.client_settings cs on u.id = cs.user_id' select [0..16] 'select u.id, u.email, cs.user_settings, cs.client_id' keyword_select [0..6] 'select' - select_expression [4..16] 'u.id, u.email, cs.user_settings, cs.client_id' - term [4..8] 'u.id' - object_reference [4..8] 'u.id' - any_identifier [4..5] 'u' + select_expression [4..16] 'u.id, u.email, cs.user_settings, cs.client_id' (@end) + term [4..8] 'u.id' (@end) + object_reference [4..8] 'u.id' (@end) + any_identifier [4..5] 'u' (@object_reference_1of2) . [5..6] '.' - any_identifier [6..8] 'id' - , [8..9] ',' - term [4..11] 'u.email' - object_reference [4..11] 'u.email' - any_identifier [4..5] 'u' + any_identifier [6..8] 'id' (@object_reference_2of2) + , [8..9] ',' (@end) + term [4..11] 'u.email' (@end) + object_reference [4..11] 'u.email' (@end) + any_identifier [4..5] 'u' (@object_reference_1of2) . [5..6] '.' - any_identifier [6..11] 'email' - , [11..12] ',' - term [4..20] 'cs.user_settings' - object_reference [4..20] 'cs.user_settings' - any_identifier [4..6] 'cs' + any_identifier [6..11] 'email' (@object_reference_2of2) + , [11..12] ',' (@end) + term [4..20] 'cs.user_settings' (@end) + object_reference [4..20] 'cs.user_settings' (@end) + any_identifier [4..6] 'cs' (@object_reference_1of2) . [6..7] '.' - any_identifier [7..20] 'user_settings' - , [20..21] ',' - term [4..16] 'cs.client_id' - object_reference [4..16] 'cs.client_id' - any_identifier [4..6] 'cs' + any_identifier [7..20] 'user_settings' (@object_reference_2of2) + , [20..21] ',' (@end) + term [4..16] 'cs.client_id' (@end) + object_reference [4..16] 'cs.client_id' (@end) + any_identifier [4..6] 'cs' (@object_reference_1of2) . [6..7] '.' - any_identifier [7..16] 'client_id' + any_identifier [7..16] 'client_id' (@object_reference_2of2) from [0..24] 'from auth.users u join public.client_settings cs on u.id = cs.user_id' keyword_from [0..4] 'from' - relation [4..16] 'auth.users u' - table_reference [4..14] 'auth.users' - schema_identifier [4..8] 'auth' + relation [4..16] 'auth.users u' (@end) + table_reference [4..14] 'auth.users' (@end) + schema_identifier [4..8] 'auth' (@table_reference_1of2) . [8..9] '.' - table_identifier [9..14] 'users' + table_identifier [9..14] 'users' (@table_reference_2of2) alias [15..16] 'u' - any_identifier [15..16] 'u' + any_identifier [15..16] 'u' (@end) join [4..24] 'join public.client_settings cs on u.id = cs.user_id' keyword_join [4..8] 'join' relation [9..34] 'public.client_settings cs' - table_reference [9..31] 'public.client_settings' - schema_identifier [9..15] 'public' + table_reference [9..31] 'public.client_settings' (@end) + schema_identifier [9..15] 'public' (@table_reference_1of2) . [15..16] '.' - table_identifier [16..31] 'client_settings' + table_identifier [16..31] 'client_settings' (@table_reference_2of2) alias [32..34] 'cs' - any_identifier [32..34] 'cs' + any_identifier [32..34] 'cs' (@end) keyword_on [4..6] 'on' - binary_expression [7..24] 'u.id = cs.user_id' - object_reference [7..11] 'u.id' - any_identifier [7..8] 'u' + binary_expression [7..24] 'u.id = cs.user_id' (@end) + object_reference [7..11] 'u.id' (@binary_expr_left) + any_identifier [7..8] 'u' (@object_reference_1of2) . [8..9] '.' - any_identifier [9..11] 'id' - = [12..13] '=' - object_reference [14..24] 'cs.user_id' - any_identifier [14..16] 'cs' + any_identifier [9..11] 'id' (@object_reference_2of2) + = [12..13] '=' (@binary_expr_operator) + object_reference [14..24] 'cs.user_id' (@end) + any_identifier [14..16] 'cs' (@object_reference_1of2) . [16..17] '.' - any_identifier [17..24] 'user_id' + any_identifier [17..24] 'user_id' (@object_reference_2of2) ; [24..25] ';' diff --git a/crates/pgls_treesitter_grammar/tests/snapshots/grammar_tests__test_4.snap b/crates/pgls_treesitter_grammar/tests/snapshots/grammar_tests__test_4.snap index e7212729a..40241c4f6 100644 --- a/crates/pgls_treesitter_grammar/tests/snapshots/grammar_tests__test_4.snap +++ b/crates/pgls_treesitter_grammar/tests/snapshots/grammar_tests__test_4.snap @@ -8,9 +8,9 @@ program [0..28] 'select "auth".REPLACED_TOKEN' statement [0..28] 'select "auth".REPLACED_TOKEN' select [0..28] 'select "auth".REPLACED_TOKEN' keyword_select [0..6] 'select' - select_expression [7..28] '"auth".REPLACED_TOKEN' - term [7..28] '"auth".REPLACED_TOKEN' - object_reference [7..28] '"auth".REPLACED_TOKEN' - any_identifier [7..13] '"auth"' + select_expression [7..28] '"auth".REPLACED_TOKEN' (@end) + term [7..28] '"auth".REPLACED_TOKEN' (@end) + object_reference [7..28] '"auth".REPLACED_TOKEN' (@end) + any_identifier [7..13] '"auth"' (@object_reference_1of2) . [13..14] '.' - any_identifier [14..28] 'REPLACED_TOKEN' + any_identifier [14..28] 'REPLACED_TOKEN' (@object_reference_2of2) diff --git a/crates/pgls_treesitter_grammar/tests/snapshots/grammar_tests__test_5.snap b/crates/pgls_treesitter_grammar/tests/snapshots/grammar_tests__test_5.snap index d7f8a2216..0da42a8cc 100644 --- a/crates/pgls_treesitter_grammar/tests/snapshots/grammar_tests__test_5.snap +++ b/crates/pgls_treesitter_grammar/tests/snapshots/grammar_tests__test_5.snap @@ -10,46 +10,46 @@ program [0..71] 'select * from users u where u.active = true and (u.role = 'admi statement [0..70] 'select * from users u where u.active = true and (u.role = 'admin' or u.role = 'moderator')' select [0..8] 'select *' keyword_select [0..6] 'select' - select_expression [7..8] '*' - term [7..8] '*' - all_fields [7..8] '*' + select_expression [7..8] '*' (@end) + term [7..8] '*' (@end) + all_fields [7..8] '*' (@end) * [7..8] '*' from [9..70] 'from users u where u.active = true and (u.role = 'admin' or u.role = 'moderator')' keyword_from [9..13] 'from' - relation [14..21] 'users u' - table_reference [14..19] 'users' - any_identifier [14..19] 'users' + relation [14..21] 'users u' (@end) + table_reference [14..19] 'users' (@end) + any_identifier [14..19] 'users' (@table_reference_1of1) alias [20..21] 'u' - any_identifier [20..21] 'u' + any_identifier [20..21] 'u' (@end) where [2..70] 'where u.active = true and (u.role = 'admin' or u.role = 'moderator')' keyword_where [2..7] 'where' - binary_expression [8..70] 'u.active = true and (u.role = 'admin' or u.role = 'moderator')' - binary_expression [8..23] 'u.active = true' - object_reference [8..16] 'u.active' - any_identifier [8..9] 'u' + binary_expression [8..70] 'u.active = true and (u.role = 'admin' or u.role = 'moderator')' (@end) + binary_expression [8..23] 'u.active = true' (@binary_expr_left) + object_reference [8..16] 'u.active' (@binary_expr_left) + any_identifier [8..9] 'u' (@object_reference_1of2) . [9..10] '.' - any_identifier [10..16] 'active' - = [17..18] '=' - literal [19..23] 'true' + any_identifier [10..16] 'active' (@object_reference_2of2) + = [17..18] '=' (@binary_expr_operator) + literal [19..23] 'true' (@end) keyword_true [19..23] 'true' - keyword_and [24..27] 'and' - parenthesized_expression [28..70] '(u.role = 'admin' or u.role = 'moderator')' + keyword_and [24..27] 'and' (@binary_expr_operator) + parenthesized_expression [28..70] '(u.role = 'admin' or u.role = 'moderator')' (@end) ( [28..29] '(' binary_expression [29..69] 'u.role = 'admin' or u.role = 'moderator'' - binary_expression [29..45] 'u.role = 'admin'' - object_reference [29..35] 'u.role' - any_identifier [29..30] 'u' + binary_expression [29..45] 'u.role = 'admin'' (@binary_expr_left) + object_reference [29..35] 'u.role' (@binary_expr_left) + any_identifier [29..30] 'u' (@object_reference_1of2) . [30..31] '.' - any_identifier [31..35] 'role' - = [36..37] '=' - literal [38..45] ''admin'' - keyword_or [46..48] 'or' - binary_expression [49..69] 'u.role = 'moderator'' - object_reference [49..55] 'u.role' - any_identifier [49..50] 'u' + any_identifier [31..35] 'role' (@object_reference_2of2) + = [36..37] '=' (@binary_expr_operator) + literal [38..45] ''admin'' (@end) + keyword_or [46..48] 'or' (@binary_expr_operator) + binary_expression [49..69] 'u.role = 'moderator'' (@end) + object_reference [49..55] 'u.role' (@binary_expr_left) + any_identifier [49..50] 'u' (@object_reference_1of2) . [50..51] '.' - any_identifier [51..55] 'role' - = [56..57] '=' - literal [58..69] ''moderator'' - ) [69..70] ')' + any_identifier [51..55] 'role' (@object_reference_2of2) + = [56..57] '=' (@binary_expr_operator) + literal [58..69] ''moderator'' (@end) + ) [69..70] ')' (@end) ; [70..71] ';' diff --git a/crates/pgls_treesitter_grammar/tests/snapshots/grammar_tests__test_6.snap b/crates/pgls_treesitter_grammar/tests/snapshots/grammar_tests__test_6.snap index 0030c84fe..0aede6486 100644 --- a/crates/pgls_treesitter_grammar/tests/snapshots/grammar_tests__test_6.snap +++ b/crates/pgls_treesitter_grammar/tests/snapshots/grammar_tests__test_6.snap @@ -9,45 +9,45 @@ program [0..97] 'select (create_composite_type(a, b)).email, (schema.actual_type statement [0..96] 'select (create_composite_type(a, b)).email, (schema.actual_type).id, client from client_settings' select [0..75] 'select (create_composite_type(a, b)).email, (schema.actual_type).id, client' keyword_select [0..6] 'select' - select_expression [7..75] '(create_composite_type(a, b)).email, (schema.actual_type).id, client' - term [7..42] '(create_composite_type(a, b)).email' - field_selection [7..42] '(create_composite_type(a, b)).email' + select_expression [7..75] '(create_composite_type(a, b)).email, (schema.actual_type).id, client' (@end) + term [7..42] '(create_composite_type(a, b)).email' (@end) + field_selection [7..42] '(create_composite_type(a, b)).email' (@end) parenthesized_expression [7..36] '(create_composite_type(a, b))' ( [7..8] '(' invocation [8..35] 'create_composite_type(a, b)' function_reference [8..29] 'create_composite_type' - any_identifier [8..29] 'create_composite_type' + any_identifier [8..29] 'create_composite_type' (@function_reference_1of1) ( [29..30] '(' - term [30..31] 'a' - object_reference [30..31] 'a' - any_identifier [30..31] 'a' + term [30..31] 'a' (@parameter) + object_reference [30..31] 'a' (@end) + any_identifier [30..31] 'a' (@object_reference_1of1) , [31..32] ',' - term [33..34] 'b' - object_reference [33..34] 'b' - any_identifier [33..34] 'b' + term [33..34] 'b' (@parameter) + object_reference [33..34] 'b' (@end) + any_identifier [33..34] 'b' (@object_reference_1of1) ) [34..35] ')' - ) [35..36] ')' + ) [35..36] ')' (@end) . [36..37] '.' - any_identifier [37..42] 'email' - , [42..43] ',' - term [44..67] '(schema.actual_type).id' - field_selection [44..67] '(schema.actual_type).id' + any_identifier [37..42] 'email' (@end) + , [42..43] ',' (@end) + term [44..67] '(schema.actual_type).id' (@end) + field_selection [44..67] '(schema.actual_type).id' (@end) composite_reference [44..64] '(schema.actual_type)' ( [44..45] '(' object_reference [45..63] 'schema.actual_type' - any_identifier [45..51] 'schema' + any_identifier [45..51] 'schema' (@object_reference_1of2) . [51..52] '.' - any_identifier [52..63] 'actual_type' - ) [63..64] ')' + any_identifier [52..63] 'actual_type' (@object_reference_2of2) + ) [63..64] ')' (@end) . [64..65] '.' - any_identifier [65..67] 'id' - , [67..68] ',' - term [69..75] 'client' - object_reference [69..75] 'client' - any_identifier [69..75] 'client' + any_identifier [65..67] 'id' (@end) + , [67..68] ',' (@end) + term [69..75] 'client' (@end) + object_reference [69..75] 'client' (@end) + any_identifier [69..75] 'client' (@object_reference_1of1) from [76..96] 'from client_settings' keyword_from [76..80] 'from' - relation [81..96] 'client_settings' - table_reference [81..96] 'client_settings' - any_identifier [81..96] 'client_settings' + relation [81..96] 'client_settings' (@end) + table_reference [81..96] 'client_settings' (@end) + any_identifier [81..96] 'client_settings' (@table_reference_1of1) ; [96..97] ';' diff --git a/packages/@postgres-language-server/backend-jsonrpc/src/workspace.ts b/packages/@postgres-language-server/backend-jsonrpc/src/workspace.ts index c6b93982d..69d727961 100644 --- a/packages/@postgres-language-server/backend-jsonrpc/src/workspace.ts +++ b/packages/@postgres-language-server/backend-jsonrpc/src/workspace.ts @@ -275,7 +275,8 @@ export type CompletionItemKind = | "column" | "schema" | "policy" - | "role"; + | "role" + | "keyword"; export interface UpdateSettingsParams { configuration: PartialConfiguration; gitignore_matches: string[]; diff --git a/packages/@postgrestools/backend-jsonrpc/src/workspace.ts b/packages/@postgrestools/backend-jsonrpc/src/workspace.ts index c6b93982d..69d727961 100644 --- a/packages/@postgrestools/backend-jsonrpc/src/workspace.ts +++ b/packages/@postgrestools/backend-jsonrpc/src/workspace.ts @@ -275,7 +275,8 @@ export type CompletionItemKind = | "column" | "schema" | "policy" - | "role"; + | "role" + | "keyword"; export interface UpdateSettingsParams { configuration: PartialConfiguration; gitignore_matches: string[];