summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2024-07-15 14:16:26 +0800
committerGitHub <noreply@github.com>2024-07-15 14:16:26 +0800
commit8dd27106bb3c07f0a63a18dba76ef4a66ea8bf74 (patch)
treef152c27a73a9623fe64601557fbcb2b8bb63b8c0
parente558d6e3ed61feffa65314a9464feda742e12b1c (diff)
parent3d88f3313263f316834b2e9e0de47485a4a8d3f3 (diff)
downloadlua-language-server-8dd27106bb3c07f0a63a18dba76ef4a66ea8bf74.zip
Merge branch 'master' into fixes-a-specific-case-for-getVisibleType
-rw-r--r--.github/workflows/build.yml4
-rw-r--r--changelog.md2
-rw-r--r--meta/template/string.lua1
-rw-r--r--script/config/template.lua5
-rw-r--r--script/core/hint.lua2
-rw-r--r--script/provider/provider.lua4
-rw-r--r--script/vm/visible.lua26
-rw-r--r--test/diagnostics/invisible.lua22
8 files changed, 53 insertions, 13 deletions
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index b6db21ca..7b4de2ca 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -27,8 +27,8 @@ jobs:
- { os: ubuntu-22.04, target: linux, platform: linux-x64, container: 'alpine:latest', libc: musl }
- { os: ubuntu-20.04, target: linux, platform: linux-x64 }
- { os: ubuntu-20.04, target: linux, platform: linux-arm64 }
- - { os: macos-11, target: darwin, platform: darwin-x64 }
- - { os: macos-11, target: darwin, platform: darwin-arm64 }
+ - { os: macos-latest, target: darwin, platform: darwin-x64 }
+ - { os: macos-latest, target: darwin, platform: darwin-arm64 }
- { os: windows-latest, target: windows, platform: win32-ia32 }
- { os: windows-latest, target: windows, platform: win32-x64 }
runs-on: ${{ matrix.os }}
diff --git a/changelog.md b/changelog.md
index 5ecbf46b..67e24e88 100644
--- a/changelog.md
+++ b/changelog.md
@@ -8,7 +8,9 @@
* `FIX` Respect `completion.showParams` config for local function completion
* `CHG` Improve performance of multithreaded `--check` and `undefined-field` diagnostic
* `FIX` Now correctly evaluates the visibility of fields in a class when they are defined directly in the object. use for completion and invisible dianostic. [#2752](https://github.com/LuaLS/lua-language-server/issues/2752)
+* `NEW` added lua regular expression support for Lua.doc.<scope>Name [#2753](https://github.com/LuaLS/lua-language-server/pull/2753)
* `FIX` Bad triggering of the `inject-field` diagnostic, when the fields are declared at the creation of the object [#2746](https://github.com/LuaLS/lua-language-server/issues/2746)
+* `CHG` Change spacing of parameter inlay hints to match other LSPs, like `rust-analyzer`
## 3.9.3
`2024-6-11`
diff --git a/meta/template/string.lua b/meta/template/string.lua
index e23b0803..14e01a7b 100644
--- a/meta/template/string.lua
+++ b/meta/template/string.lua
@@ -73,7 +73,6 @@ function string.gmatch(s, pattern, init) end
---@param n? integer
---@return string
---@return integer count
----@nodiscard
function string.gsub(s, pattern, repl, n) end
---#DES 'string.len'
diff --git a/script/config/template.lua b/script/config/template.lua
index e74a9f9c..7b044d7a 100644
--- a/script/config/template.lua
+++ b/script/config/template.lua
@@ -402,7 +402,10 @@ local template = {
['Lua.doc.privateName'] = Type.Array(Type.String),
['Lua.doc.protectedName'] = Type.Array(Type.String),
['Lua.doc.packageName'] = Type.Array(Type.String),
-
+ ['Lua.doc.regengine'] = Type.String >> 'glob' << {
+ 'glob',
+ 'lua',
+ },
-- VSCode
["Lua.addonManager.enable"] = Type.Boolean >> true,
['files.associations'] = Type.Hash(Type.String, Type.String),
diff --git a/script/core/hint.lua b/script/core/hint.lua
index 67ac8516..9d098aa9 100644
--- a/script/core/hint.lua
+++ b/script/core/hint.lua
@@ -59,7 +59,7 @@ local function typeHint(uri, results, start, finish)
end
mark[src] = true
results[#results+1] = {
- text = ':' .. view,
+ text = ': ' .. view,
offset = src.finish,
kind = define.InlayHintKind.Type,
where = 'right',
diff --git a/script/provider/provider.lua b/script/provider/provider.lua
index 15e78b9a..2e2fb5eb 100644
--- a/script/provider/provider.lua
+++ b/script/provider/provider.lua
@@ -1426,8 +1426,8 @@ m.register 'textDocument/inlayHint' {
},
position = converter.packPosition(state, res.offset),
kind = res.kind,
- paddingLeft = res.kind == 1,
- paddingRight = res.kind == 2,
+ paddingLeft = false,
+ paddingRight = res.kind == define.InlayHintKind.Parameter,
}
end
return hintResults
diff --git a/script/vm/visible.lua b/script/vm/visible.lua
index fddb7faf..518307a0 100644
--- a/script/vm/visible.lua
+++ b/script/vm/visible.lua
@@ -7,6 +7,19 @@ local glob = require 'glob'
---@class parser.object
---@field package _visibleType? parser.visibleType
+local function globMatch(patterns, fieldName)
+ return glob.glob(patterns)(fieldName)
+end
+
+local function luaMatch(patterns, fieldName)
+ for i = 1, #patterns do
+ if string.find(fieldName, patterns[i]) then
+ return true
+ end
+ end
+ return false
+end
+
local function getVisibleType(source)
if guide.isLiteral(source) then
return 'public'
@@ -42,21 +55,22 @@ local function getVisibleType(source)
if type(fieldName) == 'string' then
local uri = guide.getUri(source)
-
+ local regengine = config.get(uri, 'Lua.doc.regengine')
+ local match = regengine == "glob" and globMatch or luaMatch
local privateNames = config.get(uri, 'Lua.doc.privateName')
- if #privateNames > 0 and glob.glob(privateNames)(fieldName) then
+ if #privateNames > 0 and match(privateNames, fieldName) then
source._visibleType = 'private'
return 'private'
end
-
+
local protectedNames = config.get(uri, 'Lua.doc.protectedName')
- if #protectedNames > 0 and glob.glob(protectedNames)(fieldName) then
+ if #protectedNames > 0 and match(protectedNames, fieldName) then
source._visibleType = 'protected'
return 'protected'
end
-
+
local packageNames = config.get(uri, 'Lua.doc.packageName')
- if #packageNames > 0 and glob.glob(packageNames)(fieldName) then
+ if #packageNames > 0 and match(packageNames, fieldName) then
source._visibleType = 'package'
return 'package'
end
diff --git a/test/diagnostics/invisible.lua b/test/diagnostics/invisible.lua
index 3c0ee3fb..4bb70fcc 100644
--- a/test/diagnostics/invisible.lua
+++ b/test/diagnostics/invisible.lua
@@ -138,6 +138,28 @@ print(t2._id)
]]
config.set(nil, 'Lua.doc.protectedName', nil)
+config.set(nil, 'Lua.doc.regengine', 'lua' )
+config.set(nil, 'Lua.doc.privateName', { '^_[%w_]*%w$' })
+config.set(nil, 'Lua.doc.protectedName', { '^_[%w_]*_$' })
+TEST [[
+---@class A
+---@field _id_ number
+---@field _user number
+
+---@type A
+local t
+print(t.<!_id_!>)
+print(t.<!_user!>)
+
+---@class B: A
+local t2
+print(t2._id_)
+print(t2.<!_user!>)
+]]
+config.set(nil, 'Lua.doc.privateName', nil)
+config.set(nil, 'Lua.doc.protectedName', nil)
+config.set(nil, 'Lua.doc.regengine', nil )
+
TEST [[
---@class A
---@field private x number