summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-07-05 15:57:09 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-07-05 15:57:09 +0800
commit3ea9e2b4ca40998ac14d56e0f09b33c6b7cb3ad0 (patch)
tree2c1b298bf9690149a0b75b3671f64fc55cc2df74
parentb73c30b3bec7c56e9b46021ccf9824df3d0a529b (diff)
downloadlua-language-server-3ea9e2b4ca40998ac14d56e0f09b33c6b7cb3ad0.zip
codeAction进行过滤
-rw-r--r--server/src/core/code_action.lua26
-rw-r--r--server/src/method/textDocument/codeAction.lua11
2 files changed, 32 insertions, 5 deletions
diff --git a/server/src/core/code_action.lua b/server/src/core/code_action.lua
index d52749a4..3c61ed56 100644
--- a/server/src/core/code_action.lua
+++ b/server/src/core/code_action.lua
@@ -266,13 +266,31 @@ local function solveDiagnostic(lsp, uri, data, callback)
disableDiagnostic(lsp, uri, data, callback)
end
-return function (lsp, uri, diagnostics)
+local function rangeContain(a, b)
+ if a.start.line > b.start.line then
+ return false
+ end
+ if a.start.character > b.start.character then
+ return false
+ end
+ if a['end'].line < b['end'].line then
+ return false
+ end
+ if a['end'].character < b['end'].character then
+ return false
+ end
+ return true
+end
+
+return function (lsp, uri, diagnostics, range)
local results = {}
for _, data in ipairs(diagnostics) do
- solveDiagnostic(lsp, uri, data, function (result)
- results[#results+1] = result
- end)
+ if rangeContain(data.range, range) then
+ solveDiagnostic(lsp, uri, data, function (result)
+ results[#results+1] = result
+ end)
+ end
end
return results
diff --git a/server/src/method/textDocument/codeAction.lua b/server/src/method/textDocument/codeAction.lua
index ac1bad61..3c6e8d49 100644
--- a/server/src/method/textDocument/codeAction.lua
+++ b/server/src/method/textDocument/codeAction.lua
@@ -2,9 +2,18 @@ local core = require 'core'
return function (lsp, params)
local uri = params.textDocument.uri
+ local vm, lines = lsp:getVM(uri)
+ if not vm then
+ return
+ end
local diagnostics = params.context.diagnostics
+ local range = params.range
- local results = core.codeAction(lsp, uri, diagnostics)
+ local results = core.codeAction(lsp
+ , uri
+ , diagnostics
+ , range
+ )
if #results == 0 then
return nil