1
use conjure_cp_core::ast::Model;
2
use conjure_cp_essence_parser::{RecoverableParseError, diagnostics::source_map::SourceMap};
3
use moka::future::Cache;
4
use std::time::Duration;
5
use tower_lsp::lsp_types::*;
6
use tree_sitter::Tree;
7

            
8
#[derive(Clone, Debug)]
9
pub struct CacheCont {
10
    pub sourcemap: Option<SourceMap>,
11
    pub ast: Option<Model>,
12
    pub errors: Vec<RecoverableParseError>,
13
    pub cst: Option<Tree>,
14
    pub contents: String,
15
    //from DidChangeTextDocumentParams -> Versioned thingy -> version
16
    pub version: i32, //therefore can do dirty clean with version checking? which allows direct comparison
17
}
18

            
19
//create cache which will be used throughout lsp
20
pub async fn create_cache() -> Cache<Url, CacheCont> {
21
    Cache::builder()
22
        .max_capacity(10_000) //cache has a set upper size limit before eviction
23
        .time_to_live(Duration::from_secs(30 * 60)) //documents remain in cache while used for 30 minutes
24
        .time_to_idle(Duration::from_secs(5 * 60)) //documents remain in cache while idle for 5 minutes
25
        .build()
26
}