seagreen / unison-code-explorer

:arrow_right: :arrow_right: Superseded by the core team project Unison Share (https://github.com/unisonweb/share) :arrow_right: :arrow_right:
BSD 3-Clause "New" or "Revised" License
22 stars 2 forks source link

Pretty-print code with syntax highlighting and links #3

Closed seagreen closed 3 years ago

atacratic commented 4 years ago

I'll have a think about this and post something!

atacratic commented 4 years ago

I think this could be done as follows...

seagreen commented 4 years ago

Sorry for the slow response:(

where the Text is the FQN of the thing being referred to (assuming that's what you need?)

I'm not set on using FQNs in the displayed HTML. We'll be linking to terms/types by their hash, not their name, so there's no special requirement for it. Does that change things? I'm not very familiar with how the Unison pretty printer works.

atacratic commented 4 years ago

We can just as easily make it the hash (or both), that's fine!

seagreen commented 4 years ago

Dug around in the pretty printer, I think I understand things now. The problem is that Unison.Util.SyntaxText.SyntaxText currently doesn't include the identifiers associated with the various names it contains.

I definitely favor extending it with Referent / Reference (I'm guessing which one will vary depending on Element?) over FQNs.

Would you be willing to make an issue for this upstream, and link to it here? If the work can be broken up into beginner-accessible parts I'd be happy to help with it.

Once that's done, the plan here will be to write a function:


syntaxTextToWidget :: SyntaxText -> Widget HTML Reference
syntaxTextToWidget (AnnotatedText xs) =
  -- fold over the xs,
  -- pattern matching on each (String, Maybe Element),
  -- and using the new information in each Element
  -- to render out `<a>` links where appropriate.
atacratic commented 4 years ago

OK I've written up some tips! Sorry for not doing it myself, bit difficult to make time right now. You're right about using Referent/Reference. Hope it makes sense and you have fun. github didn't seem to let me set you as the owner of the unison issue, but here it is: https://github.com/unisonweb/unison/issues/1332

I think if you can make the current changes I've sketched out compile then you'll be pretty much there!

seagreen commented 3 years ago

Added links: https://github.com/seagreen/unison-code-explorer/commit/7bca8c8def589f41b63c4030114ae29ce5364c6d

No syntax highlighting yet, but I think we can close this and open a new issue if/when we want it.