zed icon indicating copy to clipboard operation
zed copied to clipboard

Add missing newlines in hover tooltips

Open CharlesChen0823 opened this issue 10 months ago • 1 comments

fix #10511

Release Notes:

  • N/A

CharlesChen0823 avatar Apr 15 '24 08:04 CharlesChen0823

Warnings
:warning:

This PR is missing release notes.

Please add a "Release Notes" section that describes the change:

Release Notes:

- (Added|Fixed|Improved) ... ([#<public_issue_number_if_exists>](https://github.com/zed-industries/zed/issues/<public_issue_number_if_exists>)).

If your change is not user-facing, you can use "N/A" for the entry:

Release Notes:

- N/A

Generated by :no_entry_sign: dangerJS against 2b64cb4ec5f35d8c6dd36795a0ab84f440e0d00f

zed-industries-bot avatar Apr 15 '24 08:04 zed-industries-bot

@mrnugget when enter metadata block, start new parser for content in block. Is this an acceptable method?

CharlesChen0823 avatar Apr 16 '24 02:04 CharlesChen0823

@mrnugget when enter metadata block, start new parser for content in block. Is this an acceptable method?

Hmmm, I'm a bit skeptical of recursion here. Do you have a specific bit of Markdown to reproduce the issue? I think we at least need that.

mrnugget avatar Apr 16 '24 07:04 mrnugget

just in any c/cpp file with clangd lsp. mouse hover any function name. currently display is oddly.

CharlesChen0823 avatar Apr 16 '24 07:04 CharlesChen0823

Yes, but can you get the exact Markdown here, so we can look at it and possibly write a test case? If you do RUST_LOG=lsp=trace cargo run ~/cpp-project you should be able to see the raw JSON returned by clangd and that should include the Markdown.

mrnugget avatar Apr 16 '24 07:04 mrnugget

2024-04-16T15:58:00+08:00 TRACE lsp] incoming message: {"id":4,"jsonrpc":"2.0","result":{"contents":{"kind":"markdown","value":"### function `search`  \n\n---\n→ `void`  \nParameters:  \n- `TrieNode * flag (aka struct TrieNode *)`\n- `char * word`\n\n---\n```cpp\nvoid search(TrieNode *flag, char *word)\n```"},"range":{"end":{"character":8,"line":230},"start":{"character":2,"line":230}}}}

CharlesChen0823 avatar Apr 16 '24 08:04 CharlesChen0823

Okay, so the markdown looks like this:

### function `search`

---
→ `void`
Parameters:
- `TrieNode * flag (aka struct TrieNode *)`
- `char * word`

---
```cpp
void search(TrieNode *flag, char *word)
```

That makes me wonder: aren't the --- just supposed to be dividers? Like, if I put a --- in the next line here


then it renders as a <hr> I think. So should we handle that?

mrnugget avatar Apr 16 '24 08:04 mrnugget

Okay, so the markdown looks like this:

### function `search`

---
→ `void`
Parameters:
- `TrieNode * flag (aka struct TrieNode *)`
- `char * word`

---
```cpp
void search(TrieNode *flag, char *word)

That makes me wonder: aren't the `---` just supposed to be dividers? Like, if I put a `---` in the next line here

then it renders as a `<hr>` I think. So should we handle that?

Hmm I think there are two problems which we will run into when rendering dividers:

  • It looks like our markdown parser dependency (pulldown_cmark) does not pickup dividers if there is no line break before and after the ---, see https://www.markdownguide.org/basic-syntax/#horizontal-rule-best-practices. Github is able to render that though
  • The markdown crate renders everything into an InteractiveText element, which does not support inserting elements other than text. We could 'split' up blocks here and render dividers, however at this point it would probably make the most sense to combine the language markdown implementation with the markdown_preview markdown implementation (which does support lists, tables, dividers, etc.)

bennetbo avatar Apr 16 '24 09:04 bennetbo

In markdown, start --- and end with --- is an extentsion named markdown yaml metadata block, and there also can be start +++ with end +++. this is not dividers

CharlesChen0823 avatar Apr 16 '24 09:04 CharlesChen0823

In markdown, start --- and end with --- is an extentsion named markdown yaml metadata block

Isn't that YAML frontmatter? YAML frontmatter is supposed to only show up at the start of a text (see here) and "must take the form of valid YAML set between triple-dashed lines".

In this case it doesn't look like that's YAML between the ---.

mrnugget avatar Apr 16 '24 09:04 mrnugget

Neovim also renders it as dividers:

screenshot-2024-04-16-12 16 52@2x

With this being the Markdown:

### instance-method `format`

---

→ `void`
Parameters:
- `const int &`
- `const std::tm &`
- `int & dest`

---

```cpp
// In my_formatter_flag
public: void format(const int &, const std::tm &, int &dest)
```

mrnugget avatar Apr 16 '24 10:04 mrnugget

Closing this in favor of https://github.com/zed-industries/zed/pull/10606

mrnugget avatar Apr 16 '24 10:04 mrnugget