diff options
author | CppCXY <812125110@qq.com> | 2022-01-20 01:48:41 +0800 |
---|---|---|
committer | CppCXY <812125110@qq.com> | 2022-01-20 01:48:41 +0800 |
commit | 5888272ccf7fc0b542edf88d4d8a38636351b42b (patch) | |
tree | 70458098581c4fe9964ef154f9922d1aa3aff536 /script/provider | |
parent | 8e41ce1b39044742a6aaadfd16976654666d67ca (diff) | |
download | lua-language-server-5888272ccf7fc0b542edf88d4d8a38636351b42b.zip |
提供范围格式化
Diffstat (limited to 'script/provider')
-rw-r--r-- | script/provider/capability.lua | 3 | ||||
-rw-r--r-- | script/provider/provider.lua | 30 |
2 files changed, 32 insertions, 1 deletions
diff --git a/script/provider/capability.lua b/script/provider/capability.lua index 27950d7f..31baf690 100644 --- a/script/provider/capability.lua +++ b/script/provider/capability.lua @@ -112,7 +112,8 @@ function m.getIniter() range = true, full = false, }, - documentFormattingProvider = true + documentFormattingProvider = true, + documentRangeFormattingProvider = true --documentOnTypeFormattingProvider = { -- firstTriggerCharacter = '}', --}, diff --git a/script/provider/provider.lua b/script/provider/provider.lua index 63450f59..a5e0a1ca 100644 --- a/script/provider/provider.lua +++ b/script/provider/provider.lua @@ -954,6 +954,36 @@ m.register 'textDocument/formatting' { end } +m.register 'textDocument/rangeFormatting' { + abortByFileUpdate = true, + ---@async + function(params) + local uri = files.getRealUri(params.textDocument.uri) + workspace.awaitReady(uri) + local _<close> = progress.create(workspace.getScope(uri), lang.script.WINDOW_PROCESSING_TYPE_FORMATTING, 0.5) + + if not files.exists(uri) then + return nil + end + + local core = require 'core.rangeformatting' + local edits = core(uri, params.range) + if not edits or #edits == 0 then + return nil + end + + local results = {} + for i, edit in ipairs(edits) do + results[i] = { + range = converter.packRange(uri, edit.start, edit.finish), + newText = edit.text, + } + end + + return results + end +} + m.register 'config/editorconfig/update' { abortByFileUpdate = true, ---@async |