Repository: sublimelsp/LSP

Issue:
Remove the LspTrimCompletionCommand
Remove the LspTrimCompletionCommand as it is no longer used.
Forced-break in hover popup can break syntax highlighting
Using: OSX / typescript-language-server

Line-break, that LSP forces in the popup, can cause syntax highlighting to break. For example, if breaking a plain string in JS syntax.

<img width="512" alt="line-break" src="https://user-images.githubusercontent.com/153197/72525594-cfa7ff00-3864-11ea-9e8a-c183e07995a1.png">

Notice that in the screenshot the whole string should have a yellow color. Syntax highlighting breaks because line break within a string is not a valid syntax.


Discussion:

related https://github.com/sublimelsp/LSP/issues/486
We might be able to fix this by writing some frontmatter: https://facelessuser.github.io/sublime-markdown-popups/api/#enable-code-wrapping
With `allow_code_wrap: false` option? I just feel like it would do bad things to some monospace code blocks. But maybe not...
No, we wrap manually now. If we set `allow_code_wrap: true` in the frontmatter, it might be possible to remove the manual wrapping.

https://github.com/sublimelsp/LSP/blob/c50a1547c7510c3fd9a9ccf45f8acb6a06ffbbbe/plugin/hover.py#L194-L195

I'm not sure what mdpopups can do that we're not already doing, but it might go about doing things a bit smarter with code blocks.
Sorry, I meant `allow_code_wrap: true`.
I did a quick hacky test. In that specific case, it did well but then it decided not to break (which is fine as it's not wider than popup width):
![Screenshot 2020-03-23 at 20 49 45](https://user-images.githubusercontent.com/153197/77357236-1bd15d00-6d48-11ea-93dc-df6d69ca0f1d.png)

So it seems like it actually never breaks if there is no break opportunity (spaces for example).
Compared also some other case that has spaces but I guess that case is special in LSP where it doesn't even try to break:

Without `frontmatter`:
![Screenshot 2020-03-23 at 20 54 44](https://user-images.githubusercontent.com/153197/77357566-a9ad4800-6d48-11ea-81fa-0cb58a310bcd.png)

With `frontmatter`:
![Screenshot 2020-03-23 at 20 53 59](https://user-images.githubusercontent.com/153197/77357585-af0a9280-6d48-11ea-8f07-98dbf530385a.png)
And another case where LSP actually does break the line:

Without `frontmatter`:
![Screenshot 2020-03-23 at 20 56 48](https://user-images.githubusercontent.com/153197/77357789-027ce080-6d49-11ea-9bd6-ed083d11d0d9.png)

With `frontmatter`:
![Screenshot 2020-03-23 at 20 58 06](https://user-images.githubusercontent.com/153197/77357804-090b5800-6d49-11ea-8916-2c9e1d772c82.png)

I think I like first and the last case better with `frontmatter` at least (maybe even all of them).
Sounds like you have a pull request brewing :)

Resolving patch:
diff --git a/boot.py b/boot.py
--- a/boot.py
+++ b/boot.py
@@ -4,7 +4,6 @@
 from .plugin.color import LspColorListener
 from .plugin.completion import CompletionHandler
 from .plugin.completion import LspSelectCompletionItemCommand
-from .plugin.completion import LspTrimCompletionCommand
 from .plugin.configuration import LspDisableLanguageServerGloballyCommand
 from .plugin.configuration import LspDisableLanguageServerInProjectCommand
 from .plugin.configuration import LspEnableLanguageServerGloballyCommand
diff --git a/plugin/completion.py b/plugin/completion.py
--- a/plugin/completion.py
+++ b/plugin/completion.py
@@ -10,7 +10,7 @@
 from .core.sessions import Session
 from .core.edit import parse_text_edit
 from .core.views import range_to_region
-from .core.typing import Any, List, Dict, Tuple, Optional, Union
+from .core.typing import Any, List, Dict, Optional, Union
 from .core.views import text_document_position_params
 from .core.restore_lines import RestoreLines
 
@@ -94,14 +94,6 @@ def apply_additional_edits(self, additional_edits: List[dict]) -> None:
         sublime.status_message('Applied additional edits for completion')
 
 
-class LspTrimCompletionCommand(sublime_plugin.TextCommand):
-    def run(self, edit: sublime.Edit, range: Optional[Tuple[int, int]] = None) -> None:
-        if range:
-            start, end = range
-            region = sublime.Region(start, end)
-            self.view.erase(edit, region)
-
-
 class CompletionHandler(LSPViewEventListener):
     def __init__(self, view: sublime.View) -> None:
         super().__init__(view)


Test patch: