-
Notifications
You must be signed in to change notification settings - Fork 93
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
Allow code actions to be created if no Diagnostics is provided #1516 #1517
Allow code actions to be created if no Diagnostics is provided #1516 #1517
Conversation
2a7dcaf
to
0569b59
Compare
0569b59
to
0d76910
Compare
org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/XMLCodeActions.java
Outdated
Show resolved
Hide resolved
0d76910
to
91a65ea
Compare
Perhaps Im wrong but my first feeling with noError diagnostic is that the API is strange. I wonder if we should update the API of ICodeActionPartiipant to introduce a new method like doCodeActionswithoutDiagnostic or à better name. It would be nice too to have a test which implement a code action without diagnostic by registering a mock participant. |
I also have such feeling... When I add this fake "NoError" diagnostic it makes obligatory to CodeAction participants to know and check for that special diagnostics code in order to work correctly and not to produce any CodeAction duplication. I thought in adding this diagnostics ONLY in case of empty diagnostics list, but this for sure makes CodeAction participants that do not require any dedicated error code to produce duplicated CodeAction-s in some cases without any possibility to control it. Having an API method like |
I agree the NO_ERROR is not so good, but I don't think a new API would be necessary nor desirable as it would break compatibility. The ICodeActionRequest does include the diagnostic, what about always just sending another request with this diagnostic being null, after sending requests that reference particular diagnostics? |
@mickaelistria Imagine a situation when you have a piece of code that contains one or more diagnostic (like error + warnings) and you invoke a code action request... If we make these "null-diagnostic-related" code action participants to not require"null or empty" diagnostics - then they will create their code action multiple times (as much as number of diagnostic elements we have set for the request) To avoid such skipping or duplication we need such an fake "NoError" (or what ever we name it" diagnostic or adding a new API method for code actions that are independent of diagnostics provided. |
I may be missing something, but I see |
91a65ea
to
203c931
Compare
@mickaelistria I have changed the PR according to your suggestion. From now the Code Action participants are obliged to check whether the correct diagnostic is provided for diagnostic-dependent participants and check for null-diagnostic value for the ones that should return code actions independently of presence and codes of diagnostics |
This kind of think that I would like to avoid. I like the idea with adding à New method because when you implement it you are sûre that diagnostic is null and the code is clean. When you implement doCodeAction you work with diagnostic, when you implement doCodeActionsIncondicional you work without diagnostic. We can add this method in participant and implement as default |
Why? It's really simple and efficient, and very close to LSP specification; so no-one would be surprised with such pattern. |
f6f72cb
to
68f723d
Compare
Because it requires for each participant to check diagnostic is not null. I'm surprised that there are not an NPE at More it means that you will call twice doCodeActions. IMHO I think it is better to separate the code actions:
The dispatch of those code actions are cleaned. If youhave just one doCodeActions, it will require to check if the diagnostic is null. More if we have a new method |
I suspect many already do. Do you have a list of extensions of lemminx? If it requires to just tweak a few ones to add a null-check in order to be more consistent with LSP and avoid new APIs, it can be worth it.
We already call it as many times as there are diagnostics on that position. This can be multiple times. |
See https://github.com/eclipse/lemminx/blob/main/docs/LemMinX-Extensions.md#lemminx-extensions
Adding just a new method I like the idea to have
It means that when you contribute to a lemminx extsenion of a given project that you don'tknow, you need just to seach implementation of |
f409ced
to
3053241
Compare
Haven't seen any NPEs loged regarding this Code Action. |
@mickaelistria @angelozerr Would you mind if I merge this PR - I need it to continue working on eclipse-lemminx/lemminx-maven#383 to provide Inline code actions as well as to continue on other parts of the issue. |
I defer the final say to @angelozerr |
Me I would prefer having After that if @mickaelistria and @vrubezhny you are not happy with this API, let's give up my suggestion. |
3053241
to
ab6533f
Compare
The PR is changed so now the The order of Code Action creation is saved to create at first - the code actions that refer to a certain diagnostics, and at second - the rest of code actions, which means that Error/Warnings related Code Actions would be placed above the rest of Code Actions created without any diagnostics (If the Code Action list is not going to be reordered after the creation) @angelozerr Please review. |
Actually I would suggest:
|
Thanks so mu h @vrubezhny ! |
No description provided.