Skip to content

Commit

Permalink
Don't report diagnostics for distro files
Browse files Browse the repository at this point in the history
  • Loading branch information
pfoerster committed Mar 7, 2024
1 parent 4a000a0 commit dea392e
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions crates/base-db/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::{semantics, Config};
pub enum Owner {
Client,
Server,
Distro,
}

#[derive(Debug)]
Expand Down
13 changes: 10 additions & 3 deletions crates/base-db/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand All @@ -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(());
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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);
}
}
Expand Down
24 changes: 23 additions & 1 deletion crates/diagnostics/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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(
Expand All @@ -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,
}
}
}
5 changes: 5 additions & 0 deletions crates/distro/src/file_name_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Item = (&str, &Path)> + '_ {
self.files.iter().map(|file| (file.name(), file.path()))
}
Expand Down
2 changes: 1 addition & 1 deletion crates/texlab/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit dea392e

Please sign in to comment.