Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Jul 15, 2024
2 parents 74a3803 + 491ad2f commit df30d05
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 11 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
* `FIX` Respect `completion.showParams` config for local function completion
* `CHG` Improve performance of multithreaded `--check` and `undefined-field` diagnostic
* `FIX` Addons can now self-recommend as expected. Fixed by correcting the `wholeMatch` function
* `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`
Expand Down
5 changes: 4 additions & 1 deletion script/config/template.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
3 changes: 3 additions & 0 deletions script/core/diagnostics/inject-field.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ return function (uri, callback)
if def.type == 'doc.field' then
return
end
if def.type == 'tablefield' and not isExact then
return
end
end

local howToFix = ''
Expand Down
2 changes: 1 addition & 1 deletion script/core/hint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions script/provider/provider.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 25 additions & 7 deletions script/vm/visible.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -96,10 +110,14 @@ function vm.getParentClass(source)
if source.type == 'setfield'
or source.type == 'setindex'
or source.type == 'setmethod'
or source.type == 'tablefield'
or source.type == 'tableindex' then
return vm.getDefinedClass(guide.getUri(source), source.node)
end

if source.type == 'tablefield' then
return vm.getDefinedClass(guide.getUri(source), source.node) or
vm.getDefinedClass(guide.getUri(source), source.parent.parent)
end
return nil
end

Expand Down
13 changes: 13 additions & 0 deletions test/diagnostics/inject-field.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,16 @@ function m:init() -- OK
end
end
]]

TEST [[
---@class Class
local m = {
xx = 1, -- OK
}
---@type Class
local m
m.xx = 1 -- OK
m.<!yy!> = 1 -- Warning
]]
56 changes: 56 additions & 0 deletions test/diagnostics/invisible.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,43 @@ local t2
print(t2.<!_id!>)
]]
TEST [[
---@class A
local A = {
_id = 0
}
---@type A
local t
print(t.<!_id!>)
---@class B: A
local t2
print(t2.<!_id!>)
]]

config.set(nil, 'Lua.doc.privateName', nil)

config.set(nil, 'Lua.doc.protectedName', { '_*' })
TEST [[
---@class A
local A = {
_id = 0
}
---@type A
local t
print(t.<!_id!>)
---@class B: A
local t2
print(t2._id)
]]

TEST [[
---@class A
---@field _id number
Expand All @@ -104,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
Expand Down

0 comments on commit df30d05

Please sign in to comment.