Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: supabase-community/postgres-language-server
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: supabase-community/postgres-language-server
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: refs/heads/fix/crash-303
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 3 commits
  • 3 files changed
  • 1 contributor

Commits on Apr 4, 2025

  1. fix: make sure range is correct for eof deletions

    psteinroe committed Apr 4, 2025
    Copy the full SHA
    4d0d075 View commit details
  2. fix: cleanup

    psteinroe committed Apr 4, 2025
    Copy the full SHA
    15f3df6 View commit details
  3. fix: lint-fix

    psteinroe committed Apr 4, 2025
    Copy the full SHA
    e258bea View commit details
Showing with 143 additions and 9 deletions.
  1. +131 −0 crates/pgt_lsp/tests/server.rs
  2. +8 −8 crates/pgt_workspace/src/settings.rs
  3. +4 −1 crates/pgt_workspace/src/workspace/server/change.rs
131 changes: 131 additions & 0 deletions crates/pgt_lsp/tests/server.rs
Original file line number Diff line number Diff line change
@@ -981,3 +981,134 @@ async fn test_issue_281() -> Result<()> {

Ok(())
}

#[tokio::test]
async fn test_issue_303() -> Result<()> {
let factory = ServerFactory::default();
let mut fs = MemoryFileSystem::default();
let test_db = get_new_test_db().await;

let setup = r#"
create table public.users (
id serial primary key,
name varchar(255) not null
);
"#;

test_db
.execute(setup)
.await
.expect("Failed to setup test database");

let mut conf = PartialConfiguration::init();
conf.merge_with(PartialConfiguration {
db: Some(PartialDatabaseConfiguration {
database: Some(
test_db
.connect_options()
.get_database()
.unwrap()
.to_string(),
),
..Default::default()
}),
..Default::default()
});
fs.insert(
url!("postgrestools.jsonc").to_file_path().unwrap(),
serde_json::to_string_pretty(&conf).unwrap(),
);

let (service, client) = factory
.create_with_fs(None, DynRef::Owned(Box::new(fs)))
.into_inner();

let (stream, sink) = client.split();
let mut server = Server::new(service);

let (sender, _) = channel(CHANNEL_BUFFER_SIZE);
let reader = tokio::spawn(client_handler(stream, sink, sender));

server.initialize().await?;
server.initialized().await?;

server.load_configuration().await?;

server.open_document("").await?;

let chars = [
"c", "r", "e", "a", "t", "e", " ", "t", "a", "b", "l", "e", " ", "\"\"", "h", "e", "l",
"l", "o",
];
let mut version = 1;

for (i, c) in chars.iter().enumerate() {
version += 1;
server
.change_document(
version,
vec![TextDocumentContentChangeEvent {
range: Some(Range {
start: Position {
line: 0,
character: i as u32,
},
end: Position {
line: 0,
character: i as u32,
},
}),
range_length: Some(0),
text: c.to_string(),
}],
)
.await?;
}

version += 1;
server
.change_document(
version,
vec![TextDocumentContentChangeEvent {
range: Some(Range {
start: Position {
line: 0,
character: 20,
},
end: Position {
line: 0,
character: 20,
},
}),
range_length: Some(0),
text: " ".to_string(),
}],
)
.await?;

version += 1;
server
.change_document(
version,
vec![TextDocumentContentChangeEvent {
range: Some(Range {
start: Position {
line: 0,
character: 20,
},
end: Position {
line: 0,
character: 21,
},
}),
range_length: Some(0),
text: "".to_string(),
}],
)
.await?;

server.shutdown().await?;
reader.abort();

Ok(())
}
16 changes: 8 additions & 8 deletions crates/pgt_workspace/src/settings.rs
Original file line number Diff line number Diff line change
@@ -449,32 +449,32 @@ mod tests {
#[test]
fn should_identify_allowed_statement_executions() {
let partial_config = PartialDatabaseConfiguration {
allow_statement_executions_against: Some(StringSet::from_iter(
vec![String::from("localhost/*")].into_iter(),
)),
allow_statement_executions_against: Some(StringSet::from_iter(vec![String::from(
"localhost/*",
)])),
host: Some("localhost".into()),
database: Some("test-db".into()),
..Default::default()
};

let config = DatabaseSettings::from(partial_config);

assert_eq!(config.allow_statement_executions, true)
assert!(config.allow_statement_executions)
}

#[test]
fn should_identify_not_allowed_statement_executions() {
let partial_config = PartialDatabaseConfiguration {
allow_statement_executions_against: Some(StringSet::from_iter(
vec![String::from("localhost/*")].into_iter(),
)),
allow_statement_executions_against: Some(StringSet::from_iter(vec![String::from(
"localhost/*",
)])),
host: Some("production".into()),
database: Some("test-db".into()),
..Default::default()
};

let config = DatabaseSettings::from(partial_config);

assert_eq!(config.allow_statement_executions, false)
assert!(!config.allow_statement_executions)
}
}
5 changes: 4 additions & 1 deletion crates/pgt_workspace/src/workspace/server/change.rs
Original file line number Diff line number Diff line change
@@ -195,7 +195,10 @@ impl Document {
affected_indices,
prev_index,
next_index,
full_affected_range: TextRange::new(start_incl, end_incl.min(content_size)),
full_affected_range: TextRange::new(
start_incl,
end_incl.min(content_size).max(start_incl),
),
}
}