mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-08-03 17:58:17 +00:00
dev: improve types when accessing element fields (#1062)
* dev: improve types when accessing element fields * test: update snapshot
This commit is contained in:
parent
223a142931
commit
7e3c0b2e18
6 changed files with 27 additions and 18 deletions
|
@ -10,10 +10,10 @@ snapshot_kind: text
|
|||
"isIncomplete": false,
|
||||
"items": [
|
||||
{
|
||||
"kind": 6,
|
||||
"kind": 7,
|
||||
"label": "text",
|
||||
"labelDetails": {
|
||||
"description": "any"
|
||||
"description": "str"
|
||||
},
|
||||
"textEdit": {
|
||||
"newText": "text",
|
||||
|
|
|
@ -10,10 +10,10 @@ snapshot_kind: text
|
|||
"isIncomplete": false,
|
||||
"items": [
|
||||
{
|
||||
"kind": 6,
|
||||
"kind": 7,
|
||||
"label": "text",
|
||||
"labelDetails": {
|
||||
"description": "any"
|
||||
"description": "str"
|
||||
},
|
||||
"textEdit": {
|
||||
"newText": "text",
|
||||
|
|
|
@ -10,10 +10,10 @@ snapshot_kind: text
|
|||
"isIncomplete": false,
|
||||
"items": [
|
||||
{
|
||||
"kind": 6,
|
||||
"kind": 7,
|
||||
"label": "text",
|
||||
"labelDetails": {
|
||||
"description": "any"
|
||||
"description": "str"
|
||||
},
|
||||
"textEdit": {
|
||||
"newText": "text, ",
|
||||
|
|
|
@ -10,10 +10,10 @@ snapshot_kind: text
|
|||
"isIncomplete": false,
|
||||
"items": [
|
||||
{
|
||||
"kind": 6,
|
||||
"kind": 7,
|
||||
"label": "text",
|
||||
"labelDetails": {
|
||||
"description": "any"
|
||||
"description": "str"
|
||||
},
|
||||
"textEdit": {
|
||||
"newText": "text",
|
||||
|
|
|
@ -10,10 +10,10 @@ snapshot_kind: text
|
|||
"isIncomplete": false,
|
||||
"items": [
|
||||
{
|
||||
"kind": 6,
|
||||
"kind": 7,
|
||||
"label": "text",
|
||||
"labelDetails": {
|
||||
"description": "any"
|
||||
"description": "str"
|
||||
},
|
||||
"textEdit": {
|
||||
"newText": "text",
|
||||
|
|
|
@ -770,17 +770,26 @@ impl IfaceChecker for CompletionScopeChecker<'_> {
|
|||
let Some(field_name) = val.field_name(field_id) else {
|
||||
continue;
|
||||
};
|
||||
let param_info = val.params().iter().find(|p| p.name == field_name);
|
||||
let param_docs = param_info.map(|p| p.docs.into());
|
||||
let ty_from_param = param_info.map(|f| Ty::from_cast_info(&f.input));
|
||||
|
||||
let sample_value = val.field_from_styles(field_id, styles).ok();
|
||||
let ty = sample_value.map_or(Ty::Any, |v| Ty::Builtin(BuiltinTy::Type(v.ty())));
|
||||
let ty_from_style = val
|
||||
.field_from_styles(field_id, styles)
|
||||
.ok()
|
||||
.map(|v| Ty::Builtin(BuiltinTy::Type(v.ty())));
|
||||
|
||||
self.defines.insert(field_name.into(), ty);
|
||||
let field_ty = match (ty_from_param, ty_from_style) {
|
||||
(Some(param), None) => Some(param),
|
||||
(Some(opt), Some(_)) | (None, Some(opt)) => Some(Ty::from_types(
|
||||
[opt, Ty::Builtin(BuiltinTy::None)].into_iter(),
|
||||
)),
|
||||
(None, None) => None,
|
||||
};
|
||||
|
||||
self.defines
|
||||
.insert(field_name.into(), field_ty.unwrap_or(Ty::Any));
|
||||
|
||||
let param_docs = val
|
||||
.params()
|
||||
.iter()
|
||||
.find(|p| p.name == field_name)
|
||||
.map(|p| p.docs.into());
|
||||
if let Some(docs) = param_docs {
|
||||
self.defines.docs.insert(field_name.into(), docs);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue