Closed shruti2522 closed 14 hours ago
Changes Missing Coverage | Covered Lines | Changed/Added Lines | % | ||
---|---|---|---|---|---|
kclvm/tools/src/LSP/src/main.rs | 0 | 1 | 0.0% | ||
kclvm/tools/src/LSP/src/capabilities.rs | 0 | 7 | 0.0% | ||
kclvm/tools/src/LSP/src/request.rs | 1 | 20 | 5.0% | ||
kclvm/tools/src/LSP/src/inlay_hints.rs | 0 | 80 | 0.0% | ||
<!-- | Total: | 1 | 108 | 0.93% | --> |
Files with Coverage Reduction | New Missed Lines | % | ||
---|---|---|---|---|
kclvm/tools/src/LSP/src/main.rs | 1 | 0.0% | ||
<!-- | Total: | 1 | --> |
Totals | |
---|---|
Change from base Build 9596528207: | -0.1% |
Covered Lines: | 55615 |
Relevant Lines: | 78161 |
[x]
is used for the hints where x
represents the type name.TypeKind::Str|Int|Float|Bool|Any
[: x]
if it is not already assigned.
Examples:
n [: float] = 1
x [: str] = "kcl"
value [: bool] = True
func = lambda x [: any] { x }
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.
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
please review the above design doc @He1pa @Peefy
Good Job! 👍 I will only add one implementation point: we only need to display hint for left valued variables without explicit type annotations.
for func definition, I think the first [: fn func]
is also unnecessary. but need hints for params. I prefer
func = lambda x[: any]{
x
}
for func call, y is the argument. x is not type for y, it is a param name in func definition, so the hint [x:]
before y
z = func([x:] y)
I don’t recommend you to complete all the work in one PR, so you can put the design doc in the track issue instead of the PR.
Inlay hints for TypeKind::Str|Int|Float|Bool|Any
This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Changes Missing Coverage | Covered Lines | Changed/Added Lines | % | ||
---|---|---|---|---|---|
kclvm/tools/src/LSP/src/main.rs | 0 | 1 | 0.0% | ||
kclvm/tools/src/LSP/src/capabilities.rs | 0 | 2 | 0.0% | ||
kclvm/tools/src/LSP/src/request.rs | 2 | 18 | 11.11% | ||
kclvm/tools/src/LSP/src/inlay_hints.rs | 0 | 76 | 0.0% | ||
<!-- | Total: | 2 | 97 | 2.06% | --> |
Files with Coverage Reduction | New Missed Lines | % | ||
---|---|---|---|---|
kclvm/runtime/src/value/val_func.rs | 1 | 80.0% | ||
kclvm/runtime/src/_kclvm.rs | 1 | 25.0% | ||
kclvm/ast/src/ast.rs | 1 | 83.38% | ||
kclvm/driver/src/toolchain.rs | 1 | 88.12% | ||
kclvm/tools/src/LSP/src/main.rs | 1 | 0.0% | ||
kclvm/sema/src/builtin/option.rs | 1 | 0.0% | ||
kclvm/ast/src/token.rs | 2 | 57.53% | ||
kclvm/tools/src/LSP/src/goto_def.rs | 2 | 94.96% | ||
kclvm/sema/src/builtin/system_module.rs | 2 | 99.88% | ||
kclvm/query/src/query.rs | 3 | 36.96% | ||
<!-- | Total: | 1758 | --> |
Totals | |
---|---|
Change from base Build 9596528207: | 0.2% |
Covered Lines: | 56196 |
Relevant Lines: | 78652 |
In addition to assign_stmt, other syntax including types and variables that may needs inlay hints.
pub struct LambdaExpr {
pub args: Option<NodeRef<Arguments>>,
pub body: Vec<NodeRef<Stmt>>,
pub return_ty: Option<NodeRef<Type>>,
}
func = lambda x[: any] [-> any] {
x
}
args
of function calling parameters.pub struct CallExpr {
pub func: NodeRef<Expr>,
pub args: Vec<NodeRef<Expr>>,
pub keywords: Vec<NodeRef<Keyword>>,
}
z = func([x:] y)
values = [1, 2, 3]
data = all x [: [int]] in values {
x >= 1
}
Hello @shruti2522 I've leaved some comments and You can open other PRs to deal this and I will merge this PR to test.
okay @Peefy, I will open another PR to resolve above.
1. Does this PR affect any open issues?(Y/N) and add issue references (e.g. "fix #123", "re #123".):
fix #1244
2. What is the scope of this PR (e.g. component or file name):
kclvm/tools/src/LSP/src/inlay_hints.rs kclvm/tools/src/LSP/src/capabilities.rs kclvm/tools/src/LSP/src/lib.rs kclvm/tools/src/LSP/src/main.rs kclvm/tools/src/LSP/src/request.rs kclvm/tools/src/LSP/Cargo.toml
3. Provide a description of the PR(e.g. more details, effects, motivations or doc link):
4. Are there any breaking changes?(Y/N) and describe the breaking changes(e.g. more details, motivations or doc link):
5. Are there test cases for these changes?(Y/N) select and add more details, references or doc links:
cc @He1pa @Peefy