dev: improve types when accessing element fields (#1062)

* dev: improve types when accessing element fields

* test: update snapshot
This commit is contained in:
Myriad-Dreamin 2024-12-24 10:34:16 +08:00 committed by GitHub
parent 223a142931
commit 7e3c0b2e18
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 27 additions and 18 deletions

View file

@ -10,10 +10,10 @@ snapshot_kind: text
"isIncomplete": false,
"items": [
{
"kind": 6,
"kind": 7,
"label": "text",
"labelDetails": {
"description": "any"
"description": "str"
},
"textEdit": {
"newText": "text",

View file

@ -10,10 +10,10 @@ snapshot_kind: text
"isIncomplete": false,
"items": [
{
"kind": 6,
"kind": 7,
"label": "text",
"labelDetails": {
"description": "any"
"description": "str"
},
"textEdit": {
"newText": "text",

View file

@ -10,10 +10,10 @@ snapshot_kind: text
"isIncomplete": false,
"items": [
{
"kind": 6,
"kind": 7,
"label": "text",
"labelDetails": {
"description": "any"
"description": "str"
},
"textEdit": {
"newText": "text, ",

View file

@ -10,10 +10,10 @@ snapshot_kind: text
"isIncomplete": false,
"items": [
{
"kind": 6,
"kind": 7,
"label": "text",
"labelDetails": {
"description": "any"
"description": "str"
},
"textEdit": {
"newText": "text",

View file

@ -10,10 +10,10 @@ snapshot_kind: text
"isIncomplete": false,
"items": [
{
"kind": 6,
"kind": 7,
"label": "text",
"labelDetails": {
"description": "any"
"description": "str"
},
"textEdit": {
"newText": "text",

View file

@ -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);
}