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 {
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 @@ impl Editor {
.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…
Cancel
Save