Skip to content

Display source markers in source code pane #10062

Closed

Description

@gadenbuie

Currently, custom source markers created with rstudioapi::sourceMarkers() don't appear in the actual source pane like other code diagnostics.

image

In addition to being helpful for packages like lintr, it would also be a useful approach for calling attention to particular lines of code from within a learnr tutorial or other interactive feedback system. Currently, if the message only appears in the Markers pane the annotations are too disconnected from the source to be effective for learning.

Additionally, #9010 was closed as stale but appears to provide a relatively easy solution to fix the bug that currently prohibits messages with class "html" from being rendered as HTML.

Activity

  1. jmcphers commented on Nov 24, 2021

    @jmcphers
    Member

    Consider: These should probably show up in the visual editor, too, if they're inside a code chunk there.

  2. 8 remaining items

  3. timtmok commented on Feb 9, 2022

    @timtmok
    Contributor

    I'll take a look. It seems that the gutter is not displaying the markers.

  4. timtmok commented on Feb 9, 2022

    @timtmok
    Contributor

    I can reproduce the issue using the daily but not in dev. It also seems to work with R arm64 but not if I use x86.

  5. timtmok commented on Feb 14, 2022

    @timtmok
    Contributor

    Any build since Friday contains the fix for this.

  6. jgutman commented on Feb 18, 2022

    @jgutman
    Contributor

    On Mac OS 12.2 with R 4.2 x86_64 and RStudio Desktop 2022.6.0.128, the custom markers show up in both the gutter and the Source Marker pane, but the HTML element styling doesn't render.

    For example:

    ~/test_10062.R

    foo <- shiny::HTML('<div style="color:red;">I am red</div>')
    bar <- shiny::HTML('<p style="color:red;">I am red</p>')
    inherits(foo, "html")
    #> [1] TRUE
    inherits(bar, "html")
    #> [1] TRUE
    
    markers <- list(
      list(
        type = "error",
        file = paste(getwd(), "test_10062.R", sep = "/"),
        line = 11,
        column = 1,
        message = foo),
      list(
        type = "info", 
        file = paste(getwd(), "test_10062.R", sep = "/"),
        line = 19,
        column = 1,
        message = bar))
    
    rstudioapi::sourceMarkers("Test Name", markers)
    

    image

    image

    image

    I thought that the text would be rendered in red in the source markers pane and the left gutter.
    Same if I use R 4.2 arm 64 version

    @timtmok Thoughts?

  7. timtmok commented on Feb 18, 2022

    @timtmok
    Contributor

    @jgutman Supporting HTML styling potentially opens up a vulnerability for JS script injection so the alternative is providing ANSI code support. This provides basic formatting like italics, bold, font colours and underlining. Any HTML will be rendered literally. It wasn't mention in this issue so that was my fault for not conveying the result of my conversation with Kevin.

  8. jgutman commented on Feb 18, 2022

    @jgutman
    Contributor

    @jgutman Supporting HTML styling potentially opens up a vulnerability for JS script injection so the alternative is providing ANSI code support. This provides basic formatting like italics, bold, font colours and underlining. Any HTML will be rendered literally. It wasn't mention in this issue so that was my fault for not conveying the result of my conversation with Kevin.

    Ah okay, makes sense. Is there a way to do the red color styling with ANSI for this example?

  9. jgutman commented on Feb 18, 2022

    @jgutman
    Contributor

    Confirmed this renders properly with

    foo <- cli::bg_br_white(cli::col_red("I am red!"))
    bar <- cli::bg_br_yellow(cli::col_cyan("I am cyan!"))
    
    markers <- list(
      list(
        type = "error",
        file = paste(getwd(), "test_10062.R", sep = "/"),
        line = 11,
        column = 1,
        message = foo),
      list(
        type = "info", 
        file = paste(getwd(), "test_10062.R", sep = "/"),
        line = 19,
        column = 1,
        message = bar))
    
    rstudioapi::sourceMarkers("Test Name", markers)
    

    Screen Shot 2022-02-18 at 12 29 25 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions