Fix parsetable bugs

pull/3/head
Iron-E 4 years ago
parent ca0180c0d7
commit 596b7e8859
No known key found for this signature in database
GPG Key ID: 19B71B7B7B021D22

@ -27,7 +27,7 @@ local _REPLACEMENTS = {
',', '/', ':', '?', '@', '!', '$', '*', '.', '%', '&', '\\',
}
for i, replacement in ipairs(_REPLACEMENTS) do
_REPLACEMENTS[i] = vim.pesc(replacement)
_REPLACEMENTS[i], _ = vim.pesc(replacement)
end
--[[
@ -131,14 +131,14 @@ end
------------------------------------------------------
function Prompt.createCompletionsProvider(completions)
return function(argLead, cmdLine, cursorPos)
if string.len(cmdLine) < 1 then
return completions
if string.len(cmdLine) < 1 then return completions
end
-- replace conjoining characters with spaces.
local spacedArgLead = argLead
for _, replacement in ipairs(_REPLACEMENTS) do
spacedArgLead, _ = string.gsub(spacedArgLead, vim.pesc(replacement), ' ')
-- _REPLACEMENTS are already `vim.pesc`aped
spacedArgLead, _ = string.gsub(spacedArgLead, replacement, ' ')
end
-- split the spaced version of `argLead`.
@ -146,8 +146,7 @@ function Prompt.createCompletionsProvider(completions)
--[[ make sure the user is in a position were this function
will provide accurate completions.]]
if #splitArgLead > 1 then
return nil
if #splitArgLead > 1 then return nil
end
-- get the word selected by the user. (don't compare case)
@ -157,7 +156,8 @@ function Prompt.createCompletionsProvider(completions)
local matches = {}
for _, completion in ipairs(completions) do
-- test if `word` is inside of `completions`:`v`, ignoring case.
if string.match(vim.pesc(string.upper(completion)), word) then
local escapedCompletion, _ = vim.pesc(string.upper(completion))
if string.match(escapedCompletion, word) then
matches[#matches + 1] = completion -- preserve case when providing completions.
end
end

@ -42,7 +42,7 @@ local function _get(parseTable, splitKey)
-- Make sure the dicitonary has a key for that value.
if parseTable[k] then
val = parseTable[k]
local val = parseTable[k]
local valType = type(val)
if valType == globals.TYPE_TBL then
@ -67,7 +67,7 @@ end
* `splitKey` => the key split into groups.
]]
-----------------------------------------
local function _put(parseTable, splitKey) -- †
local function _put(parseTable, splitKey, value) -- †
--[[ Get the next character in the table. ]]
local k = string.byte(table.remove(splitKey))
@ -80,7 +80,7 @@ local function _put(parseTable, splitKey) -- †
end
-- run _update() again
_put(parseTable[k], splitKey)
_put(parseTable[k], splitKey, value)
-- If parseTable[k] is a pre-existing table, don't clobber the table— clobber the `CR` value.
elseif type(parseTable[k]) == globals.TYPE_TBL then
parseTable[k][ParseTable.CR] = value
@ -157,9 +157,10 @@ end
]]
---------------------------------------------
function _metaParseTable:parsePut(key, value)
_put(self, _string_split(
string.reverse(key), '.'
))
_put(self,
_string_split(string.reverse(key), '.'),
value
)
end
--------------------------------------------------

@ -78,7 +78,13 @@ function Help.new(commandsOrMaps, title)
local toPrint = {}
for k, v in pairs(tbl) do
toPrint[#toPrint + 1] = k
for i = longestKey, string.len(k) do
local len = string.len(k)
local byte = string.byte(k)
-- account for ASCII chars that take up more space.
if byte <= 32 or byte == 127 then len = len + 1
end
for i = len, longestKey do
toPrint[#toPrint + 1] = ' '
end
toPrint[#toPrint + 1] = table.concat(SEPARATOR_TEMPLATE, v)

Loading…
Cancel
Save