tmbb

tmbb

Just created a very simple library that allows you to have syntax highlighting in the Phoenix debugger. Code here: GitHub - tmbb/phoenix_with_pretty_debugger: Add syntax highlighting to the Plug debugger used by Phoenix · GitHub

PhoenixWithPrettyDebugger

Adds support for syntax highlighting in the Phoenix debugger.

To use, replace the following line in your application’s endpoint:


use Phoenix.Endpoint, otp_app: :your_app

by the this line:


use PhoenixWithPrettyDebugger.Endpoint, otp_app: :your_app

No other changes are needed.

Happy hacking with a prettier debugging experience!

The highlighter supports elixir and erlang by default (so it can even highlight code in the cowboy modules). Internaly this project uses the makeup syntax highlighting library and you can add support for other languages by importing the appropriate lexers.

Example output:

Highlighting Elixir:

Highlighting Erlang:

Is this safe?!

This library simply defines an alternative to the default Phoenix.Endpoint module which is actually API compatible. We reuse as much functionality from that module as possible and only redefine the parts we need to add our new debugger. Becuase the debugger is only used in :dev and never in :prod

Showing Posts 1 to 5

Eiji

Eiji

@tmbb Hmm … honestly I do not see why it’s a standalone library … If I remember correctly makeup is used even in ex_doc, so I do not see why it could not be a part of phoenix … Did you proposed this enhancement before? If so can you please link to such discussion for a reference, please?

tmbb

tmbb OP

The debugger is part of Plug and not Phoenix. I’ve proposed to add syntax highlighting to Plug here: Syntax highlihting for the Debugger: minimum viable PR; needs cleaning by tmbb · Pull Request #763 · elixir-plug/plug · GitHub

I think that instead of adding syntax highlighting to plug debugger is rather have a way of of setting a custom debugger in the Phoenix.Endpoint module (as my last message from that PR explains).

Eiji

Eiji

Sorry, my mistake. I mean exactly what you wrote here:

(…) If we change the phoenix generators to include makeup as a :dev dependency, then most people will indeed have access to the improved debugger. (…)
Source: https://github.com/elixir-plug/plug/pull/763#issuecomment-502857724

Thanks! Now I can see the case …

Thanks @tmbb! If it makes your life easier, we could add a highlighter API to Plug.Debugger, where we call highlighter_module.highlight(snippet, min_line..max_line) . So your implementation has only to implement the highlighting bits. This way it is extensible but we don’t have to keep the makeup code in Plug itself. Would that help?
Source: Syntax highlihting for the Debugger: minimum viable PR; needs cleaning by tmbb · Pull Request #763 · elixir-plug/plug · GitHub

This is exactly what I had in mind …

(…) I don’t think that’s the way to go. I’d rather have a debugger module (with respective options) passed as an argument to use Phoenix.Endpoint, ... instead of hardcoding Plug.Debugger (…)
Source: Syntax highlihting for the Debugger: minimum viable PR; needs cleaning by tmbb · Pull Request #763 · elixir-plug/plug · GitHub

and that’s your answer.

I quoted those parts as I believe there are the most interesting for other people interested in this topic.

I have only one question …

That way people could use their own debuggers (a debugger with syntax highlighting, a debugger that replays the request with different parameters, a debugger that lets you update code in place, etc). That’s what my package does, it adds a completely new debugger (which is mostly copy-pasteed from the original Plug.Debugger ) which as a feature highlight the files. I only had to define a new PhoenixWithPrettyDebugger.Endpoint because Plug.Debugger is hardcoded in Phoenix.Endpoint 's __using__/1 macro.
Source: Syntax highlihting for the Debugger: minimum viable PR; needs cleaning by tmbb · Pull Request #763 · elixir-plug/plug · GitHub

Can you please describe if and how it’s possible to write said debuggers and have your syntax highlighting at the same time? From what I can see PhoenixWithPrettyDebugger.Plug.PrettyDebugger.Highlighter module is private (@moduledoc false), so you do not exposing it’s API, right?

tmbb

tmbb OP

Can you please describe if and how it’s possible to write said debuggers and have your syntax highlighting at the same time?

You just have to duplicate the functionality in your own debugger module, of course. I’m not interested at all in exposing any part of this as public API. Just copy and paste the relevant files into your own project.

tmbb

tmbb OP

I’ve added some new capabilities to my debugger. You can now (using the debugger page) add breakpoints to a function in on any of the frames and replay the request handling with that breakpoint (and pry that breakpoint in IEx). You have to start your phoenix app

It’s not as useful as I though it would be (beam stack frames aren’t that awesome and they lose a lot of information), but its pretty cool. It can also serve as an example for other who might want to extend Phoenix’s debugger.

You can get it from github master.

— All posts loaded —

Where Next? Top

Trending in Announcing Top

restlessronin
The repo is at GitHub - cyberchitta/openai_ex: Community maintained Elixir library for OpenAI API · GitHub. Docs are at OpenaiEx User Gu...
152 12366 136
New
type1fool
WebAuthnLiveComponent WebAuthnComponents See this post about renaming the package. Passwordless authentication for Phoenix LiveView app...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
ausimian
Castle is a package I put together to assist with building Elixir releases capable of being live-upgraded via the ‘official’ release hand...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
kip
In 2021 I started a new library called Tempo with the objective of modelling time as a set of intervals - not as instants. In 2022 I gave...
New

Other Trending Topics Top

budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
budgie
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with. But I don’t use it anymore. Serverless was the promis...
New
OndrejValenta
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly) AI dream has many faces, but general...
New
Null-logic-0
What IDE or editor are you using for Elixir development? Personally, I use Zed, and I really like it, but sometimes I wish there were a ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews