Skip to content

Instantly share code, notes, and snippets.

@bcardiff
Created April 17, 2020 20:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bcardiff/a650950592a0f530da4a1c8d2763278d to your computer and use it in GitHub Desktop.
Save bcardiff/a650950592a0f530da4a1c8d2763278d to your computer and use it in GitHub Desktop.
VSCode CodeLLDB Crystal Configuration

These configuration will let you use CodeLLDB extension to debug Crystal programs.

Store them as .vscode/tasks.json and .vscode/launch.json in your project.

When starting the debugging the current file will be built in the bin/ folder (as in shards build).

jMvTWMvPdD

Note: You will need to set the crystal binary path in tasks.json "command" field and the whole path in launch.json "initCommands". Read more at #8538

{
// 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": "lldb",
"request": "launch",
"name": "crystal: debug current file",
"preLaunchTask": "crystal: build current file (debug)",
"program": "${workspaceFolder}/bin/${fileBasenameNoExtension}",
"args": [],
"cwd": "${workspaceFolder}",
"initCommands": [
"command script import /path/to/crystal/etc/lldb/crystal_formatters.py"
]
}
]
}
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "crystal: build current file (debug)",
"type": "shell",
"command": "crystal build --debug ${relativeFile} -o bin/${fileBasenameNoExtension}"
}
]
}
@hraftery
Copy link

What is the path to crystal_formatters.py? Is it typically part of a lldb install or a crystal install? Specifically interested in macos, but general advice will do!

@romoxi
Copy link

romoxi commented Apr 1, 2021

Hello,

I try to start my first Crystal programm. I use Visual Sudio Code in a Windows-Subsystem for Linux Ubuntu 20.04 LTS.

CodeLLDB 1.6.1 is installed

Wenn I start debugging there comes serval errors in the TERMINAL-window:


Executing task: crystal build --debug .vscode/tasks.json -o bin/tasks <
In .vscode/tasks.json:2:6
2 | // See https://go.microsoft.com/fwlink/?LinkId=733558
^
Error: expecting token '=>', not 'See'
The terminal process "/bin/bash '-c', 'crystal build --debug .vscode/tasks.json -o bin/tasks'" failed to launch (exit code: 1).
Terminal will be reused by tasks, press any key to close it.


After removing the remarks in tasks.json and launch.json there is a problem with:


In .vscode/launch.json:10:17
10 | "args": [],
^
Error: for empty arrays use '[] of ElementType'
The terminal process "/bin/bash '-c', 'crystal build --debug .vscode/launch.json -o bin/launch'" terminated with exit code: 1.


Next try after removing args:


Executing task: crystal build --debug .vscode/launch.json -o bin/launch <
/usr/bin/ld: cannot open output file /mnt/c/linux/crystal/firstapp/src/bin/launch: No such file or directory
collect2: error: ld returned 1 exit status
Error: execution of command failed with code: 1: cc "${@}" -o /mnt/c/linux/crystal/firstapp/src/bin/launch -rdynamic -L/usr/bin/../lib/crystal/lib -lpcre -lm -lgc -lpthread /usr/share/crystal/src/ext/libcrystal.a -levent -lrt -ldl
The terminal process "/bin/bash '-c', 'crystal build --debug .vscode/launch.json -o bin/launch'" terminated with exit code: 1.


Do somebody have an idea?

Thanks a lot

Bob

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment