Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LFX PreTest] PreTest for LSP quick fix #1020

Closed
He1pa opened this issue Feb 2, 2024 · 4 comments · Fixed by #1038
Closed

[LFX PreTest] PreTest for LSP quick fix #1020

He1pa opened this issue Feb 2, 2024 · 4 comments · Fixed by #1038
Labels
good first issue Good for newcomers help wanted Extra attention is needed langserver lsp

Comments

@He1pa
Copy link
Contributor

He1pa commented Feb 2, 2024

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

@He1pa He1pa added help wanted Extra attention is needed lsp labels Feb 2, 2024
@He1pa He1pa added good first issue Good for newcomers langserver labels Feb 2, 2024
@UtkarshUmre
Copy link

As there is a reference provided, I can seek help from that. Since this is a good first issue, I would like to give it a try

@octonawish-akcodes
Copy link
Contributor

Do we need to create a gist for this or how do we present our solutions?
cc @He1pa @Peefy

@He1pa
Copy link
Contributor Author

He1pa commented Feb 4, 2024

Do we need to create a gist for this or how do we present our solutions? cc @He1pa @Peefy

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

@Bhaskary20
Copy link

I would like to take this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed langserver lsp
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants