You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
One of the core features of Erlang LS is to be able to publish a diagnostic message whenever an issue is detected in the user code. Diagnostics are often rendered by the IDE with a squiggle of different colour, depending on the severity of the message (e.g. a warning uses a yellow squiggle, while an error uses a red squiggle).
One of these messages is displayed whenever an include or include_lib attribute is added to a module, but unused. See the picture below.
A Code Action request is sent from the IDE to the language server to compute the possible code actions available for a given document and text range. In the case above, the following request is sent from the IDE to the language server as soon as the user hovers the unused include:
As you can see, the request contains the current location (file path, line number, line column) and an additional context (in this case a list containing one diagnostic, which can in turn be used by the server to provide a list of available code actions. Right now, since this feature is not yet implemented, no code actions (i.e. an empty list or []) is returned to the client.
What is Required
In case a textDocument/codeAction request is received by the language server, the server should check for presence of "Unused include" diagnostics. If one is present, the server should include a code action (say remove-unused-include) in the response.
Once the possible code action is received by the IDE, the user gets notified. This usually happens via a little bulb icon or similar, which suggests that a code action is available. In this case, the code action would be of type quickfix and suggest to remove the unused include.
Code Pointers
Code action requests are dispatched to the els_code_action_provider module, so you probably want to start there
Testing
Don't forget to include a test for the new functionality! You can look at existing examples in the els_code_action_SUITE module and at this code lenses tutorial which includes a testing overview which also applies to code actions.
Problems following the instructions?
Get in touch! We'll be glad to help you to get unblocked and to improve our docs.
The text was updated successfully, but these errors were encountered:
* Add Fix for #1202 remove unused include
* Fixing lint line length
* Fixing failing tests
* Fixing Var name
* Update diagnostic type spec
* Update diagnostic type spec
* Fixing dialyzer errors
Context
One of the core features of Erlang LS is to be able to publish a diagnostic message whenever an issue is detected in the user code. Diagnostics are often rendered by the IDE with a squiggle of different colour, depending on the severity of the message (e.g. a warning uses a yellow squiggle, while an error uses a red squiggle).
One of these messages is displayed whenever an
include
orinclude_lib
attribute is added to a module, but unused. See the picture below.A Code Action request is sent from the IDE to the language server to compute the possible code actions available for a given document and text range. In the case above, the following request is sent from the IDE to the language server as soon as the user hovers the unused include:
As you can see, the request contains the current location (file path, line number, line column) and an additional context (in this case a list containing one diagnostic, which can in turn be used by the server to provide a list of available code actions. Right now, since this feature is not yet implemented, no code actions (i.e. an empty list or
[]
) is returned to the client.What is Required
In case a
textDocument/codeAction
request is received by the language server, the server should check for presence of "Unused include" diagnostics. If one is present, the server should include a code action (sayremove-unused-include
) in the response.Once the possible code action is received by the IDE, the user gets notified. This usually happens via a little bulb icon or similar, which suggests that a code action is available. In this case, the code action would be of type quickfix and suggest to remove the unused include.
Code Pointers
els_code_action_provider
module, so you probably want to start thereTesting
Don't forget to include a test for the new functionality! You can look at existing examples in the
els_code_action_SUITE
module and at this code lenses tutorial which includes a testing overview which also applies to code actions.Problems following the instructions?
Get in touch! We'll be glad to help you to get unblocked and to improve our docs.
The text was updated successfully, but these errors were encountered: