Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
Graveflo committed Jul 7, 2024
1 parent fb725fe commit 2e7f131
Showing 1 changed file with 28 additions and 19 deletions.
47 changes: 28 additions & 19 deletions nimlangserver.nim
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import macros, strformat, faststreams/async_backend,
import std/[macros, strformat, os, sugar, sequtils, hashes, osproc, re, uri, tables,
strutils, sets, strscans, json, parseutils]
import faststreams/async_backend,
faststreams/asynctools_adapters, faststreams/inputs, faststreams/outputs,
json_rpc/streamconnection, json_rpc/server, os, sugar, sequtils, hashes, osproc,
suggestapi, protocol/enums, protocol/types, with, tables, strutils, sets,
./utils, ./pipes, chronicles, std/re, uri, "$nim/compiler/pathutils",
asyncprocmonitor, std/strscans, json_serialization, serialization/formats,
std/json, std/parseutils
json_rpc/streamconnection, json_rpc/server,
suggestapi, protocol/enums, protocol/types, with,
./utils, ./pipes, chronicles, "$nim/compiler/pathutils",
asyncprocmonitor, json_serialization, serialization/formats

when defined(posix):
import posix
Expand Down Expand Up @@ -220,6 +221,11 @@ proc getProjectFileAutoGuess(ls: LanguageServer, fileUri: string): string =
path = dir

proc parseWorkspaceConfiguration(conf: JsonNode): NlsConfig =
try:
if conf.kind == JObject and conf["settings"].kind == JObject:
return conf["settings"]["nim"].to(NlsConfig)
except CatchableError:
discard
try:
let nlsConfig: seq[NlsConfig] = (%conf).to(seq[NlsConfig])
result = if nlsConfig.len > 0 and nlsConfig[0] != nil: nlsConfig[0] else: NlsConfig()
Expand Down Expand Up @@ -901,18 +907,21 @@ proc scheduleFileCheck(ls: LanguageServer, uri: string) {.gcsafe.} =
proc didChange(ls: LanguageServer, params: DidChangeTextDocumentParams):
Future[void] {.async, gcsafe.} =
with params:
let
uri = textDocument.uri
file = open(ls.uriStorageLocation(uri), fmWrite)

ls.openFiles[uri].fingerTable = @[]
ls.openFiles[uri].changed = true
for line in contentChanges[0].text.splitLines:
ls.openFiles[uri].fingerTable.add line.createUTFMapping()
file.writeLine line
file.close()

ls.scheduleFileCheck(uri)
let
uri = textDocument.uri
file = open(ls.uriStorageLocation(uri), fmWrite)

ls.openFiles[uri].fingerTable = @[]
ls.openFiles[uri].changed = true
if contentChanges.len <= 0:
file.close()
return
for line in contentChanges[0].text.splitLines:
ls.openFiles[uri].fingerTable.add line.createUTFMapping()
file.writeLine line
file.close()

ls.scheduleFileCheck(uri)

proc didSave(ls: LanguageServer, params: DidSaveTextDocumentParams):
Future[void] {.async, gcsafe.} =
Expand Down Expand Up @@ -1029,7 +1038,7 @@ proc fixIdentation(s: string, indent: int): string =
.join("\n")

proc expand(ls: LanguageServer, params: ExpandTextDocumentPositionParams):
Future[ExpandResult] {.async} =
Future[ExpandResult] {.async.} =
with (params, params.position, params.textDocument):
let
lvl = level.get(-1)
Expand Down

0 comments on commit 2e7f131

Please sign in to comment.