diff options
-rw-r--r-- | script/core/code-action.lua | 2 | ||||
-rw-r--r-- | script/proto/define.lua | 7 | ||||
-rw-r--r-- | script/provider/provider.lua | 9 |
3 files changed, 16 insertions, 2 deletions
diff --git a/script/core/code-action.lua b/script/core/code-action.lua index 69304f98..cd5f2f80 100644 --- a/script/core/code-action.lua +++ b/script/core/code-action.lua @@ -253,7 +253,7 @@ local function solveDiagnostic(uri, diag, results) disableDiagnostic(uri, diag.code, results) end -return function (uri, range, diagnostics) +return function (uri, start, finish, diagnostics) local ast = files.getAst(uri) if not ast then return nil diff --git a/script/proto/define.lua b/script/proto/define.lua index 966a5161..1cbb8de9 100644 --- a/script/proto/define.lua +++ b/script/proto/define.lua @@ -76,6 +76,13 @@ function m.range(lines, text, offset1, offset2) return range end +--- convert `range` to `offsetStart` and `offsetFinish` +function m.unrange(lines, text, range) + local start = m.offset(lines, text, range.start) + local finish = m.offset(lines, text, range['end']) + return start, finish +end + ---@alias location table ---@param uri string ---@param range range diff --git a/script/provider/provider.lua b/script/provider/provider.lua index 3508116f..71062933 100644 --- a/script/provider/provider.lua +++ b/script/provider/provider.lua @@ -549,7 +549,14 @@ proto.on('textDocument/codeAction', function (params) local uri = params.textDocument.uri local range = params.range local diagnostics = params.context.diagnostics - local results = core(uri, range, diagnostics) + local text = files.getText(uri) + local lines = files.getLines(uri) + if not text or not lines then + return nil + end + + local start, finish = define.unrange(lines, text, range) + local results = core(uri, start, finish, diagnostics) if not results or #results == 0 then return nil |