Skip to content

Improving doc comments syntax highlighting in hovering #545

Open
@aspeddro

Description

@aspeddro

After #97 and #525 have been merged we can provider basic syntax highlight when hovering.

Current state

image

Apparently vscode does not detect ```res example as rescript syntax. In markdown highlighting works.

image

Proposal

Convert ```res example to rescript. This can be done on the client side `client/src/extension.ts`, but I'm more +1 to do it in analysis bin as it wouldn't affect other clients.

As the return is markdown we could create sections using the word after ```res?

From:

```res example

To:

## Example\n```rescript

Example:

From:

Constructs a RegExp object (Js.Re.t) from a `string`.
Regex literals `%re("/.../")` should generally be preferred, but `fromString`
is useful when you need to dynamically construct a regex using strings,
exactly like when you do so in JavaScript.

```res example
let firstReScriptFileExtension = (filename, content) => {
  let result = Js.Re.fromString(filename ++ "\.(res|resi)")->Js.Re.exec_(content)
  switch result {
  | Some(r) => Js.Nullable.toOption(Js.Re.captures(r)[1])
  | None => None
  }
}

// outputs "res"
firstReScriptFileExtension("School", "School.res School.resi Main.js School.bs.js")
```

To:

Constructs a RegExp object (Js.Re.t) from a `string`.
Regex literals `%re("/.../")` should generally be preferred, but `fromString`
is useful when you need to dynamically construct a regex using strings,
exactly like when you do so in JavaScript.

## Example

```rescript
let firstReScriptFileExtension = (filename, content) => {
  let result = Js.Re.fromString(filename ++ "\.(res|resi)")->Js.Re.exec_(content)
  switch result {
  | Some(r) => Js.Nullable.toOption(Js.Re.captures(r)[1])
  | None => None
  }
}

// outputs "res"
firstReScriptFileExtension("School", "School.res School.resi Main.js School.bs.js")
```

Below an example after convert res to rescript. Note: indentation at the beginning of the line are preserved, we must remove them.

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions