From 4d46cf9e1bff03af8260da84158bc78efaeaeda3 Mon Sep 17 00:00:00 2001 From: yblanken Date: Tue, 22 Oct 2024 11:01:53 +0200 Subject: [PATCH] [#31] Hover results in continuous server communication loop --- src/index.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index fc82d28..aba3286 100644 --- a/src/index.ts +++ b/src/index.ts @@ -312,13 +312,14 @@ class LanguageServerPlugin implements PluginValue { ): Promise { if (!this.client.ready || !this.client.capabilities!.hoverProvider) return null; - this.sendChange({ documentText: view.state.doc.toString() }); const result = await this.client.textDocumentHover({ textDocument: { uri: this.documentUri }, position: { line, character }, }); if (!result) return null; const { contents, range } = result; + let formattedContents = formatContents(contents) + if (formattedContents.length == 0) return null; let pos = posToOffset(view.state.doc, { line, character })!; let end: number; if (range) { @@ -328,8 +329,8 @@ class LanguageServerPlugin implements PluginValue { if (pos === null) return null; const dom = document.createElement('div'); dom.classList.add('documentation'); - if (this.allowHTMLContent) dom.innerHTML = formatContents(contents); - else dom.textContent = formatContents(contents); + if (this.allowHTMLContent) dom.innerHTML = formattedContents; + else dom.textContent = formattedContents; return { pos, end, create: (view) => ({ dom }), above: true }; }