Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed wholeMatch function #2756

Merged
merged 2 commits into from
Jul 15, 2024
Merged

Fixed wholeMatch function #2756

merged 2 commits into from
Jul 15, 2024

Conversation

qwertycxz
Copy link
Contributor

What did the PR do

The PR corrects the wholeMatch function, making it work effectively and more efficiently. The addon can self-recommendation as expected now.

Why do so

The doc recommends writing words in config.json like this:

"words": [ "require[%s%(\"']+MAA[%)\"']" ]

Most addon authors captured the require string in the doc. However, a commit three years ago (f4e4cc0114adba8d199f9f81298a7c15c9576d5c) modified the code from:

if text:match(word) then
...

to

local pos1, pos2 = a:match('()' .. word .. '()')
local left = a:sub(pos1 - 1, pos1-1)
local right = a:sub(pos2, pos2)
...

Unfortunately, if the pattern word itself has captures (similar to the doc example), pos2 will return a string instead of a number. Consequently, the whole self-recommend feature hasn't worked for the past three years.

@sumneko sumneko merged commit f221eb3 into LuaLS:master Jul 15, 2024
11 checks passed
@sumneko
Copy link
Collaborator

sumneko commented Jul 15, 2024

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants