VS Code extension?

Requests or suggestions for new features
Post Reply
virally
Posts: 5
Joined: 28 Jul 2020, 03:52

VS Code extension?

Post by virally »

for scripts is there a VS Code extension with intellisense? Please provide the link. Thanks

coppelia
Site Admin
Posts: 10336
Joined: 14 Dec 2012, 00:25

Re: VS Code extension?

Post by coppelia »

Sorry for the very late reply. You can generate that information/file in a similar way as we are generating the code completion and call tip files for notepad++, using a script similar to following:

Code: Select all

function sysCall_init()
    local st=-1
    if sim.getInt32Parameter(sim.intparam_program_full_version)<4010002 then
        st=0
    end
    local f=sim.getApiFunc(st,'+')
    local v=sim.getApiFunc(st,'-')
    local t={}
    local b={}
    for i=1,#f,1 do
        b[f[i]]=true
        t[#t+1]=f[i]
    end
    for i=1,#v,1 do
        b[v[i]]=false
        t[#t+1]=v[i]
    end
    table.sort(t)
    finalTxt=header1
    for i=1,#t,1 do
        if b[t[i]] then
            -- function
            local s=sim.getApiInfo(st,t[i])
            if s and not string.find(string.lower(s),"deprecated") then
                s=string.gsub(s,"\n","")
                local ep=string.find(s,")")
                if ep then
                    s=string.sub(s,1,ep-1)
                    ep=string.find(s,"%(")
                    if ep then
                        local args=string.sub(s,ep+1)
                        ep=string.find(s,"=")
                        local rets=""
                        if ep then
                            rets=string.sub(s,0,ep-1)
                        end
                        finalTxt=finalTxt..[[        <KeyWord name="]]..t[i]..[[" func="yes">
]]
                        if #rets>0 then
                            rets=rets.." ="
                        end
                        finalTxt=finalTxt..[[            <Overload retVal="]]..rets..[[" >
]]
                        ep=string.find(args,",")
                        while ep do
                            s=string.sub(args,0,ep-1)
                            finalTxt=finalTxt..[[                <Param name="]]..s..[[" />
]]
                            args=string.sub(args,ep+1)
                            ep=string.find(args,",")
                        end
                        finalTxt=finalTxt..[[                <Param name="]]..args..[[" />
]]
                        finalTxt=finalTxt..[[            </Overload>
]]
                        finalTxt=finalTxt..[[        </KeyWord>
]]
                    end
                end
            end
        else
            -- constant
            finalTxt=finalTxt..[[        <KeyWord name="]]..t[i]..[[" func="no"/>
]]
        end
    end
    finalTxt=finalTxt..footer1
    local file=io.open("lua.xml","w")
    file:write(finalTxt)
    io.close(file)
    sim.addLog(sim.verbosity_msgs,"Wrote 'lua.xml'")
    
    finalTxt=header2
    for i=1,#lkwds,1 do
        t[#t+1]=lkwds[i]
    end
    table.sort(t)
    for i=1,#t,1 do
        if i>1 then
            finalTxt=finalTxt.." "
        end
        finalTxt=finalTxt..t[i]
    end
    
    finalTxt=finalTxt..footer2
    local file=io.open("langs.xml","w")
    file:write(finalTxt)
    io.close(file)
    sim.addLog(sim.verbosity_msgs,"Wrote 'langs.xml'")
end

header1=[[<?xml version="1.0" encoding="Windows-1252" ?>
<NotepadPlus>
    <!-- language doesnt really mean anything, its more of a comment -->
    <AutoComplete language="lua">
        <!--
        Environment specifies how the language should be interpreted. ignoreCase makes autocomplete
        ignore any casing, start and stopFunc specify what chars a function starts and stops with.
        param specifies parameter separator and terminal can be used to specify a character that stops
        any function. Using the same character for different functions results in undefined behaviour.
        
        05/11/2009
        The basic word character are : A-Z a-z 0-9 and '_' 
        If your function name contains other characters,
        add your characters in "additionalWordChar" attribute (without separator)
        in order to make calltip hint work
        -->
        <Environment ignoreCase="false" startFunc="(" stopFunc=")" paramSeparator="," terminal="" additionalWordChar="._"/>
        <!--
        The following items should be alphabetically ordered.
        func="yes" means the keyword should be treated as a fuction, and thus can be used in the parameter
        calltip system. If this is the case, the retVal attribute specifies the return value/type. Any
        following Param tag specifies a parameter, they must be in order. The name attributes specifies
        the parameter name.
        -->
]]

footer1=[[    </AutoComplete>
</NotepadPlus>]]

header2=[[<?xml version="1.0" encoding="Windows-1252" ?>
<NotepadPlus>
   <!-- The key words of the supported languages, don't touch them! -->
   <Languages>
   ... etc]]

footer2=[[</Keywords>
        </Language>
        ... etc
    </Languages>
</NotepadPlus>]]

lkwds={"table.concat",
"table.insert",
"table.maxn",
"table.pack",
"table.remove",
"table.sort",
"table.unpack",
"tan",
"tanh",
"upper",
"sin",
"sinh",
"sqrt",
"string.byte",
"string.char",
"string.dump",
"string.find",
"string.format",
"string.gmatch",
"string.gsub",
"string.len",
"string.lower",
"string.match",
"string.rep",
"string.reverse",
"string.sub",
"string.upper",
"sub",
"abs",
"acos",
"arshift",
"asin",
"atan",
"atan2",
"band",
"bit32.arshift",
"bit32.band",
"bit32.bnot",
"bit32.bor",
"bit32.btest",
"bit32.bxor",
"bit32.extract",
"bit32.lrotate",
"bit32.lshift",
"bit32.replace",
"bit32.rrotate",
"bit32.rshift",
"bnot",
"bor",
"btest",
"bxor",
"byte",
"ceil",
"char",
"cos",
"cosh",
"deg",
"dump",
"exp",
"extract",
"find",
"floor",
"fmod",
"format",
"frexp",
"gmatch",
"gsub",
"ldexp",
"len",
"log",
"log10",
"lower",
"lrotate",
"lshift",
"match",
"math.abs",
"math.acos",
"math.asin",
"math.atan",
"math.atan2",
"math.ceil",
"math.cos",
"math.cosh",
"math.deg",
"math.exp",
"math.floor",
"math.fmod",
"math.frexp",
"math.huge",
"math.ldexp",
"math.log",
"math.log10",
"math.max",
"math.min",
"math.modf",
"math.pi",
"math.pow",
"math.rad",
"math.random",
"math.randomseed",
"math.sin",
"math.sinh",
"math.sqrt",
"math.tan",
"math.tanh",
"max",
"min",
"modf",
"pow",
"rad",
"random",
"randomseed",
"rep",
"replace",
"reverse",
"rrotate",
"rshift",
"shift"}
Cheers

Post Reply