Skip to content

Commit 4e3838d

Browse files
chore: autopublish 2023-02-20T03:32:08Z
1 parent 4011a7d commit 4e3838d

1 file changed

Lines changed: 50 additions & 57 deletions

File tree

docs/rgp-lua/development-environment.md

Lines changed: 50 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -45,70 +45,63 @@ One effective way to do this is to detect modifier keys. If your script has a di
4545

4646
## Using Visual Studio Code
4747

48-
1. Install the extensions [Lua](https://marketplace.visualstudio.com/items?itemName=sumneko.lua) (language server) and [Lua Debugger](https://marketplace.visualstudio.com/items?itemName=devCAT.lua-debug) (and optionally [vscode-lua-format](https://marketplace.visualstudio.com/items?itemName=Koihik.vscode-lua-format)).
48+
There are several different VS Code extensions for Lua debugging, each with different pros and cons. Here is one setup that gives satisfactory results.
4949

50-
2. As of 1/25/2023, there's an error in the package manifest for Lua Debugger that prevents VS Code from creating breakpoints in lua files. ([Pull request](https://github.com/devcat-studio/VSCodeLuaDebug/pull/28) created.) In order to fix this:
50+
1. Install the extensions [Lua](https://marketplace.visualstudio.com/items?itemName=sumneko.lua) (language server) and [Lua MobDebug adapter](https://marketplace.visualstudio.com/items?itemName=AlexeyMelnichuk.lua-mobdebug).
5151

52-
1. Go to your local extension installation directory, usually `~/.vscode/extensions`.
52+
2. For a development folder, it can be convenient to fork and clone the [Finale Lua repo](https://github.com/finale-lua/lua-scripts) and put any new scripts in the `src` folder. This lets you include existing things from the `library` and `mixin` folders. You can also set up a development folder somewhere else, if you prefer.
5353

54-
2. Find the folder for the extension, `devcat.lua-debug-1.1.1`
54+
3. Open your development folder in VS Code.
5555

56-
3. Inside the folder, edit `packages.json`, deleting the `enableBreakpointsFor` element under `debuggers` and adding a `breakpoints` element under `contributes`.
57-
58-
```diff
59-
--- package.json.original
60-
+++ package.json.revised
61-
@@ -21,21 +21,21 @@
62-
"devDependencies": {},
63-
"contributes": {
64-
+ "breakpoints": [
65-
+ {
66-
+ "language": "lua"
67-
+ }
68-
+ ],
69-
"debuggers": [
70-
{
71-
"type": "lua",
72-
"label": "Lua Debugger",
73-
- "enableBreakpointsFor": {
74-
- "languageIds": [
75-
- "lua"
76-
- ]
77-
- },
78-
"program": "./DebugAdapter.exe",
79-
```
80-
81-
4. If VS Code was open, close and restart it. You may then be prompted to reload the window when VS Code notices that the extension has changed on disk.
82-
83-
3. For a development folder, it can be convenient to fork and clone the [Finale Lua repo](https://github.com/finale-lua/lua-scripts) and put any new scripts in the `src` folder. This lets you include existing things from the `library` and `mixin` folders. You can also set up a development folder somewhere else, if you prefer.
84-
85-
4. Save the file [vscode-debuggee.lua](https://raw.githubusercontent.com/devcat-studio/VSCodeLuaDebug/master/debuggee/vscode-debuggee.lua) to your development folder, next to your script file. If you are developing outside of the repo `src` folder, also save the file [dkjson.lua](http://dkolf.de/src/dkjson-lua.fsl/raw/dkjson.lua?name=6c6486a4a589ed9ae70654a2821e956650299228) to your development folder, next to your script.
86-
87-
5. Open your development folder in VS Code.
88-
89-
5. Add the following three lines to your lua script. If you are developing outside the repo `src` folder, use `dkjson` in the first line instead of `lunajson.lunajson`. The `redirectPrint` argument tells your script to send any `print` output to the VS Code output window; it can be omitted or set to `false` if you prefer.
56+
4. Add the following lines to your lua script:
9057

9158
```lua
92-
local json = require 'lunajson.lunajson'
93-
local debuggee = require 'vscode-debuggee'
94-
debuggee.start(json, { redirectPrint = true })
59+
local home = os.getenv("HOME") or os.getenv("HOMEDRIVE") .. os.getenv("HOMEPATH")
60+
package.path = home .. "/.vscode/extensions/alexeymelnichuk.lua-mobdebug-0.0.5/lua/?.lua"
61+
.. ";" .. package.path
62+
require("vscode-mobdebug").start('127.0.0.1', 8172)
9563
```
96-
97-
6. Type <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>D</kbd> or click on the "Run and Debug" icon in the side bar, then click on the "create a launch.json file" link. From the "Select debugger" dropdown that appears, select `Lua Debugger`. This will create a default `launch.json` that should include this snippet at the bottom of the file:
98-
99-
```json
100-
{
101-
"name": "wait",
102-
"type": "lua",
103-
"request": "attach",
104-
"workingDirectory": "${workspaceRoot}",
105-
"sourceBasePath": "${workspaceRoot}",
106-
"listenPublicly": false,
107-
"listenPort": 56789,
108-
"encoding": "UTF-8"
109-
}
64+
65+
5. Type <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>D</kbd> or click on the "Run and Debug" icon in the side bar to bring up the "Run and Debug" panel. The process for adding the Lua MobDebug launch configurations to your `launch.json` file depends on whether or not you already have a `launch.json` in your workspace.
66+
67+
- If you don't have a `launch.json` file yet, you'll see a link to "create a launch.json file"; click it. If you have a Lua file open in the editor, VS Code will automatically create the appropriate `launch.json` file for you. Otherwise, from the dropdown that appears, select `Lua MobDebug`. Your `launch.json` should include these elements as part of the `configurations` array:
68+
```json
69+
{
70+
"name": "Lua MobDebug: Listen",
71+
"type": "luaMobDebug",
72+
"request": "attach",
73+
"workingDirectory": "${workspaceFolder}",
74+
"sourceBasePath": "${workspaceFolder}",
75+
"listenPublicly": false,
76+
"listenPort": 8172,
77+
"stopOnEntry": true,
78+
"sourceEncoding": "UTF-8"
79+
},
80+
{
81+
"name": "Lua MobDebug: Current File",
82+
"type": "luaMobDebug",
83+
"request": "launch",
84+
"workingDirectory": "${workspaceFolder}",
85+
"sourceBasePath": "${workspaceFolder}",
86+
"listenPort": 8172,
87+
"stopOnEntry": true,
88+
"sourceEncoding": "UTF-8",
89+
"interpreter": "lua",
90+
"arguments": [
91+
"${relativeFile}"
92+
]
93+
}
94+
```
95+
- If you do have a `launch.json`, click on the gear icon at the top of the "Run and Debug" panel to bring it up. You can then either click the "Add Configuration" button in the lower left and select the two `Lua MobDebug` items one after the other, or add the above elements to the `configurations` array directly.
96+
97+
6. Launch the `Lua MobDebug: Listen` configuration by selecting it from the dropdown at the top of the "Run and Debug" panel and clicking the arrow next to it (or hitting <kbd>F5</kbd>). This tells VS Code to listen for messages from remote execution of your script.
98+
99+
7. Run your script from Finale. Any breakpoints you have set in VS Code will be hit, and then you can use VS Code's debugging capabilities. **Note** that the line `"stopOnEntry": true` in the launch configuration will cause the debugger to stop at the top of your script even if you have no breakpoints set. If you don't like this behavior, you can change the value to `false`.
100+
101+
8. The extension collects any `print` statements and outputs them all at the end of the script. In order to work around this and print values while your script is running, you'll need to define a local function:
102+
```lua
103+
local print = function(...) print(...); io.flush() end
110104
```
111105

112-
8. Launch the `wait` configuration by selecting it from the dropdown at the top of the "Run and Debug" panel and clicking the arrow next to it (or hitting <kbd>F5</kbd>). This tells VS Code to listen for messages from remote execution of your script.
113106

114-
9. Run your script from Finale. Any breakpoints you have set in VS Code will be hit, and then you can use VS Code's debugging capabilities.
107+
9. When the script exits, your debug session will end; you'll need to launch a new session from VS Code before invoking the script from Finale again.

0 commit comments

Comments
 (0)