Suggestions for how to implement a debugger source view

I am writing a debugger GUI that wraps the Debug Adapter Protocol (DAP). I am aiming to use Iced since I am familiar with Elm. I would like some advice on implementing the source viewer.

Current debuggers such as the VS Code debug system, JetBrains debugging, or gdb tui mode show the source code around the current program position, typically with a marker in the “gutter” to indicate placed breakpoints, and a highlight for the current line.

What I am trying to achieve is similar to the TextEditor widget, but with a few tweaks:

  1. I want to disable editing (I may go back on this decision later, but for now this is the case). I can implement this simply by intercepting the iced::widget::text_editor::Action in my app update method and throwing away Edit variants :+1:
  2. I want to show syntax highlighting to help readability. This is shown in the (excellent btw!) text editor walkthrough :+1:
  3. I want to show breakpoints in a “gutter” i.e. a column before the first text column with icons representing breakpoints :person_shrugging:
  4. I want to highlight the current line indicating that the program has paused before executing a specific line. :person_shrugging:

I would specifically like help with the following:

  • Am I correct with my assessment of items 1 and 2?
  • How can I implement item 3?
  • How can I implement item 4? My current theory is that I could implement a custom iced::advanced::text::Highlighter implementation which adjusts the result of a iced_highlighter::Highlighter instance and changes the background of the “current line”

Thanks in advance for your help on this.

1 Like

You are correct with 1 and 2!

When it comes to 3 and 4, I’m afraid that the current TextEditor widget won’t be enough. I have plans to go back and iterate further on it (implementing a Gutter API is part of the plan!).

If you want to explore on your own, you could try to implement this stuff yourself using a “wrapper” custom widget or, worst case scenario, copy-paste the TextEditor code and tweak it to suit your needs!

Hope that helps a bit!

Thanks @hecrj , this input is greatly appreciated.

I was coming to the same conclusion myself. Glad to hear that a Gutter API is part of the roadmap, I think that would be quite useful for e.g. git indications, annotations in general etc.

Regarding the custom widget, I think I will try coupling the TextEditor with a narrow vertical text widget (or canvas if needed) that is kept in sync with the scroll of the text editor somehow, that responds to its own click handling.

Another couple of questions if that’s ok?

  • Would highlighting the current line require a custom Highlighter implementation? I presume I could invoke the current iced_highlighter::Highlighter implementation, but if the current line is to be highlighted, override the response somehow. I would also need to invalidate the highlighting of the “current” line if it changes.
  • Or: is there a way I could overlay e.g. a canvas over the text editor and perform the semi-transparent highlighting there?
  • Can I manipulate the text editor scroll state? I want to jump to a specific position

Sorry for the naive questions, I don’t get much time to experiment for myself, but I am really enjoying building native GUIs with Iced!