From dea392e6cd39e766c16fd400959da12a9f9a8c4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20F=C3=B6rster?= Date: Thu, 7 Mar 2024 21:10:06 +0100 Subject: [PATCH] Don't report diagnostics for distro files --- CHANGELOG.md | 6 ++++++ crates/base-db/src/document.rs | 1 + crates/base-db/src/workspace.rs | 13 ++++++++++--- crates/diagnostics/src/manager.rs | 24 +++++++++++++++++++++++- crates/distro/src/file_name_db.rs | 5 +++++ crates/texlab/src/server.rs | 2 +- 6 files changed, 46 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eb6a3c42..f830eece 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Fixed + +- Don't report diagnostics for files that are part of the TeX distro ([#1028](https://github.com/latex-lsp/texlab/issues/1028)) + ## [5.12.4] - 2024-02-22 ### Fixed diff --git a/crates/base-db/src/document.rs b/crates/base-db/src/document.rs index 9f45876d..25607a1b 100644 --- a/crates/base-db/src/document.rs +++ b/crates/base-db/src/document.rs @@ -12,6 +12,7 @@ use crate::{semantics, Config}; pub enum Owner { Client, Server, + Distro, } #[derive(Debug)] diff --git a/crates/base-db/src/workspace.rs b/crates/base-db/src/workspace.rs index 330ed5a4..0fe347f1 100644 --- a/crates/base-db/src/workspace.rs +++ b/crates/base-db/src/workspace.rs @@ -67,7 +67,7 @@ impl Workspace { })); } - pub fn load(&mut self, path: &Path, language: Language, owner: Owner) -> std::io::Result<()> { + pub fn load(&mut self, path: &Path, language: Language) -> std::io::Result<()> { log::debug!("Loading document {} from disk...", path.display()); let uri = Url::from_file_path(path).unwrap(); let data = std::fs::read(path)?; @@ -76,6 +76,12 @@ impl Workspace { Cow::Owned(text) => text, }; + let owner = if self.distro.file_name_db.contains(&path) { + Owner::Distro + } else { + Owner::Server + }; + if let Some(document) = self.lookup_path(path) { if document.text == text { return Ok(()); @@ -329,7 +335,7 @@ impl Workspace { } if self.lookup_path(&file).is_none() && file.exists() { - changed |= self.load(&file, lang, Owner::Server).is_ok(); + changed |= self.load(&file, lang).is_ok(); checked_paths.insert(file); } } @@ -350,8 +356,9 @@ impl Workspace { let mut changed = false; for file in files { let language = Language::from_path(&file).unwrap_or(Language::Tex); + if self.lookup_path(&file).is_none() && file.exists() { - changed |= self.load(&file, language, Owner::Server).is_ok(); + changed |= self.load(&file, language).is_ok(); checked_paths.insert(file); } } diff --git a/crates/diagnostics/src/manager.rs b/crates/diagnostics/src/manager.rs index 1ce5e194..606ba42d 100644 --- a/crates/diagnostics/src/manager.rs +++ b/crates/diagnostics/src/manager.rs @@ -16,6 +16,10 @@ pub struct Manager { impl Manager { /// Updates the syntax-based diagnostics for the given document. pub fn update_syntax(&mut self, workspace: &Workspace, document: &Document) { + if !Self::is_relevant(document) { + return; + } + self.grammar.remove(&document.uri); super::grammar::tex::update(document, workspace.config(), &mut self.grammar); super::grammar::bib::update(document, &mut self.grammar); @@ -49,7 +53,10 @@ impl Manager { } } - for document in workspace.iter() { + for document in workspace + .iter() + .filter(|document| Self::is_relevant(document)) + { let project = workspace.project(document); super::citations::detect_undefined_citations(&project, document, &mut results); super::citations::detect_unused_entries(&project, document, &mut results); @@ -60,6 +67,13 @@ impl Manager { super::labels::detect_undefined_and_unused_labels(workspace, &mut results); let config = &workspace.config().diagnostics; + + results.retain(|uri, _| { + workspace + .lookup(uri) + .map_or(false, |document| Self::is_relevant(document)) + }); + for (_, diagnostics) in &mut results { diagnostics.retain(|diagnostic| { filter_regex_patterns( @@ -72,4 +86,12 @@ impl Manager { results } + + fn is_relevant(document: &Document) -> bool { + match document.owner { + Owner::Client => true, + Owner::Server => true, + Owner::Distro => false, + } + } } diff --git a/crates/distro/src/file_name_db.rs b/crates/distro/src/file_name_db.rs index 06871bde..fd6750ff 100644 --- a/crates/distro/src/file_name_db.rs +++ b/crates/distro/src/file_name_db.rs @@ -55,6 +55,11 @@ impl FileNameDB { self.files.get(name).map(|file| file.path()) } + pub fn contains(&self, path: &Path) -> bool { + let name = path.file_name().unwrap().to_str().unwrap(); + self.get(name) == Some(path) + } + pub fn iter(&self) -> impl Iterator + '_ { self.files.iter().map(|file| (file.name(), file.path())) } diff --git a/crates/texlab/src/server.rs b/crates/texlab/src/server.rs index 0fb186f6..fc16775b 100644 --- a/crates/texlab/src/server.rs +++ b/crates/texlab/src/server.rs @@ -813,7 +813,7 @@ impl Server { .map_or(true, |document| document.owner == Owner::Server) { if let Some(language) = Language::from_path(&path) { - changed |= workspace.load(&path, language, Owner::Server).is_ok(); + changed |= workspace.load(&path, language).is_ok(); if let Some(document) = workspace.lookup_path(&path) { self.diagnostic_manager.update_syntax(&workspace, document);