Skip to content

refactor(pg_lsp): use tokio, partially remove crossbeam channels #143

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

Closed

Conversation

juleswritescode
Copy link
Collaborator

@juleswritescode juleswritescode commented Oct 13, 2024

This PR introduces tokio into the pg_lsp crate and tries to remove the crossbeam dependency from the LspServer.

  • All separate tasks are now spawned with tokio
  • All separate tasks listen for a cancel_token that allows us to shut down the server without dangling tasks
  • The database connection now lives in its own file
  • The ClientFlags now live in its own file
  • I refactored the setup logic a bit, for example, the InitializeRequest flow now lives in its own function
  • I split up the internal message loop into process_messages, handle_message and handle_internal_message
  • Schema Updates & DbConnectionResets are now done via channels & internal messages
  • and, last but not least, I added a tiny client.send_info_message helper. 🤓

Next steps:

  • replace the lsp_types with tower_lsp, which should work better with tokio
  • if possible, use tokio with both the LspClient and the EventDebouncer (haven't looked into that yet)
  • migrate the lsp-server to an architecture that uses daemons, such as biome's

Looking forward to your feedback!

@@ -8,7 +8,6 @@ use super::buffer::{EventBuffer, Get, State};
struct DebouncerThread<B> {
mutex: Arc<Mutex<B>>,
thread: JoinHandle<()>,
stopped: Arc<AtomicBool>,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the linter marked all of this as unused

let cloned_tx = internal_tx.clone();
let cloned_ide = ide.clone();
let cloned_pool = pool.clone();
let pool = Arc::new(threadpool::Builder::new().build());
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I didn't dare touch the EventDebouncer yet 🙈

@juleswritescode juleswritescode marked this pull request as ready for review October 18, 2024 10:36
@juleswritescode juleswritescode changed the title refactor: tokio main, isolate crossbeam channels refactor(pg_lsp): use tokio, partially remove crossbeam channels Oct 18, 2024
@juleswritescode
Copy link
Collaborator Author

Closed becausing switching to tower_lsp was the better approach 👍

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.

1 participant