kcl-lang / kcl

KCL Programming Language (CNCF Sandbox Project). https://kcl-lang.io
https://kcl-lang.io
Apache License 2.0
1.41k stars 110 forks source link

LSP inlay hints for str, int, float, bool, any types #1431

Closed shruti2522 closed 14 hours ago

shruti2522 commented 1 week ago

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

coveralls commented 1 week ago

Pull Request Test Coverage Report for Build 9631229019

Details


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 Coverage Status
Change from base Build 9596528207: -0.1%
Covered Lines: 55615
Relevant Lines: 78161

💛 - Coveralls
shruti2522 commented 5 days ago

KCL Inlay Hints

1. Introduction

2. Design principles

TypeKind::Str|Int|Float|Bool|Any

TypeKind::Schema

TypeKind::Function

TypeKind::List

TypeKind::Dict

TypeKind::NumberMultiplier

TypeKind::Union

shruti2522 commented 5 days ago

please review the above design doc @He1pa @Peefy

Peefy commented 5 days ago

Good Job! 👍 I will only add one implementation point: we only need to display hint for left valued variables without explicit type annotations.

He1pa commented 2 days ago

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.

shruti2522 commented 1 day ago

Inlay hints for TypeKind::Str|Int|Float|Bool|Any

Screenshot from 2024-07-02 21-06-46

coveralls commented 1 day ago

Pull Request Test Coverage Report for Build 9763995728

Warning: This coverage report may be inaccurate.

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.

Details


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 Coverage Status
Change from base Build 9596528207: 0.2%
Covered Lines: 56196
Relevant Lines: 78652

💛 - Coveralls
Peefy commented 14 hours ago

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
}
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
}
Peefy commented 14 hours ago

Hello @shruti2522 I've leaved some comments and You can open other PRs to deal this and I will merge this PR to test.

shruti2522 commented 13 hours ago

okay @Peefy, I will open another PR to resolve above.