lsp: Refactor code that could use document_by_path_mut
This commit is contained in:
parent
63e191ea3b
commit
dc7799b980
@ -276,15 +276,10 @@ pub async fn handle_language_server_message(
|
||||
|
||||
match notification {
|
||||
Notification::PublishDiagnostics(params) => {
|
||||
let path = Some(params.uri.to_file_path().unwrap());
|
||||
let path = params.uri.to_file_path().unwrap();
|
||||
let doc = self.editor.document_by_path_mut(&path);
|
||||
|
||||
let doc = self
|
||||
.editor
|
||||
.documents
|
||||
.iter_mut()
|
||||
.find(|(_, doc)| doc.path() == path.as_ref());
|
||||
|
||||
if let Some((_, doc)) = doc {
|
||||
if let Some(doc) = doc {
|
||||
let text = doc.text();
|
||||
|
||||
let diagnostics = params
|
||||
|
@ -340,6 +340,11 @@ pub fn document_by_path<P: AsRef<Path>>(&self, path: P) -> Option<&Document> {
|
||||
.find(|doc| doc.path().map(|p| p == path.as_ref()).unwrap_or(false))
|
||||
}
|
||||
|
||||
pub fn document_by_path_mut<P: AsRef<Path>>(&mut self, path: P) -> Option<&mut Document> {
|
||||
self.documents_mut()
|
||||
.find(|doc| doc.path().map(|p| p == path.as_ref()).unwrap_or(false))
|
||||
}
|
||||
|
||||
pub fn cursor(&self) -> (Option<Position>, CursorKind) {
|
||||
let view = view!(self);
|
||||
let doc = &self.documents[view.doc];
|
||||
|
Loading…
Reference in New Issue
Block a user