mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-08-03 17:58:17 +00:00
feat: find module path destination
This commit is contained in:
parent
e0c9d95c5a
commit
549d74858f
3 changed files with 33 additions and 1 deletions
|
@ -90,11 +90,12 @@ fn advance_prev_adjacent(node: LinkedNode) -> Option<LinkedNode> {
|
|||
}
|
||||
}
|
||||
|
||||
fn find_source_by_import(
|
||||
pub fn find_source_by_import(
|
||||
world: Tracked<'_, dyn World>,
|
||||
current: TypstFileId,
|
||||
import_node: ast::ModuleImport,
|
||||
) -> Option<Source> {
|
||||
// todo: this could be vaild: import("path.typ"), where v is parenthesized
|
||||
let v = import_node.source();
|
||||
match v {
|
||||
ast::Expr::Str(s) => {
|
||||
|
@ -395,6 +396,22 @@ pub(crate) fn find_definition<'a>(
|
|||
is_ident_only = true;
|
||||
may_ident
|
||||
}
|
||||
ast::Expr::Str(..) => {
|
||||
if let Some(parent) = ancestor.parent() {
|
||||
let e = parent.cast::<ast::ModuleImport>()?;
|
||||
let source = find_source_by_import(world, current, e)?;
|
||||
let src = ancestor.find(e.source().span())?;
|
||||
return Some(Definition::Module(ModuleDefinition {
|
||||
module: source.id(),
|
||||
use_site: src,
|
||||
span: source.root().span(),
|
||||
}));
|
||||
}
|
||||
return None;
|
||||
}
|
||||
ast::Expr::Import(..) => {
|
||||
return None;
|
||||
}
|
||||
_ => {
|
||||
debug!("unsupported kind {kind:?}", kind = ancestor.kind());
|
||||
return None;
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
// path: base.typ
|
||||
-----
|
||||
#import /* position after */ "base.typ"
|
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
source: crates/tinymist-query/src/goto_definition.rs
|
||||
expression: "JsonRepr::new_redacted(result, &REDACT_LOC)"
|
||||
input_file: crates/tinymist-query/src/fixtures/goto_definition/import_path_inner.typ
|
||||
---
|
||||
[
|
||||
{
|
||||
"originSelectionRange": "0:29:0:39",
|
||||
"targetRange": "0:0:0:0",
|
||||
"targetSelectionRange": "0:0:0:0"
|
||||
}
|
||||
]
|
Loading…
Add table
Add a link
Reference in a new issue