on master help sign in
lsp: Refactor code that could use document_by_path_mut
commitdc7799b980826ffe33ed635968def79daf20bd10 authorBlaž Hrastnik <blaz@mxxn.io> dateThu 2 Sep 2021, 11:28 (5 years ago) parent63e191e
2 files changed+8−8
helix-term/src/application.rs+3−8 helix-view/src/editor.rs+5
helix-term/src/application.rs+3−8
@@ -276,15 +276,10 @@ impl Application {
276276
277277 match notification {
278278 Notification::PublishDiagnostics(params) => {
279− let path = Some(params.uri.to_file_path().unwrap());
279+ let path = params.uri.to_file_path().unwrap();
280+ let doc = self.editor.document_by_path_mut(&path);
280281
281− let doc = self
282− .editor
283− .documents
284− .iter_mut()
285− .find(|(_, doc)| doc.path() == path.as_ref());
286−
287− if let Some((_, doc)) = doc {
282+ if let Some(doc) = doc {
288283 let text = doc.text();
289284
290285 let diagnostics = params
helix-view/src/editor.rs+5
@@ -340,6 +340,11 @@ impl Editor {
340340 .find(|doc| doc.path().map(|p| p == path.as_ref()).unwrap_or(false))
341341 }
342342
343+ pub fn document_by_path_mut<P: AsRef<Path>>(&mut self, path: P) -> Option<&mut Document> {
344+ self.documents_mut()
345+ .find(|doc| doc.path().map(|p| p == path.as_ref()).unwrap_or(false))
346+ }
347+
343348 pub fn cursor(&self) -> (Option<Position>, CursorKind) {
344349 let view = view!(self);
345350 let doc = &self.documents[view.doc];