kcl
kcl copied to clipboard
[LFX] [Track] LSP inlayhint and hover content content optimization
Enhancement
Task
-
Provide type inlay hint as shown below to improve the readability of kcl code
-
Optimize the display content of hover, including but not limited to better styles, indentation, highlighting, hyperlinks, etc.
Pretest
#1304
cc @He1pa The first one maybe the pretest.
Hey @Peefy , @He1pa , what's the pre-test being decided for the same.
@He1pa the pretest for this project seems to be closed. What tasks do new applicants need to do for selection ? Thanks.
KCL Inlay Hints
1. Introduction
- Inlay hints are provided for the cases when there is no explicit type declaration.
-
[x]
is used for the hints wherex
represents the type name. - Hints are displayed only for left valued variables without explicit type annotations.
2. Design principles
TypeKind::Str|Int|Float|Bool|Any
- Hints show the type enclosed in brackets
[: x]
if it is not already assigned. Examples:- int/float:
n [: float] = 1
- str:
x [: str] = "kcl"
- bool:
value [: bool] = True
- any:
func = lambda x [: any] { x }
- int/float:
TypeKind::Schema
-
schema definition:
for example,
schema Persons: n1 [: int] = n - 1 n2 [: int] = n1 - 1 n: int value: int
No inlay hints applied for the following cases:
-
schema signature string
schema Persons:
-
schema attributes with type definition
n: int value: int
-
-
schema assign statements:
-
for type definition no hints are provided
p: Person = Person{}
-
hints when there is no type definition
p [: Person] = Person{}
-
TypeKind::Function
-
for function definition
func = lambda x[: any]{ x }
-
for function call
z = func([x:] y)
where, y is the argument and x is the param name in func definition.
-
no inlay hints for builtin function calls
TypeKind::List
-
for list assignments
_list1 [: [int]] = [1, 2, 3] _list2 [: [str]] = ["kcl","lang"]
TypeKind::Dict
-
for dict assignments
data1 [: {str:str}] = { if False: "key1": "value1" "key2": "value2" if True: "key3": "value3" }
TypeKind::NumberMultiplier
-
for number multiplier assign stmts
x0: units.NumberMultiplier = 1M x1 [: number_multiplier] = x0
TypeKind::Union
-
for union types the name of the union type is provided as inlay hint
type num = int | float n [: num] = 1
-
no inlay hint for type assignment
n: num = 1
cc @He1pa @Peefy I will create separate PRs for each implementation in the above design doc. Please assign.
Closed by #1468, #1473, #1488 and #1491
fyi https://github.com/kcl-lang/kcl/issues/1575
cc @shruti2522 @He1pa
fyi https://github.com/kcl-lang/kcl/issues/1575
cc @shruti2522 @He1pa
working on it @Peefy
Good Job! @shruti2522 Thank you! ❤️