Skip to content

Commit 1502679

Browse files
committed
progress
1 parent 4c598cb commit 1502679

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

crates/pgt_lsp/tests/server.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
use anyhow::bail;
21
use anyhow::Context;
32
use anyhow::Error;
43
use anyhow::Result;
4+
use anyhow::bail;
55
use biome_deserialize::Merge;
66
use biome_deserialize::StringSet;
7-
use futures::channel::mpsc::{channel, Sender};
87
use futures::Sink;
98
use futures::SinkExt;
109
use futures::Stream;
1110
use futures::StreamExt;
12-
use pgt_configuration::database::PartialDatabaseConfiguration;
11+
use futures::channel::mpsc::{Sender, channel};
1312
use pgt_configuration::PartialConfiguration;
13+
use pgt_configuration::database::PartialDatabaseConfiguration;
1414
use pgt_fs::MemoryFileSystem;
1515
use pgt_lsp::LSPServer;
1616
use pgt_lsp::ServerFactory;
1717
use pgt_workspace::DynRef;
18-
use serde::de::DeserializeOwned;
1918
use serde::Serialize;
19+
use serde::de::DeserializeOwned;
2020
use serde_json::Value;
2121
use serde_json::{from_value, to_value};
2222
use sqlx::Executor;
@@ -26,6 +26,7 @@ use std::fmt::Display;
2626
use std::time::Duration;
2727
use tower::timeout::Timeout;
2828
use tower::{Service, ServiceExt};
29+
use tower_lsp::LspService;
2930
use tower_lsp::jsonrpc;
3031
use tower_lsp::jsonrpc::Response;
3132
use tower_lsp::lsp_types as lsp;
@@ -47,7 +48,6 @@ use tower_lsp::lsp_types::{
4748
PublishDiagnosticsParams, TextDocumentContentChangeEvent, TextDocumentIdentifier,
4849
TextDocumentItem, Url, VersionedTextDocumentIdentifier,
4950
};
50-
use tower_lsp::LspService;
5151
use tower_lsp::{jsonrpc::Request, lsp_types::InitializeParams};
5252

5353
/// Statically build an [Url] instance that points to the file at `$path`

crates/pgt_workspace/src/workspace/server/change.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ impl Document {
6363
// very much not guaranteed to result in correct ranges
6464
self.diagnostics.clear();
6565

66+
tracing::debug!("Changing from {:?}", self.content);
67+
tracing::debug!("Applying changes {:?}", &change.changes);
68+
6669
// when we recieive more than one change, we need to push back the changes based on the
6770
// total range of the previous ones. This is because the ranges are always related to the original state.
6871
let mut changes = Vec::new();
@@ -93,6 +96,9 @@ impl Document {
9396

9497
self.version = change.version;
9598

99+
tracing::debug!("Applied changes {:?}", changes);
100+
tracing::debug!("Changed to {:?}", self.content);
101+
96102
changes
97103
}
98104

@@ -1663,6 +1669,40 @@ KEY (\"organisation_id\") REFERENCES \"public\".\"organisation\"(\"id\") ON UPDA
16631669
assert_document_integrity(&doc);
16641670
}
16651671

1672+
#[test]
1673+
fn test_content_out_of_sync() {
1674+
let path = PgTPath::new("test.sql");
1675+
let initial_content = "select 1, 2, 2232231313393319 from unknown_users;\n";
1676+
1677+
let mut doc = Document::new(initial_content.to_string(), 0);
1678+
1679+
let change1 = ChangeFileParams {
1680+
path: path.clone(),
1681+
version: 1,
1682+
changes: vec![
1683+
ChangeParams {
1684+
range: Some(TextRange::new(29.into(), 29.into())),
1685+
text: "3".to_string(),
1686+
},
1687+
ChangeParams {
1688+
range: Some(TextRange::new(30.into(), 30.into())),
1689+
text: "1".to_string(),
1690+
},
1691+
],
1692+
};
1693+
1694+
let changes = doc.apply_file_change(&change1);
1695+
1696+
println!("changes: {:#?}", changes);
1697+
1698+
assert_eq!(
1699+
doc.content,
1700+
"select 1, 2, 22322313133933193 from unknown_users;\n"
1701+
);
1702+
1703+
assert_document_integrity(&doc);
1704+
}
1705+
16661706
#[test]
16671707
fn test_comments_only() {
16681708
let path = PgTPath::new("test.sql");

0 commit comments

Comments
 (0)