mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-08-04 02:08:17 +00:00
feat: replace param_completions with post type checking (#846)
* feat: replace param_completions with post type checking * dev: dirty code and snapshot
This commit is contained in:
parent
90626f0a5f
commit
256dd3b3a5
43 changed files with 500 additions and 746 deletions
|
@ -396,6 +396,26 @@ impl LocalContext {
|
|||
cache.get_or_init(|| self.shared.type_check(source)).clone()
|
||||
}
|
||||
|
||||
/// Get the type check information of a source file.
|
||||
pub(crate) fn type_check_by_id(&mut self, id: TypstFileId) -> Arc<TypeScheme> {
|
||||
let cache = &self.caches.modules.entry(id).or_default().type_check;
|
||||
cache
|
||||
.clone()
|
||||
.get_or_init(|| {
|
||||
let source = self.source_by_id(id).ok();
|
||||
source
|
||||
.map(|s| self.shared.type_check(&s))
|
||||
.unwrap_or_default()
|
||||
})
|
||||
.clone()
|
||||
}
|
||||
|
||||
pub(crate) fn type_of_span(&mut self, s: Span) -> Option<Ty> {
|
||||
let scheme = self.type_check_by_id(s.id()?);
|
||||
let ty = scheme.type_of_span(s)?;
|
||||
Some(scheme.simplify(ty, false))
|
||||
}
|
||||
|
||||
pub(crate) fn def_docs(&mut self, def: &Definition) -> Option<DefDocs> {
|
||||
// let plain_docs = sym.head.docs.as_deref();
|
||||
// let plain_docs = plain_docs.or(sym.head.oneliner.as_deref());
|
||||
|
@ -759,10 +779,6 @@ impl SharedContext {
|
|||
definition(self, source, doc, deref_target)
|
||||
}
|
||||
|
||||
pub(crate) fn type_of(self: &Arc<Self>, rr: &SyntaxNode) -> Option<Ty> {
|
||||
self.type_of_span(rr.span())
|
||||
}
|
||||
|
||||
pub(crate) fn type_of_span(self: &Arc<Self>, s: Span) -> Option<Ty> {
|
||||
self.type_of_span_(&self.source_by_id(s.id()?).ok()?, s)
|
||||
}
|
||||
|
@ -787,11 +803,6 @@ impl SharedContext {
|
|||
analyze_signature(self, SignatureTarget::Def(source, def))
|
||||
}
|
||||
|
||||
pub(crate) fn sig_of_func(self: &Arc<Self>, func: Func) -> Signature {
|
||||
log::debug!("check runtime func {func:?}");
|
||||
analyze_signature(self, SignatureTarget::Runtime(func)).unwrap()
|
||||
}
|
||||
|
||||
pub(crate) fn sig_of_type(self: &Arc<Self>, ti: &TypeScheme, ty: Ty) -> Option<Signature> {
|
||||
super::sig_of_type(self, ti, ty)
|
||||
}
|
||||
|
|
|
@ -235,6 +235,10 @@ impl<'a> PostTypeChecker<'a> {
|
|||
log::debug!("post check call sig: {target:?} {sig:?}");
|
||||
let mut resp = SignatureReceiver::default();
|
||||
|
||||
// if set && !param.attrs.settable {
|
||||
// continue;
|
||||
// }
|
||||
|
||||
match &target {
|
||||
ParamTarget::Named(n) => {
|
||||
let ident = n.cast::<ast::Ident>()?.into();
|
||||
|
|
|
@ -81,11 +81,6 @@ pub struct PrimarySignature {
|
|||
}
|
||||
|
||||
impl PrimarySignature {
|
||||
/// Returns the type representation of the function.
|
||||
pub(crate) fn ty(&self) -> Ty {
|
||||
Ty::Func(self.sig_ty.clone())
|
||||
}
|
||||
|
||||
/// Returns the number of positional parameters of the function.
|
||||
pub fn pos_size(&self) -> usize {
|
||||
self.sig_ty.name_started as usize
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
source: crates/tinymist-query/src/completion.rs
|
||||
description: Completion on c( (98..100)
|
||||
description: Completion on c( (99..101)
|
||||
expression: "JsonRepr::new_pure(results)"
|
||||
input_file: crates/tinymist-query/src/fixtures/completion/base.typ
|
||||
---
|
||||
|
@ -14,8 +14,9 @@ input_file: crates/tinymist-query/src/fixtures/completion/base.typ
|
|||
"labelDetails": {
|
||||
"description": "() => 1"
|
||||
},
|
||||
"sortText": "000",
|
||||
"textEdit": {
|
||||
"newText": "aa(${1:})",
|
||||
"newText": "aa()${1:}",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
|
@ -34,8 +35,9 @@ input_file: crates/tinymist-query/src/fixtures/completion/base.typ
|
|||
"labelDetails": {
|
||||
"description": "() => 1"
|
||||
},
|
||||
"sortText": "001",
|
||||
"textEdit": {
|
||||
"newText": "aab(${1:})",
|
||||
"newText": "aab()${1:}",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
|
@ -54,8 +56,9 @@ input_file: crates/tinymist-query/src/fixtures/completion/base.typ
|
|||
"labelDetails": {
|
||||
"description": "() => 1"
|
||||
},
|
||||
"sortText": "002",
|
||||
"textEdit": {
|
||||
"newText": "aabc(${1:})",
|
||||
"newText": "aabc()${1:}",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
|
@ -74,8 +77,9 @@ input_file: crates/tinymist-query/src/fixtures/completion/base.typ
|
|||
"labelDetails": {
|
||||
"description": "() => 1"
|
||||
},
|
||||
"sortText": "003",
|
||||
"textEdit": {
|
||||
"newText": "aac(${1:})",
|
||||
"newText": "aac()${1:}",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
|
@ -99,8 +103,9 @@ input_file: crates/tinymist-query/src/fixtures/completion/base.typ
|
|||
"labelDetails": {
|
||||
"description": "() => 1"
|
||||
},
|
||||
"sortText": "002",
|
||||
"textEdit": {
|
||||
"newText": "aabc(${1:})",
|
||||
"newText": "aabc()${1:}",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
|
@ -119,8 +124,9 @@ input_file: crates/tinymist-query/src/fixtures/completion/base.typ
|
|||
"labelDetails": {
|
||||
"description": "() => 1"
|
||||
},
|
||||
"sortText": "003",
|
||||
"textEdit": {
|
||||
"newText": "aac(${1:})",
|
||||
"newText": "aac()${1:}",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
source: crates/tinymist-query/src/completion.rs
|
||||
description: Completion on t (132..133)
|
||||
description: Completion on t (135..136)
|
||||
expression: "JsonRepr::new_pure(results)"
|
||||
input_file: crates/tinymist-query/src/fixtures/completion/cite_heading.typ
|
||||
---
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
source: crates/tinymist-query/src/completion.rs
|
||||
description: Completion on (22..23)
|
||||
description: Completion on (23..24)
|
||||
expression: "JsonRepr::new_pure(results)"
|
||||
input_file: crates/tinymist-query/src/fixtures/completion/colon_markup.typ
|
||||
---
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
source: crates/tinymist-query/src/completion.rs
|
||||
description: Completion on (22..23)
|
||||
description: Completion on (23..24)
|
||||
expression: "JsonRepr::new_pure(results)"
|
||||
input_file: crates/tinymist-query/src/fixtures/completion/colon_math.typ
|
||||
---
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
source: crates/tinymist-query/src/completion.rs
|
||||
description: Completion on (63..64)
|
||||
description: Completion on (65..66)
|
||||
expression: "JsonRepr::new_pure(results)"
|
||||
input_file: crates/tinymist-query/src/fixtures/completion/colon_param.typ
|
||||
---
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
source: crates/tinymist-query/src/completion.rs
|
||||
description: Completion on (92..93)
|
||||
description: Completion on (93..94)
|
||||
expression: "JsonRepr::new_pure(results)"
|
||||
input_file: crates/tinymist-query/src/fixtures/completion/fp_dict_filter.typ
|
||||
---
|
||||
|
@ -9,7 +9,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/fp_dict_filter.typ
|
|||
"isIncomplete": false,
|
||||
"items": [
|
||||
{
|
||||
"kind": 21,
|
||||
"kind": 6,
|
||||
"label": "a",
|
||||
"textEdit": {
|
||||
"newText": "a",
|
||||
|
@ -26,7 +26,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/fp_dict_filter.typ
|
|||
}
|
||||
},
|
||||
{
|
||||
"kind": 21,
|
||||
"kind": 6,
|
||||
"label": "ab",
|
||||
"textEdit": {
|
||||
"newText": "ab",
|
||||
|
@ -43,7 +43,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/fp_dict_filter.typ
|
|||
}
|
||||
},
|
||||
{
|
||||
"kind": 21,
|
||||
"kind": 6,
|
||||
"label": "ac",
|
||||
"textEdit": {
|
||||
"newText": "ac",
|
||||
|
@ -60,7 +60,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/fp_dict_filter.typ
|
|||
}
|
||||
},
|
||||
{
|
||||
"kind": 21,
|
||||
"kind": 6,
|
||||
"label": "ad",
|
||||
"textEdit": {
|
||||
"newText": "ad",
|
||||
|
|
|
@ -68,7 +68,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/func_args.typ
|
|||
"labelDetails": {
|
||||
"description": "type"
|
||||
},
|
||||
"sortText": "050",
|
||||
"sortText": "052",
|
||||
"textEdit": {
|
||||
"newText": "content",
|
||||
"range": {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
source: crates/tinymist-query/src/completion.rs
|
||||
description: Completion on u (371..372)
|
||||
description: Completion on u (372..373)
|
||||
expression: "JsonRepr::new_pure(results)"
|
||||
input_file: crates/tinymist-query/src/fixtures/completion/func_args_after.typ
|
||||
---
|
||||
|
|
|
@ -32,7 +32,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/func_builtin_args.typ
|
|||
"labelDetails": {
|
||||
"description": "(int, content, gutter: relative) => columns"
|
||||
},
|
||||
"sortText": "054",
|
||||
"sortText": "056",
|
||||
"textEdit": {
|
||||
"newText": "columns(${1:})",
|
||||
"range": {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
source: crates/tinymist-query/src/completion.rs
|
||||
description: Completion on c( (62..64)
|
||||
description: Completion on c( (63..65)
|
||||
expression: "JsonRepr::new_pure(results)"
|
||||
input_file: crates/tinymist-query/src/fixtures/completion/func_params.typ
|
||||
---
|
||||
|
|
|
@ -68,7 +68,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/func_with_args.typ
|
|||
"labelDetails": {
|
||||
"description": "type"
|
||||
},
|
||||
"sortText": "050",
|
||||
"sortText": "052",
|
||||
"textEdit": {
|
||||
"newText": "content",
|
||||
"range": {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
source: crates/tinymist-query/src/completion.rs
|
||||
description: Completion on c( (83..85)
|
||||
description: Completion on c( (84..86)
|
||||
expression: "JsonRepr::new_pure(results)"
|
||||
input_file: crates/tinymist-query/src/fixtures/completion/import.typ
|
||||
---
|
||||
|
@ -14,8 +14,9 @@ input_file: crates/tinymist-query/src/fixtures/completion/import.typ
|
|||
"labelDetails": {
|
||||
"description": "() => 1"
|
||||
},
|
||||
"sortText": "000",
|
||||
"textEdit": {
|
||||
"newText": "aab(${1:})",
|
||||
"newText": "aab()${1:}",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
|
@ -34,8 +35,9 @@ input_file: crates/tinymist-query/src/fixtures/completion/import.typ
|
|||
"labelDetails": {
|
||||
"description": "() => 1"
|
||||
},
|
||||
"sortText": "001",
|
||||
"textEdit": {
|
||||
"newText": "aac(${1:})",
|
||||
"newText": "aac()${1:}",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
|
@ -59,8 +61,9 @@ input_file: crates/tinymist-query/src/fixtures/completion/import.typ
|
|||
"labelDetails": {
|
||||
"description": "() => 1"
|
||||
},
|
||||
"sortText": "001",
|
||||
"textEdit": {
|
||||
"newText": "aac(${1:})",
|
||||
"newText": "aac()${1:}",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
source: crates/tinymist-query/src/completion.rs
|
||||
description: Completion on c( (73..75)
|
||||
description: Completion on c( (74..76)
|
||||
expression: "JsonRepr::new_pure(results)"
|
||||
input_file: crates/tinymist-query/src/fixtures/completion/import_self.typ
|
||||
---
|
||||
|
@ -12,7 +12,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/import_self.typ
|
|||
"kind": 9,
|
||||
"label": "base",
|
||||
"labelDetails": {
|
||||
"description": "base.typ"
|
||||
"description": "module(base)"
|
||||
},
|
||||
"textEdit": {
|
||||
"newText": "base",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
source: crates/tinymist-query/src/completion.rs
|
||||
description: Completion on c( (76..78)
|
||||
description: Completion on c( (77..79)
|
||||
expression: "JsonRepr::new_pure(results)"
|
||||
input_file: crates/tinymist-query/src/fixtures/completion/import_star.typ
|
||||
---
|
||||
|
@ -12,30 +12,11 @@ input_file: crates/tinymist-query/src/fixtures/completion/import_star.typ
|
|||
"kind": 3,
|
||||
"label": "aa",
|
||||
"labelDetails": {
|
||||
"description": "() => 1"
|
||||
"description": "() => any"
|
||||
},
|
||||
"sortText": "000",
|
||||
"textEdit": {
|
||||
"newText": "aa(${1:})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
"line": 2
|
||||
},
|
||||
"start": {
|
||||
"character": 1,
|
||||
"line": 2
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"kind": 3,
|
||||
"label": "aa.with",
|
||||
"labelDetails": {
|
||||
"description": "() => 1"
|
||||
},
|
||||
"textEdit": {
|
||||
"newText": "aa.with(${1:})",
|
||||
"newText": "aa()${1:}",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
|
@ -52,10 +33,11 @@ input_file: crates/tinymist-query/src/fixtures/completion/import_star.typ
|
|||
"kind": 3,
|
||||
"label": "aab",
|
||||
"labelDetails": {
|
||||
"description": "() => 1"
|
||||
"description": "() => any"
|
||||
},
|
||||
"sortText": "001",
|
||||
"textEdit": {
|
||||
"newText": "aab(${1:})",
|
||||
"newText": "aab()${1:}",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
|
@ -72,10 +54,11 @@ input_file: crates/tinymist-query/src/fixtures/completion/import_star.typ
|
|||
"kind": 3,
|
||||
"label": "aabc",
|
||||
"labelDetails": {
|
||||
"description": "() => 1"
|
||||
"description": "() => any"
|
||||
},
|
||||
"sortText": "002",
|
||||
"textEdit": {
|
||||
"newText": "aabc(${1:})",
|
||||
"newText": "aabc()${1:}",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
|
@ -92,10 +75,11 @@ input_file: crates/tinymist-query/src/fixtures/completion/import_star.typ
|
|||
"kind": 3,
|
||||
"label": "aac",
|
||||
"labelDetails": {
|
||||
"description": "() => 1"
|
||||
"description": "() => any"
|
||||
},
|
||||
"sortText": "003",
|
||||
"textEdit": {
|
||||
"newText": "aac(${1:})",
|
||||
"newText": "aac()${1:}",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
|
@ -117,10 +101,11 @@ input_file: crates/tinymist-query/src/fixtures/completion/import_star.typ
|
|||
"kind": 3,
|
||||
"label": "aabc",
|
||||
"labelDetails": {
|
||||
"description": "() => 1"
|
||||
"description": "() => any"
|
||||
},
|
||||
"sortText": "002",
|
||||
"textEdit": {
|
||||
"newText": "aabc(${1:})",
|
||||
"newText": "aabc()${1:}",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
|
@ -137,10 +122,11 @@ input_file: crates/tinymist-query/src/fixtures/completion/import_star.typ
|
|||
"kind": 3,
|
||||
"label": "aac",
|
||||
"labelDetails": {
|
||||
"description": "() => 1"
|
||||
"description": "() => any"
|
||||
},
|
||||
"sortText": "003",
|
||||
"textEdit": {
|
||||
"newText": "aac(${1:})",
|
||||
"newText": "aac()${1:}",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
source: crates/tinymist-query/src/completion.rs
|
||||
description: Completion on c( (69..71)
|
||||
description: Completion on c( (70..72)
|
||||
expression: "JsonRepr::new_pure(results)"
|
||||
input_file: crates/tinymist-query/src/fixtures/completion/item_shadow.typ
|
||||
---
|
||||
|
@ -14,8 +14,9 @@ input_file: crates/tinymist-query/src/fixtures/completion/item_shadow.typ
|
|||
"labelDetails": {
|
||||
"description": "() => 1"
|
||||
},
|
||||
"sortText": "000",
|
||||
"textEdit": {
|
||||
"newText": "aa(${1:})",
|
||||
"newText": "aa()${1:}",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
|
@ -34,8 +35,9 @@ input_file: crates/tinymist-query/src/fixtures/completion/item_shadow.typ
|
|||
"labelDetails": {
|
||||
"description": "() => 1"
|
||||
},
|
||||
"sortText": "001",
|
||||
"textEdit": {
|
||||
"newText": "aac(${1:})",
|
||||
"newText": "aac()${1:}",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
|
@ -59,8 +61,9 @@ input_file: crates/tinymist-query/src/fixtures/completion/item_shadow.typ
|
|||
"labelDetails": {
|
||||
"description": "() => 1"
|
||||
},
|
||||
"sortText": "001",
|
||||
"textEdit": {
|
||||
"newText": "aac(${1:})",
|
||||
"newText": "aac()${1:}",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
source: crates/tinymist-query/src/completion.rs
|
||||
description: Completion on (60..61)
|
||||
description: Completion on (61..62)
|
||||
expression: "JsonRepr::new_pure(results)"
|
||||
input_file: crates/tinymist-query/src/fixtures/completion/let-context.typ
|
||||
---
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
source: crates/tinymist-query/src/completion.rs
|
||||
description: Completion on c( (94..96)
|
||||
description: Completion on c( (95..97)
|
||||
expression: "JsonRepr::new_pure(results)"
|
||||
input_file: crates/tinymist-query/src/fixtures/completion/let.typ
|
||||
---
|
||||
|
@ -14,8 +14,9 @@ input_file: crates/tinymist-query/src/fixtures/completion/let.typ
|
|||
"labelDetails": {
|
||||
"description": "() => 1"
|
||||
},
|
||||
"sortText": "000",
|
||||
"textEdit": {
|
||||
"newText": "aa(${1:})",
|
||||
"newText": "aa()${1:}",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
|
@ -34,6 +35,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/let.typ
|
|||
"labelDetails": {
|
||||
"description": "1"
|
||||
},
|
||||
"sortText": "001",
|
||||
"textEdit": {
|
||||
"newText": "aab",
|
||||
"range": {
|
||||
|
@ -54,6 +56,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/let.typ
|
|||
"labelDetails": {
|
||||
"description": "1"
|
||||
},
|
||||
"sortText": "002",
|
||||
"textEdit": {
|
||||
"newText": "aabc",
|
||||
"range": {
|
||||
|
@ -74,8 +77,9 @@ input_file: crates/tinymist-query/src/fixtures/completion/let.typ
|
|||
"labelDetails": {
|
||||
"description": "() => 1"
|
||||
},
|
||||
"sortText": "003",
|
||||
"textEdit": {
|
||||
"newText": "aac(${1:})",
|
||||
"newText": "aac()${1:}",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
|
@ -99,6 +103,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/let.typ
|
|||
"labelDetails": {
|
||||
"description": "1"
|
||||
},
|
||||
"sortText": "002",
|
||||
"textEdit": {
|
||||
"newText": "aabc",
|
||||
"range": {
|
||||
|
@ -119,8 +124,9 @@ input_file: crates/tinymist-query/src/fixtures/completion/let.typ
|
|||
"labelDetails": {
|
||||
"description": "() => 1"
|
||||
},
|
||||
"sortText": "003",
|
||||
"textEdit": {
|
||||
"newText": "aac(${1:})",
|
||||
"newText": "aac()${1:}",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 4,
|
||||
|
|
|
@ -9,7 +9,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/modify_string.typ
|
|||
"isIncomplete": false,
|
||||
"items": [
|
||||
{
|
||||
"kind": 21,
|
||||
"kind": 6,
|
||||
"label": "\"New Computer Modern\"",
|
||||
"sortText": "003",
|
||||
"textEdit": {
|
||||
|
@ -32,7 +32,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/modify_string.typ
|
|||
"isIncomplete": false,
|
||||
"items": [
|
||||
{
|
||||
"kind": 21,
|
||||
"kind": 6,
|
||||
"label": "\"New Computer Modern\"",
|
||||
"sortText": "003",
|
||||
"textEdit": {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
source: crates/tinymist-query/src/completion.rs
|
||||
description: "Completion on \"\" (53..55)"
|
||||
description: "Completion on \"\" (54..56)"
|
||||
expression: "JsonRepr::new_pure(results)"
|
||||
input_file: crates/tinymist-query/src/fixtures/completion/modify_string_2.typ
|
||||
---
|
||||
|
@ -9,7 +9,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/modify_string_2.typ
|
|||
"isIncomplete": false,
|
||||
"items": [
|
||||
{
|
||||
"kind": 21,
|
||||
"kind": 6,
|
||||
"label": "\"New Computer Modern\"",
|
||||
"sortText": "003",
|
||||
"textEdit": {
|
||||
|
@ -32,7 +32,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/modify_string_2.typ
|
|||
"isIncomplete": false,
|
||||
"items": [
|
||||
{
|
||||
"kind": 21,
|
||||
"kind": 6,
|
||||
"label": "\"New Computer Modern\"",
|
||||
"sortText": "003",
|
||||
"textEdit": {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
source: crates/tinymist-query/src/completion.rs
|
||||
description: Completion on / (30..31)
|
||||
description: Completion on / (87..88)
|
||||
expression: "JsonRepr::new_pure(results)"
|
||||
input_file: crates/tinymist-query/src/fixtures/completion/set.typ
|
||||
---
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
source: crates/tinymist-query/src/completion.rs
|
||||
description: Completion on / (75..76)
|
||||
description: Completion on / (104..105)
|
||||
expression: "JsonRepr::new_pure(results)"
|
||||
input_file: crates/tinymist-query/src/fixtures/completion/show.typ
|
||||
---
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
source: crates/tinymist-query/src/completion.rs
|
||||
description: Completion on / (80..81)
|
||||
description: Completion on / (93..94)
|
||||
expression: "JsonRepr::new_pure(results)"
|
||||
input_file: crates/tinymist-query/src/fixtures/completion/show_transform.typ
|
||||
---
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
source: crates/tinymist-query/src/completion.rs
|
||||
description: Completion on ) (62..63)
|
||||
description: Completion on ) (63..64)
|
||||
expression: "JsonRepr::new_pure(results)"
|
||||
input_file: crates/tinymist-query/src/fixtures/completion/sig_dict.typ
|
||||
---
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
source: crates/tinymist-query/src/completion.rs
|
||||
description: Completion on ) (74..75)
|
||||
description: Completion on ) (75..76)
|
||||
expression: "JsonRepr::new_pure(results)"
|
||||
input_file: crates/tinymist-query/src/fixtures/completion/sig_dict_rest.typ
|
||||
---
|
||||
|
|
|
@ -12,11 +12,11 @@ input_file: crates/tinymist-query/src/fixtures/pkgs/touying-core-slides.typ
|
|||
"kind": 3,
|
||||
"label": "config-xxx",
|
||||
"labelDetails": {
|
||||
"description": "() => none"
|
||||
"description": "() => any"
|
||||
},
|
||||
"sortText": "048",
|
||||
"sortText": "050",
|
||||
"textEdit": {
|
||||
"newText": "config-xxx(${1:})",
|
||||
"newText": "config-xxx()${1:}",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 15,
|
||||
|
|
|
@ -50,7 +50,7 @@ input_file: crates/tinymist-query/src/fixtures/pkgs/touying-core-slides.typ
|
|||
"labelDetails": {
|
||||
"description": "(content, gap: length, justify: bool) => repeat"
|
||||
},
|
||||
"sortText": "238",
|
||||
"sortText": "245",
|
||||
"textEdit": {
|
||||
"newText": "repeat(${1:})",
|
||||
"range": {
|
||||
|
|
|
@ -27,14 +27,14 @@ input_file: crates/tinymist-query/src/fixtures/pkgs/touying-utils-cover-with-rec
|
|||
}
|
||||
},
|
||||
{
|
||||
"kind": 7,
|
||||
"kind": 3,
|
||||
"label": "stroke",
|
||||
"labelDetails": {
|
||||
"description": "type"
|
||||
},
|
||||
"sortText": "280",
|
||||
"sortText": "289",
|
||||
"textEdit": {
|
||||
"newText": "stroke",
|
||||
"newText": "stroke(${1:})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 17,
|
||||
|
|
|
@ -27,14 +27,14 @@ input_file: crates/tinymist-query/src/fixtures/pkgs/touying-utils-current-headin
|
|||
}
|
||||
},
|
||||
{
|
||||
"kind": 7,
|
||||
"kind": 3,
|
||||
"label": "int",
|
||||
"labelDetails": {
|
||||
"description": "type"
|
||||
},
|
||||
"sortText": "125",
|
||||
"sortText": "131",
|
||||
"textEdit": {
|
||||
"newText": "int",
|
||||
"newText": "int(${1:})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 24,
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
---
|
||||
source: crates/tinymist-query/src/completion.rs
|
||||
description: Completion on / (76..77)
|
||||
description: Completion on / (77..78)
|
||||
expression: "JsonRepr::new_pure(results)"
|
||||
input_file: crates/tinymist-query/src/fixtures/completion-pkgs/touying-utils-current-heading.typ
|
||||
input_file: crates/tinymist-query/src/fixtures/pkgs/touying-utils-current-heading.typ
|
||||
---
|
||||
[
|
||||
{
|
||||
"isIncomplete": false,
|
||||
"items": [
|
||||
{
|
||||
"kind": 21,
|
||||
"kind": 6,
|
||||
"label": "true",
|
||||
"sortText": "000",
|
||||
"textEdit": {
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
---
|
||||
source: crates/tinymist-query/src/completion.rs
|
||||
description: Completion on / (66..67)
|
||||
description: Completion on / (67..68)
|
||||
expression: "JsonRepr::new_pure(results)"
|
||||
input_file: crates/tinymist-query/src/fixtures/completion-pkgs/touying-utils-current-heading.typ
|
||||
input_file: crates/tinymist-query/src/fixtures/pkgs/touying-utils-current-heading.typ
|
||||
---
|
||||
[
|
||||
{
|
||||
"isIncomplete": false,
|
||||
"items": [
|
||||
{
|
||||
"kind": 21,
|
||||
"kind": 6,
|
||||
"label": "9999",
|
||||
"sortText": "000",
|
||||
"textEdit": {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
---
|
||||
source: crates/tinymist-query/src/completion.rs
|
||||
description: Completion on / (77..78)
|
||||
description: Completion on / (78..79)
|
||||
expression: "JsonRepr::new_pure(results)"
|
||||
input_file: crates/tinymist-query/src/fixtures/completion-pkgs/touying-utils-current-heading.typ
|
||||
input_file: crates/tinymist-query/src/fixtures/pkgs/touying-utils-current-heading.typ
|
||||
---
|
||||
[
|
||||
{
|
||||
|
|
|
@ -9,7 +9,7 @@ input_file: crates/tinymist-query/src/fixtures/pkgs/touying-utils-markup-text.ty
|
|||
"isIncomplete": false,
|
||||
"items": [
|
||||
{
|
||||
"kind": 21,
|
||||
"kind": 6,
|
||||
"label": "0",
|
||||
"sortText": "000",
|
||||
"textEdit": {
|
||||
|
|
|
@ -9,7 +9,7 @@ input_file: crates/tinymist-query/src/fixtures/pkgs/touying-utils-markup-text.ty
|
|||
"isIncomplete": false,
|
||||
"items": [
|
||||
{
|
||||
"kind": 21,
|
||||
"kind": 6,
|
||||
"label": "\"md\"",
|
||||
"sortText": "000",
|
||||
"textEdit": {
|
||||
|
@ -27,7 +27,7 @@ input_file: crates/tinymist-query/src/fixtures/pkgs/touying-utils-markup-text.ty
|
|||
}
|
||||
},
|
||||
{
|
||||
"kind": 21,
|
||||
"kind": 6,
|
||||
"label": "\"typ\"",
|
||||
"sortText": "001",
|
||||
"textEdit": {
|
||||
|
@ -63,14 +63,14 @@ input_file: crates/tinymist-query/src/fixtures/pkgs/touying-utils-markup-text.ty
|
|||
}
|
||||
},
|
||||
{
|
||||
"kind": 7,
|
||||
"kind": 3,
|
||||
"label": "str",
|
||||
"labelDetails": {
|
||||
"description": "type"
|
||||
},
|
||||
"sortText": "273",
|
||||
"sortText": "281",
|
||||
"textEdit": {
|
||||
"newText": "str",
|
||||
"newText": "str(${1:})",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 19,
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
---
|
||||
source: crates/tinymist-query/src/completion.rs
|
||||
description: Completion on / (65..66)
|
||||
description: Completion on / (66..67)
|
||||
expression: "JsonRepr::new_pure(results)"
|
||||
input_file: crates/tinymist-query/src/fixtures/completion-pkgs/touying-utils-reconstruct.typ
|
||||
input_file: crates/tinymist-query/src/fixtures/pkgs/touying-utils-reconstruct.typ
|
||||
---
|
||||
[
|
||||
{
|
||||
"isIncomplete": false,
|
||||
"items": [
|
||||
{
|
||||
"kind": 21,
|
||||
"kind": 6,
|
||||
"label": "\"body\"",
|
||||
"sortText": "000",
|
||||
"textEdit": {
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
---
|
||||
source: crates/tinymist-query/src/completion.rs
|
||||
description: Completion on / (68..69)
|
||||
description: Completion on / (69..70)
|
||||
expression: "JsonRepr::new_pure(results)"
|
||||
input_file: crates/tinymist-query/src/fixtures/completion-pkgs/touying-utils-reconstruct.typ
|
||||
input_file: crates/tinymist-query/src/fixtures/pkgs/touying-utils-reconstruct.typ
|
||||
---
|
||||
[
|
||||
{
|
||||
"isIncomplete": false,
|
||||
"items": [
|
||||
{
|
||||
"kind": 21,
|
||||
"kind": 6,
|
||||
"label": "true",
|
||||
"sortText": "000",
|
||||
"textEdit": {
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
---
|
||||
source: crates/tinymist-query/src/completion.rs
|
||||
description: Completion on / (66..67)
|
||||
description: Completion on / (67..68)
|
||||
expression: "JsonRepr::new_pure(results)"
|
||||
input_file: crates/tinymist-query/src/fixtures/completion-pkgs/touying-utils-reconstruct.typ
|
||||
input_file: crates/tinymist-query/src/fixtures/pkgs/touying-utils-reconstruct.typ
|
||||
---
|
||||
[
|
||||
{
|
||||
"isIncomplete": false,
|
||||
"items": [
|
||||
{
|
||||
"kind": 21,
|
||||
"kind": 6,
|
||||
"label": "false",
|
||||
"sortText": "000",
|
||||
"textEdit": {
|
||||
|
|
|
@ -110,19 +110,20 @@ pub fn descending_decls<T>(
|
|||
}
|
||||
(DecenderItem::Sibling(..), ast::Expr::Import(mi)) => {
|
||||
// import items
|
||||
match mi.imports()? {
|
||||
ast::Imports::Wildcard => {
|
||||
match mi.imports() {
|
||||
Some(ast::Imports::Wildcard) => {
|
||||
if let Some(t) = recv(DescentDecl::ImportAll(mi)) {
|
||||
return Some(t);
|
||||
}
|
||||
}
|
||||
ast::Imports::Items(e) => {
|
||||
Some(ast::Imports::Items(e)) => {
|
||||
for item in e.iter() {
|
||||
if let Some(t) = recv(DescentDecl::Ident(item.bound_name())) {
|
||||
return Some(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
// import it self
|
||||
|
|
|
@ -7,7 +7,6 @@ use if_chain::if_chain;
|
|||
use serde::{Deserialize, Serialize};
|
||||
use typst::foundations::{fields_on, format_str, repr, Repr, StyleChain, Styles, Value};
|
||||
use typst::model::Document;
|
||||
use typst::syntax::ast::AstNode;
|
||||
use typst::syntax::{ast, is_id_continue, is_id_start, is_ident, LinkedNode, Source, SyntaxKind};
|
||||
use typst::text::RawElem;
|
||||
use typst::World;
|
||||
|
@ -44,7 +43,6 @@ pub fn autocomplete(
|
|||
|| complete_field_accesses(&mut ctx)
|
||||
|| complete_imports(&mut ctx)
|
||||
|| complete_rules(&mut ctx)
|
||||
|| complete_params(&mut ctx)
|
||||
|| complete_markup(&mut ctx)
|
||||
|| complete_math(&mut ctx)
|
||||
|| complete_code(&mut ctx, false)
|
||||
|
@ -672,80 +670,6 @@ fn show_rule_recipe_completions(ctx: &mut CompletionContext) {
|
|||
ctx.scope_completions(false, |value| matches!(value, Value::Func(_)));
|
||||
}
|
||||
|
||||
/// Complete call and set rule parameters.
|
||||
fn complete_params(ctx: &mut CompletionContext) -> bool {
|
||||
// Ensure that we are in a function call or set rule's argument list.
|
||||
let (callee, set, args) = if_chain! {
|
||||
if let Some(parent) = ctx.leaf.parent();
|
||||
if let Some(parent) = match parent.kind() {
|
||||
SyntaxKind::Named => parent.parent(),
|
||||
_ => Some(parent),
|
||||
};
|
||||
if let Some(args) = parent.get().cast::<ast::Args>();
|
||||
if let Some(grand) = parent.parent();
|
||||
if let Some(expr) = grand.get().cast::<ast::Expr>();
|
||||
let set = matches!(expr, ast::Expr::Set(_));
|
||||
if let Some(callee) = match expr {
|
||||
ast::Expr::FuncCall(call) => Some(call.callee()),
|
||||
ast::Expr::Set(set) => Some(set.target()),
|
||||
_ => None,
|
||||
};
|
||||
then {
|
||||
(callee, set, args)
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
// Find the piece of syntax that decides what we're completing.
|
||||
let mut deciding = ctx.leaf.clone();
|
||||
while !matches!(
|
||||
deciding.kind(),
|
||||
SyntaxKind::LeftParen | SyntaxKind::Comma | SyntaxKind::Colon
|
||||
) {
|
||||
let Some(prev) = deciding.prev_leaf() else {
|
||||
break;
|
||||
};
|
||||
deciding = prev;
|
||||
}
|
||||
|
||||
// Parameter values: "func(param:|)", "func(param: |)".
|
||||
if_chain! {
|
||||
if deciding.kind() == SyntaxKind::Colon;
|
||||
if let Some(prev) = deciding.prev_leaf();
|
||||
if let Some(param) = prev.get().cast::<ast::Ident>();
|
||||
then {
|
||||
if let Some(next) = deciding.next_leaf() {
|
||||
ctx.from = ctx.cursor.min(next.offset());
|
||||
}
|
||||
let parent = deciding.parent().unwrap();
|
||||
log::debug!("named param parent: {:?}", parent);
|
||||
// get type of this param
|
||||
let ty = ctx.ctx.type_of(param.to_untyped());
|
||||
log::debug!("named param type: {:?}", ty);
|
||||
|
||||
named_param_value_completions(ctx, callee, ¶m.into(), ty.as_ref());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Parameters: "func(|)", "func(hi|)", "func(12,|)".
|
||||
if_chain! {
|
||||
if matches!(deciding.kind(), SyntaxKind::LeftParen | SyntaxKind::Comma);
|
||||
if deciding.kind() != SyntaxKind::Comma || deciding.range().end <= ctx.cursor;
|
||||
then {
|
||||
if let Some(next) = deciding.next_leaf() {
|
||||
ctx.from = ctx.cursor.min(next.offset());
|
||||
}
|
||||
|
||||
param_completions(ctx, callee, set, args);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
/// Complete in code mode.
|
||||
fn complete_code(ctx: &mut CompletionContext, from_type: bool) -> bool {
|
||||
if matches!(
|
||||
|
@ -966,6 +890,7 @@ pub struct CompletionContext<'a> {
|
|||
pub trigger_parameter_hints: bool,
|
||||
pub trigger_named_completion: bool,
|
||||
pub from: usize,
|
||||
pub from_ty: Option<Ty>,
|
||||
pub completions: Vec<Completion>,
|
||||
pub completions2: Vec<lsp_types::CompletionItem>,
|
||||
pub incomplete: bool,
|
||||
|
@ -1006,6 +931,7 @@ impl<'a> CompletionContext<'a> {
|
|||
trigger_named_completion,
|
||||
explicit,
|
||||
from: cursor,
|
||||
from_ty: None,
|
||||
incomplete: true,
|
||||
completions: vec![],
|
||||
completions2: vec![],
|
||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue