Skip to content

refactor: drop change.rs <3 #447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jul 12, 2025
Merged

refactor: drop change.rs <3 #447

merged 10 commits into from
Jul 12, 2025

Conversation

psteinroe
Copy link
Collaborator

@psteinroe psteinroe commented Jul 11, 2025

patrick-zen png

as per PR title. notable changes:

  • drop change.rs in favour of a simple update_document api that replaces the content
  • simplify StatementId to just be a simple wrapper around the actual statement string. The content is wrapped in an Arc<str> to make cloning cheap. turns out string interning only makes sense when we have a lot of duplicate strings. Arc<str> is much more efficient and simpler in our case.
  • Remove document.rs and merge it into parsed_document to then rename it to Document
  • replaces the strum usage to get the available command because it didn't feel right to make an empty string the default for a StatementId. replaced it with a simple manual implementation.

I ran a few benchmarks and the statement splitter performance seems to be good enough to run it on every keystroke on the entire file.

large statement with length 863000                                                                            
                        time:   [23.180 ms 23.278 ms 23.386 ms]

small statement with length 19000                                                                            
                        time:   [886.69 µs 890.91 µs 896.35 µs]

ToDo

  • add some tests
  • cleanup

@psteinroe psteinroe marked this pull request as ready for review July 12, 2025 12:00
Copy link
Collaborator

@juleswritescode juleswritescode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very nice! much simpler, and I love that there's no separate ParsedDocument anymore :)

Comment on lines 37 to 42
/// Creates a child statement ID with the given content and parent content.
pub fn new_child(child_content: &str, parent_content: &str) -> Self {
StatementId::Child {
content: child_content.into(),
parent_content: parent_content.into(),
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this used/needed? feels like we could create orphaned childs with this – not a problem right now, but maybe leads to confusion in the future?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, thanks!

}
}

pub fn parent(&self) -> Option<StatementId> {
pub fn content(&self) -> &str {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

love it

@@ -641,9 +637,9 @@ impl Workspace for WorkspaceServer {
});

tracing::debug!(
"Found {} completion items for statement with id {}",
"Found {} completion items for statement with id {:?}",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's probably a lot of log output – not sure we even need the print

/// Instead, we manually list the command IDs we want to register.
fn available_command_ids() -> Vec<String> {
vec![
"postgres-tools.executeStatement".to_string(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ID in pgt_lsp/src/handlers/code_actions.rs also needs to be adjusted 👍

Copy link
Collaborator

@juleswritescode juleswritescode Jul 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, we're now just sending the full statement over to the client anyway, so we might as well change the CommandActionCategory::ExecuteStatement(_) to hold a String instead of a StatementId – I think you can then use strum again :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah good point!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverted my changes. I think its simpler to just add a comment to the default implementation

@psteinroe psteinroe merged commit 27b6e7f into main Jul 12, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants