Closed seagreen closed 3 years ago
I think this could be done as follows...
Element
type in SyntaxText.hs in the unison repo so that Reference
becomes Reference Text
, where the Text is the FQN of the thing being referred to (assuming that's what you need?) and similarly Constructor
and Request
. That SyntaxText
defines a simple markup on top of the text being output (the Pretty
in Pretty SyntaxText
then defines a second layer of markup, FWIW, used for line breaking when you call render 80
.) Currently the SyntaxText
markup is just used to enable a bit of color highlighting when printing to console in ucm
. TermPrinter.hs
and TypePrinter.hs
where we use a PrettyPrintEnv
, and for most of them add the extra FQN info for the SyntaxText
markup (currently the markup is added with fmt
).toPlain
. You could add syntax highlighting as well here, without doing the two bullets above - might be a good place to start.
If you try this, feel free to get in touch on slack if you need info. 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.
We can just as easily make it the hash (or both), that's fine!
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.
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!
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.
I'll have a think about this and post something!