summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2024-08-06 21:00:43 +0800
committer最萌小汐 <sumneko@hotmail.com>2024-08-06 21:00:43 +0800
commita7a40a5b095f0d7dde928ec14560af1818aa3f5c (patch)
tree9817d71fef5959cdfc3507f56dd2614e384f492d
parent011f95c71a96ddb2c15a75b95d42c0fddf6f37cc (diff)
downloadlua-language-server-a7a40a5b095f0d7dde928ec14560af1818aa3f5c.zip
语言设置挪到服务器里
-rw-r--r--script/provider/language-configuration.lua86
-rw-r--r--script/provider/provider.lua12
2 files changed, 98 insertions, 0 deletions
diff --git a/script/provider/language-configuration.lua b/script/provider/language-configuration.lua
new file mode 100644
index 00000000..1d34f765
--- /dev/null
+++ b/script/provider/language-configuration.lua
@@ -0,0 +1,86 @@
+-- Enumeration of commonly encountered syntax token types.
+local SyntaxTokenType = {
+ Other = 0, -- Everything except tokens that are part of comments, string literals and regular expressions.
+ Comment = 1, -- A comment.
+ String = 2, -- A string literal.
+ RegEx = 3 -- A regular expression.
+}
+
+-- Describes what to do with the indentation when pressing Enter.
+local IndentAction = {
+ None = 0, -- Insert new line and copy the previous line's indentation.
+ Indent = 1, -- Insert new line and indent once (relative to the previous line's indentation).
+ IndentOutdent = 2, -- Insert two new lines: the first one indented which will hold the cursor, and the second one at the same indentation level.
+ Outdent = 3 -- Insert new line and outdent once (relative to the previous line's indentation).
+}
+
+local languageConfiguration = {
+ id = 'lua',
+ configuration = {
+ autoClosingPairs = {
+ { open = "{", close = "}" },
+ { open = "[", close = "]" },
+ { open = "(", close = ")" },
+ { open = "'", close = "'", notIn = { SyntaxTokenType.String } },
+ { open = '"', close = '"', notIn = { SyntaxTokenType.String } },
+ { open = "[=", close = "=]" },
+ { open = "[==", close = "==]" },
+ { open = "[===", close = "===]" },
+ { open = "[====", close = "====]" },
+ { open = "[=====", close = "=====]" },
+ },
+ onEnterRules = {
+ {
+ beforeText = [[\)\s*$]],
+ afterText = [[^\s*end\b]],
+ action = {
+ indentAction = IndentAction.IndentOutdent,
+ }
+ },
+ {
+ beforeText = [[\b()\s*$]],
+ afterText = [[^\s*end\b]],
+ action = {
+ indentAction = IndentAction.IndentOutdent,
+ }
+ },
+ {
+ beforeText = [[\b(repeat)\s*$]],
+ afterText = [[^\s*until\b]],
+ action = {
+ indentAction = IndentAction.IndentOutdent,
+ }
+ },
+ {
+ beforeText = [[^\s*---@]],
+ action = {
+ indentAction = IndentAction.None,
+ appendText = "---@"
+ }
+ },
+ {
+ beforeText = [[^\s*--- @]],
+ action = {
+ indentAction = IndentAction.None,
+ appendText = "--- @"
+ }
+ },
+ {
+ beforeText = [[^\s*--- ]],
+ action = {
+ indentAction = IndentAction.None,
+ appendText = "--- "
+ }
+ },
+ {
+ beforeText = [[^\s*---]],
+ action = {
+ indentAction = IndentAction.None,
+ appendText = "---"
+ }
+ },
+ },
+ },
+}
+
+return languageConfiguration
diff --git a/script/provider/provider.lua b/script/provider/provider.lua
index af01aaf8..6a4b2406 100644
--- a/script/provider/provider.lua
+++ b/script/provider/provider.lua
@@ -1597,6 +1597,18 @@ m.register '$/psi/select' {
end
}
+local function refreshLanguageConfiguration()
+ if not client.getOption('languageConfiguration') then
+ return
+ end
+ proto.notify('$/languageConfiguration', require 'provider.language-configuration')
+end
+
+config.watch(function (uri, key, value)
+ if key == '' then
+ refreshLanguageConfiguration()
+ end
+end)
local function refreshStatusBar()
if not client.getOption('statusBar') then