-
Notifications
You must be signed in to change notification settings - Fork 137
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve presentation of diagnostics on the command line #496
Comments
I labeled this "good first issue" because it's an isolated area for someone who is new to the code base to get started with but the downside of that is that it doesn't let a new developer interact with the more central parts of the code base. |
Hey! 👋 I'm not familiar with how diagnostics works in DocC but I'm interested. I had a brief look at the ideas for readability improvements mentioned and I have a couple of follow up questions:
Would displaying the
Did you have any ideas to achieve this properly? I thought about using the Thanks! |
Great. I assigned this issue to you. There's a lot of creative freedom in how to present these diagnostics where there's no definitive right or wrongs approaches. Don't hesitate to ask questions if you wonder how something works or if you just want a feedback on the format/presentation of the diagnostic.
No, the The bundle itself doesn't have a property for the url to its catalog but that could be worth adding. It's also possible to have a "bundle" that only consist of symbols graph files and no .docc catalog. The directory of symbol graph files is most likely going to be build directory somewhere so it likely doesn't make a meaningful base URL to the developer. In this case it may be better to use the
Using the The one recommendation I would make with reading the lines from the source is that you check if there are multiple diagnostics in the same file and only read that file content once and extract all the lines. Reading from disk can be comparatively very slow. By "surrounding context" I meant some number of lines above and below the line with the diagnostic. It's probably best to start with just the line with the diagnostic but I could see cases where the extra context helps; for example it's possible that a diagnostic about a directive argument isn't on the same line as the name of the directive. (It's also possible that the The |
The specific diagnostic formatting that's intended to be read by people happens in |
That's super helpful thank you so much! I appreciate it. I'll keep you updated on my progress here. 😊
I'll probably have more questions as I start playing more with those suggestions, I'll post them here as well. Thank you again for the support!
That's a great point. Could you point me to some existing logic for reading lines from a source? I'm wondering if there is some existing work we could reuse but I couldn't find what I was looking for. |
The documentation processing flow mainly operates on already parsed markdown or on line lists from symbol graph files so it doesn't read lines from the source directly. A handful of tests use |
Hi @d-ronnqvist! I got a chance to try out a few things regarding this issue. I opened a pull request on my fork to help with the discussions. I will open the pull request on this repository once it's cleaned up and all the features are added, I hope that's okay! Could you take a look at this pull request when you have some time and let me know if it's going in the right direction? I would appreciate some feedback. |
Yes, this looks like the right direction to me. My main feedback would be to run this on some content and tweak the output according to your preferences for what feels useful and most understandable. For example, the TestBundle test content has some intentional diagnostics:
You may also want to add some more issues to that content to have a few more diagnostics with solutions to make adjustments for. For example; remove the level-1 heading in an article, introduce a typo in a link, change a SeeAlso section to a level-3 heading, or skip from a level-2 heading to a level-4 heading. As you are tweaking the output; if that's easy to iterate on, then that's a good sign. When you open the PR on the DocC repo I suspect that more people will have feedback on the output based on their preferences. The goal is to find something that most people can agree upon. Those final refinements will be easier if it's easy to change the output format in the code. |
Also, you'll possible find that some diagnostics have incorrect ranges. For example, I think this is a bug that the diagnostic range spans the entire
I would consider those changes out-of-scope for this issue. |
Thank you so much for the quick feedback! I'll continue with this approach and keep you updated!
Right, that's the approach I took so far. I'll continue to tweak the output and introduce some more problems to get a wider range of diagnostics.
That definitely makes sense, I look forward to hear ideas from more people once the PR is up! |
One idea would be look at the output from the Swift compiler. Here I added some build errors to the DocC code
This style of presentation highlights the range of the diagnostic with However, it doesn't include the description of the solution, so there's room for improvement there. I introduced some link warnings in TestBundle.docc to get a few examples to work with. Using the approach of highlighting and displaying the replacement would looks something like this for those 3 (I manually edited this output):
For the first 2 issues I think the range and replacement is enough to be understandable but the 2 suggestions for the 3rd issue are not understandable without the individual fixit descriptions. One approach there could be to display each description inline:
(these are actually identical copies in the test data so the collision provides less detail than a real example would) One little complication here is that the fixit description sometimes spans multiple lines. One approach to this could be to always display the fixit descriptions on one line. Another alternative could be to only display the summary description. That could also help avoid formatting issues if the line is long, the diagnostic happens late in the line, and the fixit summary is long. For example
|
These are just some ideas. Another area to look at for inspiration are the diagnostics from Rust. This post contains some examples. Like the blog post describes, these diagnostics present more information inline with the code. Another place to look at for inspiration is the new diagnostic formatter in Swift-Syntax. In both these cases I think that source code has more reasons to display multiple source ranges together to point out where a variable was defined or mutated. So it's possible that diagnostics for documentation content wouldn't benefit as much from this type of formatting. |
Thank you for those ideas, it's super helpful, I particularly found this post very interesting.
Right, I tried an approach without highlighting possible solutions and replacements in the code. I think that by adding enough context around the diagnostic source range and displaying solutions/replacements close to the source code, it's relatively easy to figure out what to change to fix the problem.
I also found that highlighting, either with color or some style, the diagnostic summary and the diagnostic source range in the source code display really makes a difference to pinpoint the issue in the source code. |
This is a big improvement over the current formatting.
In some of these diagnostics I find that 3 lines before and 3 lines after is too much context and makes it hard to spot where the issue is. The paragraph of text in the TestTutorial.tutorial:44:64 above illustrate this well. Other than that; I would maybe consider "suggestion" as an alternate phrase for "help" only because I find it more inviting to read. I'm not sure what would be a good solution for displaying the fixit replacements. One way could be to "apply" the replacements and display them as a line of code. For example:
However, this may end up mostly repeating the same line, making it hard for the reader to spot what changed. For example:
Another option would be to display the replacement inline and reference the suggestion description below
|
That's a great point. I think 2 lines before and after should be enough then.
Right, that's the topic I'm struggling with now. I took a look at showing the fixits inline but I faced a few roadblocks. Now, for possible solutions with a single replacement, I'm leaning only showing summary inline at the replacement source location:
I noticed that displaying both replacement and summary for a possible solution could be redundant.
Also, it might happen that some replacements for a solution are far from the diagnostic source line so showing those source lines to the user might be confusing. In those cases where the replacement is too far from the diagnostic source line or if there are more than one replacement, I'm not sure what is the best way to approach this. I'm thinking dispalying the solution summary at the diagnostic source line might be enough in that case? |
I'm leaning towards only displaying the solution summary and not the solution replacement. To some extent this depend on the way solutions summaries are phrased and since DocC didn't use to display solutions we haven't spent much time on guidelines for phrasing solution summaries. I think once the solutions are more visible people will be more aware of them and more motivated to improve the solution summaries. |
I feel that this is ready for more input from more people on the diagnostic output format. Do you want to bring over the PR to the DocC repo and we can continue the conversation there with more people? |
Right, it makes sense to me! I'll clean up some of the code a bit and I will bring the PR over to the DocC repo shortly! Thank you for your amazing support on this again! 🙇🏻 I look forward to hear more feedback from more people! |
With #535 merged I'd say that this issue is complete. If there are future enhancements we want to do to the presentation of diagnostics we should open new issues for those. |
Feature Name
Improve presentation of diagnostics on the command line
Description
The current format for diagnostics (warnings and errors) on the command line is in some ways limited by needed to be parsed by tools.
With #494 there's a flag for tools to opt-in to an output format intended to be parsed by tools. This frees up the default command line output format to present diagnostics in a way that's more readable for people.
For example, a readability improvements we could make with the default format
Motivation
Improving the readability of diagnostics on the command line helps developers who are using DocC outside of an IDE be more productive by making it easier to act on warnings and errors.
Importance
This enhancement is fairly limited to developers using DocC on the command line directly. That is already possible today but improvements to the experience could make developers more productive in their command line use cases.
Alternatives Considered
No response
The text was updated successfully, but these errors were encountered: