Skip to content

[LFX PreTest] PreTest for LSP quick fix #1020

@He1pa

Description

@He1pa

Provide quick fix with LSP for this case.
image

What you need to do:

  1. Find the place where this error is generated in the kcl compiler(~/kclvm/sema/src/resolver/scope.rs lookup_type_from_scope() and set_type_to_scope()) and fill in suggested_replacement in the structure representing the error. In this case it would be Some("aaa")
  2. Convert KCL's Diagnostic to LSP's Diagnostic. Most of the work is already done, but you need to convert suggested_replacement into the data field.
pub struct Diagnostic { /// The range at which the message applies. pub range: Range, ... /// A data entry field that is preserved between a `textDocument/publishDiagnostics` /// notification and `textDocument/codeAction` request. pub data: Option<serde_json::Value>, } 
  1. handle the CodeActionRequest and provide a quick fix response. you can ref this pr: feat: lsp quick fix #652. This is a very simple demo that fix warning about useless import. It replaces the useless import stmt with an empty string. But you need to get the new_text from RequestParam(The IDE will return the data generated in the previous step as a parameter)
  2. Install KCL extension within VSCode and build lsp binary locally, add the kcl-language-server to PATH
  3. After completing above, you can see a button like this in the IDE (VSCode). Click the button and the IDE will fix the incorrect code (aa->aaa)
    image

You can fork this repository and develop in your own repository. After completion, you can contact me via email or slack. Of course, if you have any questions during this process, you can also contact me

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions