Provide human readable code action descriptions
These strings will be displayed in a menu for the user to select. The error codes, in addition to not being human readable sentences, describe the issue being reported, not the solution that will be applied. The code action response only includes the human readable string, so the tests need to check for that. I considered adding a custom field but decided against going out of spec.
This commit is contained in:
parent
66bc08a616
commit
b1986395cf
@ -4,6 +4,7 @@
|
||||
|
||||
### Features
|
||||
|
||||
* Provide human readable code actions titles.
|
||||
* Add --help and --version command line flags.
|
||||
* Support providing improved completion kinds to clients.
|
||||
* Support highlighting references to the symbol under the cursor in the current file.
|
||||
|
||||
@ -294,8 +294,7 @@ Every time the client sends a message, it gets handled by a function in the corr
|
||||
(icollect [_ diagnostic (ipairs file.diagnostics)]
|
||||
(if (and (overlap? diagnostic.range range)
|
||||
diagnostic.quickfix)
|
||||
{:title diagnostic.codeDescription
|
||||
:edit {:changes {uri (diagnostic.quickfix)}}}))))
|
||||
(message.diagnostic->code-action server file diagnostic :quickfix)))))
|
||||
|
||||
(λ notifications.textDocument/didChange [server send {: contentChanges :textDocument {: uri}}]
|
||||
(local file (files.get-by-uri server uri))
|
||||
|
||||
@ -73,6 +73,24 @@ LSP json objects."
|
||||
:end (utils.byte->position file.text (+ byteend 1)
|
||||
server.position-encoding)}))
|
||||
|
||||
(λ code-action-title [diag]
|
||||
(let [titles {:match-should-case "Replace match with case"
|
||||
:unused-definition "Prefix with _ to silence warning"
|
||||
:op-with-no-arguments "Replace with the corresponding literal"
|
||||
:no-decreasing-comparison "Reverse comparison"
|
||||
:unnecessary-tset "Replace with set"
|
||||
:unnecessary-do-values "Remove unnecessary do or values"
|
||||
:redundant-do "Remove redundant do"
|
||||
:bad-unpack "Replace with table.concat call"}]
|
||||
(or (. titles diag.codeDescription)
|
||||
(.. "Action title missing - " diag.codeDescription))))
|
||||
|
||||
(λ diagnostic->code-action [_server file diagnostic ?kind]
|
||||
(let [{: uri} file]
|
||||
{:title (code-action-title diagnostic)
|
||||
:kind ?kind
|
||||
:edit {:changes {uri (diagnostic.quickfix)}}}))
|
||||
|
||||
(λ multisym->range [server file ast n]
|
||||
(let [spl (utils.multi-sym-split ast)
|
||||
n (if (< n 0) (+ n 1 (length spl)) n)]
|
||||
@ -110,6 +128,7 @@ LSP json objects."
|
||||
: create-response
|
||||
: create-error
|
||||
: ast->range
|
||||
: diagnostic->code-action
|
||||
: multisym->range
|
||||
: range-and-uri
|
||||
: diagnostics
|
||||
|
||||
@ -20,6 +20,7 @@
|
||||
(let [edits (?. action :edit :changes uri)
|
||||
edited-text (apply-edits text edits encoding)]
|
||||
(faith.= desired-file-contents edited-text))))
|
||||
|
||||
(fn check-negative [file-contents action-not-suggested]
|
||||
(let [{: client : uri :locations [range]} (create-client file-contents)
|
||||
[{:result responses}] (client:code-action uri range.range)]
|
||||
@ -32,13 +33,13 @@
|
||||
(fn test-fix-op-no-arguments []
|
||||
(check "(let [x (+====)]
|
||||
(print x))"
|
||||
"op-with-no-arguments"
|
||||
"Replace with the corresponding literal"
|
||||
"(let [x 0]
|
||||
(print x))"))
|
||||
|
||||
(fn test-fix-unused-definition []
|
||||
(check "(local x==== 10)"
|
||||
"unused-definition"
|
||||
"Prefix with _ to silence warning"
|
||||
"(local _x 10)"))
|
||||
|
||||
; (fn test-fix-method-function []
|
||||
|
||||
Loading…
Reference in New Issue
Block a user