Repository: sublimelsp/LSP

Issue:
LSP sometimes confuses autocompletion even in unrelated syntaxes
**Describe the bug**

Every here and then I find me surprised by ST's mini_auto_completion to commit different content than it previews. See how it shows `true` and commits `terminator` in the following code snippet.

![Animation](https://user-images.githubusercontent.com/16542113/112184936-ffd4f580-8bff-11eb-80d6-c3cb7fac9242.png)

Why do I report it here? Well, in fact disabling the LSP package fixes the issue.

The strange thing is, the syntax in use not being supported by any language-server on earth. So there's none active.

The question is, how can or does LSP interact with ST's auto-completion in syntaxes which do not use LSP?

The only thing I saw on console was the `commit_completion` command being executed when hitting tab.

**Expected behavior**

The previewe'd completion should be committed.

This is what it looks like with LSP disabled:

![Animation](https://user-images.githubusercontent.com/16542113/112187961-dc5f7a00-8c02-11eb-846b-dbd6fc47ff6d.png)


**Screenshots**
If applicable, add screenshots to help explain your problem.

**Environment (please complete the following information):**
- OS: Windows 10 x64 2004
- Sublime Text version: 4099
- LSP version: ST4000-exploration (commit 1bc9cff7f4385637cafdb0ae43ec843367cee19f)
- Language servers used: all disabled for debugging



Discussion:
If there's no langserver attached to the view then this is essentially what happens:

```python
from typing import Any, List
import sublime_plugin
import sublime


class Foo(sublime_plugin.ViewEventListener):
    def on_query_completions(self, prefix: str, locations: List[int]) -> Any:
        promise = sublime.CompletionList()
        sublime.set_timeout_async(
            lambda: sublime.set_timeout(
                lambda: promise.set_completions([], 0)
            )
        )
        return promise
```

https://github.com/sublimelsp/LSP/blob/1bc9cff7f4385637cafdb0ae43ec843367cee19f/plugin/documents.py#L388-L396

https://github.com/sublimelsp/LSP/blob/1bc9cff7f4385637cafdb0ae43ec843367cee19f/plugin/documents.py#L641-L645
Thanks to for pointing to the entry for debugging, but your minimal example is not very correct. The promise is reloved by `promise.set_completions([], INHIBIT_WORD_COMPLETIONS)`, which seems to be the root cause here. replacing `flags` by `0` in line 392 solves the issue.
`self.sessions` in line 642 returns a generator. So the `if` statement in `643` is never true.

Resolving patch:
diff --git a/plugin/documents.py b/plugin/documents.py
--- a/plugin/documents.py
+++ b/plugin/documents.py
@@ -639,7 +639,7 @@ def render_highlights_on_main_thread() -> None:
     # --- textDocument/complete ----------------------------------------------------------------------------------------
 
     def _on_query_completions_async(self, resolve_completion_list: ResolveCompletionsFn, location: int) -> None:
-        sessions = self.sessions('completionProvider')
+        sessions = list(self.sessions('completionProvider'))
         if not sessions:
             resolve_completion_list([], 0)
             return


Test patch: