- Notifications
You must be signed in to change notification settings - Fork397
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
feat(gnoweb): add hyperlinks to importp/*
andr/*
in source code viewer#3759
base:master
Are you sure you want to change the base?
Conversation
🛠 PR Checks SummaryAllAutomated Checks passed. ✅ Manual Checks (for Reviewers):
Read More🤖 This bot helps streamline PR reviews by verifying automated checks and providing guidance for contributors and reviewers. ✅ Automated Checks (for Contributors):🟢 Maintainers must be able to edit this pull request (more info) ☑️ Contributor Actions:
☑️ Reviewer Actions:
📚 Resources:Debug
|
@mous1985 before any reviews, can you add tests, especially testing:
import ("abc.yx/a/b/c""abc.yx/a/b/c""abc.yx/a/b/c")
import ( hello"abc.yx/a/b/c")
import ( _"abc.yx/a/b/c") thanks |
Codecov ReportAttention: Patch coverage is
📢 Thoughts on this report?Let us know! |
@@ -344,3 +344,12 @@ | |||
scrollbar-width: none; | |||
} | |||
} | |||
/* Styling for import links */ | |||
.gno-import { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Could you please try to use Tailwind and its config theme instead of using a new classes, new colors etc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
fffb7f4
It's good if i use<a href="/%s$source">"%s"</a>
the same color as the original import ?
Co-authored-by: Alexis Colin <alexis@jaunebleu.co>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Looks good 👍 I've left a few points related to refactoring things
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
LGTM
remove:review/triage-pending
flag
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Nice feature 👍
Nit: Could using a regex help by robustly matching import tokens, so we are not relying on fixed strings and specific newline formatting? But maybe it's a picky safeguard against potential changes in output format.
|
return nil | ||
formatted := buf.String() | ||
// Process .gno files to add links |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
This is a hack
We have an extensible markdown engine, we should implement this as an extension there, unless you can show it's impossible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Using Chroma would be correct but also more robust, maintainable, and less dependent on final HTML structure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
@thehowl This feature is not related togoldmark
, but rather tochroma
, which is responsible for syntax highlighting.
I gave a quick look atchroma
to explore integration possibilities. Unfortunately, extending it is bit challenging, but not impossible. It would require creating a new renderer and a new lexer forgno
, supporting import as a specific token, and integrating it into the rendering system.
This PR is indeed a hacky solution; even if it can be negligible most of the time, usingre.ReplaceAllString
to process the whole file can be a heavy task based on the file size andI wonder if it could not even be a potential DDoS vector if people create some on-purpose files containing ton of (probably still negligible). Also, it relies on Chroma syntax, which can change over time. But the main issue is that we will likely and quickly encounter other changes like this one, e.g., linking the source function to the documentation page, adding hover variable inspection, etc. We cannot apply this hack every time we want to integrate source extensions."gno.land/.*"
string reference
I'm unsure whether to wait for a proper Chroma extension or to merge this as a temporary solution. Another less risky option could be to implement this hack on the JS side temporarily, as it would be better for the client to handle this "heavy" task (cc@alexiscolin). However, since there is nothing urgent, I'm hesitant to rush into a hacky and temporary solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Thanks for your feedback@thehowl@gfanton@alexiscolin
I'm currently exploring possible ways to solving this issue. the best solution in my opinion is to extendchroma
forgno
, and then there will be more possibilities to manipulate source code, what do you think about that ?
I can put this PR in draft and working on it if you want
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I'm not worried on the regex/performance side; Go's regex engine is very good and runs inO(n)
. I'm just worried that this is too dependent on the syntax coming out of goldmark and is not robust.
Goldmark highlighting is added with an extension that does the following:
m.Renderer().AddOptions(renderer.WithNodeRenderers(util.Prioritized(NewHTMLRenderer(e.options...), 200),))
Can we not also add an extension on the renderer, that runs after the HTMLRenderer (which adds the syntax highlighting)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
goldmark
useschroma
under the hood to generate the highlight. So you cannot just extendgoldmark
. You necessarily have to extendchroma
first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Please, update chroma so that everything we do for "source code viewer" may also work for when we embed gno code in the render function, i.e.,
lorem ipsum```gnoimport "gno.land/p/demo/avl"// ...```foo bar
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
my request isn't about this PR especially but about the current way gnoweb use chroma in two different manners. i think this can be tackled in a dedicated PR (cc@alexiscolin@gfanton)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Fine, we can go with the regex and then look to improve this on chroma eventually. We have tests so we should know if it breaks.
Let's address moul's feedback then we're good to go I'd say?
Co-authored-by: Manfred Touron <94029+moul@users.noreply.github.com>
This PR adds hyperlinks to
package
andrealm
imported in the source code viewer ongnoweb
.When users view source code on
gnoweb
, they often need to explore dependencies and related code. the goal was to make this easier by making imports linkable for example, when you seeimport "gno.land/p/demo/avl"
, you should be able to click it to see that package's source code.thanks to@gfanton for the help