This repository has been archived by the owner on Nov 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 77
/
manager.rs
94 lines (78 loc) · 2.42 KB
/
manager.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
use std::collections::HashSet;
use tower_lsp::lsp_types::{TextDocumentContentChangeEvent, Url};
use typst::eval::Bytes;
use typst::syntax::Source;
use crate::config::PositionEncoding;
use crate::workspace::package::manager::PackageManager;
use super::cache::Cache;
use super::local::LocalFs;
use super::lsp::LspFs;
use super::{FsResult, KnownUriProvider, ReadProvider, WriteProvider};
/// Composes [`ReadProvider`]s and [`WriteProvider`]s into a single provider for a workspace
#[derive(Debug, Default)]
pub struct FsManager {
lsp: LspFs,
local: Cache<LocalFs>,
}
impl ReadProvider for FsManager {
fn read_bytes(&self, uri: &Url, package_manager: &PackageManager) -> FsResult<Bytes> {
self.lsp
.read_bytes(uri, package_manager)
.or_else(|_| self.local.read_bytes(uri, package_manager))
}
fn read_source(&self, uri: &Url, package_manager: &PackageManager) -> FsResult<Source> {
self.lsp
.read_source(uri, package_manager)
.or_else(|_| self.local.read_source(uri, package_manager))
}
}
impl WriteProvider for FsManager {
fn write_raw(&self, uri: &Url, data: &[u8]) -> FsResult<()> {
self.local.inner().write_raw(uri, data)
}
}
impl KnownUriProvider for FsManager {
fn known_uris(&self) -> HashSet<Url> {
let mut uris = self.local.known_uris();
uris.extend(self.lsp.known_uris());
uris
}
}
impl FsManager {
#[tracing::instrument]
pub fn register_files(&mut self, root: &Url) -> FsResult<()> {
self.local.register_files(root)
}
pub fn open_lsp(
&mut self,
uri: Url,
text: String,
package_manager: &PackageManager,
) -> FsResult<()> {
self.lsp.open(uri, text, package_manager)
}
pub fn close_lsp(&mut self, uri: &Url) {
self.lsp.close(uri)
}
pub fn edit_lsp(
&mut self,
uri: &Url,
changes: impl IntoIterator<Item = TextDocumentContentChangeEvent>,
position_encoding: PositionEncoding,
) {
self.lsp.edit(uri, changes, position_encoding)
}
pub fn new_local(&mut self, uri: Url) {
self.local.cache_new(uri)
}
pub fn invalidate_local(&mut self, uri: Url) {
self.local.invalidate(uri)
}
pub fn delete_local(&mut self, uri: &Url) {
self.local.delete(uri)
}
pub fn clear(&mut self) {
self.lsp.clear();
self.local.clear();
}
}