summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
authorCppCXY <812125110@qq.com>2022-02-07 22:04:45 +0800
committerCppCXY <812125110@qq.com>2022-02-07 22:04:45 +0800
commit4a2203daaf5ff5935eb185db1d938a7ed25772e6 (patch)
treeb2a0451e2e3b3b7fe1a14384d3cb7d18a94cf478 /script
parent3f620ce549997ecaf9db3b3ddf86ca8bb488527f (diff)
parent38adf62e8dec279ef76073a807989dd8b7669afc (diff)
downloadlua-language-server-4a2203daaf5ff5935eb185db1d938a7ed25772e6.zip
Merge branch 'format' of https://github.com/CppCXY/lua-language-server into format
Diffstat (limited to 'script')
-rw-r--r--script/core/diagnostics/codestyle-check.lua34
-rw-r--r--script/core/formatting.lua4
-rw-r--r--script/core/rangeformatting.lua4
-rw-r--r--script/core/type-formatting.lua3
-rw-r--r--script/proto/define.lua1
-rw-r--r--script/provider/capability.lua3
-rw-r--r--script/provider/provider.lua12
7 files changed, 47 insertions, 14 deletions
diff --git a/script/core/diagnostics/codestyle-check.lua b/script/core/diagnostics/codestyle-check.lua
new file mode 100644
index 00000000..16623eca
--- /dev/null
+++ b/script/core/diagnostics/codestyle-check.lua
@@ -0,0 +1,34 @@
+local files = require("files")
+local codeFormat = require "code_format"
+local converter = require("proto.converter")
+local log = require("log")
+local config = require("config")
+
+
+---@async
+return function(uri, callback)
+ local text = files.getText(uri)
+ if not text then
+ return
+ end
+
+ local status, diagnosticInfos = codeFormat.diagnose_file(uri, text)
+
+ if not status then
+ if diagnosticInfos ~= nil then
+ log.error(diagnosticInfos)
+ end
+
+ return
+ end
+
+ if diagnosticInfos then
+ for _, diagnosticInfo in pairs(diagnosticInfos) do
+ callback {
+ start = converter.unpackPosition(uri, diagnosticInfo.range.start),
+ finish = converter.unpackPosition(uri, diagnosticInfo.range["end"]),
+ message = diagnosticInfo.message
+ }
+ end
+ end
+end
diff --git a/script/core/formatting.lua b/script/core/formatting.lua
index 8f72028b..6c57b8c2 100644
--- a/script/core/formatting.lua
+++ b/script/core/formatting.lua
@@ -1,11 +1,11 @@
-local code_format = require "code_format"
+local codeFormat = require("code_format")
local files = require("files")
local log = require("log")
return function(uri)
local text = files.getText(uri)
local ast = files.getState(uri)
- local status, formattedText = code_format.format(uri, text)
+ local status, formattedText = codeFormat.format(uri, text)
if not status then
if formattedText ~= nil then
diff --git a/script/core/rangeformatting.lua b/script/core/rangeformatting.lua
index b66f0fbd..de9516c1 100644
--- a/script/core/rangeformatting.lua
+++ b/script/core/rangeformatting.lua
@@ -1,11 +1,11 @@
-local code_format = require "code_format"
+local codeFormat = require("code_format")
local files = require("files")
local log = require("log")
local converter = require("proto.converter")
return function(uri, range)
local text = files.getText(uri)
- local status, formattedText, startLine, endLine = code_format.range_format(
+ local status, formattedText, startLine, endLine = codeFormat.range_format(
uri, text, range.start.line, range["end"].line)
if not status then
diff --git a/script/core/type-formatting.lua b/script/core/type-formatting.lua
index b946184b..cc305982 100644
--- a/script/core/type-formatting.lua
+++ b/script/core/type-formatting.lua
@@ -46,6 +46,7 @@ local function checkSplitOneLine(results, uri, position, ch)
if ch ~= '\n' then
return
end
+
local fPosition, fSymbol = findForward(uri, position, 'end', '}')
if not fPosition then
return
@@ -77,7 +78,7 @@ local function checkSplitOneLine(results, uri, position, ch)
end
return function (uri, position, ch)
- local ast = files.getState(uri)
+ local ast = files.getState(uri)
if not ast then
return nil
end
diff --git a/script/proto/define.lua b/script/proto/define.lua
index dbb6ba85..b4a0da0c 100644
--- a/script/proto/define.lua
+++ b/script/proto/define.lua
@@ -58,6 +58,7 @@ m.DiagnosticDefaultSeverity = {
['doc-field-no-class'] = 'Warning',
['duplicate-doc-field'] = 'Warning',
['unknown-diag-code'] = 'Waiting',
+ ['codestyle-check'] = "Warning",
}
---@alias DiagnosticDefaultNeededFileStatus
diff --git a/script/provider/capability.lua b/script/provider/capability.lua
index 31baf690..e13e11e0 100644
--- a/script/provider/capability.lua
+++ b/script/provider/capability.lua
@@ -114,9 +114,6 @@ function m.getIniter()
},
documentFormattingProvider = true,
documentRangeFormattingProvider = true
- --documentOnTypeFormattingProvider = {
- -- firstTriggerCharacter = '}',
- --},
}
--testFileEvents()
diff --git a/script/provider/provider.lua b/script/provider/provider.lua
index a5e0a1ca..329bc66b 100644
--- a/script/provider/provider.lua
+++ b/script/provider/provider.lua
@@ -103,9 +103,9 @@ m.register 'initialize' {
if params.initializationOptions then
if params.initializationOptions.editorConfigFiles then
- local code_format = require "code_format"
+ local codeFormat = require "code_format"
for _, config in pairs(params.initializationOptions.editorConfigFiles) do
- local status, err = code_format.update_config(1, config.workspace, config.path)
+ local status, err = codeFormat.update_config(1, config.workspace, config.path)
if not status and err ~= nil then
log.error(err)
@@ -930,7 +930,7 @@ m.register 'textDocument/formatting' {
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)
+ local _ <close> = progress.create(workspace.getScope(uri), lang.script.WINDOW_PROCESSING_TYPE_FORMATTING, 0.5)
if not files.exists(uri) then
return nil
@@ -960,7 +960,7 @@ m.register 'textDocument/rangeFormatting' {
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)
+ local _ <close> = progress.create(workspace.getScope(uri), lang.script.WINDOW_PROCESSING_TYPE_FORMATTING, 0.5)
if not files.exists(uri) then
return nil
@@ -988,8 +988,8 @@ m.register 'config/editorconfig/update' {
abortByFileUpdate = true,
---@async
function(params)
- local code_format = require "code_format"
- local status, err = code_format.update_config(params.type, params.source.workspace, params.source.path)
+ local codeFormat = require "code_format"
+ local status, err = codeFormat.update_config(params.type, params.source.workspace, params.source.path)
if not status and err ~= nil then
log.error(err)