Skip to content

Commit 67f5fc1

Browse files
authored
Update EmmyLua VSCode debugging tutorial (#1153)
mostly a copy-paste from pob1's current version
1 parent 61c0107 commit 67f5fc1

1 file changed

Lines changed: 47 additions & 52 deletions

File tree

CONTRIBUTING.md

Lines changed: 47 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -136,60 +136,61 @@ It is recommended to use it over the built-in Lua plugins.
136136
Please note that EmmyLua is not available for other editors based on Visual Studio Code,
137137
such as [VSCodium](https://vscodium.com) or [Eclipse Theia](https://theia-ide.org) but can be built from source if needed.
138138

139-
Note that you will need to have [Java](https://www.java.com/) installed to use emmyLua, and have either the JAVA_HOME environment variable correctly set up or have the path to java added to the `settings.json` file. Example:
140-
141-
```"emmylua.java.home": "C:/Program Files (x86)/Java/jre1.8.0_201/"```
142-
143-
To do this in VSCode find the Java installation folder on your computer as displayed above.
144-
1. Navigate to extensions inside VSCode
145-
2. Click the cog icon next to EmmyLua -> Extension Settings
146-
3. Find "Java: Home" -> Edit settings
147-
4. Place the directory address between the quotes
148-
5. File -> Save
149-
150-
151139
### Visual Studio Code
152140

153-
1. Create a new "Debug Configuration" of type "EmmyLua New Debug"
154-
2. Open the Visual Studio Code extensions folder. On Windows, this defaults to `%USERPROFILE%/.vscode/extensions`.
155-
3. Find the sub-folder that contains `emmy_core.dll`. You should find both x86 and x64; pick x64. For example, `C:/Users/someuser/.vscode/extensions/tangzx.emmylua-0.5.19/debugger/emmy/windows/x64`.
156-
4. Paste the following code snippet directly below `function launch:OnInit()` in `./src/Launch.lua`:
157-
```lua
158-
-- This is the path to emmy_core.dll. The ?.dll at the end is intentional.
159-
package.cpath = package.cpath .. ";C:/Users/someuser/.vscode/extensions/tangzx.emmylua-0.5.19/debugger/emmy/windows/x64/?.dll"
160-
local dbg = require("emmy_core")
161-
-- This port must match the IDE configuration. Default is 9966.
162-
dbg.tcpListen("localhost", 9966)
163-
-- Uncomment the next line if you want Path of Building to block until the debugger is attached
164-
--dbg.waitIDE()
165-
```
166-
5. Start Path of Building Community
167-
6. Attach the debugger
168-
169-
#### Excluding directories from emmyLua
141+
1. Create a new <kbd>Debug Configuration</kbd> of type <kbd>EmmyLua New Debug</kbd>
142+
1. Open `./src/Launch.lua`
143+
1. Click the beginning of the line directly after `function launch:OnInit()`
144+
1. Insert the debugger code:
145+
146+
Automatically:
147+
1. Open the Command Palette (<kbd>F1</kbd>)
148+
1. Type <kbd>EmmyLua: Insert Emmy Debugger Code</kbd>
149+
1. Choose `x64` from the drop-down list
150+
151+
Or manually:
152+
1. Open the Visual Studio Code extensions folder. On Windows, this defaults to `%USERPROFILE%/.vscode/extensions`
153+
1. Find the sub-folder that contains `emmy_core.dll`. You should find both x86 and x64; pick x64. For example, `C:/Users/someuser/.vscode/extensions/tangzx.emmylua-0.9.22-win32-x64/debugger/emmy/windows/x64`. Uses this in the snippet below. Note the version number will change with every update.
154+
1. Copy-paste the following code snippet:
155+
```lua
156+
-- Path to emmy_core.dll. You will need to update it to point to the EmmyLua dlls in YOUR installation.
157+
-- Note the "?.dll" at the end of the path is mandatory.
158+
package.cpath = package.cpath .. ";C:/Users/someuser/.vscode/extensions/tangzx.emmylua-0.5.19/debugger/emmy/windows/x64/?.dll"
159+
local dbg = require("emmy_core")
160+
-- This port must match the IDE configuration. Default is 9966.
161+
dbg.tcpListen("localhost", 9966)
162+
--dbg.waitIDE() -- Uncomment this line if you want PoB to wait until the debugger is attached.
163+
```
164+
1. Set breakpoints in the source with VSCode's built-in breakpoint system (or use a non-local `dbg` and call `_G.dbg.breakHere()`)
165+
1. Click the <kbd>Run and Debug</kbd> icon on the *Activity Bar*
166+
1. Make sure <kbd>EmmyLua New Debug</kbd> is selected in the "Run and Debug" dropdown
167+
1. Start your modified <kbd>Path of Building Community</kbd>
168+
1. In VSCode click <kbd>Start Debugging</kbd> (the green icon) or press <kbd>F5</kbd>
169+
1. The debugger should connect
170+
171+
172+
#### Excluding directories from EmmyLua
170173

171174
Depending on the amount of system ram you have available and the amount that gets assigned to the jvm running the emmylua language server you might run into issues when trying to debug Path of building.
172-
Files in /Data /Export and /TreeData can be massive and cause the emmyLua language server to use a significant amount of memory. Sometimes causing the language server to crash. To avoid this and speed up initialization consider adding an `emmy.config.json` file to the .vscode folder in the root of the Path of building repository with the following content:
175+
Files in `/Data` `/Export` and `/TreeData` can be massive and cause the EmmyLua language server to use a significant amount of memory. Sometimes causing the language server to crash. To avoid this and speed up initialization consider adding an `.emmyrc.json` file to the `.vscode` folder in the root of the Path of building folder with the following content:
173176

174-
```
177+
```json
175178
{
176-
"source": [
177-
{
178-
"dir": "../",
179-
"exclude": [
180-
"src/Export/**.lua",
181-
"src/Data/**.lua",
182-
"src/TreeData/**.lua"
183-
]
184-
}
185-
]
179+
"$schema": "https://raw.githubusercontent.com/EmmyLuaLs/emmylua-analyzer-rust/refs/heads/main/crates/emmylua_code_analysis/resources/schema.json",
180+
"workspace": {
181+
"ignoreGlobs": [
182+
"src/Data/**.lua",
183+
"src/TreeData/**.lua",
184+
"src/Modules/ModParser.lua"
185+
]
186+
}
186187
}
187188
```
188189

189190
### PyCharm Community / IntelliJ Idea Community
190191

191192
1. Create a new "Debug Configuration" of type "Emmy Debugger(NEW)".
192-
2. Select "x64" version
193+
2. Select "x64" version.
193194
3. Select if you want the program to block (checkbox) until you attached the debugger (useful if you have to debug the startup process).
194195
4. Copy the generated code snippet directly below `function launch:OnInit()` in `./src/Launch.lua`.
195196
5. Start Path of Building Community
@@ -208,7 +209,7 @@ Z:\home\dev\.vscode\extensions\tangzx.emmylua-0.8.20-linux-x64\debugger\emmy\win
208209

209210
## Testing
210211

211-
PoB uses the [Busted](https://olivinelabs.com/busted/) framework to run its tests. Tests are stored under `spec/System` and run automatically when a PR is modified.
212+
PoB uses the [Busted](https://lunarmodules.github.io/busted/) framework to run its tests. Tests are stored under `spec/System` and run automatically when a PR is modified.
212213
More tests can be added to this folder to test specific functionality, or new test builds can be added to ensure nothing changed that wasn't intended.
213214

214215
### Running tests
@@ -220,15 +221,9 @@ More tests can be added to this folder to test specific functionality, or new te
220221
Please try to include tests for your new features in your pull request. Additionally, if your pr breaks a test that should be passing please update it accordingly.
221222

222223
### Debugging tests
223-
When running tests with a docker container it is possible to use emmylua for debugging. Paste in the following right under `function launch:OnInit()` in `./src/Launch.lua`:
224-
```lua
225-
package.cpath = package.cpath .. ";/usr/local/bin/?.so"
226-
local dbg = require("emmy_core")
227-
-- This port must match the IDE Code configuration. Default is 9966.
228-
dbg.tcpListen("localhost", 9966)
229-
dbg.waitIDE()
230-
```
231-
After running `docker-compose up` the code will wait at the `dbg.waitIDE()` line until a debugger is attached. This will allow stepping through any code that is internal to POB but will not work for busted related code. Note that this only works for unit tests described above.
224+
When running tests with a docker container it is possible to use EmmyLua for debugging. Follow the instructions for inserting the debugger snippet as shown above in [Visual Studio Code](#Visual-Studio-Code), then uncomment the `dbg.waitIDE()` line.
225+
226+
After running `docker-compose up` the code will wait at that line until a debugger is attached. This will allow stepping through any code that is internal to POB but will not work for busted related code. Note that this only works for unit tests described above.
232227

233228
## Path of Building development tutorials
234229

0 commit comments

Comments
 (0)