[FEATURE] Tooling to debug and develop

SpaceLua Debugger - Enhance Your Development Workflow (Alpha version)

debugger

Description:

This SpaceLua script provides a set of tools designed to aid in the development and debugging of Lua code directly within the Silverbullet environment. It helps you identify errors, improve code quality, and maintain consistent formatting.

Features

  • Lua Linting: Integrates with luacheck to automatically analyze your code for potential errors, stylistic issues, and adherence to best practices. Issues are clearly displayed within Silverbullet.
  • Code Formatting (Beautification): Utilizes lua-format to automatically format your Lua code, ensuring consistent indentation, spacing, and overall readability. The formatted code is conveniently copied to your clipboard.
  • Position Highlighting: Allows you to quickly locate and visually inspect code at a specific character position. This is useful when dealing with error messages that point to a particular location within your Lua files.
  • Easy Access with Slash Commands: The script offers three slash commands for rapid execution of key features:
    • /debugger:check - Runs Lua linting on the current code block.
    • /debugger:beautify - Formats the current code block and copies it to the clipboard.
    • /debugger:position - Prompts you for a character position and highlights the corresponding code in a panel.
  • Dedicated Lint Panel: A toggleable panel on the right-hand side of the editor continuously displays linting information, providing real-time feedback as you write code. This panel automatically updates when you save your page.

How to Use:

  1. Installation: The script automatically attempts to install required dependencies (Utilities.md and Luacheck.md) from the Silverbullet library repository. You’ll see a notification if installation is successful or if there are any errors.
  2. Code Block Designation: Place the Lua code you want to debug within a Silverbullet code block specifically labelled with the tag space-lua. The script will automatically identify and process this code block.
  3. Executing Commands: Type the corresponding slash command into the Silverbullet editor to trigger:
    • Linting: Type /debugger:check and press Enter. The results will be displayed in the editor.
    • Formatting: Type /debugger:beautify and press Enter. The formatted code will be inserted into the editor and copied to your clipboard.
    • Position Highlighting: Type /debugger:position and press Enter. You will be prompted to enter a character position. Enter the position and press Enter again to see the code highlighted in a panel.
  4. Using the Lint Panel: Run the command Debugger: Toggle Lint Panel to show a panel with linting errors. The panel automatically reloads when the page is saved.

Installation

Undercover

  • Library/Malys/Luacheck : luacheck wrapper
4 Likes

Is there a repository we can use to install this and its deps?

Install silverbullet-libraries/src/Utilities/Debugger.md at main · malys/silverbullet-libraries · GitHub
Read prerequisites

This looks very impressive! Btw, are you aware there is an editor:lint event? You could hook your linting stuff into this, potentially and get inline underlining of issues. The event is not very well documented, but here are two pointers:

It’s dispatched here (so you can see the data sent): silverbullet/client/codemirror/lint.ts at main · silverbulletmd/silverbullet · GitHub

Here are some example listeners (note the LintDiagnostic type):

The LintDiagnostic type: silverbullet/plug-api/types/client.ts at main · silverbulletmd/silverbullet · GitHub

1 Like

Update! see changelog in md file.

Is there an event on library install or update to scan automatically updated page? @zef

No, not right now.

1 Like