Skip to content

Commit

Permalink
improve code completion
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroflag committed Feb 2, 2025
1 parent dab7977 commit 74b0a5b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
12 changes: 8 additions & 4 deletions src/equinox_bundle.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1557,7 +1557,7 @@ local function add_completions(input, words, result)
else
before = before .. " "
end
if word:find("^" .. after) then
if utils.startswith(word, after) then
table.insert(result, before .. word)
end
end
Expand All @@ -1584,15 +1584,15 @@ local function add_props(input, result)
if not prefix then prefix = "" end
local last = input:match("[^%.]+$")
for key, val in pairs(obj) do
if not last or key:find("^" .. last) then
if not last or utils.startswith(key, last) then
table.insert(result, prefix .. key)
end
end
end

local function add_commands(input, result, commands)
for _, cmd in ipairs(commands) do
if cmd:find("^" .. input) then
if utils.startswith(cmd, input) then
table.insert(result, cmd)
end
end
Expand Down Expand Up @@ -3047,11 +3047,15 @@ function utils.keys(tbl)
return result
end

function utils.startswith(str, prefix)
return string.sub(str, 1, #prefix) == prefix
end

return utils
end
end

__VERSION__="0.1-64"
__VERSION__="0.1-66"

local Compiler = require("compiler")
local Optimizer = require("ast_optimizer")
Expand Down
6 changes: 3 additions & 3 deletions src/ln_repl_backend.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ local function add_completions(input, words, result)
else
before = before .. " "
end
if word:find("^" .. after) then
if utils.startswith(word, after) then
table.insert(result, before .. word)
end
end
Expand All @@ -63,15 +63,15 @@ local function add_props(input, result)
if not prefix then prefix = "" end
local last = input:match("[^%.]+$")
for key, val in pairs(obj) do
if not last or key:find("^" .. last) then
if not last or utils.startswith(key, last) then
table.insert(result, prefix .. key)
end
end
end

local function add_commands(input, result, commands)
for _, cmd in ipairs(commands) do
if cmd:find("^" .. input) then
if utils.startswith(cmd, input) then
table.insert(result, cmd)
end
end
Expand Down
4 changes: 4 additions & 0 deletions src/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,8 @@ function utils.keys(tbl)
return result
end

function utils.startswith(str, prefix)
return string.sub(str, 1, #prefix) == prefix
end

return utils
2 changes: 1 addition & 1 deletion src/version/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1-64
0.1-66

0 comments on commit 74b0a5b

Please sign in to comment.