17
17
chronicles,
18
18
asyncprocmonitor,
19
19
json_serialization,
20
- std/ [strscans, times, json, parseutils],
20
+ std/ [strscans, times, json, parseutils, strutils ],
21
21
ls,
22
22
stew/ [byteutils]
23
23
@@ -753,21 +753,23 @@ proc exit*(
753
753
result = newJNull()
754
754
await p.onExit()
755
755
756
- proc tasks*(
757
- ls: LanguageServer, conf: JsonNode
758
- ): Future[seq [NimbleTask]] {.async, gcsafe.} =
759
- let rootPath: string = ls.initializeParams.getRootPath
760
-
761
- debug "Received tasks ", rootPath = rootPath
762
- delEnv "NIMBLE_DIR"
763
- let process = await startProcess(
756
+ proc startNimbleProcess(ls: LanguageServer, args: seq [string ]): Future[AsyncProcessRef] {.async.} =
757
+ await startProcess(
764
758
"nimble",
765
- arguments = @["tasks " ] ,
759
+ arguments = args ,
766
760
options = {UsePath},
767
- workingDir = rootPath ,
761
+ workingDir = ls.initializeParams.getRootPath ,
768
762
stdoutHandle = AsyncProcess.Pipe,
769
763
stderrHandle = AsyncProcess.Pipe,
770
764
)
765
+
766
+ proc tasks*(
767
+ ls: LanguageServer, conf: JsonNode
768
+ ): Future[seq [NimbleTask]] {.async.} =
769
+ let rootPath: string = ls.initializeParams.getRootPath
770
+ debug "Received tasks ", rootPath = rootPath
771
+ delEnv "NIMBLE_DIR"
772
+ let process = await ls.startNimbleProcess(@["tasks " ])
771
773
let res =
772
774
await process.waitForExit(InfiniteDuration) # TODO handle error (i.e. no nimble file)
773
775
let output = await process.stdoutStream.readLine()
@@ -778,6 +780,23 @@ proc tasks*(
778
780
if name.isWord:
779
781
result .add NimbleTask(name: name.strip(), description: desc.strip())
780
782
783
+ proc runTask* (
784
+ ls: LanguageServer, params: RunTaskParams
785
+ ): Future[RunTaskResult] {.async.} =
786
+ let process = await ls.startNimbleProcess(params.command)
787
+ let res = await process.waitForExit(InfiniteDuration)
788
+ result .command = params.command
789
+ let prefix = " \" "
790
+ while not process.stdoutStream.atEof():
791
+ var lines = process.stdoutStream.readLine().await.splitLines
792
+ for line in lines.mitems:
793
+ if line.startsWith(prefix):
794
+ line = line.unescape(prefix)
795
+ if line != " " :
796
+ result .output.add line
797
+
798
+ debug " Ran nimble cmd/task" , command = $ params.command, output = $ result .output
799
+
781
800
# Notifications
782
801
proc initialized* (ls: LanguageServer, _: JsonNode): Future[void ] {.async.} =
783
802
debug " Client initialized."
0 commit comments