-
-
Notifications
You must be signed in to change notification settings - Fork 501
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
refactor: foundations for LSP workspaces support #2589
Conversation
CodSpeed Performance ReportMerging #2589 will create unknown performance changesComparing Summary
Benchmarks breakdown
|
/// Retrieves the settings of the organize imports | ||
pub fn organize_imports(&self) -> &OrganizeImportsSettings { | ||
&self.organize_imports | ||
pub fn get_settings_by_path(&self, path: &BiomePath) -> &Settings { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So these two get_settings_by_path
methods seem to be the only places where we iterate over the paths, and I don't the methods being used anywhere. Do we anticipate that they will be commonly used going forward?
I'm asking because the DenseSlotMap
was chosen because of fast iteration, but at least as of yet we don't do any iteration yet. Based on the current state that would not make it a good choice, but that could change if these methods become the most commonly used ones in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remove two functions and kept only one: get_settings_by_path
.
As mentioned in the description, in the LSP there's way to retrieve the current project when handling a file. When the LSP sends us the request textDocument/didOpen
, we only get its absolute URL.
In order to understand if a user opened a file that belongs to a different project from the previous, we need to inspect its path, and that's where the iteration will come into play.
If you come up with a better solution by the time I will open the next PR, that would be awesome.
9375835
to
e876fc0
Compare
e876fc0
to
6e1ae1f
Compare
6e1ae1f
to
830f8d8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
ae8a723
to
dccb988
Compare
Summary
Related to #1573
This refactoring doesn't change any logic, but it does some internal refactoring to prepare the LSP to support multiple workspaces.
I created some data structures to help to query/mutate the workspaces.
To save the workspaces data, I used
slotmap::DenseSlotmap
. You can read more in the documentation.The good about
slotmap
is that it emits a unique key every time we insert something; that key can be used later on to access the stored data. Those keys are always unique. Also, upon deletion, the slot that was used stays free, and it gets reused when a new element is inserted.I chose
DenseSlotmap
because it's the fastest during iteration and slowest upon insertion. Inserting workspace folders will be a one-time operation or a rare operation. How many times does a user add a new project to a workspace? However, choosing the correct workspace will be an operation that we will have to do often. The LSP isn't able to signal if a file belongs to a certain workspace, so we have to guess it based on its path.Test Plan
The current tests should pass