-
Notifications
You must be signed in to change notification settings - Fork 23
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
feat: Support syntax coloration for code block in LSP hover #360
Conversation
95b5f21
to
cb401c0
Compare
5210e66
to
fbd6310
Compare
fbd6310
to
a394208
Compare
Good catch, my translate of kotlin to Java code was bad, it should be fixed now (I have updated screenshot). |
635c0f8
to
1c3e275
Compare
1c3e275
to
44e40ae
Compare
.../java/com/redhat/devtools/lsp4ij/features/documentation/LightQuickDocHighlightingHelper.java
Outdated
Show resolved
Hide resolved
.../java/com/redhat/devtools/lsp4ij/features/documentation/LightQuickDocHighlightingHelper.java
Outdated
Show resolved
Hide resolved
...ava/com/redhat/devtools/lsp4ij/features/documentation/SyntaxColorationCodeBlockRenderer.java
Outdated
Show resolved
Hide resolved
src/main/java/com/redhat/devtools/lsp4ij/features/documentation/TextMateHighlighterHelper.java
Outdated
Show resolved
Hide resolved
Thanks. Glad to know that I'll be able to customize hover support using something more than just a boolean. For comparison, here's how the native API renders the same signature: Notable differences:
|
44e40ae
to
b2ea228
Compare
It is. A Python function may have many parameters, with type hints for each. Take def dump(
obj: Any,
fp: SupportsWrite[str],
*,
skipkeys: bool = False,
ensure_ascii: bool = True,
check_circular: bool = True,
allow_nan: bool = True,
cls: type[JSONEncoder] | None = None,
indent: None | int | str = None,
separators: tuple[str, str] | None = None,
default: Callable[[Any], Any] | None = None,
sort_keys: bool = False,
**kwds: Any,
) -> None: ... Not crazy enough? Check out def __init__(
self,
*,
color_system: Optional[
Literal["auto", "standard", "256", "truecolor", "windows"]
] = "auto",
force_terminal: Optional[bool] = None,
force_jupyter: Optional[bool] = None,
force_interactive: Optional[bool] = None,
soft_wrap: bool = False,
theme: Optional[Theme] = None,
stderr: bool = False,
file: Optional[IO[str]] = None,
quiet: bool = False,
width: Optional[int] = None,
height: Optional[int] = None,
style: Optional[StyleType] = None,
no_color: Optional[bool] = None,
tab_size: int = 8,
record: bool = False,
markup: bool = True,
emoji: bool = True,
emoji_variant: Optional[EmojiVariant] = None,
highlight: bool = True,
log_time: bool = True,
log_path: bool = True,
log_time_format: Union[str, FormatTimeCallable] = "[%X]",
highlighter: Optional["HighlighterType"] = ReprHighlighter(),
legacy_windows: Optional[bool] = None,
safe_box: bool = True,
get_datetime: Optional[Callable[[], datetime]] = None,
get_time: Optional[Callable[[], float]] = None,
_environ: Optional[Mapping[str, str]] = None,
): For the main part, these signatures are code, and (unless you are into that kind of thing) code are meant to be displayed in monospace font. |
src/main/java/com/redhat/devtools/lsp4ij/features/documentation/LSPDocumentationHelper.java
Outdated
Show resolved
Hide resolved
src/main/java/com/redhat/devtools/lsp4ij/features/documentation/LSPDocumentationHelper.java
Outdated
Show resolved
Hide resolved
I, for one, largely prefer it this way, and I think dyslexic people would agree: Readability notwithstanding, here's how the block is sent via LSP (pseudo-JSON): {
"result": {
"contents": {
"kind": "markdown",
"value": """
```python
(function) def dumps(
obj: Any,
*,
skipkeys: bool = False,
...
) -> str
```
---
Serialize `obj` to a JSON formatted `str`.
If `skipkeys` is true then `dict` keys that are not basic types [...]
"""
},
"range": {/* ... */}
} That message should, obviously, be rendered as one code block followed by a horizontal ruler and multiple paragraphs:
|
...ava/com/redhat/devtools/lsp4ij/features/documentation/SyntaxColorationCodeBlockRenderer.java
Outdated
Show resolved
Hide resolved
ec7985c
to
92a1e4a
Compare
@fbricon if you want to test quickly this PR, you can create a ts file with documentation like: /** ts: const s= '';
java: String s = new String("abed");
def dump(
obj: Any,
fp: SupportsWrite[str],
*,
skipkeys: bool = False,
ensure_ascii: bool = True,
check_circular: bool = True,
allow_nan: bool = True,
cls: type[JSONEncoder] | None = None,
indent: None | int | str = None,
separators: tuple[str, str] | None = None,
default: Callable[[Any], Any] | None = None,
sort_keys: bool = False,
**kwds: Any,
) -> None: ... **/ function foo() { foo(); and hover the foo: |
f131dff
to
eee023f
Compare
src/main/java/com/redhat/devtools/lsp4ij/features/documentation/LSPDocumentationHelper.java
Outdated
Show resolved
Hide resolved
eee023f
to
16ce947
Compare
} else if (content.isRight()) { | ||
MarkedString markedString = content.getRight(); | ||
if (!isValidContent(markedString)) { | ||
return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return should be @NotNull
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should, because it is filtered after.
16ce947
to
3fdb264
Compare
src/main/java/com/redhat/devtools/lsp4ij/features/documentation/LSPDocumentationHelper.java
Outdated
Show resolved
Hide resolved
e04f184
to
5c4fef8
Compare
Fixes redhat-developer#297 Signed-off-by: azerr <azerr@redhat.com>
5c4fef8
to
9a8da99
Compare
Thanks @angelozerr! |
Support syntax coloration for code block in LSP hover
Fixes #297
Lua
(the coloration comes from a custom lexer):Do you think it is correct CppCXY?
I copied / pasted some piece of code from QuickDocHighlightingHelper and it seems it is working with Language. For TextMate Language is not enough (because Language is equals to "textmate). I have implemented TextMate support too.
TypeScript
TextMate:Rust
TextMate: