Skip to content

Commit

Permalink
Fixed bugs with and improved completions/lsp handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Nimaoth committed May 10, 2024
1 parent 12056a8 commit ca7ea4d
Show file tree
Hide file tree
Showing 7 changed files with 273 additions and 117 deletions.
3 changes: 3 additions & 0 deletions src/misc/custom_unicode.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# abc ä cde .
import std/unicode
from std/strutils import Digits

export Rune
export runeLenAt, runeAt, strip, validateUtf8, graphemeLen, lastRune, `$`, runes, `==`, isWhiteSpace, isAlpha
Expand All @@ -8,6 +9,8 @@ type
RuneIndex* = distinct int
RuneCount* = distinct int

func isDigit*(r: Rune): bool = r.int <= char.high.int and r.char in Digits

template toOa(s: string): auto = s.toOpenArray(0, s.high)

func `-`*(a, b: RuneIndex): RuneCount = RuneCount(a.int - b.int)
Expand Down
10 changes: 7 additions & 3 deletions src/text/completion_provider_lsp.nim
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,16 @@ proc getLspCompletionsAsync(self: CompletionProviderLsp) {.async.} =

# debugf"[getLspCompletionsAsync] start"
let completions = await self.languageServer.getCompletions(self.document.languageId, self.document.fullPath, location)
if completions.isSuccess and completions.result.items.len > 0:
# debugf"[getLspCompletionsAsync] at {location} got {completions.result.items.len} completions"
if completions.isSuccess:
log lvlInfo, fmt"[getLspCompletionsAsync] at {location}: got {completions.result.items.len} completions"
self.unfilteredCompletions = completions.result.items
self.refilterCompletions()
elif completions.isCanceled:
discard
else:
log lvlError, fmt"Failed to get completions"
log lvlError, fmt"Failed to get completions: {completions.error}"
self.unfilteredCompletions = @[]
self.refilterCompletions()

proc handleTextInserted(self: CompletionProviderLsp, document: TextDocument, location: Selection, text: string) =
self.location = location.getChangedSelection(text).last
Expand Down
5 changes: 3 additions & 2 deletions src/text/language/language_server_base.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import std/[options, tables, json]
import misc/[custom_async, custom_logger, event, custom_unicode]
import scripting_api except DocumentEditor, TextDocumentEditor, AstDocumentEditor
import workspaces/workspace
import document

from lsp_types as lsp_types import CompletionItem

Expand Down Expand Up @@ -89,8 +90,8 @@ var getOrCreateLanguageServer*: proc(languageId: string, filename: string, works
method start*(self: LanguageServer): Future[void] {.base.} = discard
method stop*(self: LanguageServer) {.base.} = discard
method deinit*(self: LanguageServer) {.base.} = discard
method connect*(self: LanguageServer) {.base.} = discard
method disconnect*(self: LanguageServer) {.base.} = discard
method connect*(self: LanguageServer, document: Document) {.base.} = discard
method disconnect*(self: LanguageServer, document: Document) {.base.} = discard
method getDefinition*(self: LanguageServer, filename: string, location: Cursor): Future[seq[Definition]] {.base.} = discard
method getDeclaration*(self: LanguageServer, filename: string, location: Cursor): Future[seq[Definition]] {.base.} = discard
method getImplementation*(self: LanguageServer, filename: string, location: Cursor): Future[seq[Definition]] {.base.} = discard
Expand Down
Loading

0 comments on commit ca7ea4d

Please sign in to comment.