Skip to content

Commit

Permalink
Merge branch 'master' into generic-pattern1
Browse files Browse the repository at this point in the history
  • Loading branch information
fesily committed Mar 18, 2024
2 parents 74e74d2 + 8da156b commit ad310d1
Show file tree
Hide file tree
Showing 45 changed files with 325 additions and 121 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
matrix:
include:
- { os: ubuntu-20.04, platform: linux-x64 }
- { os: macos-latest, platform: darwin-x64 }
- { os: macos-14, platform: darwin-arm64 }
- { os: windows-latest, platform: win32-x64 }
runs-on: ${{ matrix.os }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion 3rd/EmmyLuaCodeStyle
Submodule EmmyLuaCodeStyle updated 32 files
+1 −1 .github/workflows/build.yml
+0 −28 .github/workflows/codestyle.yml
+1 −1 .github/workflows/pr.yml
+200 −144 CHANGELOG.md
+493 −0 CHANGELOG_CN.md
+0 −430 CHANGELOG_EN.md
+2 −4 CodeFormat/src/FormatContext.cpp
+4 −0 CodeFormatCore/include/CodeFormatCore/Config/LuaDiagnosticStyle.h
+3 −6 CodeFormatCore/include/CodeFormatCore/Config/LuaEditorConfig.h
+3 −2 CodeFormatCore/include/CodeFormatCore/Config/LuaStyle.h
+10 −0 CodeFormatCore/include/CodeFormatCore/Config/LuaStyleStruct.h
+1 −1 CodeFormatCore/include/CodeFormatCore/Diagnostic/CodeStyle/CodeStyleChecker.h
+1 −0 CodeFormatCore/include/CodeFormatCore/Diagnostic/NameStyle/NameDefineType.h
+2 −1 CodeFormatCore/include/CodeFormatCore/Format/Analyzer/FormatStrategy.h
+4 −0 CodeFormatCore/include/CodeFormatCore/Format/Analyzer/IndentationAnalyzer.h
+85 −36 CodeFormatCore/src/Config/LuaEditorConfig.cpp
+126 −97 CodeFormatCore/src/Config/LuaStyle.cpp
+5 −6 CodeFormatCore/src/Diagnostic/CodeStyle/CodeStyleChecker.cpp
+26 −1 CodeFormatCore/src/Diagnostic/NameStyle/NameStyleChecker.cpp
+6 −8 CodeFormatCore/src/Format/Analyzer/FormatDocAnalyze.cpp
+50 −29 CodeFormatCore/src/Format/Analyzer/IndentationAnalyzer.cpp
+6 −3 CodeFormatCore/src/Format/Analyzer/SpaceAnalyzer.cpp
+1 −1 CodeFormatCore/src/Format/FormatState.cpp
+2 −4 CodeFormatLib/src/LuaCodeFormat.cpp
+2 −4 CodeFormatServer/src/Service/ConfigService.cpp
+5 −2 LuaParser/include/LuaParser/Lexer/TextReader.h
+33 −8 LuaParser/src/Lexer/TextReader.cpp
+21 −0 Test/src/FormatResult_unitest.cpp
+47 −2 Test/src/FormatStyle_unitest.cpp
+1 −0 docs/name_style.md
+1 −0 docs/name_style_EN.md
+3 −0 lua.template.editorconfig
2 changes: 1 addition & 1 deletion 3rd/bee.lua
Submodule bee.lua updated 50 files
+7 −6 3rd/fmt/fmt/args.h
+3,044 −0 3rd/fmt/fmt/base.h
+222 −151 3rd/fmt/fmt/chrono.h
+63 −74 3rd/fmt/fmt/color.h
+13 −10 3rd/fmt/fmt/compile.h
+4 −2,932 3rd/fmt/fmt/core.h
+308 −78 3rd/fmt/fmt/format-inl.h
+562 −670 3rd/fmt/fmt/format.h
+37 −26 3rd/fmt/fmt/os.h
+40 −27 3rd/fmt/fmt/ostream.h
+98 −100 3rd/fmt/fmt/printf.h
+134 −92 3rd/fmt/fmt/ranges.h
+164 −66 3rd/fmt/fmt/std.h
+100 −41 3rd/fmt/fmt/xchar.h
+10 −10 bee/filewatch/filewatch.h
+6 −6 bee/filewatch/filewatch_linux.cpp
+10 −8 bee/filewatch/filewatch_osx.cpp
+9 −9 bee/filewatch/filewatch_win.cpp
+5 −5 bee/net/socket.cpp
+3 −3 bee/net/socket.h
+12 −0 bee/nonstd/charconv.h
+12 −0 bee/nonstd/format.h
+3 −3 bee/platform/version.cpp
+1 −1 bee/platform/version.h
+2 −2 bee/platform/win/module_version.h
+2 −2 bee/platform/win/module_version_win.cpp
+6 −6 bee/platform/win/unicode.h
+6 −6 bee/platform/win/unicode_win.cpp
+1 −1 bee/subprocess/process_select.cpp
+1 −1 bee/subprocess/process_select.h
+15 −15 bee/subprocess/subprocess_posix.cpp
+17 −17 bee/subprocess/subprocess_posix.h
+19 −19 bee/subprocess/subprocess_win.cpp
+7 −7 bee/subprocess/subprocess_win.h
+1 −1 bee/thread/setname.cpp
+1 −1 bee/thread/setname.h
+4 −4 bee/utility/dynarray.h
+18 −13 bee/utility/path_helper.cpp
+3 −3 bee/utility/path_helper.h
+1 −13 binding/lua_platform.cpp
+1 −0 binding/lua_thread.cpp
+5 −5 compile/bootstrap.lua
+24 −34 compile/config.lua
+11 −10 compile/emcc.lua
+1,042 −0 test/ltest.lua
+0 −133 test/ltest/coverage.lua
+0 −436 test/ltest/ltest.lua
+0 −198 test/ltest/stringify.lua
+0 −261 test/ltest/undump.lua
+1 −4 test/test.lua
6 changes: 6 additions & 0 deletions locale/en-us/setting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,12 @@ When checking the type of union type, ignore the `nil` in it.
When this setting is `false`, the `number|nil` type cannot be assigned to the `number` type. It can be with `true`.
]]
config.type.inferParamType =
[[
When a parameter type is not annotated, it is inferred from the function's call sites.
When this setting is `false`, the type of the parameter is `any` when it is not annotated.
]]
config.doc.privateName =
'Treat specific field names as private, e.g. `m_*` means `XXX.m_id` and `XXX.m_type` are private, witch can only be accessed in the class where the definition is located.'
config.doc.protectedName =
Expand Down
6 changes: 6 additions & 0 deletions locale/pt-br/setting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,12 @@ When checking the type of union type, ignore the `nil` in it.
When this setting is `false`, the `number|nil` type cannot be assigned to the `number` type. It can be with `true`.
]]
config.type.inferParamType = -- TODO: need translate!
[[
When the parameter type is not annotated, the parameter type is inferred from the function's incoming parameters.
When this setting is `false`, the type of the parameter is `any` when it is not annotated.
]]
config.doc.privateName = -- TODO: need translate!
'Treat specific field names as private, e.g. `m_*` means `XXX.m_id` and `XXX.m_type` are private, witch can only be accessed in the class where the definition is located.'
config.doc.protectedName = -- TODO: need translate!
Expand Down
6 changes: 6 additions & 0 deletions locale/zh-cn/setting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,12 @@ config.type.weakNilCheck =
此设置为 `false` 时,`numer|nil` 类型无法赋给 `number` 类型;为 `true` 是则可以。
]]
config.type.inferParamType =
[[
未注释参数类型时,参数类型由函数传入参数推断。
如果设置为 "false",则在未注释时,参数类型为 "any"。
]]
config.doc.privateName =
'将特定名称的字段视为私有,例如 `m_*` 意味着 `XXX.m_id` 与 `XXX.m_type` 是私有字段,只能在定义所在的类中访问。'
config.doc.protectedName =
Expand Down
6 changes: 6 additions & 0 deletions locale/zh-tw/setting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,12 @@ When checking the type of union type, ignore the `nil` in it.
When this setting is `false`, the `number|nil` type cannot be assigned to the `number` type. It can be with `true`.
]]
config.type.inferParamType = -- TODO: need translate!
[[
未注释参数类型时,参数类型由函数传入参数推断。
如果设置为 "false",则在未注释时,参数类型为 "any"。
]]
config.doc.privateName = -- TODO: need translate!
'Treat specific field names as private, e.g. `m_*` means `XXX.m_id` and `XXX.m_type` are private, witch can only be accessed in the class where the definition is located.'
config.doc.protectedName = -- TODO: need translate!
Expand Down
22 changes: 11 additions & 11 deletions make.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ local includeCodeFormat = true

require "make.detect_platform"

lm:import "3rd/bee.lua"
lm:import "3rd/bee.lua/make.lua"
lm:import "make/code_format.lua"

lm:source_set 'lpeglabel' {
Expand Down Expand Up @@ -55,21 +55,21 @@ lm:executable "lua-language-server" {
}

local platform = require 'bee.platform'
local exe = platform.OS == 'Windows' and ".exe" or ""
local exe = platform.os == 'windows' and ".exe" or ""

lm:copy "copy_lua-language-server" {
input = lm.bindir .. "/lua-language-server" .. exe,
output = "bin/lua-language-server" .. exe,
inputs = "$bin/lua-language-server" .. exe,
outputs = "bin/lua-language-server" .. exe,
}

lm:copy "copy_bootstrap" {
input = "make/bootstrap.lua",
output = "bin/main.lua",
inputs = "make/bootstrap.lua",
outputs = "bin/main.lua",
}

lm:msvc_copydll 'copy_vcrt' {
type = "vcrt",
output = "bin",
outputs = "bin",
}

lm:phony "all" {
Expand All @@ -93,27 +93,27 @@ if lm.notest then
end

lm:rule "run-bee-test" {
lm.bindir .. "/lua-language-server" .. exe, "$in",
args = { "$bin/lua-language-server" .. exe, "$in" },
description = "Run test: $in.",
pool = "console",
}

lm:rule "run-unit-test" {
"bin/lua-language-server" .. exe, "$in",
args = { "bin/lua-language-server" .. exe, "$in" },
description = "Run test: $in.",
pool = "console",
}

lm:build "bee-test" {
rule = "run-bee-test",
deps = { "lua-language-server", "copy_script" },
input = "3rd/bee.lua/test/test.lua",
inputs = "3rd/bee.lua/test/test.lua",
}

lm:build 'unit-test' {
rule = "run-unit-test",
deps = { "bee-test", "all" },
input = "test.lua",
inputs = "test.lua",
}

lm:default {
Expand Down
10 changes: 5 additions & 5 deletions make/detect_platform.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local lm = require 'luamake'

local platform = require 'bee.platform'

if platform.OS == 'macOS' then
if platform.os == 'macos' then
if lm.platform == nil then
elseif lm.platform == "darwin-arm64" then
lm.target = "arm64-apple-macos11"
Expand All @@ -11,7 +11,7 @@ if platform.OS == 'macOS' then
else
error "unknown platform"
end
elseif platform.OS == 'Windows' then
elseif platform.os == 'windows' then
if lm.platform == nil then
elseif lm.platform == "win32-ia32" then
lm.arch = "x86"
Expand All @@ -20,7 +20,7 @@ elseif platform.OS == 'Windows' then
else
error "unknown platform"
end
elseif platform.OS == 'Linux' then
elseif platform.os == 'linux' then
if lm.platform == nil then
elseif lm.platform == "linux-x64" then
elseif lm.platform == "linux-arm64" then
Expand Down Expand Up @@ -52,7 +52,7 @@ local ARCH <const> = {
}

local function detectArch()
if platform.OS == 'Windows' then
if platform.os == 'windows' then
return detectWindowsArch()
end
local posixArch = detectPosixArch()
Expand All @@ -67,5 +67,5 @@ local function targetPlatformArch()
end

if not lm.notest then
lm.notest = (platform.OS ~= 'Windows' and targetPlatformArch() ~= detectArch())
lm.notest = (platform.os ~= 'windows' and targetPlatformArch() ~= detectArch())
end
5 changes: 4 additions & 1 deletion script/cli/check.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ local config = require 'config.config'
local fs = require 'bee.filesystem'
local provider = require 'provider'

require 'plugin'
require 'vm'

lang(LOCALE)
Expand All @@ -26,6 +27,7 @@ if not rootUri then
print(lang.script('CLI_CHECK_ERROR_URI', rootPath))
return
end
rootUri = rootUri:gsub("/$", "")

if CHECKLEVEL then
if not define.DiagnosticSeverity[CHECKLEVEL] then
Expand Down Expand Up @@ -69,7 +71,7 @@ lclient():start(function (client)
end
config.set(rootUri, 'Lua.diagnostics.disable', util.getTableKeys(disables, true))

local uris = files.getAllUris(rootUri)
local uris = files.getChildFiles(rootUri)
local max = #uris
for i, uri in ipairs(uris) do
files.open(uri)
Expand All @@ -83,6 +85,7 @@ lclient():start(function (client)
.. ('0'):rep(#tostring(max) - #tostring(i))
.. tostring(i) .. '/' .. tostring(max)
io.write(output)
io.flush()
end
end
io.write('\x0D')
Expand Down
72 changes: 72 additions & 0 deletions script/cli/doc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,13 @@ local function collectTypes(global, results)
field.rawdesc = getDesc(source, true)
field.extends = packObject(source.value)
field.visible = vm.getVisibleType(source)
if vm.isAsync(source, true) then
field.async = true
end
local depr = vm.getDeprecated(source)
if (depr and not depr.versions) then
field.deprecated = true
end
return
end
if source.type == 'tableindex' then
Expand Down Expand Up @@ -250,6 +257,13 @@ local function collectVars(global, results)
result.rawdesc = result.rawdesc or getDesc(set, true)
result.defines[#result.defines].extends['desc'] = getDesc(set)
result.defines[#result.defines].extends['rawdesc'] = getDesc(set, true)
if vm.isAsync(set, true) then
result.defines[#result.defines].extends['async'] = true
end
local depr = vm.getDeprecated(set)
if (depr and not depr.versions) then
result.defines[#result.defines].extends['deprecated'] = true
end
end
end
if #result.defines == 0 then
Expand All @@ -264,12 +278,26 @@ local function collectVars(global, results)
results[#results+1] = result
end

---Add config settings to JSON output.
---@param results table
local function collectConfig(results)
local result = {
name = 'LuaLS',
type = 'luals.config',
DOC = fs.absolute(fs.path(DOC)):string(),
defines = {},
fields = {}
}
results[#results+1] = result
end

---@async
---@param callback fun(i, max)
function export.export(outputPath, callback)
local results = {}
local globals = vm.getAllGlobals()

collectConfig(results)
local max = 0
for _ in pairs(globals) do
max = max + 1
Expand Down Expand Up @@ -331,9 +359,53 @@ function export.makeDoc(outputPath)
return docPath, mdPath
end


---Find file 'doc.json'.
---@return fs.path
local function findDocJson()
local doc_json_path
if type(DOC_UPDATE) == 'string' then
doc_json_path = fs.absolute(fs.path(DOC_UPDATE)) .. '/doc.json'
else
doc_json_path = fs.current_path() .. '/doc.json'
end
if fs.exists(doc_json_path) then
return doc_json_path
else
error(string.format('Error: File "%s" not found.', doc_json_path))
end
end

---@return string # path of 'doc.json'
---@return string # path to be documented
local function getPathDocUpdate()
local doc_json_path = findDocJson()
local ok, doc_path = pcall(
function ()
local json = require('json')
local json_file = io.open(doc_json_path:string(), 'r'):read('*all')
local json_data = json.decode(json_file)
for _, section in ipairs(json_data) do
if section.type == 'luals.config' then
return section.DOC
end
end
end)
if ok then
local doc_json_dir = doc_json_path:string():gsub('/doc.json', '')
return doc_json_dir, doc_path
else
error(string.format('Error: Cannot update "%s".', doc_json_path .. '/doc.json'))
end
end

function export.runCLI()
lang(LOCALE)

if DOC_UPDATE then
DOC_OUT_PATH, DOC = getPathDocUpdate()
end

if type(DOC) ~= 'string' then
print(lang.script('CLI_CHECK_ERROR_TYPE', type(DOC)))
return
Expand Down
5 changes: 5 additions & 0 deletions script/cli/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ if _G['CHECK'] then
os.exit(0, true)
end

if _G['DOC_UPDATE'] then
require 'cli.doc' .runCLI()
os.exit(0, true)
end

if _G['DOC'] then
require 'cli.doc' .runCLI()
os.exit(0, true)
Expand Down
4 changes: 2 additions & 2 deletions script/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ local function searchPatchInfo(cfg, rawKey)
}
end

---@param uri uri
---@param uri? uri
---@param cfg table
---@param change config.change
---@return json.patch?
Expand Down Expand Up @@ -330,7 +330,7 @@ local function makeConfigPatch(uri, cfg, change)
return nil
end

---@param uri uri
---@param uri? uri
---@param path string
---@param changes config.change[]
---@return string?
Expand Down
1 change: 1 addition & 0 deletions script/config/template.lua
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ local template = {
['Lua.type.castNumberToInteger'] = Type.Boolean >> true,
['Lua.type.weakUnionCheck'] = Type.Boolean >> false,
['Lua.type.weakNilCheck'] = Type.Boolean >> false,
['Lua.type.inferParamType'] = Type.Boolean >> false,
['Lua.doc.privateName'] = Type.Array(Type.String),
['Lua.doc.protectedName'] = Type.Array(Type.String),
['Lua.doc.packageName'] = Type.Array(Type.String),
Expand Down
5 changes: 4 additions & 1 deletion script/core/command/autoRequire.lua
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ end

---@async
return function (data)
---@type uri
local uri = data.uri
local target = data.target
local name = data.name
Expand All @@ -158,5 +159,7 @@ return function (data)
end

local offset, fmt = findInsertRow(uri)
applyAutoRequire(uri, offset, name, requireName, fmt)
if offset and fmt then
applyAutoRequire(uri, offset, name, requireName, fmt)
end
end
Loading

0 comments on commit ad310d1

Please sign in to comment.