kcl icon indicating copy to clipboard operation
kcl copied to clipboard

[LFX] [Track] LSP inlayhint and hover content content optimization

Open He1pa opened this issue 10 months ago • 5 comments

Enhancement

Task

  1. Provide type inlay hint as shown below to improve the readability of kcl code image

  2. Optimize the display content of hover, including but not limited to better styles, indentation, highlighting, hyperlinks, etc.

Pretest

#1304

He1pa avatar Apr 24 '24 11:04 He1pa

cc @He1pa The first one maybe the pretest.

Peefy avatar May 04 '24 09:05 Peefy

Hey @Peefy , @He1pa , what's the pre-test being decided for the same.

d4v1d03 avatar May 10 '24 08:05 d4v1d03

@He1pa the pretest for this project seems to be closed. What tasks do new applicants need to do for selection ? Thanks.

literalEval avatar May 22 '24 15:05 literalEval

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 where x 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 }

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
    

shruti2522 avatar Jul 01 '24 10:07 shruti2522

cc @He1pa @Peefy I will create separate PRs for each implementation in the above design doc. Please assign.

shruti2522 avatar Jul 01 '24 10:07 shruti2522

Closed by #1468, #1473, #1488 and #1491

Peefy avatar Aug 14 '24 05:08 Peefy

fyi https://github.com/kcl-lang/kcl/issues/1575

cc @shruti2522 @He1pa

Peefy avatar Aug 15 '24 05:08 Peefy

fyi https://github.com/kcl-lang/kcl/issues/1575

cc @shruti2522 @He1pa

working on it @Peefy

shruti2522 avatar Aug 15 '24 05:08 shruti2522

Good Job! @shruti2522 Thank you! ❤️

Peefy avatar Aug 15 '24 05:08 Peefy