Skip to content

VSCode setup

Mikhail Kochegarov edited this page Dec 21, 2022 · 2 revisions

How to Setup VSCode for Soldr modules development

VSCode

VSCode can be donwloaded from official page.

VSCode extensions

Development of lua-modules requires some additional extentions to be installed in VSCode:

VSCode configuration

First of all you need to download modules source code:

git clone [email protected]:vxcontrol/soldr-modules.git
cd soldr-modules
git submodule init
git submodule update
cd luapower/
./mgit clone [email protected]:vxcontrol/soldr-luapower-repos.git
./mgit clone-all

To simplify next configuration steps add a global environment variable:

echo "\n\nLUAPOWER_PLATFORM=$([[ $(uname) == "Darwin"  ]] && echo "osx64" || echo "linux64")\n" >> ~/.bash_profile
source ~/.bash-profile

Open source code repository in VSCode and set some user settings (Shift+Cmd+P/Shift+Ctrl+P → Preferences:Open User Settings (JSON)):

"lua.debug.settings.luaVersion": "jit",
"lua.debug.settings.path": "${workspaceFolder}/tests_framework/lua/?.lua;${workspaceFolder}/tests_framework/lua/?/init.lua;${workspaceFolder}/luapower/?.lua;${workspaceFolder}/luapower/?/init.lua;${workspaceFolder}/utils/?.lua;${workspaceFolder}/utils/?/init.lua",
"lua.debug.settings.cpath": "${workspaceFolder}/luapower/bin/${env:LUAPOWER_PLATFORM}/lib?.dylib;${workspaceFolder}/luapower/bin/${env:LUAPOWER_PLATFORM}/clib/?.so;${workspaceFolder}/luapower/bin/${env:LUAPOWER_PLATFORM}/lib?.dll;${workspaceFolder}/luapower/bin/${env:LUAPOWER_PLATFORM}/clib/?.dll",
"Lua.telemetry.enable": false,
"Lua.diagnostics.globals": [ "lfs", "describe", "it", "setup", "teardown", ],
"Lua.runtime.path": [
    "${workspaceFolder}/?.lua",
    "${workspaceFolder}/?/init.lua",
    "${workspaceFolder}/utils/?.lua",
    "${workspaceFolder}/utils/?/init.lua",
    "${workspaceFolder}/tests_framework/lua/?.lua",
    "${workspaceFolder}/tests_framework/lua/?/init.lua",
    "${workspaceFolder}/luapower/?.lua",
    "${workspaceFolder}/luapower/?/init.lua"
],
"Lua.diagnostics.libraryFiles": "Disable",
"Lua.diagnostics.ignoredFiles": "Disable",
"Lua.workspace.ignoreDir": [ ".vscode", "tests_framework" ],
"busted-test-explorer.testfilepattern": "tests/*_spec.lua",
"busted-test-explorer.executable": "${workspaceFolder}/tests_framework/lua/bin/busted.${env:LUAPOWER_PLATFORM}.cmd",
"busted-test-explorer.cwd": "${workspaceFolder}",
"busted-test-explorer.env": {
    "LOG_LEVEL": "error",
    "LUA_PATH": "${workspaceFolder}/tests_framework/lua/?.lua;${workspaceFolder}/tests_framework/lua/?/init.lua;${workspaceFolder}/luapower/?.lua;${workspaceFolder}/luapower/?/init.lua;${workspaceFolder}/utils/?.lua;${workspaceFolder}/utils/?/init.lua",
    "LUA_CPATH": "${workspaceFolder}/luapower/bin/${env:LUAPOWER_PLATFORM}/lib?.dylib;${workspaceFolder}/luapower/bin/${env:LUAPOWER_PLATFORM}/clib/?.so;${workspaceFolder}/luapower/bin/${env:LUAPOWER_PLATFORM}/lib?.dll;${workspaceFolder}/luapower/bin/${env:LUAPOWER_PLATFORM}/clib/?.dll",
    "LUA_BIN": "${workspaceFolder}/luapower/bin/${env:LUAPOWER_PLATFORM}/luajit-bin",
},

Now running tests from "Testing" side menu as well as from "*_spec.lua" files should work.

Setting up Lua Debugger

In VSCode you need to add following launch configuration:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Debug Editor Contents",
	  "program": "${workspaceFolder}/${relativeFile}",
	  "arg": [
        "-e", "require 'busted.runner'({ standalone = false })",
      ],
	  "arg0": "-e dofile('${workspaceFolder}/utils/mock/thread.lua')",
	  "env": {
        "LOG_LEVEL": "error",
        "LUA_DEBUG_PATH": "${userHome}/.vscode/extensions/actboy168.lua-debug-1.60.1-darwin-x64",
      },
	  "request": "launch",
	  "cwd": "${workspaceFolder}",
	  "luaexe": "${workspaceFolder}/luapower/bin/${env:LUAPOWER_PLATFORM}/luajit-bin",
	  "path": "${workspaceFolder}/tests_framework/lua/?.lua;${workspaceFolder}/tests_framework/lua/?/init.lua;${workspaceFolder}/luapower/?.lua;${workspaceFolder}/luapower/?/init.lua;${workspaceFolder}/utils/?.lua;${workspaceFolder}/utils/?/init.lua",
	  "cpath": "${workspaceFolder}/luapower/bin/${env:LUAPOWER_PLATFORM}/lib?.dylib;${workspaceFolder}/luapower/bin/${env:LUAPOWER_PLATFORM}/clib/?.so;${workspaceFolder}/luapower/bin/${env:LUAPOWER_PLATFORM}/lib?.dll;${workspaceFolder}/luapower/bin/${env:LUAPOWER_PLATFORM}/clib/?.dll",
	  "stopOnEntry": false,
	  "stopOnThreadEntry": false,
	  "type": "lua"
    }
  ]
}

Environment variable "LUA_DEBUG_PATH" should point to a directory with Lua Debug plugin.

Now "Run" (Ctrl/Cmd+F5) and "Run and Debug" (F5) should be available in VSCode.

Note: in case if breakpoints are set in several threads then you can observe that both threads can be stopped on these breakpoints, unfortunately you can continue debugging only in one thread, all other will be released with normal execution (or can again be paused on other breakpoints).