Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

signature_help_generic_support #115

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions nimlsp.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ bin = @["nimlsp"]

requires "nim >= 1.0.0"
requires "jsonschema >= 0.2.1"
requires "regex"

# nimble test does not work for me out of the box
#task test, "Runs the test suite":
Expand Down
42 changes: 27 additions & 15 deletions src/nimlsp.nim
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import sets
import uri
import osproc
import asyncfile, asyncdispatch
import regex

const
version = block:
Expand Down Expand Up @@ -451,21 +452,32 @@ proc main(){.async.} =
openFiles[fileuri].fingerTable[rawLine].utf16to8(rawChar)
let suggestions = getNimsuggest(fileuri).con(uriToPath(fileuri), dirtyfile = filestash, rawLine + 1, rawChar)
var signatures = newSeq[SignatureInformation]()
for suggestion in suggestions:
var label = suggestion.qualifiedPath.join(".")
if suggestion.forth != "":
label &= ": " & suggestion.forth
signatures.add create(SignatureInformation,
label = label,
documentation = some(suggestion.nimDocstring),
parameters = none(seq[ParameterInformation])
)

await message.respond create(SignatureHelp,
signatures = signatures,
activeSignature = some(0),
activeParameter = some(0)
).JsonNode
for sig in suggestions:
let label = sig.qualifiedPath[^1]
let documentation = sig.doc
var parameters = newSeq[ParameterInformation]()
if sig.forth.len > 0:
var genericsCleanType = ""
var insideGeneric = 0
var i = 0
let forthLen = sig.forth.len
while i < forthLen:
if sig.forth[i] == '[':
inc insideGeneric
if insideGeneric <= 0:
genericsCleanType.add sig.forth[i]
if sig.forth[i] == ']':
dec insideGeneric
inc i
var m: RegexMatch
var signatureCutDown = genericsCleanType.find(re"(proc|macro|template|iterator|func) \((.+: .+)*\)",m)
if (signatureCutDown):
debugLog "signatureCutDown:", $m.group(1,genericsCleanType)
var params = m.group(1, genericsCleanType)[0].split(", ")
for label in params:
parameters.add create(ParameterInformation,label, none(string))
signatures.add create(SignatureInformation,label,some(documentation),some(parameters))
await message.respond create(SignatureHelp,signatures,none(int),none(int)).JsonNode # ,activeSignature,activeParameter
else:
debugLog "Unknown request"
await message.error(errorCode = -32600, message = "Unknown request: " & frame, data = newJObject())
Expand Down