This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Fix whitespace between chunks in markdown paragraphs.
ClosedPublic

Authored by sammccall on Apr 29 2020, 4:04 PM.

Details

Summary

Old model: chunks are always separated by one space.

This makes it impossible to render "Foo `bar`." correctly.

New model: chunks are separated by space if the left had trailing space, or

the right had leading space, or space was explicitly requested.
(Only leading/trailing space in plaintext chunks count, not code)

Diff Detail

Event Timeline

sammccall created this revision.Apr 29 2020, 4:04 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 29 2020, 4:04 PM
kadircet marked an inline comment as done.Apr 30 2020, 4:00 AM
kadircet added inline comments.
clang-tools-extra/clangd/FormattedString.cpp
446–449

i think we always want a space before code chunks, for example in case of multiple code chunks this would result in malformed makrdown:

`foo``bar`

can you also add a test case for that?

if you would like to keep SpaceBefore/After to text only chunks, I suppose we can also check for chunk's kind for outputting a space.

clang-tools-extra/clangd/FormattedString.h
69–75

argh... this one doesn't belong here :( wonder how we missed it. sent out 7a3be975b92fece93e07bfc6451e9a39eb6f5142 sorry for conflict :/

73

nit: define in two lines?

clang-tools-extra/clangd/Hover.cpp
887

nit Out.appendText().appendSpace() ?

sammccall marked 4 inline comments as done.Apr 30 2020, 11:33 AM
sammccall added inline comments.
clang-tools-extra/clangd/FormattedString.cpp
446–449

Good catch!

I think it's better to solve this in appendCode as you suggest - inconsistencies between markdown and plaintext are good places for bugs to hide without being seen.

sammccall marked an inline comment as done.

Address comments.

kadircet added inline comments.Apr 30 2020, 1:35 PM
clang-tools-extra/clangd/FormattedString.cpp
439

I would say we should also put a space even when the previous chunk is text, as:

foo`bar`

is also malformed.

clang-tools-extra/clangd/FormattedString.h
72

this is no longer true :/

sammccall updated this revision to Diff 261399.Apr 30 2020, 5:18 PM
sammccall marked an inline comment as done.

tweak coment

sammccall marked 2 inline comments as done.Apr 30 2020, 5:18 PM
sammccall added inline comments.
clang-tools-extra/clangd/FormattedString.cpp
439

Do you have a reference or example for that? I can't find it in the spec, and the couple of parsers I tried accept it.

clang-tools-extra/clangd/FormattedString.h
72

Weakened it a bit. Don't think it's worth giving details inline here.

kadircet accepted this revision.May 1 2020, 10:15 AM
kadircet marked an inline comment as done.

thanks lgtm!

clang-tools-extra/clangd/FormattedString.cpp
439

i remembered this rule from emphasis(IIRC asdf_foo_bar doesn't count as emphasis because it is not separated from surrounding letters.), and thought it also applies to code spans, tried it over phab and it didn't render as inline :D so i didn't check more.

but you are right, looks like preceding/trailing whitespaces are not required. sorry for the hussle.

This revision is now accepted and ready to land.May 1 2020, 10:15 AM
This revision was automatically updated to reflect the committed changes.
sammccall marked an inline comment as done.