mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-07-24 21:23:45 +00:00
feat: find module and external definitions
This commit is contained in:
parent
7f839e6319
commit
e0c9d95c5a
13 changed files with 107 additions and 8 deletions
|
@ -409,22 +409,17 @@ pub(crate) fn find_definition<'a>(
|
|||
|
||||
let values = analyze_expr(world.deref(), &use_site);
|
||||
|
||||
let func_or_module = values.into_iter().find_map(|v| match &v {
|
||||
Value::Func(..) | Value::Module(..) => Some(v),
|
||||
let func = values.into_iter().find_map(|v| match &v {
|
||||
Value::Func(..) => Some(v),
|
||||
_ => None,
|
||||
});
|
||||
|
||||
Some(match func_or_module {
|
||||
Some(match func {
|
||||
Some(Value::Func(f)) => Definition::Func(FuncDefinition {
|
||||
value: f.clone(),
|
||||
span: f.span(),
|
||||
use_site,
|
||||
}),
|
||||
Some(Value::Module(m)) => {
|
||||
trace!("find module. {m:?}");
|
||||
// todo
|
||||
return None;
|
||||
}
|
||||
_ => {
|
||||
return match may_ident {
|
||||
ast::Expr::Ident(e) => find_syntax_definition(world, current, use_site, e.get()),
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
// path: base.typ
|
||||
#let f() = 1;
|
||||
-----
|
||||
#import "base.typ": f as one
|
||||
#(/* position after */ one);
|
|
@ -0,0 +1,5 @@
|
|||
// path: base.typ
|
||||
#let f() = 1;
|
||||
-----
|
||||
#import "base.typ": f
|
||||
#(/* position after */ f);
|
|
@ -0,0 +1,4 @@
|
|||
// path: base.typ
|
||||
-----
|
||||
#import "base.typ" as x
|
||||
#(/* position after */ x);
|
|
@ -0,0 +1,4 @@
|
|||
// path: base.typ
|
||||
-----
|
||||
#import "base.typ"
|
||||
#(/* position after */ base);
|
|
@ -0,0 +1,7 @@
|
|||
// path: base.typ
|
||||
#let f() = 1;
|
||||
-----
|
||||
.
|
||||
|
||||
#import "base.typ": *
|
||||
#(/* position after */ f);
|
|
@ -0,0 +1,7 @@
|
|||
// path: variable.typ
|
||||
#let x = 2;
|
||||
-----
|
||||
.
|
||||
|
||||
#import "variable.typ": *
|
||||
#(/* position after */ x);
|
|
@ -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_alias.typ
|
||||
---
|
||||
[
|
||||
{
|
||||
"originSelectionRange": "1:23:1:26",
|
||||
"targetRange": "0:6:0:8",
|
||||
"targetSelectionRange": "0:6:0:8"
|
||||
}
|
||||
]
|
|
@ -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_ident.typ
|
||||
---
|
||||
[
|
||||
{
|
||||
"originSelectionRange": "1:23:1:24",
|
||||
"targetRange": "0:6:0:8",
|
||||
"targetSelectionRange": "0:6:0:8"
|
||||
}
|
||||
]
|
|
@ -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_new_name.typ
|
||||
---
|
||||
[
|
||||
{
|
||||
"originSelectionRange": "1:23:1:24",
|
||||
"targetRange": "0:22:0:23",
|
||||
"targetSelectionRange": "0:22:0:23"
|
||||
}
|
||||
]
|
|
@ -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_self.typ
|
||||
---
|
||||
[
|
||||
{
|
||||
"originSelectionRange": "1:23:1:27",
|
||||
"targetRange": "0:8:0:18",
|
||||
"targetSelectionRange": "0:8:0:18"
|
||||
}
|
||||
]
|
|
@ -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_star.typ
|
||||
---
|
||||
[
|
||||
{
|
||||
"originSelectionRange": "3:23:3:24",
|
||||
"targetRange": "0:6:0:8",
|
||||
"targetSelectionRange": "0:6:0:8"
|
||||
}
|
||||
]
|
|
@ -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_star_variable.typ
|
||||
---
|
||||
[
|
||||
{
|
||||
"originSelectionRange": "3:23:3:24",
|
||||
"targetRange": "0:1:0:10",
|
||||
"targetSelectionRange": "0:1:0:10"
|
||||
}
|
||||
]
|
Loading…
Add table
Add a link
Reference in a new issue