This write-up details the steps required to get emacs on ubuntu 20.04 setup with the erlang_ls extension and enable code reloading and debugging.
I'm hoping these instructions should be nearly identical for setup on a Mac.
CouchDB uses long names and the erlang_ls extension defaults to using short names. There is a bug that appends a dot
.
to the end of the node hostname when using long names and PR to fix it is pending, until then we will need to build the erlang extension from the PR repo so that we can connect ErlangLS to[email protected]
git clone https://github.com/zach-writes-code/erlang_ls
cd erlang_ls
git checkout 1371-add-custom-host-and-domain-name
# need to pull in the upstream to get tags, otherwise the vsn assignment breaks
git remote add upstream https://github.com/erlang-ls/erlang_ls
git fetch upstream
sudo make install
Update the erlang_ls.config
like so:
apps_dirs:
- "src/*"
include_dirs:
- "src"
- "src/*/include"
code_reload:
node: "node1"
runtime:
use_long_names: true
hostname: "127.0.0.1"
domain: ""
Create a launch.json
file in the root directory of the couchdb repo
{
"version": "0.2.0",
"configurations": [
{
"name": "Existing Erlang Node",
"type": "erlang",
"request": "attach",
"projectnode": "[email protected]",
"use_long_names": true,
"timeout": 300
}
]
}
Update your dotemacs .emacs
or init.el
file.
Chances are, you have the lsp-mode package and erlang_ls already setup. If you do not, the instructions for this are found in the erlang_ls docs
The only thing that needs to be added to your emacs config file is the debugger packages:
(require 'dap-mode)
(require 'dap-erlang)
First spin up a CouchDB dev server, you can do this however you like, but here is my favorite:
./dev/run --with-admin-party-please --no-eval dev/remsh
After your dev server is running, fire up emacs, navigate to any file you want to work on, make a change, save it, and run it! Your changes should automatically recompile and be live the next time that code executes. You should also see a line that looks similar to LSP :: code_reload success for: [whatever_module_you_saved]
in the Messages buffer after saving any changes.
To see what this should look like checkout this short youtube video that shows this working: https://youtu.be/5H9W6VDaSag
Now for the real fun part... Set a breakpoint in the emacs editor on any line you would like to inspect. To set a breakpoint use your keyboard to navigate to the line and then type:
M-x dap-breakpoint-add
and a Dot like the one shown above should appear next to the line.
Next enter the following command:
M-x dap-debug
You will get prompted for a configuration template. Select Existing Erlang Node. (Pressing Tab should autocomplete to this)
Run whatever curl
command or perform whatever action you need to in fauxton to get the code to run and you should see emacs editor open up more windows that show the locals, call stack, breakpoint, etc. May need to make sure your emacs frame is wide enough to accomodate this. If the frame is too narrow these may not display. The youtube video above also shows the debugger in action and what it should look like.
For a full walkthrough on using the debugger the ErlangLS Article details more ways to use this.