From 74a38036bc64940520502fc8f6a28f710ce42dbb Mon Sep 17 00:00:00 2001 From: qwertycxz Date: Sun, 14 Jul 2024 08:22:24 +0800 Subject: [PATCH] Fixed wholeMatch function --- changelog.md | 7 ++++--- script/library.lua | 19 ++++++------------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/changelog.md b/changelog.md index 87ef33ef6..68b6317b3 100644 --- a/changelog.md +++ b/changelog.md @@ -4,9 +4,10 @@ * `NEW` Add postfix snippet for `unpack` * `FIX` `diagnostics.severity` defaulting to "Warning" when run using `--check` [#2730](https://github.com/LuaLS/lua-language-server/issues/2730) -* `NEW` Add support for lambda style functions, `|paramList| expr` is syntactic sugar for `function(paramList) return expr end` -* `FIX` Respect `completion.showParams` config for local function completion +* `NEW` Add support for lambda style functions, `|paramList| expr` is syntactic sugar for `function(paramList) return expr end` +* `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 ## 3.9.3 `2024-6-11` @@ -145,7 +146,7 @@ Cat = 1, Dog = 2, } - + ---@param animal userdata ---@param atp AnimalType ---@return boolean diff --git a/script/library.lua b/script/library.lua index 2e925e8d8..cfc7e328d 100644 --- a/script/library.lua +++ b/script/library.lua @@ -360,7 +360,7 @@ local function loadSingle3rdConfig(libraryDir) if cfg.words then for i, word in ipairs(cfg.words) do - cfg.words[i] = '()' .. word .. '()' + cfg.words[i] = '([%w_]?)' .. word .. '([%w_]?)' end end if cfg.files then @@ -370,7 +370,7 @@ local function loadSingle3rdConfig(libraryDir) else filename = filename:gsub('\\', '/') end - cfg.files[i] = '()' .. filename .. '()' + cfg.files[i] = '([%w_]?)' .. filename .. '([%w_]?)' end end @@ -515,17 +515,10 @@ end ---@param b string ---@return boolean local function wholeMatch(a, b) - local pos1, pos2 = a:match(b) - if not pos1 then - return false - end - local left = a:sub(pos1 - 1, pos1 - 1) - local right = a:sub(pos2, pos2) - if left:match '[%w_]' - or right:match '[%w_]' then - return false - end - return true + local captures = { + a:match(b), + } + return captures[1] == '' and captures[#captures] == '' end local function check3rdByWords(uri, configs, checkThirdParty)