summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.editorconfig87
-rw-r--r--debugger.lua6
-rw-r--r--main.lua3
-rw-r--r--make.lua5
-rw-r--r--make/bootstrap.lua15
-rw-r--r--script/brave/init.lua2
-rw-r--r--script/client.lua4
-rw-r--r--script/core/code-action.lua7
-rw-r--r--script/core/command/jsonToLua.lua6
-rw-r--r--script/core/command/setConfig.lua2
-rw-r--r--script/core/completion/completion.lua2
-rw-r--r--script/provider/diagnostic.lua22
12 files changed, 127 insertions, 34 deletions
diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 00000000..3dc03084
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,87 @@
+# see https://github.com/CppCXY/EmmyLuaCodeStyle
+[*.lua]
+# [basic code reformat option]
+# optional space/tab
+indent_style = space
+# if indent_style is space, this is valid
+indent_size = 4
+# if indent_style is tab, this is valid
+tab_width = 4
+# only support number
+continuation_indent_size = 4
+# if true, continuation_indent_size for local or assign statement is invalid
+# however, if the expression list has cross row expression, it will not be aligned to the first expression
+local_assign_continuation_align_to_first_expression = false
+# function call expression's args will align to first arg
+# however, if the args has cross row arg, it will not be aligned to the first arg
+align_call_args = false
+# if true, format like this "print( "123", 456 )"
+keep_one_space_between_call_args_and_parentheses = false
+# if true, all function define params will align to first param
+align_function_define_params = true
+# if true, format like this "local t = { 1, 2, 3 }"
+keep_one_space_between_table_and_bracket = true
+# if indent_style is tab, this option is invalid
+align_table_field_to_first_field = false
+# if true, ormat like this "local t <const> = 1"
+keep_one_space_between_namedef_and_attribute = false
+# continous line distance
+max_continuous_line_distance = 1
+# if true, iff any one of the consecutive rows meets the condition of aligning to the equal sign,
+# the consecutive rows will be aligned to the equal sign
+weak_alignment_rule = true
+# see document for detail
+continuous_assign_statement_align_to_equal_sign = true
+# see document for detail
+continuous_assign_table_field_align_to_equal_sign = true
+# if true, the label loses its current indentation
+label_no_indent = false
+# if true, there will be no indentation in the do statement
+do_statement_no_indent = false
+# if true, the conditional expression of the if statement will not be a continuation line indent
+if_condition_no_continuation_indent = false
+
+
+# optional crlf/lf
+end_of_line = crlf
+
+# [line layout]
+# The following configuration supports three expressions
+# minLine:${n}
+# keepLine
+# KeepLine:${n}
+
+keep_line_after_if_statement = minLine:0
+keep_line_after_do_statement = minLine:0
+keep_line_after_while_statement = minLine:0
+keep_line_after_repeat_statement = minLine:0
+keep_line_after_for_statement = minLine:0
+keep_line_after_local_or_assign_statement = keepLine
+keep_line_after_function_define_statement = keepLine:1
+
+# [diagnostic]
+# the following is code diagnostic options
+enable_check_codestyle = true
+# this mean utf8 length
+max_line_length = 120
+# this will check text end with new line(format always end with new line)
+insert_final_newline = true
+
+# [name style check]
+enable_name_style_check = true
+# the following is name style check rule
+# base option off/camel_case/snake_case/upper_snake_case/pascal_case/same(filename/first_param/'<const string>', snake_case/pascal_case/camel_case)
+# all option can use '|' represent or
+# for example:
+# snake_case | upper_snake_case
+# same(first_param, snake_case)
+# same('m')
+local_name_define_style = camel_case
+function_param_name_style = camel_case
+function_name_define_style = camel_case
+local_function_name_define_style = camel_case
+table_field_name_define_style = camel_case
+global_variable_name_define_style = camel_case|upper_snake_case
+module_name_define_style = camel_case
+require_module_name_style = camel_case
+class_name_define_style = camel_case
diff --git a/debugger.lua b/debugger.lua
index 84579b9d..5d2c540f 100644
--- a/debugger.lua
+++ b/debugger.lua
@@ -5,7 +5,7 @@ end
local fs = require 'bee.filesystem'
local luaDebugs = {}
-for _, vscodePath in ipairs {'.vscode', '.vscode-insiders', '.vscode-server-insiders'} do
+for _, vscodePath in ipairs { '.vscode', '.vscode-insiders', '.vscode-server-insiders' } do
local extensionPath = fs.path(os.getenv 'USERPROFILE' or os.getenv 'HOME') / vscodePath / 'extensions'
log.debug('Search extensions at:', extensionPath:string())
@@ -39,8 +39,8 @@ table.sort(luaDebugs, function (a, b)
end)
local debugPath = luaDebugs[1]
-local cpath = "/runtime/win64/lua54/?.dll;/runtime/win64/lua54/?.so"
-local path = "/script/?.lua"
+local cpath = "/runtime/win64/lua54/?.dll;/runtime/win64/lua54/?.so"
+local path = "/script/?.lua"
local function tryDebugger()
local entry = assert(package.searchpath('debugger', debugPath .. path))
diff --git a/main.lua b/main.lua
index 4fa302ac..59cf9a89 100644
--- a/main.lua
+++ b/main.lua
@@ -27,7 +27,8 @@ end
loadArgs()
local currentPath = debug.getinfo(1, 'S').source:sub(2)
-local rootPath = currentPath:gsub('[/\\]*[^/\\]-$', '')
+local rootPath = currentPath:gsub('[/\\]*[^/\\]-$', '')
+
rootPath = (rootPath == '' and '.' or rootPath)
ROOT = fs.path(util.expandPath(rootPath))
LOGPATH = LOGPATH and util.expandPath(LOGPATH) or (ROOT:string() .. '/log')
diff --git a/make.lua b/make.lua
index 466fe4a4..3be875c5 100644
--- a/make.lua
+++ b/make.lua
@@ -4,6 +4,7 @@ local exe = platform.OS == 'Windows' and ".exe" or ""
lm.bindir = "bin"
+---@diagnostic disable-next-line: codestyle-check
lm.EXE_DIR = ""
if platform.OS == 'macOS' then
@@ -49,7 +50,7 @@ lm:source_set 'lpeglabel' {
}
lm:executable "lua-language-server" {
- deps = {"lpeglabel", "source_bootstrap", "code_format"},
+ deps = { "lpeglabel", "source_bootstrap", "code_format" },
includes = {
"3rd/bee.lua",
"3rd/bee.lua/3rd/lua",
@@ -67,7 +68,7 @@ lm:executable "lua-language-server" {
lm:copy "copy_bootstrap" {
input = "make/bootstrap.lua",
- output = lm.bindir.."/main.lua",
+ output = lm.bindir .. "/main.lua",
}
lm:build 'copy_vcrt' {
diff --git a/make/bootstrap.lua b/make/bootstrap.lua
index 3d2ce465..42de853a 100644
--- a/make/bootstrap.lua
+++ b/make/bootstrap.lua
@@ -35,7 +35,8 @@ if main then
end
end
-local root; do
+local root
+do
if main then
local fs = require 'bee.filesystem'
local mainPath = fs.path(arg[0])
@@ -44,21 +45,21 @@ local root; do
root = '.'
end
else
- local sep = package.config:sub(1,1)
+ local sep = package.config:sub(1, 1)
if sep == '\\' then
sep = '/\\'
end
- local pattern = "["..sep.."]+[^"..sep.."]+"
- root = package.cpath:match("([^;]+)"..pattern..pattern.."$")
- arg[0] = root .. package.config:sub(1,1) .. 'main.lua'
+ local pattern = "[" .. sep .. "]+[^" .. sep .. "]+"
+ root = package.cpath:match("([^;]+)" .. pattern .. pattern .. "$")
+ arg[0] = root .. package.config:sub(1, 1) .. 'main.lua'
end
- root = root:gsub('[/\\]', package.config:sub(1,1))
+ root = root:gsub('[/\\]', package.config:sub(1, 1))
end
package.path = table.concat({
root .. "/script/?.lua",
root .. "/script/?/init.lua",
-}, ";"):gsub('/', package.config:sub(1,1))
+}, ";"):gsub('/', package.config:sub(1, 1))
package.searchers[2] = function (name)
local filename, err = package.searchpath(name, package.path)
diff --git a/script/brave/init.lua b/script/brave/init.lua
index 24c2e412..9cad8c4e 100644
--- a/script/brave/init.lua
+++ b/script/brave/init.lua
@@ -1,4 +1,4 @@
-local brave = require 'brave.brave'
+local brave = require 'brave.brave'
require 'brave.work'
return brave
diff --git a/script/client.lua b/script/client.lua
index 86b13179..9074239a 100644
--- a/script/client.lua
+++ b/script/client.lua
@@ -250,7 +250,9 @@ local function tryModifyRC(uri, finalChanges, create)
end
local scp = scope.getScope(uri)
local rc = scp:get('lastRCConfig') or {
- ['$schema'] = lang.id == 'zh-cn' and [[https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema-zh-cn.json]] or [[https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json]]
+ ['$schema'] = lang.id == 'zh-cn'
+ and [[https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema-zh-cn.json]]
+ or [[https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json]]
}
local suc = applyConfig(rc, uri, finalChanges)
if not suc then
diff --git a/script/core/code-action.lua b/script/core/code-action.lua
index b2a6fac9..f96e341a 100644
--- a/script/core/code-action.lua
+++ b/script/core/code-action.lua
@@ -43,13 +43,13 @@ local function checkDisableByLuaDocInsert(uri, row, mode, code)
end
local function disableDiagnostic(uri, code, start, results)
- local row = guide.rowColOf(start)
+ local row = guide.rowColOf(start)
results[#results+1] = {
title = lang.script('ACTION_DISABLE_DIAG', code),
kind = 'quickfix',
command = {
- title = lang.script.COMMAND_DISABLE_DIAG,
- command = 'lua.setConfig',
+ title = lang.script.COMMAND_DISABLE_DIAG,
+ command = 'lua.setConfig',
arguments = {
{
key = 'Lua.diagnostics.disable',
@@ -174,7 +174,6 @@ local function solveSyntaxByChangeVersion(uri, err, results)
end
local function solveSyntaxByAddDoEnd(uri, err, results)
- local text = files.getText(uri)
results[#results+1] = {
title = lang.script.ACTION_ADD_DO_END,
kind = 'quickfix',
diff --git a/script/core/command/jsonToLua.lua b/script/core/command/jsonToLua.lua
index d29ad608..fb0fc6c9 100644
--- a/script/core/command/jsonToLua.lua
+++ b/script/core/command/jsonToLua.lua
@@ -14,9 +14,9 @@ return function (data)
if not text then
return
end
- local start = guide.positionToOffset(state, data.start)
- local finish = guide.positionToOffset(state, data.finish)
- local jsonStr = text:sub(start + 1, finish)
+ local start = guide.positionToOffset(state, data.start)
+ local finish = guide.positionToOffset(state, data.finish)
+ local jsonStr = text:sub(start + 1, finish)
local suc, res = pcall(json.decode, jsonStr)
if not suc then
proto.notify('window/showMessage', {
diff --git a/script/core/command/setConfig.lua b/script/core/command/setConfig.lua
index e3eb0d0a..4587dd47 100644
--- a/script/core/command/setConfig.lua
+++ b/script/core/command/setConfig.lua
@@ -1,5 +1,5 @@
local client = require 'client'
return function (data)
- client.setConfig {data}
+ client.setConfig { data }
end
diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua
index 680b9a23..a8000c91 100644
--- a/script/core/completion/completion.lua
+++ b/script/core/completion/completion.lua
@@ -75,7 +75,7 @@ local function findNearestTableField(state, position)
if not soffset then
return nil
end
- local symbol = text:sub(soffset, soffset)
+ local symbol = text:sub(soffset, soffset)
if symbol == '}' then
return nil
end
diff --git a/script/provider/diagnostic.lua b/script/provider/diagnostic.lua
index d0de0962..32b6fc6f 100644
--- a/script/provider/diagnostic.lua
+++ b/script/provider/diagnostic.lua
@@ -28,7 +28,7 @@ end
local function buildSyntaxError(uri, err)
local text = files.getText(uri)
- local message = lang.script('PARSER_'..err.type, err.info)
+ local message = lang.script('PARSER_' .. err.type, err.info)
if err.version then
local version = err.info and err.info.version or config.get(uri, 'Lua.runtime.version')
@@ -45,7 +45,7 @@ local function buildSyntaxError(uri, err)
for _, rel in ipairs(related) do
local rmessage
if rel.message then
- rmessage = lang.script('PARSER_'..rel.message)
+ rmessage = lang.script('PARSER_' .. rel.message)
else
rmessage = text:sub(rel.start, rel.finish)
end
@@ -63,8 +63,9 @@ local function buildSyntaxError(uri, err)
severity = define.DiagnosticSeverity[err.level],
source = lang.script.DIAG_SYNTAX_CHECK,
message = message,
- relatedInformation = relatedInformation,
data = 'syntax',
+
+ relatedInformation = relatedInformation,
}
end
@@ -77,7 +78,7 @@ local function buildDiagnostic(uri, diag)
if diag.related then
relatedInformation = {}
for _, rel in ipairs(diag.related) do
- local rtext = files.getText(rel.uri)
+ local rtext = files.getText(rel.uri)
relatedInformation[#relatedInformation+1] = {
message = rel.message or rtext:sub(rel.start, rel.finish),
location = converter.location(rel.uri, converter.packRange(rel.uri, rel.start, rel.finish))
@@ -93,6 +94,7 @@ local function buildDiagnostic(uri, diag)
code = diag.code,
tags = diag.tags,
data = diag.data,
+
relatedInformation = relatedInformation,
}
end
@@ -292,12 +294,17 @@ function m.refresh(uri)
end
await.close('diag:' .. uri)
await.call(function () ---@async
- m.diagnosticsScope(uri)
if uri then
await.setID('diag:' .. uri)
await.sleep(0.1)
xpcall(m.doDiagnostic, log.error, uri)
end
+ local delay = config.get(uri, 'Lua.diagnostics.workspaceDelay') / 1000
+ if delay < 0 then
+ return
+ end
+ await.sleep(math.max(delay, 0.2))
+ m.diagnosticsScope(uri)
end)
end
@@ -357,15 +364,10 @@ function m.diagnosticsScope(uri, force)
m.clearAll()
return
end
- local delay = config.get(uri, 'Lua.diagnostics.workspaceDelay') / 1000
- if not force and delay < 0 then
- return
- end
local scp = scope.getScope(uri)
local id = 'diagnosticsScope:' .. scp:getName()
await.close(id)
await.call(function () ---@async
- await.sleep(math.max(delay, 0.2))
while loading.count() > 0 do
await.sleep(1.0)
end