Compute the AST digest in the LSP (#3037)
This is a slow-roll to calling this in more places; but this is non-critical, so if this breaks on some unexpected AST or what have you, we're not breaking anything except the LSP (which we'll see pretty quickly) while also testing it on all user input. If something goes south, please feel free to revert this commit. Signed-off-by: Paul Tagliamonte <paul@zoo.dev>
|
Before Width: | Height: | Size: 44 KiB After Width: | Height: | Size: 42 KiB |
|
Before Width: | Height: | Size: 44 KiB After Width: | Height: | Size: 44 KiB |
|
Before Width: | Height: | Size: 51 KiB After Width: | Height: | Size: 50 KiB |
|
Before Width: | Height: | Size: 45 KiB After Width: | Height: | Size: 44 KiB |
|
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 35 KiB |
|
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 35 KiB |
|
Before Width: | Height: | Size: 39 KiB After Width: | Height: | Size: 38 KiB |
|
Before Width: | Height: | Size: 71 KiB After Width: | Height: | Size: 70 KiB |
|
Before Width: | Height: | Size: 44 KiB After Width: | Height: | Size: 44 KiB |
|
Before Width: | Height: | Size: 62 KiB After Width: | Height: | Size: 61 KiB |
|
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 31 KiB |
@ -232,7 +232,7 @@ impl crate::lsp::backend::Backend for Backend {
|
|||||||
// Lets update the ast.
|
// Lets update the ast.
|
||||||
let parser = crate::parser::Parser::new(tokens.clone());
|
let parser = crate::parser::Parser::new(tokens.clone());
|
||||||
let result = parser.ast();
|
let result = parser.ast();
|
||||||
let ast = match result {
|
let mut ast = match result {
|
||||||
Ok(ast) => ast,
|
Ok(ast) => ast,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
self.add_to_diagnostics(¶ms, &[err], true).await;
|
self.add_to_diagnostics(¶ms, &[err], true).await;
|
||||||
@ -243,6 +243,11 @@ impl crate::lsp::backend::Backend for Backend {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Here we will want to store the digest and compare, but for now
|
||||||
|
// we're doing this in a non-load-bearing capacity so we can remove
|
||||||
|
// this if it backfires and only hork the LSP.
|
||||||
|
ast.compute_digest();
|
||||||
|
|
||||||
// Check if the ast changed.
|
// Check if the ast changed.
|
||||||
let ast_changed = match self.ast_map.get(&filename) {
|
let ast_changed = match self.ast_map.get(&filename) {
|
||||||
Some(old_ast) => {
|
Some(old_ast) => {
|
||||||
|
|||||||
@ -2371,9 +2371,12 @@ async fn serial_test_kcl_lsp_full_to_empty_file_updates_ast_and_memory() {
|
|||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
let mut default_hashed = crate::ast::types::Program::default();
|
||||||
|
default_hashed.compute_digest();
|
||||||
|
|
||||||
// Get the ast.
|
// Get the ast.
|
||||||
let ast = server.ast_map.get("file:///test.kcl").unwrap().clone();
|
let ast = server.ast_map.get("file:///test.kcl").unwrap().clone();
|
||||||
assert_eq!(ast, crate::ast::types::Program::default());
|
assert_eq!(ast, default_hashed);
|
||||||
// Get the memory.
|
// Get the memory.
|
||||||
let memory = server.memory_map.get("file:///test.kcl").unwrap().clone();
|
let memory = server.memory_map.get("file:///test.kcl").unwrap().clone();
|
||||||
assert_eq!(memory, ProgramMemory::default());
|
assert_eq!(memory, ProgramMemory::default());
|
||||||
@ -2835,9 +2838,12 @@ async fn serial_test_kcl_lsp_cant_execute_set() {
|
|||||||
let units = server.executor_ctx().await.clone().unwrap().settings.units;
|
let units = server.executor_ctx().await.clone().unwrap().settings.units;
|
||||||
assert_eq!(units, crate::settings::types::UnitLength::Mm);
|
assert_eq!(units, crate::settings::types::UnitLength::Mm);
|
||||||
|
|
||||||
|
let mut default_hashed = crate::ast::types::Program::default();
|
||||||
|
default_hashed.compute_digest();
|
||||||
|
|
||||||
// Get the ast.
|
// Get the ast.
|
||||||
let ast = server.ast_map.get("file:///test.kcl").unwrap().clone();
|
let ast = server.ast_map.get("file:///test.kcl").unwrap().clone();
|
||||||
assert!(ast != crate::ast::types::Program::default());
|
assert!(ast != default_hashed);
|
||||||
// Get the memory.
|
// Get the memory.
|
||||||
let memory = server.memory_map.get("file:///test.kcl").unwrap().clone();
|
let memory = server.memory_map.get("file:///test.kcl").unwrap().clone();
|
||||||
// Now it should be the default memory.
|
// Now it should be the default memory.
|
||||||
|
|||||||