summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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