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

fix: render examples as yaml on hover #947

Merged

Conversation

twelvelabs
Copy link
Contributor

@twelvelabs twelvelabs commented Dec 27, 2023

What does this PR do?

This MR improves the rendering of examples on hover by:

  1. Rendering the examples as YAML rather than JSON.
  2. Adding an info string to the fenced code block so that the examples are properly syntax highlighted. According to the LSP spec, markdown content should be expected to be GFM, so this shouldn't be an issue for clients.
  3. Moving the indentation escaping logic to toMarkdown, so that we only escape non-markdown strings. Currently the escaping is done on the entire hover content, regardless of whether that content contains actual markdown. This change also fixes a bug where intentional indentation in markdownDescription is erroneously escaped.

Before:

Screenshot 2023-12-27 at 3 17 58 PM

After:

Screenshot 2023-12-27 at 3 12 24 PM

Note: I originally tried to keep the single header (rather than repeating it per-example), but the code fences don't appear to have a margin applied so the examples were all bunched together. Repeating the header looked much nicer.

What issues does this PR fix or reference?

Is it tested? How?

I updated an existing unit test. Also tested manually with the following (see screenshots):

  • schema.json:
{
    "$id": "schema.json",
    "$schema": "https://json-schema.org/draft-07/schema",
    "title": "Example Schema",
    "properties": {
        "example": {
            "title": "Example Property",
            "description": "This property has examples that should be rendered as YAML code blocks.",
            "examples": [
                "string value",
                {
                    "object_value": {
                        "enabled": true
                    }
                }
            ],
            "type": [
                "object",
                "string"
            ]
        }
    },
    "type": "object"
}
  • example.yaml:
# yaml-language-server: $schema=schema.json
example: "hello"

@coveralls
Copy link

coveralls commented Dec 27, 2023

Coverage Status

coverage: 84.076% (+0.005%) from 84.071%
when pulling 7ff405f on twelvelabs:examples-on-hover
into 5458ed3 on redhat-developer:main.

@twelvelabs
Copy link
Contributor Author

ping @msivasubramaniaan and @gorkem

Copy link
Contributor

@msivasubramaniaan msivasubramaniaan left a comment

Choose a reason for hiding this comment

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

LGTM

@msivasubramaniaan msivasubramaniaan merged commit dfccc6f into redhat-developer:main Jan 5, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment