-
Notifications
You must be signed in to change notification settings - Fork 662
Conversation
✅ Deploy Preview for docs-rometools canceled.Built without sensitive environment variables
|
.documents | ||
.get(¶ms.path) | ||
.ok_or(WorkspaceError::not_found())?; | ||
Ok(document.content.clone()) |
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 don't know what we can do here to replace clone.
Because we clone a content of a file here.
We had the same issue here when we clone a document every time:
tools/crates/rome_lsp/src/session.rs
Lines 220 to 227 in aec33ef
pub(crate) fn document(&self, url: &lsp_types::Url) -> Result<Document, WorkspaceError> { | |
self.documents | |
.read() | |
.unwrap() | |
.get(url) | |
.cloned() | |
.ok_or_else(WorkspaceError::not_found) | |
} |
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.
That's OK to clone the content. It's not an issue; it's the architecture constraint, which is what we want. Workspace requests need to travel - among other things - across a server, which means we need owned data.
@@ -281,10 +281,7 @@ pub struct ReportNotSerializable { | |||
pub struct NotFound; | |||
|
|||
#[derive(Debug, Serialize, Deserialize, Diagnostic)] | |||
#[diagnostic( |
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.
There was a typo in the message.
#4182 (comment) could have an incorrect error message.
|
||
tracing::trace!("new document: {:?}", doc.text()); | ||
let old_text = session.workspace.get_file_content(GetFileContentParams { |
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.
Could you tell me why we need to get the text from the workspace now? We didn't do it before. I'm genuinely interested
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.
We had a content field in a LineIndex struct.
tools/crates/rome_lsp/src/line_index.rs
Lines 11 to 16 in aec33ef
#[derive(Clone, Debug, PartialEq, Eq)] | |
pub(crate) struct LineIndex { | |
text: String, | |
/// Offset the the beginning of each line, zero-based | |
newlines: Vec<TextSize>, | |
} |
It looks like it was ineffective. Because we had two copies of a file content - in the workspace and in the line index.
Moreover, the index is part of the document, which is cloned in each handler. So it could be a performance improvement too
.documents | ||
.get(¶ms.path) | ||
.ok_or(WorkspaceError::not_found())?; | ||
Ok(document.content.clone()) |
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.
That's OK to clone the content. It's not an issue; it's the architecture constraint, which is what we want. Workspace requests need to travel - among other things - across a server, which means we need owned data.
bd540cc
to
89e1d0d
Compare
89e1d0d
to
93448b5
Compare
Summary
Fix #4222
Fix #4182 (comment)
The server and the client communicate with each other using messages which contain information about the Position.
The character offset can be encoded with PositionEncodingKind:
Our server file representation is a rust string encoded in UTF8.
If we get an offset encoded in UTF16/UTF32, we need to convert it to UTF8 to handle the content of our file and convert it back before sending it to the client.
tower-lsp = { version = "0.19.0" }
providesposition_encodings
- ebkalderon/tower-lsp#375The main logic how to transform different UTF was copied from rust-analyzer
Test Plan
cargo test
Documentation