mirror of
https://github.com/latex-lsp/texlab.git
synced 2025-12-23 09:19:21 +00:00
parent
4dd2518c7d
commit
10908316dd
6 changed files with 64 additions and 22 deletions
|
|
@ -20,6 +20,7 @@ use lsp_types::{
|
|||
*,
|
||||
};
|
||||
use notification::DidCloseTextDocument;
|
||||
use notify::RecursiveMode;
|
||||
use request::{
|
||||
Completion, DocumentHighlightRequest, DocumentSymbolRequest, HoverRequest,
|
||||
ResolveCompletionItem, WorkspaceSymbol,
|
||||
|
|
@ -180,7 +181,7 @@ impl Server {
|
|||
let workspace = Arc::clone(&self.workspace);
|
||||
self.pool.execute(move || {
|
||||
register_config_capability(&req_queue, &sender, &context.client_capabilities);
|
||||
pull_and_reparse(req_queue, sender, context, workspace);
|
||||
pull_and_reparse_all(req_queue, sender, context, workspace);
|
||||
});
|
||||
|
||||
Ok(())
|
||||
|
|
@ -230,10 +231,18 @@ impl Server {
|
|||
let context = Arc::clone(&self.context);
|
||||
let workspace = Arc::clone(&self.workspace);
|
||||
self.pool.execute(move || {
|
||||
pull_and_reparse(req_queue, sender, context, workspace);
|
||||
pull_and_reparse_all(req_queue, sender, context, workspace);
|
||||
});
|
||||
} else {
|
||||
push_config(&self.context.options, params.settings);
|
||||
if let Some(path) = { self.context.options.read().unwrap().aux_directory.clone() } {
|
||||
let _ = self.workspace.watch(path, RecursiveMode::NonRecursive);
|
||||
}
|
||||
|
||||
let workspace = Arc::clone(&self.workspace);
|
||||
self.pool.execute(move || {
|
||||
reparse_all(workspace.as_ref());
|
||||
});
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
@ -846,7 +855,7 @@ impl Server {
|
|||
}
|
||||
}
|
||||
|
||||
fn pull_and_reparse(
|
||||
fn pull_and_reparse_all(
|
||||
req_queue: Arc<Mutex<lsp_server::ReqQueue<IncomingData, req_queue::OutgoingData>>>,
|
||||
sender: Sender<Message>,
|
||||
context: Arc<ServerContext>,
|
||||
|
|
@ -854,6 +863,14 @@ fn pull_and_reparse(
|
|||
) {
|
||||
let client_capabilities = { context.client_capabilities.lock().unwrap().clone() };
|
||||
pull_config(&req_queue, &sender, &context.options, &client_capabilities);
|
||||
if let Some(path) = { context.options.read().unwrap().aux_directory.clone() } {
|
||||
let _ = workspace.watch(path, RecursiveMode::NonRecursive);
|
||||
}
|
||||
|
||||
reparse_all(workspace.as_ref());
|
||||
}
|
||||
|
||||
fn reparse_all(workspace: &dyn Workspace) {
|
||||
for document in workspace.documents() {
|
||||
workspace.open(
|
||||
Arc::clone(&document.uri),
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
use std::{fs, path::PathBuf, sync::Arc};
|
||||
|
||||
use anyhow::Result;
|
||||
use notify::RecursiveMode;
|
||||
|
||||
use crate::{DocumentLanguage, Uri};
|
||||
|
||||
|
|
@ -37,9 +38,9 @@ pub trait Workspace: Send + Sync {
|
|||
return Ok(self.get(&uri));
|
||||
}
|
||||
|
||||
let data = fs::read(&path)?;
|
||||
let text = String::from_utf8_lossy(&data).into_owned();
|
||||
if let Some(language) = DocumentLanguage::by_path(&path) {
|
||||
let data = fs::read(&path)?;
|
||||
let text = String::from_utf8_lossy(&data).into_owned();
|
||||
Ok(Some(self.open(
|
||||
uri,
|
||||
text,
|
||||
|
|
@ -83,4 +84,6 @@ pub trait Workspace: Send + Sync {
|
|||
fn is_open(&self, uri: &Uri) -> bool;
|
||||
|
||||
fn subset(&self, uri: Arc<Uri>) -> Option<WorkspaceSubset>;
|
||||
|
||||
fn watch(&self, path: PathBuf, mode: RecursiveMode) -> Result<()>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
use std::sync::Arc;
|
||||
use std::{path::PathBuf, sync::Arc};
|
||||
|
||||
use anyhow::Result;
|
||||
use notify::RecursiveMode;
|
||||
use rayon::iter::{IntoParallelIterator, ParallelIterator};
|
||||
|
||||
use crate::{
|
||||
|
|
@ -89,4 +91,8 @@ impl<W: Workspace> Workspace for ChildrenExpander<W> {
|
|||
fn subset(&self, uri: Arc<Uri>) -> Option<WorkspaceSubset> {
|
||||
self.workspace.subset(uri)
|
||||
}
|
||||
|
||||
fn watch(&self, path: PathBuf, mode: RecursiveMode) -> Result<()> {
|
||||
self.workspace.watch(path, mode)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
use std::{fs, sync::Arc};
|
||||
use std::{fs, path::PathBuf, sync::Arc};
|
||||
|
||||
use anyhow::Result;
|
||||
use notify::RecursiveMode;
|
||||
use rayon::iter::{IntoParallelIterator, ParallelIterator};
|
||||
use rustc_hash::FxHashSet;
|
||||
|
||||
|
|
@ -96,6 +98,10 @@ where
|
|||
fn subset(&self, uri: Arc<Uri>) -> Option<WorkspaceSubset> {
|
||||
self.workspace.subset(uri)
|
||||
}
|
||||
|
||||
fn watch(&self, path: PathBuf, mode: RecursiveMode) -> Result<()> {
|
||||
self.workspace.watch(path, mode)
|
||||
}
|
||||
}
|
||||
|
||||
impl<W> ParentExpander<W>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,10 @@
|
|||
use std::sync::{Arc, Mutex};
|
||||
use std::{
|
||||
path::PathBuf,
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
|
||||
use anyhow::Result;
|
||||
use notify::RecursiveMode;
|
||||
use petgraph::{graphmap::UnGraphMap, visit::Dfs};
|
||||
use rustc_hash::{FxHashMap, FxHashSet};
|
||||
|
||||
|
|
@ -133,4 +138,8 @@ impl Workspace for Storage {
|
|||
|
||||
Some(WorkspaceSubset { documents })
|
||||
}
|
||||
|
||||
fn watch(&self, _path: PathBuf, _mode: RecursiveMode) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,20 +57,11 @@ impl<W: Workspace> Workspace for DocumentWatcher<W> {
|
|||
if document.uri.scheme() == "file" {
|
||||
if let Ok(mut path) = document.uri.to_file_path() {
|
||||
path.pop();
|
||||
let mut watched_paths = self.watched_paths.lock().unwrap();
|
||||
if !watched_paths.contains(&path) {
|
||||
if let Err(why) = self
|
||||
.watcher
|
||||
.lock()
|
||||
.unwrap()
|
||||
.watch(&path, RecursiveMode::NonRecursive)
|
||||
{
|
||||
warn!(
|
||||
"Failed to watch folder of document \"{}\": {}",
|
||||
document.uri, why
|
||||
);
|
||||
}
|
||||
watched_paths.insert(path);
|
||||
if let Err(why) = self.watch(path, RecursiveMode::NonRecursive) {
|
||||
warn!(
|
||||
"Failed to watch folder of document \"{}\": {}",
|
||||
document.uri, why
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -104,4 +95,14 @@ impl<W: Workspace> Workspace for DocumentWatcher<W> {
|
|||
fn subset(&self, uri: Arc<Uri>) -> Option<WorkspaceSubset> {
|
||||
self.workspace.subset(uri)
|
||||
}
|
||||
|
||||
fn watch(&self, path: PathBuf, mode: RecursiveMode) -> Result<()> {
|
||||
let mut watched_paths = self.watched_paths.lock().unwrap();
|
||||
if !watched_paths.contains(&path) {
|
||||
self.watcher.lock().unwrap().watch(&path, mode)?;
|
||||
watched_paths.insert(path);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue