redhat-developer / redhat-developer/yaml-language-server

Add indent on json stringify of examples

Open
#791 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
TypeScript
Stars
1.5k
Forks
352
Avg merge
2d 7h
Merged PRs (30d)
11

Description

Hi, when doing examples if it is an object, or array and not a primitive type, the examples section isn't that useful, if a large object is shown, would it be possible to add indentation to the examples

https://github.com/redhat-developer/yaml-language-server/blob/220519da363544f659e63302fc31bdda0800c34c/src/languageservice/services/yamlHover.ts#L149

I'd be happy to add it if it is something we want =D

probably something like this:

s.schema.examples.forEach((example) => {
    markdownExamples.push(JSON.stringify(example, null, 4 / '\t'));
});

So instead of

```{"someObject": {"someProperty": "someValue"}}```

it would be

\```
{
    "someObject": {
         "someProperty": "someValue"
     }
}
\```

The ` formatting was a bit messed up.

If we were more ambitious we could probably even output it as yaml instead, which is more fitting to the package name =D

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/languageservice/services/yamlHover.ts at the linked line where schema examples are converted with JSON.stringify. Review how object and array examples are added to the examples section, then verify that large non-primitive examples render with readable indentation while primitive examples remain appropriate.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.