Skip to content

Commit

Permalink
Allow extra fields, but don't interfere with message identification
Browse files Browse the repository at this point in the history
  • Loading branch information
PMunch committed Mar 8, 2021
1 parent 02777ca commit c0e05cd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion nimlsp.nimble
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Package

version = "0.3.0"
version = "0.3.1"
author = "PMunch"
description = "Nim Language Server Protocol - nimlsp implements the Language Server Protocol"
license = "MIT"
Expand Down
12 changes: 6 additions & 6 deletions src/nimlsp.nim
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,18 @@ var
openFiles = initTable[string, tuple[projectFile: string, fingerTable: seq[seq[tuple[u16pos, offset: int]]]]]()

template whenValid(data, kind, body) =
if data.isValid(kind):
if data.isValid(kind, allowExtra = true):
var data = kind(data)
body
else:
debugEcho("Unable to parse data as " & $kind)

template whenValid(data, kind, body, elseblock) =
if data.isValid(kind, allowExtra = true):
template whenValidStrict(data, kind, body) =
if data.isValid(kind):
var data = kind(data)
body
else:
elseblock
debugEcho("Unable to parse data as " & $kind)

proc getFileStash(fileuri: string): string =
return storage / (hash(fileuri).toHex & ".nim" )
Expand Down Expand Up @@ -214,7 +214,7 @@ while true:
let frame = ins.readFrame
debugEcho "Got frame:\n" & frame
let message = frame.parseJson
whenValid(message, RequestMessage):
whenValidStrict(message, RequestMessage):
debugEcho "Got valid Request message of type " & message["method"].getStr
if not initialized and message["method"].getStr != "initialize":
message.error(-32002, "Unable to accept requests before being initialized", newJNull())
Expand Down Expand Up @@ -456,7 +456,7 @@ while true:
else:
debugEcho "Unknown request"
continue
whenValid(message, NotificationMessage):
whenValidStrict(message, NotificationMessage):
debugEcho "Got valid Notification message of type " & message["method"].getStr
if not initialized and message["method"].getStr != "exit":
continue
Expand Down

0 comments on commit c0e05cd

Please sign in to comment.