feat: ignore type completion having no constructors (#1481)

This commit is contained in:
Myriad-Dreamin 2025-03-10 22:13:16 +08:00 committed by GitHub
parent 7b35973741
commit 62815ae028
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 101 additions and 42 deletions

View file

@ -308,7 +308,16 @@ impl TypeCompletionWorker<'_, '_, '_, '_> {
true,
Some(docs),
);
} else {
} else if ty.scope().iter().any(|(_, b)| {
if let Value::Func(f) = b.read() {
let pos = f
.params()
.and_then(|params| params.iter().find(|s| s.required));
pos.is_none_or(|pos| pos.name != "self")
} else {
true
}
}) {
let docs = docs.unwrap_or(ty.docs());
self.base.push_completion(Completion {
kind: CompletionKind::Syntax,
@ -318,6 +327,11 @@ impl TypeCompletionWorker<'_, '_, '_, '_> {
..Completion::default()
});
}
// Otherwise, if the type doesn't have constructor and
// associated scope, we do nothing here. For example,
// - complete `content` doesn't make much sense.
// - complete `color` is okay because it has associated
// constructors in scope.`
}
BuiltinTy::Element(elem) => {
self.base.value_completion(

View file

@ -3,7 +3,6 @@ source: crates/tinymist-query/src/completion.rs
description: "Completion on ] (52..53)"
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/bracket_strong_delta.typ
snapshot_kind: text
---
[
{
@ -15,7 +14,7 @@ snapshot_kind: text
"labelDetails": {
"description": "int"
},
"sortText": "001",
"sortText": "000",
"textEdit": {
"newText": "delta: ${1:})",
"range": {

View file

@ -3,7 +3,6 @@ source: crates/tinymist-query/src/completion.rs
description: "Completion on ] (52..53)"
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/bracket_strong_delta2.typ
snapshot_kind: text
---
[
{
@ -15,7 +14,7 @@ snapshot_kind: text
"labelDetails": {
"description": "int"
},
"sortText": "001",
"sortText": "000",
"textEdit": {
"newText": "delta: ${1:}",
"range": {

View file

@ -3,30 +3,10 @@ source: crates/tinymist-query/src/completion.rs
description: Completion on (65..66)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/colon_param.typ
snapshot_kind: text
---
[
{
"isIncomplete": false,
"items": [
{
"kind": 15,
"label": "length",
"sortText": "000",
"textEdit": {
"newText": " ${1:length}",
"range": {
"end": {
"character": 19,
"line": 2
},
"start": {
"character": 19,
"line": 2
}
}
}
}
]
"items": []
}
]

View file

@ -3,7 +3,6 @@ source: crates/tinymist-query/src/completion.rs
description: Completion on / (30..31)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/func_builtin_args.typ
snapshot_kind: text
---
[
{
@ -36,7 +35,7 @@ snapshot_kind: text
"labelDetails": {
"description": "(int, content, gutter: relative) => columns"
},
"sortText": "040",
"sortText": "039",
"textEdit": {
"newText": "columns(${1:})",
"range": {

View file

@ -3,7 +3,6 @@ source: crates/tinymist-query/src/completion.rs
description: Completion on / (41..42)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/func_where_args.typ
snapshot_kind: text
---
[
{
@ -15,7 +14,7 @@ snapshot_kind: text
"labelDetails": {
"description": "auto | int"
},
"sortText": "004",
"sortText": "003",
"textEdit": {
"newText": "level: ${1:}",
"range": {

View file

@ -3,7 +3,6 @@ source: crates/tinymist-query/src/completion.rs
description: Completion on o (31..33)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/half_completion.typ
snapshot_kind: text
---
[
{
@ -15,7 +14,7 @@ snapshot_kind: text
"labelDetails": {
"description": "array | text.font"
},
"sortText": "011",
"sortText": "010",
"textEdit": {
"newText": "font: ${1:}, ",
"range": {
@ -41,7 +40,7 @@ snapshot_kind: text
"labelDetails": {
"description": "array | text.font"
},
"sortText": "011",
"sortText": "010",
"textEdit": {
"newText": "font: ${1:}",
"range": {

View file

@ -3,7 +3,6 @@ source: crates/tinymist-query/src/completion.rs
description: Completion on n (32..33)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/keyword_ident.typ
snapshot_kind: text
---
[
{
@ -15,7 +14,7 @@ snapshot_kind: text
"labelDetails": {
"description": "inset"
},
"sortText": "007",
"sortText": "006",
"textEdit": {
"newText": "inset: ${1:}",
"range": {

View file

@ -32,7 +32,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/math_call_in_call.typ
"labelDetails": {
"description": "(content, size: relative) => content"
},
"sortText": "058",
"sortText": "057",
"textEdit": {
"newText": "abs(${1:})",
"range": {

View file

@ -14,7 +14,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/math_call_in_call2.typ
"labelDetails": {
"description": "(content, size: relative) => content"
},
"sortText": "057",
"sortText": "056",
"textEdit": {
"newText": "abs(${1:})",
"range": {

View file

@ -14,7 +14,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/math_ident_in_call2.ty
"labelDetails": {
"description": "(content, size: relative) => content"
},
"sortText": "231",
"sortText": "230",
"textEdit": {
"newText": "norm(${1:})",
"range": {

View file

@ -3,7 +3,6 @@ source: crates/tinymist-query/src/completion.rs
description: Completion on / (35..36)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/set_param.typ
snapshot_kind: text
---
[
{
@ -15,7 +14,7 @@ snapshot_kind: text
"labelDetails": {
"description": "color"
},
"sortText": "010",
"sortText": "009",
"textEdit": {
"newText": "fill: ${1:}",
"range": {

View file

@ -0,0 +1,34 @@
---
source: crates/tinymist-query/src/completion.rs
description: Completion on ) (27..28)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/type_dir.typ
---
[
{
"isIncomplete": false,
"items": [
{
"kind": 6,
"label": "start",
"labelDetails": {
"description": "alignment"
},
"sortText": "183",
"textEdit": {
"newText": "start",
"range": {
"end": {
"character": 7,
"line": 1
},
"start": {
"character": 7,
"line": 1
}
}
}
}
]
}
]

View file

@ -0,0 +1,34 @@
---
source: crates/tinymist-query/src/completion.rs
description: Completion on ) (30..31)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/type_naive_completion.typ
---
[
{
"isIncomplete": false,
"items": [
{
"kind": 7,
"label": "content",
"labelDetails": {
"description": "type"
},
"sortText": "032",
"textEdit": {
"newText": "content",
"range": {
"end": {
"character": 8,
"line": 1
},
"start": {
"character": 8,
"line": 1
}
}
}
}
]
}
]

View file

@ -0,0 +1,2 @@
/// contains: start
#place()/* range -1..0 */

View file

@ -0,0 +1,2 @@
/// contains: content
#strong()/* range -1..0 */

View file

@ -14,7 +14,7 @@ input_file: crates/tinymist-query/src/fixtures/pkgs/touying-utils-cover-with-rec
"labelDetails": {
"description": "auto | color | int | ratio | type"
},
"sortText": "001",
"sortText": "000",
"textEdit": {
"newText": "fill: ${1:}",
"range": {
@ -35,7 +35,7 @@ input_file: crates/tinymist-query/src/fixtures/pkgs/touying-utils-cover-with-rec
"labelDetails": {
"description": "type"
},
"sortText": "188",
"sortText": "185",
"textEdit": {
"newText": "stroke(${1:})",
"range": {