feat(service): hide "index" inlay hint when identifier is present

This commit is contained in:
Pig Fang 2025-11-15 14:55:47 +08:00
parent 0037ed6d57
commit aead348f2a
No known key found for this signature in database
GPG key ID: A8198F548DADA9E2
9 changed files with 23 additions and 50 deletions

View file

@ -1,7 +1,9 @@
use crate::{
LanguageService,
binder::{SymbolKind, SymbolTable},
helpers, types_analyzer,
helpers,
idx::Idx,
types_analyzer,
};
use lspt::{InlayHint, InlayHintKind, InlayHintParams, Union2};
use rowan::ast::support;
@ -95,7 +97,10 @@ impl LanguageService {
});
}
if options.index
&& let Some(num) = symbol.idx.num
&& let Idx {
num: Some(num),
name: None,
} = symbol.idx
&& let Some(keyword) =
support::token(&symbol.key.to_node(&root), SyntaxKind::KEYWORD)
{
@ -151,7 +156,10 @@ impl LanguageService {
| SymbolKind::TableDef
| SymbolKind::TagDef => {
if options.index
&& let Some(num) = symbol.idx.num
&& let Idx {
num: Some(num),
name: None,
} = symbol.idx
&& let Some(keyword) =
support::token(&symbol.key.to_node(&root), SyntaxKind::KEYWORD)
{
@ -172,7 +180,10 @@ impl LanguageService {
}
SymbolKind::Param | SymbolKind::Local | SymbolKind::FieldDef => {
if options.index
&& let Some(num) = symbol.idx.num
&& let Idx {
num: Some(num),
name: None,
} = symbol.idx
{
let end = support::token(&symbol.key.to_node(&root), SyntaxKind::KEYWORD)
.filter(|token| matches!(token.text(), "param" | "local" | "field"))

View file

@ -324,8 +324,8 @@ fn index_only() {
let uri = "untitled:test".to_string();
let source = "
(module
(global $g i32)
(func (param $p i32) (param f32 i64) (local (ref 0)))
(global i32)
(func (param i32) (param f32 i64) (local (ref 0)))
(memory 1 2)
(table 1 2 funcref)
(type (struct (field (mut i32))))

View file

@ -10,13 +10,5 @@ expression: response
},
"label": "(func $name)",
"paddingLeft": true
},
{
"position": {
"line": 2,
"character": 9
},
"label": "(;0;)",
"paddingLeft": true
}
]

View file

@ -3,14 +3,6 @@ source: crates/service/tests/inlay_hint/mod.rs
expression: response
---
[
{
"position": {
"line": 2,
"character": 11
},
"label": "(;0;)",
"paddingLeft": true
},
{
"position": {
"line": 3,

View file

@ -22,7 +22,7 @@ expression: response
{
"position": {
"line": 3,
"character": 14
"character": 18
},
"label": "(;0;)",
"paddingLeft": true
@ -30,7 +30,7 @@ expression: response
{
"position": {
"line": 3,
"character": 33
"character": 30
},
"label": "(;1;)",
"paddingLeft": true
@ -38,7 +38,7 @@ expression: response
{
"position": {
"line": 3,
"character": 37
"character": 34
},
"label": "(;2;)",
"paddingLeft": true
@ -46,7 +46,7 @@ expression: response
{
"position": {
"line": 3,
"character": 53
"character": 50
},
"label": "(;3;)",
"paddingLeft": true

View file

@ -11,14 +11,6 @@ expression: response
"label": "(;0;)",
"paddingLeft": true
},
{
"position": {
"line": 2,
"character": 16
},
"label": "(;0;)",
"paddingLeft": true
},
{
"position": {
"line": 3,

View file

@ -11,14 +11,6 @@ expression: response
"label": "(;0;)",
"paddingLeft": true
},
{
"position": {
"line": 2,
"character": 16
},
"label": "(;0;)",
"paddingLeft": true
},
{
"position": {
"line": 3,

View file

@ -11,14 +11,6 @@ expression: response
"label": "(;0;)",
"paddingLeft": true
},
{
"position": {
"line": 2,
"character": 16
},
"label": "(;0;)",
"paddingLeft": true
},
{
"position": {
"line": 3,

View file

@ -15,3 +15,5 @@ It only shows when the function or block contains an identifier.
This inlay hint shows numeric idx of functions, types, globals, memories, tables, tags and etc in their definitions.
This can be helpful when calling these functions or referencing these items elsewhere.
It will be hidden when an identifier is present.