VS Code and launch.json

Hi,

Has anyone created a launch.json file that will run the corona simulator from VS Code? If so can you please share it or suggest how to get it working?

Thanks, Greg

Hi Greg!

Here my launch.json.

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [

        {
            "type": "lua-local",
            "request": "launch",
            "name": "Debug Corona",
            "program": {
                "command": "%CORONA_PATH%\\Corona Simulator.exe"
            },
            "args": [
                "${workspaceFolder}",
                "-no-console",
                "YES",
                "-debug",
                "YES"
            ]
        }
    ]
}

You need to install Local Lua Debugger extension.
And main.lua

if system.getInfo( "environment" ) == "simulator" then
    if os.getenv("LOCAL_LUA_DEBUGGER_VSCODE") == "1" then
      local lldebugger = loadfile(os.getenv("LOCAL_LUA_DEBUGGER_FILEPATH"))()
      lldebugger.start()
    end
end 

Trace function

function Trace()
    local info = debug.getinfo(3)
    local file, line = string.gsub(info.source, "=", ""), info.currentline

    print("Trace", "\n\tFile: " ..
        file .. ":" .. line)
end
1 Like

Awesome, thank you so much Kan98, I have been using zerobrane ide for a long time and am looking forward to migrating completely to VS code!

1 Like

I’ve needed this for a long time, I didn’t migrate from Zerobrane to VScode precisely because of this simulator debugging problem, but how and where do I include this launch.json file in VScode? And do I have to add this verification code to all the main.lua files of projects that I create?

Just open debug tab in side menu you will see a hyper link create launch.json.

Hi Kan98,

I’ve been trying to get this working for a bit now. I installed lua-local debugger, added this to my main.lua
if system.getInfo( “environment” ) == “simulator” then
os.getenv(“LOCAL_LUA_DEBUGGER_VSCODE”) == “1” then
local lldebugger = loadfile(os.getenv(“LOCAL_LUA_DEBUGGER_FILEPATH”))()
lldebugger.start()
end
end

and in my launcher.json I’ve been playing around with different settings. It just doesn’t seem to return my full project path.

“version”: “0.2.0”,
“configurations”: [
{
“type”: “lua-local”,
“request”: “launch”,
“name”: “Debug Corona”,
“windows”: {
“program”: {
“command”: “C:\Program Files (x86)\Corona Labs\Corona\Corona Simulator.exe”,
},
“args”: [
“/no-console”,
“/debug”,
“${workspaceFolder}\main.lua”
]
},
}
]

When I run main.lua from code. I get a Solar2D message 'not found

its close…

Are you sure that path exists?

Wait me a minute, i’ll make video tutorial.

But in your case need to replace \ to \\ in command path

Awesome, thanks for the video, you made it so easy. Guess what my problem was? There was a space in my project folder name! I took it out and everything worked great. Totally VS Code now :slight_smile: I am so excited about real debugging!!

Thanks again, Greg

1 Like
  • I changed my lua extension to lua language server like yours and the Outline works great *

Can I ask a follow up question, do you have the Outline working in the panel to the left? That’s what I am trying to get working now but it is blank.

1 Like

It works fine for me.

Here are all the extensions I use.

And make sure you restarted vscode. Yeah i’m dumb. I didn’t pay attention to the note above :joy:

@jdsmedeirosbr I have a video tutorial for you, you can also install extensions like me, it is very useful for supporting Solar2D code.

Also you should remove all spaces in the project path.

1 Like