lsp: Refactor code that could use document_by_path_mut

pull/724/head
Blaž Hrastnik 3 years ago
parent 63e191ea3b
commit dc7799b980

@ -276,15 +276,10 @@ impl Application {
match notification { match notification {
Notification::PublishDiagnostics(params) => { 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 if let Some(doc) = doc {
.editor
.documents
.iter_mut()
.find(|(_, doc)| doc.path() == path.as_ref());
if let Some((_, doc)) = doc {
let text = doc.text(); let text = doc.text();
let diagnostics = params let diagnostics = params

@ -340,6 +340,11 @@ impl Editor {
.find(|doc| doc.path().map(|p| p == path.as_ref()).unwrap_or(false)) .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) { pub fn cursor(&self) -> (Option<Position>, CursorKind) {
let view = view!(self); let view = view!(self);
let doc = &self.documents[view.doc]; let doc = &self.documents[view.doc];

Loading…
Cancel
Save