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
|
### Features
|
||||||
|
|
||||||
|
* Provide human readable code actions titles.
|
||||||
* Add --help and --version command line flags.
|
* Add --help and --version command line flags.
|
||||||
* Support providing improved completion kinds to clients.
|
* Support providing improved completion kinds to clients.
|
||||||
* Support highlighting references to the symbol under the cursor in the current file.
|
* 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)]
|
(icollect [_ diagnostic (ipairs file.diagnostics)]
|
||||||
(if (and (overlap? diagnostic.range range)
|
(if (and (overlap? diagnostic.range range)
|
||||||
diagnostic.quickfix)
|
diagnostic.quickfix)
|
||||||
{:title diagnostic.codeDescription
|
(message.diagnostic->code-action server file diagnostic :quickfix)))))
|
||||||
:edit {:changes {uri (diagnostic.quickfix)}}}))))
|
|
||||||
|
|
||||||
(λ notifications.textDocument/didChange [server send {: contentChanges :textDocument {: uri}}]
|
(λ notifications.textDocument/didChange [server send {: contentChanges :textDocument {: uri}}]
|
||||||
(local file (files.get-by-uri server uri))
|
(local file (files.get-by-uri server uri))
|
||||||
|
|||||||
@ -73,6 +73,24 @@ LSP json objects."
|
|||||||
:end (utils.byte->position file.text (+ byteend 1)
|
:end (utils.byte->position file.text (+ byteend 1)
|
||||||
server.position-encoding)}))
|
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]
|
(λ multisym->range [server file ast n]
|
||||||
(let [spl (utils.multi-sym-split ast)
|
(let [spl (utils.multi-sym-split ast)
|
||||||
n (if (< n 0) (+ n 1 (length spl)) n)]
|
n (if (< n 0) (+ n 1 (length spl)) n)]
|
||||||
@ -110,6 +128,7 @@ LSP json objects."
|
|||||||
: create-response
|
: create-response
|
||||||
: create-error
|
: create-error
|
||||||
: ast->range
|
: ast->range
|
||||||
|
: diagnostic->code-action
|
||||||
: multisym->range
|
: multisym->range
|
||||||
: range-and-uri
|
: range-and-uri
|
||||||
: diagnostics
|
: diagnostics
|
||||||
|
|||||||
@ -20,6 +20,7 @@
|
|||||||
(let [edits (?. action :edit :changes uri)
|
(let [edits (?. action :edit :changes uri)
|
||||||
edited-text (apply-edits text edits encoding)]
|
edited-text (apply-edits text edits encoding)]
|
||||||
(faith.= desired-file-contents edited-text))))
|
(faith.= desired-file-contents edited-text))))
|
||||||
|
|
||||||
(fn check-negative [file-contents action-not-suggested]
|
(fn check-negative [file-contents action-not-suggested]
|
||||||
(let [{: client : uri :locations [range]} (create-client file-contents)
|
(let [{: client : uri :locations [range]} (create-client file-contents)
|
||||||
[{:result responses}] (client:code-action uri range.range)]
|
[{:result responses}] (client:code-action uri range.range)]
|
||||||
@ -32,13 +33,13 @@
|
|||||||
(fn test-fix-op-no-arguments []
|
(fn test-fix-op-no-arguments []
|
||||||
(check "(let [x (+====)]
|
(check "(let [x (+====)]
|
||||||
(print x))"
|
(print x))"
|
||||||
"op-with-no-arguments"
|
"Replace with the corresponding literal"
|
||||||
"(let [x 0]
|
"(let [x 0]
|
||||||
(print x))"))
|
(print x))"))
|
||||||
|
|
||||||
(fn test-fix-unused-definition []
|
(fn test-fix-unused-definition []
|
||||||
(check "(local x==== 10)"
|
(check "(local x==== 10)"
|
||||||
"unused-definition"
|
"Prefix with _ to silence warning"
|
||||||
"(local _x 10)"))
|
"(local _x 10)"))
|
||||||
|
|
||||||
; (fn test-fix-method-function []
|
; (fn test-fix-method-function []
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user