Skip to content
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

feat: add diagnostic marker #12374

Closed

Conversation

carrascomj
Copy link

Related to #11864

Add a configurable marker (● by default) to separate between the line and the end of line diagnostic decoration.

image

The default is the same as the gutter symbol, maybe it should be changed, but I have seen another PR about changing the gutter, so let me know what you think!

@@ -110,7 +110,7 @@ impl Renderer<'_, '_> {
(end_col, _) = self.renderer.set_string_truncated(
self.renderer.viewport.x + draw_col,
row,
line,
format!("{} {}", self.config.diagnostic_marker, line).as_str(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should just be drawn separately. Allocating a string for every diagnostic on every frame is too expensive

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was quick! It makes sense but I am not sure how to do it, would you have any pointers?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I would need to change set_string_truncated for the TextRenderer and the Surface or is there a different way that I am missing?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

He probably means that you should first draw the marker and then draw the line as before. You are allocating here to just draw in a column, which could just be done as offsetting the x value along as you draw.

Copy link
Author

@carrascomj carrascomj Dec 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the end, I changed set_string_truncated. The reason that I do not simply call draw_decoration is because, while it is true that without making it configurable is easy:

// diagnostic marker
const DIAG: &str = "● ";
// trigger before eol diagnostic at <InlineDiagnostics as Decoration>::render_virt_lines
renderer.draw_decoration(DIAG, eol_diagnostic.severity(), virt_off.col as u16);
col_off = renderer.draw_eol_diagnostic(eol_diagnostic, pos.visual_line, virt_off.col);

If DIAG is not const, and it is part of the InlineDiagnostics (state.config), we cannot
make it outlive the TextRenderer (I think), so it would not be possible to borrow the diagnostic marker, given this signature:

impl Decoration for InlineDiagnostics<'_> {
  fn render_virt_lines(
      &mut self,
      renderer: &mut TextRenderer,
      pos: LinePos,
      virt_off: Position,
  ) -> Position {}
}

It seems like I am a bit rusty, so I might be over complicating this.

@carrascomj carrascomj requested a review from pascalkuthe January 6, 2025 17:13
@carrascomj
Copy link
Author

Thinking about this, perhaps this should not be configurable, in the spirit of other PRs/comments related to symbols. Am I right? What should the default/fixed marker be?

@the-mikedavis
Copy link
Member

Yeah I feel that this could be combined with (or based on) #12060. For example I have this patch locally as the-mikedavis@5cf96a3

@carrascomj
Copy link
Author

Makes sense, I'll close this one and leave the implementation for that PR (or reopen it once that one is merged).

@carrascomj carrascomj closed this Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants