From 4c598cb0474d6759bf17fcac7e203a2e13aae2c1 Mon Sep 17 00:00:00 2001 From: psteinroe Date: Mon, 2 Jun 2025 21:37:54 +0200 Subject: [PATCH 1/5] chore: add relevant logs --- crates/pgt_lsp/tests/server.rs | 170 ++++++++++++++++++++++++++++++++- 1 file changed, 165 insertions(+), 5 deletions(-) diff --git a/crates/pgt_lsp/tests/server.rs b/crates/pgt_lsp/tests/server.rs index 438c7298..d8c5e45b 100644 --- a/crates/pgt_lsp/tests/server.rs +++ b/crates/pgt_lsp/tests/server.rs @@ -1,22 +1,22 @@ +use anyhow::bail; use anyhow::Context; use anyhow::Error; use anyhow::Result; -use anyhow::bail; use biome_deserialize::Merge; use biome_deserialize::StringSet; +use futures::channel::mpsc::{channel, Sender}; use futures::Sink; use futures::SinkExt; use futures::Stream; use futures::StreamExt; -use futures::channel::mpsc::{Sender, channel}; -use pgt_configuration::PartialConfiguration; use pgt_configuration::database::PartialDatabaseConfiguration; +use pgt_configuration::PartialConfiguration; use pgt_fs::MemoryFileSystem; use pgt_lsp::LSPServer; use pgt_lsp::ServerFactory; use pgt_workspace::DynRef; -use serde::Serialize; use serde::de::DeserializeOwned; +use serde::Serialize; use serde_json::Value; use serde_json::{from_value, to_value}; use sqlx::Executor; @@ -26,7 +26,6 @@ use std::fmt::Display; use std::time::Duration; use tower::timeout::Timeout; use tower::{Service, ServiceExt}; -use tower_lsp::LspService; use tower_lsp::jsonrpc; use tower_lsp::jsonrpc::Response; use tower_lsp::lsp_types as lsp; @@ -48,6 +47,7 @@ use tower_lsp::lsp_types::{ PublishDiagnosticsParams, TextDocumentContentChangeEvent, TextDocumentIdentifier, TextDocumentItem, Url, VersionedTextDocumentIdentifier, }; +use tower_lsp::LspService; use tower_lsp::{jsonrpc::Request, lsp_types::InitializeParams}; /// Statically build an [Url] instance that points to the file at `$path` @@ -1542,3 +1542,163 @@ async fn extends_config(test_db: PgPool) -> Result<()> { Ok(()) } + +// └─┐pgt_lsp::handlers::text_document::did_open{params=DidOpenTextDocumentParams { text_document: TextDocumentItem { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", query: None, fragment: None }, language_id: "sql", version: 0, text: "alter table \"public\".\"event\" drop constraint \"assign_event\";\n\nalter table \"public\".\"event\" drop constraint \"unassign_event\";\n\nalter table \"public\".\"event\" drop constraint \"validate_entities\";\n\ndrop index if exists \"public\".\"idx_appointment_custom_field_string\";\n\ndrop index if exists \"public\".\"idx_contact_custom_field_string\";\n\ndrop index if exists \"public\".\"idx_deal_custom_field_string\";\n\nCREATE INDEX idx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);\n\nCREATE INDEX idx_contact_custom_field_string_value_btree ON public.contact_custom_field USING btree (custom_field_id, contact_id, string_value) WHERE (type = 'string'::field_type);\n\nCREATE INDEX idx_deal_custom_field_string_value_btree ON public.deal_custom_field USING btree (custom_field_id, deal_id, string_value) WHERE (type = 'string'::field_type);\n\nalter table \"public\".\"event\" add constraint \"assign_event\" CHECK (((type <> 'assign'::event_type) OR ((source_type = ANY (ARRAY['employee'::event_entity_type, 'api_token'::event_entity_type, 'service_role'::event_entity_type, 'rule'::event_entity_type, 'cs_agent_session'::event_entity_type])) AND (target_type = ANY (ARRAY['employee'::event_entity_type, 'cs_agent'::event_entity_type]))))) not valid;\n\nalter table \"public\".\"event\" validate constraint \"assign_event\";\n\nalter table \"public\".\"event\" add constraint \"unassign_event\" CHECK (((type <> 'unassign'::event_type) OR ((source_type = ANY (ARRAY['employee'::event_entity_type, 'api_token'::event_entity_type, 'service_role'::event_entity_type, 'rule'::event_entity_type, 'cs_agent_session'::event_entity_type])) AND (target_type IS NULL)))) not valid;\n\nalter table \"public\".\"event\" validate constraint \"unassign_event\";\n\nalter table \"public\".\"event\" add constraint \"validate_entities\" CHECK (((((source_type IS NOT NULL) AND (source_type = 'comment'::event_entity_type)) = (source_comment_id IS NOT NULL)) AND (((source_type IS NOT NULL) AND (source_type = 'channel'::event_entity_type)) = (source_channel_id IS NOT NULL)) AND (((source_type IS NOT NULL) AND (source_type = 'recipient'::event_entity_type)) = (source_recipient_id IS NOT NULL)) AND (((target_type IS NOT NULL) AND (target_type = 'employee'::event_entity_type)) = (target_employee_id IS NOT NULL)) AND (((target_type IS NOT NULL) AND (target_type = 'cs_agent'::event_entity_type)) = (target_cs_agent_id IS NOT NULL)) AND (((target_type IS NOT NULL) AND (target_type = 'comment'::event_entity_type)) = (target_comment_id IS NOT NULL)) AND (((target_type IS NOT NULL) AND (target_type = 'message'::event_entity_type)) = (target_message_id IS NOT NULL)) AND (((target_type IS NOT NULL) AND (target_type = 'tag'::event_entity_type)) = (target_tag_id IS NOT NULL)) AND (((target_type IS NOT NULL) AND (target_type = 'message_action'::event_entity_type)) = (target_message_action_id IS NOT NULL)))) not valid;\n\nalter table \"public\".\"event\" validate constraint \"validate_entities\";\n\n\n" } }} +// └─┐pgt_workspace::workspace::server::open_file{path="/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql"} +// ┌─┘ +// ├─2025-06-02 9:46:46.224804 11ms INFO pgt_workspace::workspace::server Pulled 0 diagnostic(s) +// ┌─┘ +// └─┐pgt_lsp::handlers::text_document::did_change{params=DidChangeTextDocumentParams { text_document: VersionedTextDocumentIdentifier { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", query: None, fragment: None }, version: 3 }, content_changes: [TextDocumentContentChangeEvent { range: Some(Range { start: Position { line: 0, character: 0 }, end: Position { line: 5, character: 0 } }), range_length: Some(192), text: "" }] }} +// └─┐pgt_workspace::workspace::server::change_file{path="/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", version=3} +// ├─2025-06-02 9:46:50.316788 0ms DEBUG pgt_workspace::workspace::server::parsed_document Deleting statement: id Root(RootId { inner: 3 }) +// ├─2025-06-02 9:46:50.316957 1ms DEBUG pgt_workspace::workspace::server::parsed_document Deleting statement: id Root(RootId { inner: 2 }) +// ├─2025-06-02 9:46:50.317032 1ms DEBUG pgt_workspace::workspace::server::parsed_document Deleting statement: id Root(RootId { inner: 1 }) +// ├─2025-06-02 9:46:50.317102 1ms DEBUG pgt_workspace::workspace::server::parsed_document Deleting statement: id Root(RootId { inner: 0 }) +// ├─2025-06-02 9:46:50.317161 1ms DEBUG pgt_workspace::workspace::server::parsed_document Adding statement: id:Root(RootId { inner: 15 }), text:"drop index if exists \"public\".\"idx_appointment_custom_field_string\";" +// ┌─┘ +// ├─2025-06-02 9:46:50.321136 6ms INFO pgt_workspace::workspace::server Pulled 0 diagnostic(s) +// ┌─┘ +// └─┐pgt_lsp::handlers::text_document::did_change{params=DidChangeTextDocumentParams { text_document: VersionedTextDocumentIdentifier { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", query: None, fragment: None }, version: 4 }, content_changes: [TextDocumentContentChangeEvent { range: Some(Range { start: Position { line: 13, character: 0 }, end: Position { line: 26, character: 0 } }), range_length: Some(2097), text: "" }] }} +// └─┐pgt_workspace::workspace::server::change_file{path="/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", version=4} +// ├─2025-06-02 9:46:53.741847 0ms DEBUG pgt_workspace::workspace::server::parsed_document Deleting statement: id Root(RootId { inner: 14 }) +// ├─2025-06-02 9:46:53.741989 1ms DEBUG pgt_workspace::workspace::server::parsed_document Deleting statement: id Root(RootId { inner: 13 }) +// ├─2025-06-02 9:46:53.742232 1ms DEBUG pgt_workspace::workspace::server::parsed_document Deleting statement: id Root(RootId { inner: 12 }) +// ├─2025-06-02 9:46:53.742321 1ms DEBUG pgt_workspace::workspace::server::parsed_document Deleting statement: id Root(RootId { inner: 11 }) +// ├─2025-06-02 9:46:53.742426 1ms DEBUG pgt_workspace::workspace::server::parsed_document Deleting statement: id Root(RootId { inner: 10 }) +// ├─2025-06-02 9:46:53.742493 1ms DEBUG pgt_workspace::workspace::server::parsed_document Deleting statement: id Root(RootId { inner: 9 }) +// ├─2025-06-02 9:46:53.742643 1ms DEBUG pgt_workspace::workspace::server::parsed_document Deleting statement: id Root(RootId { inner: 8 }) +// ├─2025-06-02 9:46:53.742737 1ms DEBUG pgt_workspace::workspace::server::parsed_document Adding statement: id:Root(RootId { inner: 16 }), text:"CREATE INDEX idx_deal_custom_field_string_value_btree ON public.deal_custom_field USING btree (custom_field_id, deal_id, string_value) WHERE (type = 'string'::field_type);" +// ┌─┘ +// ├─2025-06-02 9:46:53.744504 4ms INFO pgt_workspace::workspace::server Pulled 0 diagnostic(s) +// ┌─┘ +// ├─2025-06-02 9:46:54.366107 83m WARN tower_lsp Got a textDocument/didSave notification, but it is not implemented +// └─┐pgt_lsp::handlers::text_document::did_change{params=DidChangeTextDocumentParams { text_document: VersionedTextDocumentIdentifier { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", query: None, fragment: None }, version: 6 }, content_changes: [TextDocumentContentChangeEvent { range: Some(Range { start: Position { line: 7, character: 13 }, end: Position { line: 7, character: 13 } }), range_length: Some(0), text: "I" }] }} +// └─┐pgt_workspace::workspace::server::change_file{path="/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", version=6} +// ├─2025-06-02 9:47:00.147075 0ms DEBUG pgt_workspace::workspace::server::parsed_document Modifying statement with id Root(RootId { inner: 6 }) (new id Root(RootId { inner: 17 })). Range 13..13, Changed from '"CREATE INDEX idx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"' to '"CREATE INDEX Iidx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"', changed text: "I" +// ┌─┘ +// ├─2025-06-02 9:47:00.148493 2ms INFO pgt_workspace::workspace::server Pulled 0 diagnostic(s) +// ┌─┘ +// └─┐pgt_lsp::handlers::completions::get_completions{params=CompletionParams { text_document_position: TextDocumentPositionParams { text_document: TextDocumentIdentifier { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", query: None, fragment: None } }, position: Position { line: 7, character: 14 } }, work_done_progress_params: WorkDoneProgressParams { work_done_token: None }, partial_result_params: PartialResultParams { partial_result_token: None }, context: Some(CompletionContext { trigger_kind: Invoked, trigger_character: None }) }} +// └─┐pgt_workspace::workspace::server::get_completions{path="/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", position="214"} +// └─┐pgt_completions::complete::complete{text="CREATE INDEX Iidx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);", position="14"} +// ┌─┘ +// ├─2025-06-02 9:47:00.201384 52ms DEBUG pgt_workspace::workspace::server Found 0 completion items for statement with id 17 +// ┌─┘ +// ┌─┘ +// └─┐pgt_lsp::handlers::text_document::did_change{params=DidChangeTextDocumentParams { text_document: VersionedTextDocumentIdentifier { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", query: None, fragment: None }, version: 7 }, content_changes: [TextDocumentContentChangeEvent { range: Some(Range { start: Position { line: 7, character: 14 }, end: Position { line: 7, character: 14 } }), range_length: Some(0), text: "F" }] }} +// └─┐pgt_workspace::workspace::server::change_file{path="/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", version=7} +// ├─2025-06-02 9:47:00.295825 0ms DEBUG pgt_workspace::workspace::server::parsed_document Modifying statement with id Root(RootId { inner: 17 }) (new id Root(RootId { inner: 18 })). Range 14..14, Changed from '"CREATE INDEX Iidx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"' to '"CREATE INDEX IFidx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"', changed text: "F" +// ┌─┘ +// ├─2025-06-02 9:47:00.296768 1ms INFO pgt_workspace::workspace::server Pulled 0 diagnostic(s) +// ┌─┘ +// └─┐pgt_lsp::handlers::text_document::did_change{params=DidChangeTextDocumentParams { text_document: VersionedTextDocumentIdentifier { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", query: None, fragment: None }, version: 8 }, content_changes: [TextDocumentContentChangeEvent { range: Some(Range { start: Position { line: 7, character: 15 }, end: Position { line: 7, character: 15 } }), range_length: Some(0), text: " " }] }} +// └─┐pgt_workspace::workspace::server::change_file{path="/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", version=8} +// ├─2025-06-02 9:47:00.363926 0ms DEBUG pgt_workspace::workspace::server::parsed_document Modifying statement with id Root(RootId { inner: 18 }) (new id Root(RootId { inner: 19 })). Range 15..15, Changed from '"CREATE INDEX IFidx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"' to '"CREATE INDEX IF idx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"', changed text: " " +// ┌─┘ +// ├─2025-06-02 9:47:00.364897 1ms INFO pgt_workspace::workspace::server Pulled 1 diagnostic(s) +// ┌─┘ +// └─┐pgt_lsp::handlers::completions::get_completions{params=CompletionParams { text_document_position: TextDocumentPositionParams { text_document: TextDocumentIdentifier { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", query: None, fragment: None } }, position: Position { line: 7, character: 16 } }, work_done_progress_params: WorkDoneProgressParams { work_done_token: None }, partial_result_params: PartialResultParams { partial_result_token: None }, context: Some(CompletionContext { trigger_kind: TriggerCharacter, trigger_character: Some(" ") }) }} +// └─┐pgt_workspace::workspace::server::get_completions{path="/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", position="216"} +// └─┐pgt_completions::complete::complete{text="CREATE INDEX IF idx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);", position="16"} +// ┌─┘ +// ├─2025-06-02 9:47:00.405793 40ms DEBUG pgt_workspace::workspace::server Found 0 completion items for statement with id 19 +// ┌─┘ +// ┌─┘ +// └─┐pgt_lsp::handlers::text_document::did_change{params=DidChangeTextDocumentParams { text_document: VersionedTextDocumentIdentifier { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", query: None, fragment: None }, version: 9 }, content_changes: [TextDocumentContentChangeEvent { range: Some(Range { start: Position { line: 7, character: 16 }, end: Position { line: 7, character: 16 } }), range_length: Some(0), text: "N" }] }} +// └─┐pgt_workspace::workspace::server::change_file{path="/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", version=9} +// ├─2025-06-02 9:47:00.418329 0ms DEBUG pgt_workspace::workspace::server::parsed_document Modifying statement with id Root(RootId { inner: 19 }) (new id Root(RootId { inner: 20 })). Range 16..16, Changed from '"CREATE INDEX IF idx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"' to '"CREATE INDEX IF Nidx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"', changed text: "N" +// ┌─┘ +// ├─2025-06-02 9:47:00.41892 1ms INFO pgt_workspace::workspace::server Pulled 1 diagnostic(s) +// ┌─┘ +// └─┐pgt_lsp::handlers::completions::get_completions{params=CompletionParams { text_document_position: TextDocumentPositionParams { text_document: TextDocumentIdentifier { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", query: None, fragment: None } }, position: Position { line: 7, character: 17 } }, work_done_progress_params: WorkDoneProgressParams { work_done_token: None }, partial_result_params: PartialResultParams { partial_result_token: None }, context: Some(CompletionContext { trigger_kind: Invoked, trigger_character: None }) }} +// └─┐pgt_workspace::workspace::server::get_completions{path="/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", position="217"} +// └─┐pgt_completions::complete::complete{text="CREATE INDEX IF Nidx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);", position="17"} +// ┌─┘ +// ├─2025-06-02 9:47:00.448103 28ms DEBUG pgt_workspace::workspace::server Found 0 completion items for statement with id 20 +// ┌─┘ +// ┌─┘ +// └─┐pgt_lsp::handlers::text_document::did_change{params=DidChangeTextDocumentParams { text_document: VersionedTextDocumentIdentifier { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", query: None, fragment: None }, version: 10 }, content_changes: [TextDocumentContentChangeEvent { range: Some(Range { start: Position { line: 7, character: 17 }, end: Position { line: 7, character: 17 } }), range_length: Some(0), text: "O" }] }} +// └─┐pgt_workspace::workspace::server::change_file{path="/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", version=10} +// ├─2025-06-02 9:47:00.588574 0ms DEBUG pgt_workspace::workspace::server::parsed_document Modifying statement with id Root(RootId { inner: 20 }) (new id Root(RootId { inner: 21 })). Range 17..17, Changed from '"CREATE INDEX IF Nidx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"' to '"CREATE INDEX IF NOidx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"', changed text: "O" +// ┌─┘ +// ├─2025-06-02 9:47:00.589522 1ms INFO pgt_workspace::workspace::server Pulled 1 diagnostic(s) +// ┌─┘ +// └─┐pgt_lsp::handlers::text_document::did_change{params=DidChangeTextDocumentParams { text_document: VersionedTextDocumentIdentifier { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", query: None, fragment: None }, version: 11 }, content_changes: [TextDocumentContentChangeEvent { range: Some(Range { start: Position { line: 7, character: 18 }, end: Position { line: 7, character: 18 } }), range_length: Some(0), text: "T" }] }} +// └─┐pgt_workspace::workspace::server::change_file{path="/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", version=11} +// ├─2025-06-02 9:47:00.721041 0ms DEBUG pgt_workspace::workspace::server::parsed_document Modifying statement with id Root(RootId { inner: 21 }) (new id Root(RootId { inner: 22 })). Range 18..18, Changed from '"CREATE INDEX IF NOidx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"' to '"CREATE INDEX IF NOTidx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"', changed text: "T" +// ┌─┘ +// ├─2025-06-02 9:47:00.722806 2ms INFO pgt_workspace::workspace::server Pulled 1 diagnostic(s) +// ┌─┘ +// └─┐pgt_lsp::handlers::text_document::did_change{params=DidChangeTextDocumentParams { text_document: VersionedTextDocumentIdentifier { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", query: None, fragment: None }, version: 12 }, content_changes: [TextDocumentContentChangeEvent { range: Some(Range { start: Position { line: 7, character: 19 }, end: Position { line: 7, character: 19 } }), range_length: Some(0), text: " " }] }} +// └─┐pgt_workspace::workspace::server::change_file{path="/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", version=12} +// ├─2025-06-02 9:47:00.724899 0ms DEBUG pgt_workspace::workspace::server::parsed_document Modifying statement with id Root(RootId { inner: 22 }) (new id Root(RootId { inner: 23 })). Range 19..19, Changed from '"CREATE INDEX IF NOTidx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"' to '"CREATE INDEX IF NOT idx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"', changed text: " " +// ┌─┘ +// ├─2025-06-02 9:47:00.725877 1ms INFO pgt_workspace::workspace::server Pulled 1 diagnostic(s) +// ┌─┘ +// └─┐pgt_lsp::handlers::completions::get_completions{params=CompletionParams { text_document_position: TextDocumentPositionParams { text_document: TextDocumentIdentifier { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", query: None, fragment: None } }, position: Position { line: 7, character: 20 } }, work_done_progress_params: WorkDoneProgressParams { work_done_token: None }, partial_result_params: PartialResultParams { partial_result_token: None }, context: Some(CompletionContext { trigger_kind: TriggerCharacter, trigger_character: Some(" ") }) }} +// └─┐pgt_workspace::workspace::server::get_completions{path="/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", position="220"} +// └─┐pgt_completions::complete::complete{text="CREATE INDEX IF NOT idx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);", position="20"} +// ┌─┘ +// ├─2025-06-02 9:47:00.776552 50ms DEBUG pgt_workspace::workspace::server Found 0 completion items for statement with id 23 +// ┌─┘ +// ┌─┘ +// └─┐pgt_lsp::handlers::text_document::did_change{params=DidChangeTextDocumentParams { text_document: VersionedTextDocumentIdentifier { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", query: None, fragment: None }, version: 13 }, content_changes: [TextDocumentContentChangeEvent { range: Some(Range { start: Position { line: 7, character: 20 }, end: Position { line: 7, character: 20 } }), range_length: Some(0), text: "E" }] }} +// └─┐pgt_workspace::workspace::server::change_file{path="/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", version=13} +// ├─2025-06-02 9:47:00.813959 0ms DEBUG pgt_workspace::workspace::server::parsed_document Modifying statement with id Root(RootId { inner: 23 }) (new id Root(RootId { inner: 24 })). Range 20..20, Changed from '"CREATE INDEX IF NOT idx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"' to '"CREATE INDEX IF NOT Eidx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"', changed text: "E" +// ┌─┘ +// ├─2025-06-02 9:47:00.814674 1ms INFO pgt_workspace::workspace::server Pulled 1 diagnostic(s) +// ┌─┘ +// └─┐pgt_lsp::handlers::completions::get_completions{params=CompletionParams { text_document_position: TextDocumentPositionParams { text_document: TextDocumentIdentifier { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", query: None, fragment: None } }, position: Position { line: 7, character: 21 } }, work_done_progress_params: WorkDoneProgressParams { work_done_token: None }, partial_result_params: PartialResultParams { partial_result_token: None }, context: Some(CompletionContext { trigger_kind: Invoked, trigger_character: None }) }} +// └─┐pgt_workspace::workspace::server::get_completions{path="/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", position="221"} +// └─┐pgt_completions::complete::complete{text="CREATE INDEX IF NOT Eidx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);", position="21"} +// ┌─┘ +// ├─2025-06-02 9:47:00.848701 33ms DEBUG pgt_workspace::workspace::server Found 0 completion items for statement with id 24 +// ┌─┘ +// ┌─┘ +// └─┐pgt_lsp::handlers::text_document::did_change{params=DidChangeTextDocumentParams { text_document: VersionedTextDocumentIdentifier { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", query: None, fragment: None }, version: 14 }, content_changes: [TextDocumentContentChangeEvent { range: Some(Range { start: Position { line: 7, character: 21 }, end: Position { line: 7, character: 21 } }), range_length: Some(0), text: "X" }] }} +// └─┐pgt_workspace::workspace::server::change_file{path="/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", version=14} +// ├─2025-06-02 9:47:01.051286 0ms DEBUG pgt_workspace::workspace::server::parsed_document Modifying statement with id Root(RootId { inner: 24 }) (new id Root(RootId { inner: 25 })). Range 21..21, Changed from '"CREATE INDEX IF NOT Eidx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"' to '"CREATE INDEX IF NOT EXidx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"', changed text: "X" +// ┌─┘ +// ├─2025-06-02 9:47:01.052446 2ms INFO pgt_workspace::workspace::server Pulled 1 diagnostic(s) +// ┌─┘ +// └─┐pgt_lsp::handlers::text_document::did_change{params=DidChangeTextDocumentParams { text_document: VersionedTextDocumentIdentifier { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", query: None, fragment: None }, version: 15 }, content_changes: [TextDocumentContentChangeEvent { range: Some(Range { start: Position { line: 7, character: 22 }, end: Position { line: 7, character: 22 } }), range_length: Some(0), text: "I" }] }} +// └─┐pgt_workspace::workspace::server::change_file{path="/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", version=15} +// ├─2025-06-02 9:47:01.201943 1ms DEBUG pgt_workspace::workspace::server::parsed_document Modifying statement with id Root(RootId { inner: 25 }) (new id Root(RootId { inner: 26 })). Range 22..22, Changed from '"CREATE INDEX IF NOT EXidx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"' to '"CREATE INDEX IF NOT EXIidx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"', changed text: "I" +// ┌─┘ +// ├─2025-06-02 9:47:01.203949 3ms INFO pgt_workspace::workspace::server Pulled 1 diagnostic(s) +// ┌─┘ +// └─┐pgt_lsp::handlers::text_document::did_change{params=DidChangeTextDocumentParams { text_document: VersionedTextDocumentIdentifier { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", query: None, fragment: None }, version: 16 }, content_changes: [TextDocumentContentChangeEvent { range: Some(Range { start: Position { line: 7, character: 23 }, end: Position { line: 7, character: 23 } }), range_length: Some(0), text: "S" }] }} +// └─┐pgt_workspace::workspace::server::change_file{path="/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", version=16} +// ├─2025-06-02 9:47:01.310226 0ms DEBUG pgt_workspace::workspace::server::parsed_document Modifying statement with id Root(RootId { inner: 26 }) (new id Root(RootId { inner: 27 })). Range 23..23, Changed from '"CREATE INDEX IF NOT EXIidx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"' to '"CREATE INDEX IF NOT EXISidx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"', changed text: "S" +// ┌─┘ +// ├─2025-06-02 9:47:01.311452 2ms INFO pgt_workspace::workspace::server Pulled 1 diagnostic(s) +// ┌─┘ +// └─┐pgt_lsp::handlers::text_document::did_change{params=DidChangeTextDocumentParams { text_document: VersionedTextDocumentIdentifier { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", query: None, fragment: None }, version: 17 }, content_changes: [TextDocumentContentChangeEvent { range: Some(Range { start: Position { line: 7, character: 24 }, end: Position { line: 7, character: 24 } }), range_length: Some(0), text: "T" }] }} +// └─┐pgt_workspace::workspace::server::change_file{path="/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", version=17} +// ├─2025-06-02 9:47:01.391161 1ms DEBUG pgt_workspace::workspace::server::parsed_document Modifying statement with id Root(RootId { inner: 27 }) (new id Root(RootId { inner: 28 })). Range 24..24, Changed from '"CREATE INDEX IF NOT EXISidx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"' to '"CREATE INDEX IF NOT EXISTidx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"', changed text: "T" +// ┌─┘ +// ├─2025-06-02 9:47:01.393041 3ms INFO pgt_workspace::workspace::server Pulled 1 diagnostic(s) +// ┌─┘ +// └─┐pgt_lsp::handlers::text_document::did_change{params=DidChangeTextDocumentParams { text_document: VersionedTextDocumentIdentifier { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", query: None, fragment: None }, version: 19 }, content_changes: [TextDocumentContentChangeEvent { range: Some(Range { start: Position { line: 7, character: 25 }, end: Position { line: 7, character: 25 } }), range_length: Some(0), text: "S" }, TextDocumentContentChangeEvent { range: Some(Range { start: Position { line: 7, character: 26 }, end: Position { line: 7, character: 26 } }), range_length: Some(0), text: " " }] }} +// └─┐pgt_workspace::workspace::server::change_file{path="/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", version=19} +// ├─2025-06-02 9:47:01.480581 0ms DEBUG pgt_workspace::workspace::server::parsed_document Modifying statement with id Root(RootId { inner: 28 }) (new id Root(RootId { inner: 29 })). Range 25..25, Changed from '"CREATE INDEX IF NOT EXISTidx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"' to '"CREATE INDEX IF NOT EXISTSidx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"', changed text: "S" +// ├─2025-06-02 9:47:01.480915 1ms DEBUG pgt_workspace::workspace::server::parsed_document Modifying statement with id Root(RootId { inner: 29 }) (new id Root(RootId { inner: 30 })). Range 27..27, Changed from '"CREATE INDEX IF NOT EXISTSidx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"' to '"CREATE INDEX IF NOT EXISTSi dx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"', changed text: " " +// ┌─┘ +// ├─2025-06-02 9:47:01.481901 2ms INFO pgt_workspace::workspace::server Pulled 1 diagnostic(s) +// ┌─┘ +// └─┐pgt_lsp::handlers::completions::get_completions{params=CompletionParams { text_document_position: TextDocumentPositionParams { text_document: TextDocumentIdentifier { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", query: None, fragment: None } }, position: Position { line: 7, character: 27 } }, work_done_progress_params: WorkDoneProgressParams { work_done_token: None }, partial_result_params: PartialResultParams { partial_result_token: None }, context: Some(CompletionContext { trigger_kind: TriggerCharacter, trigger_character: Some(" ") }) }} +// └─┐pgt_workspace::workspace::server::get_completions{path="/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", position="227"} +// └─┐pgt_completions::complete::complete{text="CREATE INDEX IF NOT EXISTSi dx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);", position="27"} +// ┌─┘ +// ├─2025-06-02 9:47:01.530715 48ms DEBUG pgt_workspace::workspace::server Found 0 completion items for statement with id 30 +// ┌─┘ +// ┌─┘ +// └─┐pgt_lsp::handlers::text_document::did_change{params=DidChangeTextDocumentParams { text_document: VersionedTextDocumentIdentifier { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", query: None, fragment: None }, version: 20 }, content_changes: [TextDocumentContentChangeEvent { range: Some(Range { start: Position { line: 9, character: 13 }, end: Position { line: 9, character: 13 } }), range_length: Some(0), text: "IF NOT EXISTS " }] }} +// └─┐pgt_workspace::workspace::server::change_file{path="/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", version=20} +// ├─2025-06-02 9:47:08.691711 1ms DEBUG pgt_workspace::workspace::server::parsed_document Modifying statement with id Root(RootId { inner: 7 }) (new id Root(RootId { inner: 31 })). Range 13..13, Changed from '"CREATE INDEX idx_contact_custom_field_string_value_btree ON public.contact_custom_field USING btree (custom_field_id, contact_id, string_value) WHERE (type = 'string'::field_type);"' to '"CREATE INDEX IF NOT EXISTS idx_contact_custom_field_string_value_btree ON public.contact_custom_field USING btree (custom_field_id, contact_id, string_value) WHERE (type = 'string'::field_type);"', changed text: "IF NOT EXISTS " +// ┌─┘ +// ├─2025-06-02 9:47:08.693581 3ms INFO pgt_workspace::workspace::server Pulled 1 diagnostic(s) +// ┌─┘ +// └─┐pgt_lsp::handlers::text_document::did_change{params=DidChangeTextDocumentParams { text_document: VersionedTextDocumentIdentifier { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", query: None, fragment: None }, version: 21 }, content_changes: [TextDocumentContentChangeEvent { range: Some(Range { start: Position { line: 11, character: 13 }, end: Position { line: 11, character: 13 } }), range_length: Some(0), text: "IF NOT EXISTS " }] }} +// └─┐pgt_workspace::workspace::server::change_file{path="/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", version=21} +// ├─2025-06-02 9:47:10.683595 0ms DEBUG pgt_workspace::workspace::server::parsed_document Modifying statement with id Root(RootId { inner: 16 }) (new id Root(RootId { inner: 32 })). Range 13..13, Changed from '"CREATE INDEX idx_deal_custom_field_string_value_btree ON public.deal_custom_field USING btree (custom_field_id, deal_id, string_value) WHERE (type = 'string'::field_type);"' to '"CREATE INDEX IF NOT EXISTS idx_deal_custom_field_string_value_btree ON public.deal_custom_field USING btree (custom_field_id, deal_id, string_value) WHERE (type = 'string'::field_type);"', changed text: "IF NOT EXISTS " From 1502679fe3bed3138f03f03c0b7ae1656cf9e16a Mon Sep 17 00:00:00 2001 From: psteinroe Date: Wed, 4 Jun 2025 09:43:12 +0200 Subject: [PATCH 2/5] progress --- crates/pgt_lsp/tests/server.rs | 10 ++--- .../src/workspace/server/change.rs | 40 +++++++++++++++++++ 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/crates/pgt_lsp/tests/server.rs b/crates/pgt_lsp/tests/server.rs index d8c5e45b..202b7256 100644 --- a/crates/pgt_lsp/tests/server.rs +++ b/crates/pgt_lsp/tests/server.rs @@ -1,22 +1,22 @@ -use anyhow::bail; use anyhow::Context; use anyhow::Error; use anyhow::Result; +use anyhow::bail; use biome_deserialize::Merge; use biome_deserialize::StringSet; -use futures::channel::mpsc::{channel, Sender}; use futures::Sink; use futures::SinkExt; use futures::Stream; use futures::StreamExt; -use pgt_configuration::database::PartialDatabaseConfiguration; +use futures::channel::mpsc::{Sender, channel}; use pgt_configuration::PartialConfiguration; +use pgt_configuration::database::PartialDatabaseConfiguration; use pgt_fs::MemoryFileSystem; use pgt_lsp::LSPServer; use pgt_lsp::ServerFactory; use pgt_workspace::DynRef; -use serde::de::DeserializeOwned; use serde::Serialize; +use serde::de::DeserializeOwned; use serde_json::Value; use serde_json::{from_value, to_value}; use sqlx::Executor; @@ -26,6 +26,7 @@ use std::fmt::Display; use std::time::Duration; use tower::timeout::Timeout; use tower::{Service, ServiceExt}; +use tower_lsp::LspService; use tower_lsp::jsonrpc; use tower_lsp::jsonrpc::Response; use tower_lsp::lsp_types as lsp; @@ -47,7 +48,6 @@ use tower_lsp::lsp_types::{ PublishDiagnosticsParams, TextDocumentContentChangeEvent, TextDocumentIdentifier, TextDocumentItem, Url, VersionedTextDocumentIdentifier, }; -use tower_lsp::LspService; use tower_lsp::{jsonrpc::Request, lsp_types::InitializeParams}; /// Statically build an [Url] instance that points to the file at `$path` diff --git a/crates/pgt_workspace/src/workspace/server/change.rs b/crates/pgt_workspace/src/workspace/server/change.rs index c8799922..ed4ef462 100644 --- a/crates/pgt_workspace/src/workspace/server/change.rs +++ b/crates/pgt_workspace/src/workspace/server/change.rs @@ -63,6 +63,9 @@ impl Document { // very much not guaranteed to result in correct ranges self.diagnostics.clear(); + tracing::debug!("Changing from {:?}", self.content); + tracing::debug!("Applying changes {:?}", &change.changes); + // when we recieive more than one change, we need to push back the changes based on the // total range of the previous ones. This is because the ranges are always related to the original state. let mut changes = Vec::new(); @@ -93,6 +96,9 @@ impl Document { self.version = change.version; + tracing::debug!("Applied changes {:?}", changes); + tracing::debug!("Changed to {:?}", self.content); + changes } @@ -1663,6 +1669,40 @@ KEY (\"organisation_id\") REFERENCES \"public\".\"organisation\"(\"id\") ON UPDA assert_document_integrity(&doc); } + #[test] + fn test_content_out_of_sync() { + let path = PgTPath::new("test.sql"); + let initial_content = "select 1, 2, 2232231313393319 from unknown_users;\n"; + + let mut doc = Document::new(initial_content.to_string(), 0); + + let change1 = ChangeFileParams { + path: path.clone(), + version: 1, + changes: vec![ + ChangeParams { + range: Some(TextRange::new(29.into(), 29.into())), + text: "3".to_string(), + }, + ChangeParams { + range: Some(TextRange::new(30.into(), 30.into())), + text: "1".to_string(), + }, + ], + }; + + let changes = doc.apply_file_change(&change1); + + println!("changes: {:#?}", changes); + + assert_eq!( + doc.content, + "select 1, 2, 22322313133933193 from unknown_users;\n" + ); + + assert_document_integrity(&doc); + } + #[test] fn test_comments_only() { let path = PgTPath::new("test.sql"); From d248d56668294b92a2746716f94909344431b13c Mon Sep 17 00:00:00 2001 From: psteinroe Date: Thu, 5 Jun 2025 09:16:33 +0200 Subject: [PATCH 3/5] progress --- .../src/workspace/server/change.rs | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/crates/pgt_workspace/src/workspace/server/change.rs b/crates/pgt_workspace/src/workspace/server/change.rs index ed4ef462..5c31a596 100644 --- a/crates/pgt_workspace/src/workspace/server/change.rs +++ b/crates/pgt_workspace/src/workspace/server/change.rs @@ -63,11 +63,10 @@ impl Document { // very much not guaranteed to result in correct ranges self.diagnostics.clear(); - tracing::debug!("Changing from {:?}", self.content); - tracing::debug!("Applying changes {:?}", &change.changes); - // when we recieive more than one change, we need to push back the changes based on the // total range of the previous ones. This is because the ranges are always related to the original state. + // BUT: only for the statement range changes, not for the text changes + // this is why we pass both varaints to apply_change let mut changes = Vec::new(); let mut offset: i64 = 0; @@ -89,16 +88,13 @@ impl Document { change }; - changes.extend(self.apply_change(adjusted_change)); + changes.extend(self.apply_change(adjusted_change, change)); - offset += change.change_size(); + offset += adjusted_change.change_size(); } self.version = change.version; - tracing::debug!("Applied changes {:?}", changes); - tracing::debug!("Changed to {:?}", self.content); - changes } @@ -246,9 +242,17 @@ impl Document { } /// Applies a single change to the document and returns the affected statements - fn apply_change(&mut self, change: &ChangeParams) -> Vec { + /// + /// * `change`: The range-adjusted change to use for statement changes + /// * `original_change`: The original change to use for text changes (yes, this is a bit confusing, and we might want to refactor this entire thing at some point.) + fn apply_change( + &mut self, + change: &ChangeParams, + original_change: &ChangeParams, + ) -> Vec { // if range is none, we have a full change if change.range.is_none() { + // doesnt matter what change since range is null return self.apply_full_change(change); } @@ -261,7 +265,7 @@ impl Document { let change_range = change.range.unwrap(); let previous_content = self.content.clone(); - let new_content = change.apply_to_text(&self.content); + let new_content = original_change.apply_to_text(&self.content); // we first need to determine the affected range and all affected statements, as well as // the index of the prev and the next statement, if any. The full affected range is the @@ -1691,13 +1695,11 @@ KEY (\"organisation_id\") REFERENCES \"public\".\"organisation\"(\"id\") ON UPDA ], }; - let changes = doc.apply_file_change(&change1); - - println!("changes: {:#?}", changes); + let _changes = doc.apply_file_change(&change1); assert_eq!( doc.content, - "select 1, 2, 22322313133933193 from unknown_users;\n" + "select 1, 2, 223223131339331931 from unknown_users;\n" ); assert_document_integrity(&doc); From 28eba547647dbb4accb86a1bdcd52d78ed6ea11b Mon Sep 17 00:00:00 2001 From: psteinroe Date: Thu, 5 Jun 2025 09:17:24 +0200 Subject: [PATCH 4/5] progress --- crates/pgt_lsp/tests/server.rs | 160 --------------------------------- 1 file changed, 160 deletions(-) diff --git a/crates/pgt_lsp/tests/server.rs b/crates/pgt_lsp/tests/server.rs index 202b7256..438c7298 100644 --- a/crates/pgt_lsp/tests/server.rs +++ b/crates/pgt_lsp/tests/server.rs @@ -1542,163 +1542,3 @@ async fn extends_config(test_db: PgPool) -> Result<()> { Ok(()) } - -// └─┐pgt_lsp::handlers::text_document::did_open{params=DidOpenTextDocumentParams { text_document: TextDocumentItem { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", query: None, fragment: None }, language_id: "sql", version: 0, text: "alter table \"public\".\"event\" drop constraint \"assign_event\";\n\nalter table \"public\".\"event\" drop constraint \"unassign_event\";\n\nalter table \"public\".\"event\" drop constraint \"validate_entities\";\n\ndrop index if exists \"public\".\"idx_appointment_custom_field_string\";\n\ndrop index if exists \"public\".\"idx_contact_custom_field_string\";\n\ndrop index if exists \"public\".\"idx_deal_custom_field_string\";\n\nCREATE INDEX idx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);\n\nCREATE INDEX idx_contact_custom_field_string_value_btree ON public.contact_custom_field USING btree (custom_field_id, contact_id, string_value) WHERE (type = 'string'::field_type);\n\nCREATE INDEX idx_deal_custom_field_string_value_btree ON public.deal_custom_field USING btree (custom_field_id, deal_id, string_value) WHERE (type = 'string'::field_type);\n\nalter table \"public\".\"event\" add constraint \"assign_event\" CHECK (((type <> 'assign'::event_type) OR ((source_type = ANY (ARRAY['employee'::event_entity_type, 'api_token'::event_entity_type, 'service_role'::event_entity_type, 'rule'::event_entity_type, 'cs_agent_session'::event_entity_type])) AND (target_type = ANY (ARRAY['employee'::event_entity_type, 'cs_agent'::event_entity_type]))))) not valid;\n\nalter table \"public\".\"event\" validate constraint \"assign_event\";\n\nalter table \"public\".\"event\" add constraint \"unassign_event\" CHECK (((type <> 'unassign'::event_type) OR ((source_type = ANY (ARRAY['employee'::event_entity_type, 'api_token'::event_entity_type, 'service_role'::event_entity_type, 'rule'::event_entity_type, 'cs_agent_session'::event_entity_type])) AND (target_type IS NULL)))) not valid;\n\nalter table \"public\".\"event\" validate constraint \"unassign_event\";\n\nalter table \"public\".\"event\" add constraint \"validate_entities\" CHECK (((((source_type IS NOT NULL) AND (source_type = 'comment'::event_entity_type)) = (source_comment_id IS NOT NULL)) AND (((source_type IS NOT NULL) AND (source_type = 'channel'::event_entity_type)) = (source_channel_id IS NOT NULL)) AND (((source_type IS NOT NULL) AND (source_type = 'recipient'::event_entity_type)) = (source_recipient_id IS NOT NULL)) AND (((target_type IS NOT NULL) AND (target_type = 'employee'::event_entity_type)) = (target_employee_id IS NOT NULL)) AND (((target_type IS NOT NULL) AND (target_type = 'cs_agent'::event_entity_type)) = (target_cs_agent_id IS NOT NULL)) AND (((target_type IS NOT NULL) AND (target_type = 'comment'::event_entity_type)) = (target_comment_id IS NOT NULL)) AND (((target_type IS NOT NULL) AND (target_type = 'message'::event_entity_type)) = (target_message_id IS NOT NULL)) AND (((target_type IS NOT NULL) AND (target_type = 'tag'::event_entity_type)) = (target_tag_id IS NOT NULL)) AND (((target_type IS NOT NULL) AND (target_type = 'message_action'::event_entity_type)) = (target_message_action_id IS NOT NULL)))) not valid;\n\nalter table \"public\".\"event\" validate constraint \"validate_entities\";\n\n\n" } }} -// └─┐pgt_workspace::workspace::server::open_file{path="/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql"} -// ┌─┘ -// ├─2025-06-02 9:46:46.224804 11ms INFO pgt_workspace::workspace::server Pulled 0 diagnostic(s) -// ┌─┘ -// └─┐pgt_lsp::handlers::text_document::did_change{params=DidChangeTextDocumentParams { text_document: VersionedTextDocumentIdentifier { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", query: None, fragment: None }, version: 3 }, content_changes: [TextDocumentContentChangeEvent { range: Some(Range { start: Position { line: 0, character: 0 }, end: Position { line: 5, character: 0 } }), range_length: Some(192), text: "" }] }} -// └─┐pgt_workspace::workspace::server::change_file{path="/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", version=3} -// ├─2025-06-02 9:46:50.316788 0ms DEBUG pgt_workspace::workspace::server::parsed_document Deleting statement: id Root(RootId { inner: 3 }) -// ├─2025-06-02 9:46:50.316957 1ms DEBUG pgt_workspace::workspace::server::parsed_document Deleting statement: id Root(RootId { inner: 2 }) -// ├─2025-06-02 9:46:50.317032 1ms DEBUG pgt_workspace::workspace::server::parsed_document Deleting statement: id Root(RootId { inner: 1 }) -// ├─2025-06-02 9:46:50.317102 1ms DEBUG pgt_workspace::workspace::server::parsed_document Deleting statement: id Root(RootId { inner: 0 }) -// ├─2025-06-02 9:46:50.317161 1ms DEBUG pgt_workspace::workspace::server::parsed_document Adding statement: id:Root(RootId { inner: 15 }), text:"drop index if exists \"public\".\"idx_appointment_custom_field_string\";" -// ┌─┘ -// ├─2025-06-02 9:46:50.321136 6ms INFO pgt_workspace::workspace::server Pulled 0 diagnostic(s) -// ┌─┘ -// └─┐pgt_lsp::handlers::text_document::did_change{params=DidChangeTextDocumentParams { text_document: VersionedTextDocumentIdentifier { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", query: None, fragment: None }, version: 4 }, content_changes: [TextDocumentContentChangeEvent { range: Some(Range { start: Position { line: 13, character: 0 }, end: Position { line: 26, character: 0 } }), range_length: Some(2097), text: "" }] }} -// └─┐pgt_workspace::workspace::server::change_file{path="/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", version=4} -// ├─2025-06-02 9:46:53.741847 0ms DEBUG pgt_workspace::workspace::server::parsed_document Deleting statement: id Root(RootId { inner: 14 }) -// ├─2025-06-02 9:46:53.741989 1ms DEBUG pgt_workspace::workspace::server::parsed_document Deleting statement: id Root(RootId { inner: 13 }) -// ├─2025-06-02 9:46:53.742232 1ms DEBUG pgt_workspace::workspace::server::parsed_document Deleting statement: id Root(RootId { inner: 12 }) -// ├─2025-06-02 9:46:53.742321 1ms DEBUG pgt_workspace::workspace::server::parsed_document Deleting statement: id Root(RootId { inner: 11 }) -// ├─2025-06-02 9:46:53.742426 1ms DEBUG pgt_workspace::workspace::server::parsed_document Deleting statement: id Root(RootId { inner: 10 }) -// ├─2025-06-02 9:46:53.742493 1ms DEBUG pgt_workspace::workspace::server::parsed_document Deleting statement: id Root(RootId { inner: 9 }) -// ├─2025-06-02 9:46:53.742643 1ms DEBUG pgt_workspace::workspace::server::parsed_document Deleting statement: id Root(RootId { inner: 8 }) -// ├─2025-06-02 9:46:53.742737 1ms DEBUG pgt_workspace::workspace::server::parsed_document Adding statement: id:Root(RootId { inner: 16 }), text:"CREATE INDEX idx_deal_custom_field_string_value_btree ON public.deal_custom_field USING btree (custom_field_id, deal_id, string_value) WHERE (type = 'string'::field_type);" -// ┌─┘ -// ├─2025-06-02 9:46:53.744504 4ms INFO pgt_workspace::workspace::server Pulled 0 diagnostic(s) -// ┌─┘ -// ├─2025-06-02 9:46:54.366107 83m WARN tower_lsp Got a textDocument/didSave notification, but it is not implemented -// └─┐pgt_lsp::handlers::text_document::did_change{params=DidChangeTextDocumentParams { text_document: VersionedTextDocumentIdentifier { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", query: None, fragment: None }, version: 6 }, content_changes: [TextDocumentContentChangeEvent { range: Some(Range { start: Position { line: 7, character: 13 }, end: Position { line: 7, character: 13 } }), range_length: Some(0), text: "I" }] }} -// └─┐pgt_workspace::workspace::server::change_file{path="/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", version=6} -// ├─2025-06-02 9:47:00.147075 0ms DEBUG pgt_workspace::workspace::server::parsed_document Modifying statement with id Root(RootId { inner: 6 }) (new id Root(RootId { inner: 17 })). Range 13..13, Changed from '"CREATE INDEX idx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"' to '"CREATE INDEX Iidx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"', changed text: "I" -// ┌─┘ -// ├─2025-06-02 9:47:00.148493 2ms INFO pgt_workspace::workspace::server Pulled 0 diagnostic(s) -// ┌─┘ -// └─┐pgt_lsp::handlers::completions::get_completions{params=CompletionParams { text_document_position: TextDocumentPositionParams { text_document: TextDocumentIdentifier { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", query: None, fragment: None } }, position: Position { line: 7, character: 14 } }, work_done_progress_params: WorkDoneProgressParams { work_done_token: None }, partial_result_params: PartialResultParams { partial_result_token: None }, context: Some(CompletionContext { trigger_kind: Invoked, trigger_character: None }) }} -// └─┐pgt_workspace::workspace::server::get_completions{path="/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", position="214"} -// └─┐pgt_completions::complete::complete{text="CREATE INDEX Iidx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);", position="14"} -// ┌─┘ -// ├─2025-06-02 9:47:00.201384 52ms DEBUG pgt_workspace::workspace::server Found 0 completion items for statement with id 17 -// ┌─┘ -// ┌─┘ -// └─┐pgt_lsp::handlers::text_document::did_change{params=DidChangeTextDocumentParams { text_document: VersionedTextDocumentIdentifier { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", query: None, fragment: None }, version: 7 }, content_changes: [TextDocumentContentChangeEvent { range: Some(Range { start: Position { line: 7, character: 14 }, end: Position { line: 7, character: 14 } }), range_length: Some(0), text: "F" }] }} -// └─┐pgt_workspace::workspace::server::change_file{path="/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", version=7} -// ├─2025-06-02 9:47:00.295825 0ms DEBUG pgt_workspace::workspace::server::parsed_document Modifying statement with id Root(RootId { inner: 17 }) (new id Root(RootId { inner: 18 })). Range 14..14, Changed from '"CREATE INDEX Iidx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"' to '"CREATE INDEX IFidx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"', changed text: "F" -// ┌─┘ -// ├─2025-06-02 9:47:00.296768 1ms INFO pgt_workspace::workspace::server Pulled 0 diagnostic(s) -// ┌─┘ -// └─┐pgt_lsp::handlers::text_document::did_change{params=DidChangeTextDocumentParams { text_document: VersionedTextDocumentIdentifier { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", query: None, fragment: None }, version: 8 }, content_changes: [TextDocumentContentChangeEvent { range: Some(Range { start: Position { line: 7, character: 15 }, end: Position { line: 7, character: 15 } }), range_length: Some(0), text: " " }] }} -// └─┐pgt_workspace::workspace::server::change_file{path="/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", version=8} -// ├─2025-06-02 9:47:00.363926 0ms DEBUG pgt_workspace::workspace::server::parsed_document Modifying statement with id Root(RootId { inner: 18 }) (new id Root(RootId { inner: 19 })). Range 15..15, Changed from '"CREATE INDEX IFidx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"' to '"CREATE INDEX IF idx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"', changed text: " " -// ┌─┘ -// ├─2025-06-02 9:47:00.364897 1ms INFO pgt_workspace::workspace::server Pulled 1 diagnostic(s) -// ┌─┘ -// └─┐pgt_lsp::handlers::completions::get_completions{params=CompletionParams { text_document_position: TextDocumentPositionParams { text_document: TextDocumentIdentifier { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", query: None, fragment: None } }, position: Position { line: 7, character: 16 } }, work_done_progress_params: WorkDoneProgressParams { work_done_token: None }, partial_result_params: PartialResultParams { partial_result_token: None }, context: Some(CompletionContext { trigger_kind: TriggerCharacter, trigger_character: Some(" ") }) }} -// └─┐pgt_workspace::workspace::server::get_completions{path="/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", position="216"} -// └─┐pgt_completions::complete::complete{text="CREATE INDEX IF idx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);", position="16"} -// ┌─┘ -// ├─2025-06-02 9:47:00.405793 40ms DEBUG pgt_workspace::workspace::server Found 0 completion items for statement with id 19 -// ┌─┘ -// ┌─┘ -// └─┐pgt_lsp::handlers::text_document::did_change{params=DidChangeTextDocumentParams { text_document: VersionedTextDocumentIdentifier { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", query: None, fragment: None }, version: 9 }, content_changes: [TextDocumentContentChangeEvent { range: Some(Range { start: Position { line: 7, character: 16 }, end: Position { line: 7, character: 16 } }), range_length: Some(0), text: "N" }] }} -// └─┐pgt_workspace::workspace::server::change_file{path="/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", version=9} -// ├─2025-06-02 9:47:00.418329 0ms DEBUG pgt_workspace::workspace::server::parsed_document Modifying statement with id Root(RootId { inner: 19 }) (new id Root(RootId { inner: 20 })). Range 16..16, Changed from '"CREATE INDEX IF idx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"' to '"CREATE INDEX IF Nidx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"', changed text: "N" -// ┌─┘ -// ├─2025-06-02 9:47:00.41892 1ms INFO pgt_workspace::workspace::server Pulled 1 diagnostic(s) -// ┌─┘ -// └─┐pgt_lsp::handlers::completions::get_completions{params=CompletionParams { text_document_position: TextDocumentPositionParams { text_document: TextDocumentIdentifier { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", query: None, fragment: None } }, position: Position { line: 7, character: 17 } }, work_done_progress_params: WorkDoneProgressParams { work_done_token: None }, partial_result_params: PartialResultParams { partial_result_token: None }, context: Some(CompletionContext { trigger_kind: Invoked, trigger_character: None }) }} -// └─┐pgt_workspace::workspace::server::get_completions{path="/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", position="217"} -// └─┐pgt_completions::complete::complete{text="CREATE INDEX IF Nidx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);", position="17"} -// ┌─┘ -// ├─2025-06-02 9:47:00.448103 28ms DEBUG pgt_workspace::workspace::server Found 0 completion items for statement with id 20 -// ┌─┘ -// ┌─┘ -// └─┐pgt_lsp::handlers::text_document::did_change{params=DidChangeTextDocumentParams { text_document: VersionedTextDocumentIdentifier { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", query: None, fragment: None }, version: 10 }, content_changes: [TextDocumentContentChangeEvent { range: Some(Range { start: Position { line: 7, character: 17 }, end: Position { line: 7, character: 17 } }), range_length: Some(0), text: "O" }] }} -// └─┐pgt_workspace::workspace::server::change_file{path="/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", version=10} -// ├─2025-06-02 9:47:00.588574 0ms DEBUG pgt_workspace::workspace::server::parsed_document Modifying statement with id Root(RootId { inner: 20 }) (new id Root(RootId { inner: 21 })). Range 17..17, Changed from '"CREATE INDEX IF Nidx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"' to '"CREATE INDEX IF NOidx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"', changed text: "O" -// ┌─┘ -// ├─2025-06-02 9:47:00.589522 1ms INFO pgt_workspace::workspace::server Pulled 1 diagnostic(s) -// ┌─┘ -// └─┐pgt_lsp::handlers::text_document::did_change{params=DidChangeTextDocumentParams { text_document: VersionedTextDocumentIdentifier { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", query: None, fragment: None }, version: 11 }, content_changes: [TextDocumentContentChangeEvent { range: Some(Range { start: Position { line: 7, character: 18 }, end: Position { line: 7, character: 18 } }), range_length: Some(0), text: "T" }] }} -// └─┐pgt_workspace::workspace::server::change_file{path="/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", version=11} -// ├─2025-06-02 9:47:00.721041 0ms DEBUG pgt_workspace::workspace::server::parsed_document Modifying statement with id Root(RootId { inner: 21 }) (new id Root(RootId { inner: 22 })). Range 18..18, Changed from '"CREATE INDEX IF NOidx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"' to '"CREATE INDEX IF NOTidx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"', changed text: "T" -// ┌─┘ -// ├─2025-06-02 9:47:00.722806 2ms INFO pgt_workspace::workspace::server Pulled 1 diagnostic(s) -// ┌─┘ -// └─┐pgt_lsp::handlers::text_document::did_change{params=DidChangeTextDocumentParams { text_document: VersionedTextDocumentIdentifier { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", query: None, fragment: None }, version: 12 }, content_changes: [TextDocumentContentChangeEvent { range: Some(Range { start: Position { line: 7, character: 19 }, end: Position { line: 7, character: 19 } }), range_length: Some(0), text: " " }] }} -// └─┐pgt_workspace::workspace::server::change_file{path="/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", version=12} -// ├─2025-06-02 9:47:00.724899 0ms DEBUG pgt_workspace::workspace::server::parsed_document Modifying statement with id Root(RootId { inner: 22 }) (new id Root(RootId { inner: 23 })). Range 19..19, Changed from '"CREATE INDEX IF NOTidx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"' to '"CREATE INDEX IF NOT idx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"', changed text: " " -// ┌─┘ -// ├─2025-06-02 9:47:00.725877 1ms INFO pgt_workspace::workspace::server Pulled 1 diagnostic(s) -// ┌─┘ -// └─┐pgt_lsp::handlers::completions::get_completions{params=CompletionParams { text_document_position: TextDocumentPositionParams { text_document: TextDocumentIdentifier { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", query: None, fragment: None } }, position: Position { line: 7, character: 20 } }, work_done_progress_params: WorkDoneProgressParams { work_done_token: None }, partial_result_params: PartialResultParams { partial_result_token: None }, context: Some(CompletionContext { trigger_kind: TriggerCharacter, trigger_character: Some(" ") }) }} -// └─┐pgt_workspace::workspace::server::get_completions{path="/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", position="220"} -// └─┐pgt_completions::complete::complete{text="CREATE INDEX IF NOT idx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);", position="20"} -// ┌─┘ -// ├─2025-06-02 9:47:00.776552 50ms DEBUG pgt_workspace::workspace::server Found 0 completion items for statement with id 23 -// ┌─┘ -// ┌─┘ -// └─┐pgt_lsp::handlers::text_document::did_change{params=DidChangeTextDocumentParams { text_document: VersionedTextDocumentIdentifier { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", query: None, fragment: None }, version: 13 }, content_changes: [TextDocumentContentChangeEvent { range: Some(Range { start: Position { line: 7, character: 20 }, end: Position { line: 7, character: 20 } }), range_length: Some(0), text: "E" }] }} -// └─┐pgt_workspace::workspace::server::change_file{path="/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", version=13} -// ├─2025-06-02 9:47:00.813959 0ms DEBUG pgt_workspace::workspace::server::parsed_document Modifying statement with id Root(RootId { inner: 23 }) (new id Root(RootId { inner: 24 })). Range 20..20, Changed from '"CREATE INDEX IF NOT idx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"' to '"CREATE INDEX IF NOT Eidx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"', changed text: "E" -// ┌─┘ -// ├─2025-06-02 9:47:00.814674 1ms INFO pgt_workspace::workspace::server Pulled 1 diagnostic(s) -// ┌─┘ -// └─┐pgt_lsp::handlers::completions::get_completions{params=CompletionParams { text_document_position: TextDocumentPositionParams { text_document: TextDocumentIdentifier { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", query: None, fragment: None } }, position: Position { line: 7, character: 21 } }, work_done_progress_params: WorkDoneProgressParams { work_done_token: None }, partial_result_params: PartialResultParams { partial_result_token: None }, context: Some(CompletionContext { trigger_kind: Invoked, trigger_character: None }) }} -// └─┐pgt_workspace::workspace::server::get_completions{path="/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", position="221"} -// └─┐pgt_completions::complete::complete{text="CREATE INDEX IF NOT Eidx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);", position="21"} -// ┌─┘ -// ├─2025-06-02 9:47:00.848701 33ms DEBUG pgt_workspace::workspace::server Found 0 completion items for statement with id 24 -// ┌─┘ -// ┌─┘ -// └─┐pgt_lsp::handlers::text_document::did_change{params=DidChangeTextDocumentParams { text_document: VersionedTextDocumentIdentifier { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", query: None, fragment: None }, version: 14 }, content_changes: [TextDocumentContentChangeEvent { range: Some(Range { start: Position { line: 7, character: 21 }, end: Position { line: 7, character: 21 } }), range_length: Some(0), text: "X" }] }} -// └─┐pgt_workspace::workspace::server::change_file{path="/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", version=14} -// ├─2025-06-02 9:47:01.051286 0ms DEBUG pgt_workspace::workspace::server::parsed_document Modifying statement with id Root(RootId { inner: 24 }) (new id Root(RootId { inner: 25 })). Range 21..21, Changed from '"CREATE INDEX IF NOT Eidx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"' to '"CREATE INDEX IF NOT EXidx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"', changed text: "X" -// ┌─┘ -// ├─2025-06-02 9:47:01.052446 2ms INFO pgt_workspace::workspace::server Pulled 1 diagnostic(s) -// ┌─┘ -// └─┐pgt_lsp::handlers::text_document::did_change{params=DidChangeTextDocumentParams { text_document: VersionedTextDocumentIdentifier { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", query: None, fragment: None }, version: 15 }, content_changes: [TextDocumentContentChangeEvent { range: Some(Range { start: Position { line: 7, character: 22 }, end: Position { line: 7, character: 22 } }), range_length: Some(0), text: "I" }] }} -// └─┐pgt_workspace::workspace::server::change_file{path="/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", version=15} -// ├─2025-06-02 9:47:01.201943 1ms DEBUG pgt_workspace::workspace::server::parsed_document Modifying statement with id Root(RootId { inner: 25 }) (new id Root(RootId { inner: 26 })). Range 22..22, Changed from '"CREATE INDEX IF NOT EXidx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"' to '"CREATE INDEX IF NOT EXIidx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"', changed text: "I" -// ┌─┘ -// ├─2025-06-02 9:47:01.203949 3ms INFO pgt_workspace::workspace::server Pulled 1 diagnostic(s) -// ┌─┘ -// └─┐pgt_lsp::handlers::text_document::did_change{params=DidChangeTextDocumentParams { text_document: VersionedTextDocumentIdentifier { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", query: None, fragment: None }, version: 16 }, content_changes: [TextDocumentContentChangeEvent { range: Some(Range { start: Position { line: 7, character: 23 }, end: Position { line: 7, character: 23 } }), range_length: Some(0), text: "S" }] }} -// └─┐pgt_workspace::workspace::server::change_file{path="/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", version=16} -// ├─2025-06-02 9:47:01.310226 0ms DEBUG pgt_workspace::workspace::server::parsed_document Modifying statement with id Root(RootId { inner: 26 }) (new id Root(RootId { inner: 27 })). Range 23..23, Changed from '"CREATE INDEX IF NOT EXIidx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"' to '"CREATE INDEX IF NOT EXISidx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"', changed text: "S" -// ┌─┘ -// ├─2025-06-02 9:47:01.311452 2ms INFO pgt_workspace::workspace::server Pulled 1 diagnostic(s) -// ┌─┘ -// └─┐pgt_lsp::handlers::text_document::did_change{params=DidChangeTextDocumentParams { text_document: VersionedTextDocumentIdentifier { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", query: None, fragment: None }, version: 17 }, content_changes: [TextDocumentContentChangeEvent { range: Some(Range { start: Position { line: 7, character: 24 }, end: Position { line: 7, character: 24 } }), range_length: Some(0), text: "T" }] }} -// └─┐pgt_workspace::workspace::server::change_file{path="/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", version=17} -// ├─2025-06-02 9:47:01.391161 1ms DEBUG pgt_workspace::workspace::server::parsed_document Modifying statement with id Root(RootId { inner: 27 }) (new id Root(RootId { inner: 28 })). Range 24..24, Changed from '"CREATE INDEX IF NOT EXISidx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"' to '"CREATE INDEX IF NOT EXISTidx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"', changed text: "T" -// ┌─┘ -// ├─2025-06-02 9:47:01.393041 3ms INFO pgt_workspace::workspace::server Pulled 1 diagnostic(s) -// ┌─┘ -// └─┐pgt_lsp::handlers::text_document::did_change{params=DidChangeTextDocumentParams { text_document: VersionedTextDocumentIdentifier { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", query: None, fragment: None }, version: 19 }, content_changes: [TextDocumentContentChangeEvent { range: Some(Range { start: Position { line: 7, character: 25 }, end: Position { line: 7, character: 25 } }), range_length: Some(0), text: "S" }, TextDocumentContentChangeEvent { range: Some(Range { start: Position { line: 7, character: 26 }, end: Position { line: 7, character: 26 } }), range_length: Some(0), text: " " }] }} -// └─┐pgt_workspace::workspace::server::change_file{path="/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", version=19} -// ├─2025-06-02 9:47:01.480581 0ms DEBUG pgt_workspace::workspace::server::parsed_document Modifying statement with id Root(RootId { inner: 28 }) (new id Root(RootId { inner: 29 })). Range 25..25, Changed from '"CREATE INDEX IF NOT EXISTidx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"' to '"CREATE INDEX IF NOT EXISTSidx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"', changed text: "S" -// ├─2025-06-02 9:47:01.480915 1ms DEBUG pgt_workspace::workspace::server::parsed_document Modifying statement with id Root(RootId { inner: 29 }) (new id Root(RootId { inner: 30 })). Range 27..27, Changed from '"CREATE INDEX IF NOT EXISTSidx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"' to '"CREATE INDEX IF NOT EXISTSi dx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);"', changed text: " " -// ┌─┘ -// ├─2025-06-02 9:47:01.481901 2ms INFO pgt_workspace::workspace::server Pulled 1 diagnostic(s) -// ┌─┘ -// └─┐pgt_lsp::handlers::completions::get_completions{params=CompletionParams { text_document_position: TextDocumentPositionParams { text_document: TextDocumentIdentifier { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", query: None, fragment: None } }, position: Position { line: 7, character: 27 } }, work_done_progress_params: WorkDoneProgressParams { work_done_token: None }, partial_result_params: PartialResultParams { partial_result_token: None }, context: Some(CompletionContext { trigger_kind: TriggerCharacter, trigger_character: Some(" ") }) }} -// └─┐pgt_workspace::workspace::server::get_completions{path="/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", position="227"} -// └─┐pgt_completions::complete::complete{text="CREATE INDEX IF NOT EXISTSi dx_appointment_custom_field_string_value_btree ON public.appointment_custom_field USING btree (custom_field_id, appointment_id, string_value) WHERE (type = 'string'::field_type);", position="27"} -// ┌─┘ -// ├─2025-06-02 9:47:01.530715 48ms DEBUG pgt_workspace::workspace::server Found 0 completion items for statement with id 30 -// ┌─┘ -// ┌─┘ -// └─┐pgt_lsp::handlers::text_document::did_change{params=DidChangeTextDocumentParams { text_document: VersionedTextDocumentIdentifier { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", query: None, fragment: None }, version: 20 }, content_changes: [TextDocumentContentChangeEvent { range: Some(Range { start: Position { line: 9, character: 13 }, end: Position { line: 9, character: 13 } }), range_length: Some(0), text: "IF NOT EXISTS " }] }} -// └─┐pgt_workspace::workspace::server::change_file{path="/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", version=20} -// ├─2025-06-02 9:47:08.691711 1ms DEBUG pgt_workspace::workspace::server::parsed_document Modifying statement with id Root(RootId { inner: 7 }) (new id Root(RootId { inner: 31 })). Range 13..13, Changed from '"CREATE INDEX idx_contact_custom_field_string_value_btree ON public.contact_custom_field USING btree (custom_field_id, contact_id, string_value) WHERE (type = 'string'::field_type);"' to '"CREATE INDEX IF NOT EXISTS idx_contact_custom_field_string_value_btree ON public.contact_custom_field USING btree (custom_field_id, contact_id, string_value) WHERE (type = 'string'::field_type);"', changed text: "IF NOT EXISTS " -// ┌─┘ -// ├─2025-06-02 9:47:08.693581 3ms INFO pgt_workspace::workspace::server Pulled 1 diagnostic(s) -// ┌─┘ -// └─┐pgt_lsp::handlers::text_document::did_change{params=DidChangeTextDocumentParams { text_document: VersionedTextDocumentIdentifier { uri: Url { scheme: "file", cannot_be_a_base: false, username: "", password: None, host: None, port: None, path: "/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", query: None, fragment: None }, version: 21 }, content_changes: [TextDocumentContentChangeEvent { range: Some(Range { start: Position { line: 11, character: 13 }, end: Position { line: 11, character: 13 } }), range_length: Some(0), text: "IF NOT EXISTS " }] }} -// └─┐pgt_workspace::workspace::server::change_file{path="/Users/psteinroe/Developer/hellomateo/supabase/migrations/20250423142692_better_cf_indices.sql", version=21} -// ├─2025-06-02 9:47:10.683595 0ms DEBUG pgt_workspace::workspace::server::parsed_document Modifying statement with id Root(RootId { inner: 16 }) (new id Root(RootId { inner: 32 })). Range 13..13, Changed from '"CREATE INDEX idx_deal_custom_field_string_value_btree ON public.deal_custom_field USING btree (custom_field_id, deal_id, string_value) WHERE (type = 'string'::field_type);"' to '"CREATE INDEX IF NOT EXISTS idx_deal_custom_field_string_value_btree ON public.deal_custom_field USING btree (custom_field_id, deal_id, string_value) WHERE (type = 'string'::field_type);"', changed text: "IF NOT EXISTS " From f850f6b5e37698d810bd31f3dca1cedce22ac275 Mon Sep 17 00:00:00 2001 From: psteinroe Date: Tue, 10 Jun 2025 08:03:54 +0200 Subject: [PATCH 5/5] fix: test --- .../src/workspace/server/change.rs | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/crates/pgt_workspace/src/workspace/server/change.rs b/crates/pgt_workspace/src/workspace/server/change.rs index 5c31a596..cdd5a569 100644 --- a/crates/pgt_workspace/src/workspace/server/change.rs +++ b/crates/pgt_workspace/src/workspace/server/change.rs @@ -1570,28 +1570,29 @@ mod tests { fn multiple_deletions_at_once() { let path = PgTPath::new("test.sql"); - let mut doc = Document::new("\n\n\n\nALTER TABLE ONLY \"public\".\"sendout\"\n ADD CONSTRAINT \"sendout_organisation_id_fkey\" FOREIGN -KEY (\"organisation_id\") REFERENCES \"public\".\"organisation\"(\"id\") ON UPDATE RESTRICT ON DELETE CASCADE;\n".to_string(), 0); + let mut doc = Document::new("ALTER TABLE ONLY public.omni_channel_message ADD CONSTRAINT omni_channel_message_organisation_id_fkey FOREIGN KEY (organisation_id) REFERENCES public.organisation(id) ON UPDATE RESTRICT ON DELETE CASCADE;".to_string(), 0); let change = ChangeFileParams { path: path.clone(), version: 1, changes: vec![ ChangeParams { - range: Some(TextRange::new(31.into(), 38.into())), - text: "te".to_string(), + range: Some(TextRange::new(60.into(), 80.into())), + text: "sendout".to_string(), }, ChangeParams { - range: Some(TextRange::new(60.into(), 67.into())), - text: "te".to_string(), + range: Some(TextRange::new(24.into(), 44.into())), + text: "sendout".to_string(), }, ], }; let changed = doc.apply_file_change(&change); - assert_eq!(doc.content, "\n\n\n\nALTER TABLE ONLY \"public\".\"te\"\n ADD CONSTRAINT \"te_organisation_id_fkey\" FOREIGN -KEY (\"organisation_id\") REFERENCES \"public\".\"organisation\"(\"id\") ON UPDATE RESTRICT ON DELETE CASCADE;\n"); + assert_eq!( + doc.content, + "ALTER TABLE ONLY public.sendout ADD CONSTRAINT sendout_organisation_id_fkey FOREIGN KEY (organisation_id) REFERENCES public.organisation(id) ON UPDATE RESTRICT ON DELETE CASCADE;" + ); assert_eq!(changed.len(), 2); @@ -1602,19 +1603,18 @@ KEY (\"organisation_id\") REFERENCES \"public\".\"organisation\"(\"id\") ON UPDA fn multiple_additions_at_once() { let path = PgTPath::new("test.sql"); - let mut doc = Document::new("\n\n\n\nALTER TABLE ONLY \"public\".\"sendout\"\n ADD CONSTRAINT \"sendout_organisation_id_fkey\" FOREIGN -KEY (\"organisation_id\") REFERENCES \"public\".\"organisation\"(\"id\") ON UPDATE RESTRICT ON DELETE CASCADE;\n".to_string(), 0); + let mut doc = Document::new("ALTER TABLE ONLY public.sendout ADD CONSTRAINT sendout_organisation_id_fkey FOREIGN KEY (organisation_id) REFERENCES public.organisation(id) ON UPDATE RESTRICT ON DELETE CASCADE;".to_string(), 0); let change = ChangeFileParams { path: path.clone(), version: 1, changes: vec![ ChangeParams { - range: Some(TextRange::new(31.into(), 38.into())), + range: Some(TextRange::new(47.into(), 54.into())), text: "omni_channel_message".to_string(), }, ChangeParams { - range: Some(TextRange::new(60.into(), 67.into())), + range: Some(TextRange::new(24.into(), 31.into())), text: "omni_channel_message".to_string(), }, ], @@ -1622,8 +1622,10 @@ KEY (\"organisation_id\") REFERENCES \"public\".\"organisation\"(\"id\") ON UPDA let changed = doc.apply_file_change(&change); - assert_eq!(doc.content, "\n\n\n\nALTER TABLE ONLY \"public\".\"omni_channel_message\"\n ADD CONSTRAINT \"omni_channel_message_organisation_id_fkey\" FOREIGN -KEY (\"organisation_id\") REFERENCES \"public\".\"organisation\"(\"id\") ON UPDATE RESTRICT ON DELETE CASCADE;\n"); + assert_eq!( + doc.content, + "ALTER TABLE ONLY public.omni_channel_message ADD CONSTRAINT omni_channel_message_organisation_id_fkey FOREIGN KEY (organisation_id) REFERENCES public.organisation(id) ON UPDATE RESTRICT ON DELETE CASCADE;" + ); assert_eq!(changed.len(), 2);