Skip to content

Commit

Permalink
Do not rely on documentclass to detect root file
Browse files Browse the repository at this point in the history
See #845.
  • Loading branch information
pfoerster committed Jan 28, 2023
1 parent e42c172 commit bd38d6f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Concatenate more than two lines of maximum length in build diagnostics ([#842](https://github.com/latex-lsp/texlab/pull/842))
- Apply the correct range of references to labels when renaming ([#841](https://github.com/latex-lsp/texlab/issues/841))
- Use `document` environment to detect root file instead of `\documentclass` ([#845](https://github.com/latex-lsp/texlab/issues/845))

## [5.1.0] - 2023-01-21

Expand Down
10 changes: 10 additions & 0 deletions src/db/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,16 @@ pub struct TexAnalysis {
pub environment_names: Vec<String>,
}

#[salsa::tracked]
impl TexAnalysis {
#[salsa::tracked]
pub fn has_document_environment(self, db: &dyn Db) -> bool {
self.environment_names(db)
.iter()
.any(|name| name == "document")
}
}

impl TexAnalysis {
pub(super) fn analyze(db: &dyn Db, root: &latex::SyntaxNode) -> Self {
let mut links = Vec::new();
Expand Down
23 changes: 11 additions & 12 deletions src/db/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,23 +175,22 @@ impl Document {
}

#[salsa::tracked]
pub fn can_be_index(self, db: &dyn Db) -> bool {
pub fn can_be_root(self, db: &dyn Db) -> bool {
self.parse(db).as_tex().map_or(false, |data| {
data.analyze(db)
.links(db)
.iter()
.filter(|link| link.kind(db) == TexLinkKind::Cls)
.any(|link| link.path(db).text(db) != "subfiles")
let analysis = data.analyze(db);
analysis.has_document_environment(db)
|| !analysis
.links(db)
.iter()
.filter(|link| link.kind(db) == TexLinkKind::Cls)
.any(|link| link.path(db).text(db) == "subfiles")
})
}

#[salsa::tracked]
pub fn can_be_built(self, db: &dyn Db) -> bool {
self.parse(db).as_tex().map_or(false, |data| {
data.analyze(db)
.links(db)
.iter()
.any(|link| link.kind(db) == TexLinkKind::Cls)
})
self.parse(db)
.as_tex()
.map_or(false, |data| data.analyze(db).has_document_environment(db))
}
}
2 changes: 1 addition & 1 deletion src/db/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl Workspace {
self.documents(db)
.iter()
.copied()
.filter(|&document| document.can_be_index(db))
.filter(|&document| document.can_be_root(db))
}

pub fn open(
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct Jar(
db::LinterData,
db::Document,
db::Document_parse,
db::Document_can_be_index,
db::Document_can_be_root,
db::Document_can_be_built,
db::parse::TexDocumentData,
db::parse::TexDocumentData_analyze,
Expand All @@ -35,6 +35,7 @@ pub struct Jar(
db::analysis::TheoremEnvironment,
db::analysis::GraphicsPath,
db::analysis::TexAnalysis,
db::analysis::TexAnalysis_has_document_environment,
db::MissingDependencies,
db::hidden_dependency,
db::source_dependency,
Expand Down

0 comments on commit bd38d6f

Please sign in to comment.