Skip to content

Commit

Permalink
Apply percent decoding when searching for PDFs
Browse files Browse the repository at this point in the history
See #848.
  • Loading branch information
pfoerster committed Feb 5, 2023
1 parent c59d977 commit 178cba7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ 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

- Do not use percent-encoded path when searching for PDF files during forward search
([#848](https://github.com/latex-lsp/texlab/issues/848))

## [5.2.0] - 2023-01-29

### Added
Expand Down
8 changes: 4 additions & 4 deletions src/db/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ impl Location {
}
}

pub fn stem<'db>(self, db: &'db dyn Db) -> Option<&'db str> {
let name = self.uri(db).path_segments()?.last()?;
let stem = name.rsplit_once('.').map_or(name, |(stem, _)| stem);
Some(stem)
pub fn stem(self, db: &dyn Db) -> Option<String> {
let path = self.uri(db).to_file_path().ok()?;
let stem = path.file_stem()?.to_str()?;
Some(String::from(stem))
}

pub fn join(self, db: &dyn Db, path: &str) -> Option<Location> {
Expand Down
15 changes: 13 additions & 2 deletions src/features/forward_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ pub enum Error {
#[error("TeX document '{0}' not found")]
TexNotFound(Url),

#[error("TeX document '{0}' is invalid")]
InvalidTexFile(Url),

#[error("PDF document '{0}' not found")]
PdfNotFound(PathBuf),

Expand Down Expand Up @@ -59,8 +62,16 @@ impl Command {
.as_deref()
.ok_or_else(|| Error::NoLocalFile(uri.clone()))?;

let pdf_name = format!("{}.pdf", parent.location(db).stem(db).unwrap());
let pdf_path = output_dir.join(pdf_name);
let pdf_path = match parent.location(db).stem(db) {
Some(stem) => {
let pdf_name = format!("{}.pdf", stem);
output_dir.join(pdf_name)
}
None => {
return Err(Error::InvalidTexFile(uri.clone()));
}
};

if !pdf_path.exists() {
return Err(Error::PdfNotFound(pdf_path));
}
Expand Down
1 change: 1 addition & 0 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,7 @@ impl From<forward_search::Error> for ForwardSearchStatus {
fn from(err: forward_search::Error) -> Self {
match err {
forward_search::Error::TexNotFound(_) => ForwardSearchStatus::FAILURE,
forward_search::Error::InvalidTexFile(_) => ForwardSearchStatus::ERROR,
forward_search::Error::PdfNotFound(_) => ForwardSearchStatus::ERROR,
forward_search::Error::NoLocalFile(_) => ForwardSearchStatus::FAILURE,
forward_search::Error::Unconfigured => ForwardSearchStatus::UNCONFIGURED,
Expand Down

0 comments on commit 178cba7

Please sign in to comment.