summaryrefslogtreecommitdiff
path: root/script/provider
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-03-04 18:40:55 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-03-04 18:40:55 +0800
commit0730e556fc224cd18318a548d8eca5e75ae2b76e (patch)
tree87cbd3fc4f4f0d1f18bf22e59033726a9b7e9fe8 /script/provider
parentb021a261036690d354b56451ada1d22144b1950b (diff)
downloadlua-language-server-0730e556fc224cd18318a548d8eca5e75ae2b76e.zip
first try of auto end
Diffstat (limited to 'script/provider')
-rw-r--r--script/provider/capability.lua4
-rw-r--r--script/provider/provider.lua39
2 files changed, 43 insertions, 0 deletions
diff --git a/script/provider/capability.lua b/script/provider/capability.lua
index a6195ebb..08b4779a 100644
--- a/script/provider/capability.lua
+++ b/script/provider/capability.lua
@@ -82,6 +82,10 @@ function m.getIniter()
},
},
foldingRangeProvider = true,
+ documentOnTypeFormattingProvider = {
+ firstTriggerCharacter = '\n',
+ moreTriggerCharacter = nil, -- string[]
+ },
workspace = {}
--documentOnTypeFormattingProvider = {
-- firstTriggerCharacter = '}',
diff --git a/script/provider/provider.lua b/script/provider/provider.lua
index f7579881..fa2b8874 100644
--- a/script/provider/provider.lua
+++ b/script/provider/provider.lua
@@ -825,6 +825,45 @@ proto.on('$/status/click', function ()
end
end)
+proto.on('textDocument/onTypeFormatting', function (params)
+ workspace.awaitReady()
+ local _ <close> = progress.create(lang.script.WINDOW_PROCESSING_TYPE_FORMATTING, 0.5)
+ local ch = params.ch
+ local uri = params.textDocument.uri
+ if not files.exists(uri) then
+ return nil
+ end
+ local core = require 'core.type-formatting'
+ local offset = files.offset(uri, params.position)
+ local edits = core(uri, offset, ch)
+ if #edits == 0 then
+ return nil
+ end
+ local results = {}
+ for i, edit in ipairs(edits) do
+ results[i] = {
+ range = files.range(uri, edit.start, edit.finish),
+ newText = edit.text,
+ }
+ end
+ results = {
+ {
+ range = {
+ ['start'] = {
+ line = 1,
+ character = 5,
+ },
+ ['end'] = {
+ line = 1,
+ character = 5,
+ },
+ },
+ newText = '\nend',
+ }
+ }
+ return results
+end)
+
-- Hint
do
local function updateHint(uri)