mirror of
https://github.com/latex-lsp/texlab.git
synced 2025-08-04 10:49:55 +00:00
Add root directory setting for resolving includes
This commit is contained in:
parent
67ed52d976
commit
f1d7d49906
5 changed files with 33 additions and 8 deletions
|
@ -68,6 +68,7 @@ pub struct LatexOptions {
|
|||
pub forward_search: Option<LatexForwardSearchOptions>,
|
||||
pub lint: Option<LatexLintOptions>,
|
||||
pub build: Option<LatexBuildOptions>,
|
||||
pub root_directory: Option<PathBuf>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Default, Serialize, Deserialize)]
|
||||
|
|
|
@ -7,6 +7,7 @@ authors = [
|
|||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
dunce = "1.0.0"
|
||||
itertools = "0.8.2"
|
||||
once_cell = "1.3.1"
|
||||
path-clean = "0.1.0"
|
||||
|
|
|
@ -159,8 +159,7 @@ impl LatexInclude {
|
|||
|
||||
let mut all_targets = Vec::new();
|
||||
for relative_path in command.extract_comma_separated_words(description.index) {
|
||||
let mut path = input.uri.to_file_path().ok()?;
|
||||
path.pop();
|
||||
let mut path = input.base_path()?;
|
||||
path.push(relative_path.text());
|
||||
path = PathBuf::from(path.to_string_lossy().into_owned().replace('\\', "/"));
|
||||
path = path.clean();
|
||||
|
|
|
@ -10,15 +10,10 @@ pub use self::latex::*;
|
|||
pub use self::lsp_kind::*;
|
||||
pub use self::text::*;
|
||||
|
||||
use std::path::PathBuf;
|
||||
use texlab_distro::{Language, Resolver};
|
||||
use texlab_protocol::{Options, Uri};
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||
pub enum SyntaxTree {
|
||||
Latex(Box<LatexSyntaxTree>),
|
||||
Bibtex(Box<BibtexSyntaxTree>),
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
||||
pub struct SyntaxTreeInput<'a> {
|
||||
pub options: &'a Options,
|
||||
|
@ -28,6 +23,28 @@ pub struct SyntaxTreeInput<'a> {
|
|||
pub language: Language,
|
||||
}
|
||||
|
||||
impl<'a> SyntaxTreeInput<'a> {
|
||||
pub fn base_path(&self) -> Option<PathBuf> {
|
||||
self.options
|
||||
.latex
|
||||
.as_ref()
|
||||
.and_then(|opts| opts.root_directory.as_ref())
|
||||
.and_then(|path| dunce::canonicalize(path).ok())
|
||||
.or_else(|| {
|
||||
self.uri.to_file_path().ok().map(|mut path| {
|
||||
path.pop();
|
||||
path
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||
pub enum SyntaxTree {
|
||||
Latex(Box<LatexSyntaxTree>),
|
||||
Bibtex(Box<BibtexSyntaxTree>),
|
||||
}
|
||||
|
||||
impl SyntaxTree {
|
||||
pub fn parse(input: SyntaxTreeInput) -> Self {
|
||||
match input.language {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue