Fix to cache correct PathToNode in artifact graph (#6632)

* Add NodePath to artifact graph

Since this is cached, this should make PathToNode computation correct
even when code is formatted, whitespace changes, and source ranges
are different.

* Remove dead code

* Add unit tests

* Add tests for PathToNode conversion

* Remove unused parameter

* Add missing PathToNode cases

* Fix to handle unlabeled arg

* Cherry pick unlabeled arg fix

* Change PathToNode comment to match TS implementation
This commit is contained in:
Jonathan Tran
2025-05-01 23:55:12 -04:00
committed by GitHub
parent 02a37e207f
commit 819ee23565
12 changed files with 767 additions and 67 deletions

View File

@ -95,7 +95,7 @@ pub use lsp::{
kcl::{Backend as KclLspBackend, Server as KclLspServerSubCommand},
};
pub use modules::ModuleId;
pub use parsing::ast::types::FormatOptions;
pub use parsing::ast::types::{FormatOptions, NodePath};
pub use settings::types::{project::ProjectConfiguration, Configuration, UnitLength};
pub use source_range::SourceRange;
#[cfg(not(target_arch = "wasm32"))]
@ -236,6 +236,10 @@ impl Program {
self.ast.lint(rule)
}
pub fn node_path_from_range(&self, range: SourceRange) -> Option<NodePath> {
NodePath::from_range(&self.ast, range)
}
pub fn recast(&self) -> String {
// Use the default options until we integrate into the UI the ability to change them.
self.ast.recast(&Default::default(), 0)