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

Order of suggestions of code-fixes is not really optimized, especially with imports #9

Closed
josteink opened this issue Nov 11, 2021 · 7 comments

Comments

@josteink
Copy link

josteink commented Nov 11, 2021

Consider the following code:

a/Class1.cs

namespace A
{
    public class Class1
    {
        // code
    }
}

b/Class2.cs

namespace B
{
    public class Class2
    {
        var instance = new Class1();
    }
}

Then put your cursor on Class1() and invoke M-x lsp-execute-code-action in Emacs, or similar action in other editor.

Observed that

You will be provided several different options:

image
(Screenshot for demonstrationg-purposes. Does not match example code 1-to-1)

Expected that

Generally, in my experience, some actions are almost always "more" preferred than others.

In this particular case I almost always want to have using-statements as first suggestion, explicit-namespacing as second and create new class as third and expect to find code-fixes in that order.

Does the LSP protocol provide any sort of ... priority for the code actions or is it up to the LSP-client itself to determine how to present them?

@razzmatazz
Copy link
Owner

It looks like there is :) I thought there wasnt.

‘CodeAction.isPreferred’
https://microsoft.github.io/language-server-protocol/specifications/specification-3-17/#codeAction

@josteink
Copy link
Author

josteink commented Nov 11, 2021

On the same spec there’s also CodeActionKind:

kind?: CodeActionKind;

It seems one possible value for that is quickfix.

So I guess we should prioritise isPreferred and quickfix-kind actions, and in that order?

@razzmatazz
Copy link
Owner

razzmatazz commented Nov 20, 2021

pending on ionide/LanguageServerProtocol#4

@razzmatazz
Copy link
Owner

pending on ionide/LanguageServerProtocol#4

ok, that one has been merged

@razzmatazz
Copy link
Owner

I have published 0.1.8, which should pull usings action up a bit, not 100% sure this was the right way to fix, as isPreffered was not taken into account in emacs-lsp/lsp-mode at the time I was checking it so not only that but I sorted simply those actions before returing to the editor -- hopefully ergonomics are better now

(it might take a couple of minutes for the package to show up on https://www.nuget.org/packages/csharp-ls/0.1.8)

@josteink
Copy link
Author

josteink commented Dec 8, 2021

Tested and works. Great stuff! 😃

Edit: Proof!

image

@josteink
Copy link
Author

josteink commented Dec 8, 2021

This works 100% as I described in the "expected" section in the issue, so I guess I have no choice but consider this 100% resolved 😄

@josteink josteink closed this as completed Dec 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants