Skip to content

Conversation

@Polynominal
Copy link

Fixed help text autocompletion error.
would occur at :h usage after typing the first character

I presume it worked at some point in the past and wasn't tested after one refactor or another

Thanks for the plugin, it's nice and fast

made this a bit more sane as my local config has string[]
@Polynominal Polynominal changed the title Update utils.lua Fixed help text autocompletion error Nov 26, 2025
@soifou
Copy link
Collaborator

soifou commented Nov 26, 2025

Thanks for the PR!

Adding a defensive safeguard makes sense to prevent edge case errors but the way flatten is called in the help module, it normally receives an array of tags. So, I'm curious how it could possibly receive a string there. I haven't encountered any errors using :help. Do you have a way to reproduce this?

@Polynominal
Copy link
Author

Polynominal commented Nov 26, 2025

I managed to trace it down, its indeed to do with my config
I have changed lua strings to act like they do in other languages eg they can be indexed such as

local text = "text"
if(text[1] == "t") -- evaluates to True

however under normal circumstances

local text = "text"
if(text[1] == nil) -- evaluates to True

this is done via

local meta = getmetatable("")
local oldindex = meta.__index
meta.__index = function(self,i,...)
    if type(i) == "number" then
        return string.sub(self,i,i)
    end
    return rawget(oldindex,i)
end

so when you do

if t[1] == nil then return t end

this will evaluate to true (as t[1] is nil) if 't' is a string without the operator overloading
however with it, it will evaluate to False hence interpreting 't' as a table

I am not sure regarding performance implication of runtime type checking vs indexing in lua, but I presume it's more sane to check if t is a string

Note that after some testing, t is never actually a string unless the operator overload is in place and I havent found exactly where it's causing the issue but if you are using indexing as a means of type checking it could be all over the place.

To reproduce the bug simply put this into your init.lua

local meta = getmetatable("")
local oldindex = meta.__index
meta.__index = function(self,i,...)
    if type(i) == "number" then
        return string.sub(self,i,i)
    end
    return rawget(oldindex,i)
end

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