Skip to content
Permalink
Browse files

Improved autocompletion for edit.lua

At the Moment, edit.lua will only complete global functions. But must Programs have local functions. With this PR, edit.lua will search the code of your file and add all functions to autocompletion.
  • Loading branch information...
Wilma456 committed Jan 19, 2018
1 parent 3b3dd80 commit ecd7cedd6f659157aea361347c85061a09facac5
Showing with 34 additions and 1 deletion.
  1. +34 −1 src/main/resources/assets/computercraft/lua/rom/programs/edit.lua
@@ -171,8 +171,16 @@ end

local tCompletions
local nCompletion
local tCompleteEnv = {}

for k, v in pairs( _ENV ) do
tCompleteEnv[k] = v
end

for k, v in pairs( _G ) do
tCompleteEnv[k] = v
end

local tCompleteEnv = _ENV
local function complete( sLine )
if settings.get( "edit.autocomplete" ) then
local nStartPos = string.find( sLine, "[a-zA-Z0-9_%.:]+$" )
@@ -448,9 +456,34 @@ local function setCursor( newX, newY )
redrawMenu()
end

local function addAutocompletion( sSearch )
for sResult in sSearch:gmatch( "function .-%(.-%)" ) do
local tObject = tCompleteEnv
sResult = sResult:sub( 10, sResult:find( "(",1 , true ) - 1 )
while true do
local nPoint = sResult:find( ".", 1, true )
if nPoint == nil then
break
else
local sIndex = sResult:sub( 1, -(#sResult - nPoint) - 2 )
if type(tObject[sIndex]) ~= "table" then
tObject[sIndex] = {}
end
tObject = tObject[sIndex]
sResult = sResult:sub( nPoint + 1 )
end
end
tObject[sResult] = function() end
end
end

-- Actual program functionality begins
load(sPath)

for k, v in ipairs( tLines ) do
addAutocompletion( v )
end

term.setBackgroundColour( bgColour )
term.clear()
term.setCursorPos(x,y)

0 comments on commit ecd7ced

Please sign in to comment.
You can’t perform that action at this time.