Skip to content

Commit

Permalink
Add "latex.build.forwardSearchAfter" setting
Browse files Browse the repository at this point in the history
  • Loading branch information
pfoerster committed May 10, 2020
1 parent d210520 commit 678c547
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/forward_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ fn replace_placeholder(
argument
.replace("%f", tex_file.to_str()?)
.replace("%p", pdf_file.to_str()?)
.replace("%l", &line_number.to_string())
.replace("%l", &(line_number + 1).to_string())
};
Some(result)
}
Expand Down
5 changes: 5 additions & 0 deletions src/protocol/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ pub struct LatexBuildOptions {
pub args: Option<Vec<String>>,
pub on_save: Option<bool>,
pub output_directory: Option<PathBuf>,
pub forward_search_after: Option<bool>,
}

impl LatexBuildOptions {
Expand All @@ -74,6 +75,10 @@ impl LatexBuildOptions {
pub fn on_save(&self) -> bool {
self.on_save.unwrap_or(false)
}

pub fn forward_search_after(&self) -> bool {
self.forward_search_after.unwrap_or(false)
}
}

#[derive(Debug, PartialEq, Eq, Clone, Default, Serialize, Deserialize)]
Expand Down
35 changes: 34 additions & 1 deletion src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use crate::{
workspace::{DocumentContent, Workspace},
};
use async_trait::async_trait;
use chashmap::CHashMap;
use futures::lock::Mutex;
use jsonrpc::{server::Result, Middleware};
use jsonrpc_derive::{jsonrpc_method, jsonrpc_server};
Expand Down Expand Up @@ -48,6 +49,7 @@ pub struct LatexLspServer<C> {
symbol_provider: SymbolProvider,
hover_provider: HoverProvider,
diagnostics_manager: DiagnosticsManager,
last_position_by_uri: CHashMap<Uri, Position>,
}

#[jsonrpc_server]
Expand All @@ -74,6 +76,7 @@ impl<C: LspClient + Send + Sync + 'static> LatexLspServer<C> {
symbol_provider: SymbolProvider::new(),
hover_provider: HoverProvider::new(),
diagnostics_manager: DiagnosticsManager::default(),
last_position_by_uri: CHashMap::new(),
}
}

Expand Down Expand Up @@ -242,6 +245,12 @@ impl<C: LspClient + Send + Sync + 'static> LatexLspServer<C> {
let req = self
.make_feature_request(params.text_document_position.text_document.as_uri(), params)
.await?;

self.last_position_by_uri.insert(
req.current().uri.clone(),
req.params.text_document_position.position,
);

Ok(CompletionList {
is_incomplete: true,
items: self.completion_provider.execute(&req).await,
Expand Down Expand Up @@ -276,6 +285,10 @@ impl<C: LspClient + Send + Sync + 'static> LatexLspServer<C> {
let req = self
.make_feature_request(params.text_document.as_uri(), params)
.await?;

self.last_position_by_uri
.insert(req.current().uri.clone(), req.params.position);

Ok(self.hover_provider.execute(&req).await)
}

Expand Down Expand Up @@ -464,7 +477,27 @@ impl<C: LspClient + Send + Sync + 'static> LatexLspServer<C> {
let req = self
.make_feature_request(params.text_document.as_uri(), params)
.await?;
Ok(self.build_provider.execute(&req).await)

let pos = self
.last_position_by_uri
.get(&req.current().uri)
.map(|pos| *pos)
.unwrap_or_default();

let res = self.build_provider.execute(&req).await;

if req
.options
.latex
.and_then(|opts| opts.build)
.unwrap_or_default()
.forward_search_after()
{
let params = TextDocumentPositionParams::new(req.params.text_document, pos);
self.forward_search(params).await?;
}

Ok(res)
}

#[jsonrpc_method("textDocument/forwardSearch", kind = "request")]
Expand Down

0 comments on commit 678c547

Please sign in to comment.