Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

refactor(rome_lsp): refactor the initialization and configuration loading logic #4044

Merged
merged 2 commits into from
Dec 13, 2022

Conversation

leops
Copy link
Contributor

@leops leops commented Dec 12, 2022

Summary

This PR refactors the initialization and configuration loading logic of the language server Session to limit the use of Mutex and RwLock:

  • The client_capabilities, client_information and root_uri fields are only written to when the session is initialized, with all following access being read-only. I've moved these fields to a new InitializeParams struct stored in a OnceCell container (I'm using the implementation from tokio to avoid having to pull in another crate until std::sync::OnceLock is stabilized) that should provide a similar "write-once read-many" synchronization primitive at a lower performance and memory cost than Mutex or RwLock.
  • The workspace configuration used to be loaded in update_configuration but applied to the workspace in update_workspace_settings, requiring it to be stored in an RwLock in the meantime. I've separated the logic for loading the configuration into load_workspace_settings (load the rome.json file and apply it to the workspace) and load_client_configuration (load the editor configuration and store it in the session config) to eliminate the need for an intermediate storage.

In addition to these changes, I also added or modified some of the tracing logs related to initialization and configuration loading to help us debug potential issues using the output of rome rage

Test Plan

This is intended as an internal change only, it should not modify the observable behavior of the language server. In particular the rome_lsp test suite should continue to pass, as well as the rome_cli tests that make use of the daemon service infrastructure.

@netlify
Copy link

netlify bot commented Dec 12, 2022

Deploy Preview for docs-rometools ready!

Name Link
🔨 Latest commit 85963da
🔍 Latest deploy log https://app.netlify.com/sites/docs-rometools/deploys/639853ab4915db0008b4a001
😎 Deploy Preview https://deploy-preview-4044--docs-rometools.netlify.app/playground
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

if let Some(uri) = params.root_uri {
self.session.root_uri.write().unwrap().replace(uri);
if params.root_path.is_some() {
warn!("The Rome Server was initialized with the deprecated `root_path` parameter: this is not supported, use `root_uri` instead");
Copy link
Contributor

Choose a reason for hiding this comment

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

Out of curiosity, who sends root_path? A client that still uses an old version of the LSP?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From the LSP specification, rootPath was deprecated in version 3.0 of the protocol in favor of rootUri. The rootUri field was later deprecated in version 3.16 in favor of workspaceFolders, but we don't support that yet

crates/rome_lsp/src/session.rs Show resolved Hide resolved
let client_configurations = match self.client.configuration(vec![item]).await {
Ok(client_configurations) => client_configurations,
Err(err) => {
error!("Cannot read configuration from the client: {err}");
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I suggest normalizing the use of the verbs: some messages use "Couldn't" and other messages use "Cannot"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I normalized the error messages to use the past tense, that seems to be what we use the most

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants