Skip to content

Commit

Permalink
Merge branch 'master' into async
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasMatthias committed Feb 26, 2024
2 parents d99570b + c156377 commit 6b8b102
Show file tree
Hide file tree
Showing 43 changed files with 221 additions and 128 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/bee.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
18 changes: 9 additions & 9 deletions make.lua
Original file line number Diff line number Diff line change
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,7 +93,7 @@ if lm.notest then
end

lm:rule "run-bee-test" {
lm.bindir .. "/lua-language-server" .. exe, "$in",
"$bin/lua-language-server" .. exe, "$in",
description = "Run test: $in.",
pool = "console",
}
Expand All @@ -107,13 +107,13 @@ lm:rule "run-unit-test" {
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
12 changes: 10 additions & 2 deletions script/cli/doc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,11 @@ local function collectTypes(global, results)
field.extends = packObject(source.value)
field.visible = vm.getVisibleType(source)
if vm.isAsync(source, true) then
field.async = true
field.async = true
end
local depr = vm.getDeprecated(source)
if (depr and not depr.versions) then
field.deprecated = true
end
return
end
Expand Down Expand Up @@ -254,7 +258,11 @@ local function collectVars(global, results)
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
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
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
52 changes: 37 additions & 15 deletions script/core/completion/completion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ end

local function findParent(state, position)
local text = state.lua
if not text then
return
end
local offset = guide.positionToOffset(state, position)
for i = offset, 1, -1 do
local char = text:sub(i, i)
Expand Down Expand Up @@ -675,6 +678,7 @@ local function checkGlobal(state, word, startPos, position, parent, oop, results
end

---@async
---@param parent parser.object
local function checkField(state, word, start, position, parent, oop, results)
if parent.tag == '_ENV' or parent.special == '_G' then
local globals = vm.getGlobalSets(state.uri, 'variable')
Expand Down Expand Up @@ -955,8 +959,7 @@ local function checkFunctionArgByDocParam(state, word, startPos, results)
end
end

local function isAfterLocal(state, startPos)
local text = state.lua
local function isAfterLocal(state, text, startPos)
local offset = guide.positionToOffset(state, startPos)
local pos = lookBackward.skipSpace(text, offset)
local word = lookBackward.findWord(text, pos)
Expand All @@ -965,6 +968,8 @@ end

local function collectRequireNames(mode, myUri, literal, source, smark, position, results)
local collect = {}
local source_start = source and smark and (source.start + #smark) or position
local source_finish = source and smark and (source.finish - #smark) or position
if mode == 'require' then
for uri in files.eachFile(myUri) do
if myUri == uri then
Expand All @@ -978,8 +983,8 @@ local function collectRequireNames(mode, myUri, literal, source, smark, position
if not collect[info.name] then
collect[info.name] = {
textEdit = {
start = smark and (source.start + #smark) or position,
finish = smark and (source.finish - #smark) or position,
start = source_start,
finish = source_finish,
newText = smark and info.name or util.viewString(info.name),
},
path = relative,
Expand All @@ -1006,8 +1011,8 @@ local function collectRequireNames(mode, myUri, literal, source, smark, position
if not collect[open] then
collect[open] = {
textEdit = {
start = smark and (source.start + #smark) or position,
finish = smark and (source.finish - #smark) or position,
start = source_start,
finish = source_finish,
newText = smark and open or util.viewString(open),
},
path = path,
Expand All @@ -1034,8 +1039,8 @@ local function collectRequireNames(mode, myUri, literal, source, smark, position
if not collect[path] then
collect[path] = {
textEdit = {
start = smark and (source.start + #smark) or position,
finish = smark and (source.finish - #smark) or position,
start = source_start,
finish = source_finish,
newText = smark and path or util.viewString(path),
}
}
Expand Down Expand Up @@ -1097,6 +1102,9 @@ end

local function checkLenPlusOne(state, position, results)
local text = state.lua
if not text then
return
end
guide.eachSourceContain(state.ast, position, function (source)
if source.type == 'getindex'
or source.type == 'setindex' then
Expand Down Expand Up @@ -1392,6 +1400,9 @@ end

local function checkEqualEnum(state, position, results)
local text = state.lua
if not text then
return
end
local start = lookBackward.findTargetSymbol(text, guide.positionToOffset(state, position), '=')
if not start then
return
Expand Down Expand Up @@ -1493,6 +1504,9 @@ local function tryWord(state, position, triggerCharacter, results)
return
end
local text = state.lua
if not text then
return
end
local offset = guide.positionToOffset(state, position)
local finish = lookBackward.skipSpace(text, offset)
local word, start = lookBackward.findWord(text, offset)
Expand All @@ -1518,7 +1532,7 @@ local function tryWord(state, position, triggerCharacter, results)
checkProvideLocal(state, word, startPos, results)
checkFunctionArgByDocParam(state, word, startPos, results)
else
local afterLocal = isAfterLocal(state, startPos)
local afterLocal = isAfterLocal(state, text, startPos)
local stop = checkKeyWord(state, startPos, position, word, hasSpace, afterLocal, results)
if stop then
return
Expand All @@ -1530,8 +1544,10 @@ local function tryWord(state, position, triggerCharacter, results)
checkLocal(state, word, startPos, results)
checkTableField(state, word, startPos, results)
local env = guide.getENV(state.ast, startPos)
checkGlobal(state, word, startPos, position, env, false, results)
checkModule(state, word, startPos, results)
if env then
checkGlobal(state, word, startPos, position, env, false, results)
checkModule(state, word, startPos, results)
end
end
end
end
Expand Down Expand Up @@ -1592,6 +1608,9 @@ end

local function checkTableLiteralField(state, position, tbl, fields, results)
local text = state.lua
if not text then
return
end
local mark = {}
for _, field in ipairs(tbl) do
if field.type == 'tablefield'
Expand All @@ -1610,9 +1629,11 @@ local function checkTableLiteralField(state, position, tbl, fields, results)
local left = lookBackward.findWord(text, guide.positionToOffset(state, position))
if not left then
local pos = lookBackward.findAnyOffset(text, guide.positionToOffset(state, position))
local char = text:sub(pos, pos)
if char == '{' or char == ',' or char == ';' then
left = ''
if pos then
local char = text:sub(pos, pos)
if char == '{' or char == ',' or char == ';' then
left = ''
end
end
end
if left then
Expand Down Expand Up @@ -1801,6 +1822,7 @@ local function getluaDocByContain(state, position)
return result
end

---@return parser.state.err?, parser.object?
local function getluaDocByErr(state, start, position)
local targetError
for _, err in ipairs(state.errs) do
Expand Down Expand Up @@ -2008,7 +2030,7 @@ local function tryluaDocByErr(state, position, err, docState, results)
for _, doc in ipairs(vm.getDocSets(state.uri)) do
if doc.type == 'doc.class'
and not used[doc.class[1]]
and doc.class[1] ~= docState.class[1] then
and docState and doc.class[1] ~= docState.class[1] then
used[doc.class[1]] = true
results[#results+1] = {
label = doc.class[1],
Expand Down
Loading

0 comments on commit 6b8b102

Please sign in to comment.