forked from nim-lang/langserver
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds
extension/tasks
which returns all nimble tasks for the current…
… project
- Loading branch information
Showing
9 changed files
with
127 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# This is just an example to get you started. A typical hybrid package | ||
# uses this file as the main entry point of the application. | ||
|
||
import tasks/submodule | ||
|
||
when isMainModule: | ||
echo(getWelcomeMessage()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# This is just an example to get you started. Users of your hybrid library will | ||
# import this file by writing ``import taskspkg/submodule``. Feel free to rename or | ||
# remove this file altogether. You may create additional modules alongside | ||
# this file as required. | ||
|
||
proc getWelcomeMessage*(): string = "Hello, World!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Package | ||
|
||
version = "0.1.0" | ||
author = "jmgomez" | ||
description = "A new awesome nimble package" | ||
license = "MIT" | ||
srcDir = "src" | ||
installExt = @["nim"] | ||
bin = @["tasks"] | ||
|
||
|
||
# Dependencies | ||
|
||
requires "nim >= 2.1.99" | ||
|
||
task helloWorld, "hello world": | ||
echo "helo world" | ||
|
||
task anotherTask, "Another task": | ||
echo "another task" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
switch("path", "$projectDir/../src") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# This is just an example to get you started. You may wish to put all of your | ||
# tests into a single file, or separate them into multiple `test1`, `test2` | ||
# etc. files (better names are recommended, just make sure the name starts with | ||
# the letter 't'). | ||
# | ||
# To run these tests, simply execute `nimble test`. | ||
|
||
import unittest | ||
|
||
import tasks/submodule | ||
test "correct welcome": | ||
check getWelcomeMessage() == "Hello, World!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,80 @@ | ||
import ../[ | ||
nimlangserver, ls, lstransports, utils | ||
] | ||
import ../[nimlangserver, ls, lstransports, utils] | ||
import ../protocol/[enums, types] | ||
import std/[options, unittest, json, os, jsonutils, sequtils, strutils, sugar, strformat] | ||
import | ||
std/[options, unittest, json, os, jsonutils, sequtils, strutils, sugar, strformat] | ||
import json_rpc/[rpcclient] | ||
import chronicles | ||
import lspsocketclient | ||
import chronos/asyncproc | ||
|
||
|
||
suite "Nimlangserver": | ||
let cmdParams = CommandLineParams(transport: some socket, port: getNextFreePort()) | ||
let ls = main(cmdParams) #we could accesss to the ls here to test against its state | ||
let client = newLspSocketClient() | ||
waitFor client.connect("localhost", cmdParams.port) | ||
client.registerNotification( | ||
"window/showMessage", | ||
"window/workDoneProgress/create", | ||
"workspace/configuration", | ||
"extension/statusUpdate", | ||
"textDocument/publishDiagnostics", | ||
"$/progress" | ||
) | ||
|
||
"window/showMessage", "window/workDoneProgress/create", "workspace/configuration", | ||
"extension/statusUpdate", "textDocument/publishDiagnostics", "$/progress", | ||
) | ||
|
||
test "calling extension/suggest with restart in the project uri should restart nimsuggest": | ||
let initParams = InitializeParams %* { | ||
let initParams = | ||
InitializeParams %* { | ||
"processId": %getCurrentProcessId(), | ||
"rootUri": fixtureUri("projects/hw/"), | ||
"capabilities": { | ||
"window": { | ||
"workDoneProgress": true | ||
}, | ||
"workspace": {"configuration": true} | ||
} | ||
} | ||
"capabilities": | ||
{"window": {"workDoneProgress": true}, "workspace": {"configuration": true}}, | ||
} | ||
let initializeResult = waitFor client.initialize(initParams) | ||
|
||
check initializeResult.capabilities.textDocumentSync.isSome | ||
|
||
let helloWorldUri = fixtureUri("projects/hw/hw.nim") | ||
let helloWorldFile = "projects/hw/hw.nim" | ||
let helloWorldFile = "projects/hw/hw.nim" | ||
let hwAbsFile = uriToPath(helloWorldFile.fixtureUri()) | ||
client.notify("textDocument/didOpen", %createDidOpenParams(helloWorldFile)) | ||
|
||
let progressParam = %ProgressParams(token: fmt "Creating nimsuggest for {hwAbsFile}") | ||
check waitFor client.waitForNotification("$/progress", (json: JsonNode) => progressParam["token"] == json["token"]) | ||
check waitFor client.waitForNotification("$/progress", (json: JsonNode) => json["value"]["kind"].getStr == "begin") | ||
check waitFor client.waitForNotification("$/progress", (json: JsonNode) => json["value"]["kind"].getStr == "end") | ||
let progressParam = | ||
%ProgressParams(token: fmt "Creating nimsuggest for {hwAbsFile}") | ||
check waitFor client.waitForNotification( | ||
"$/progress", (json: JsonNode) => progressParam["token"] == json["token"] | ||
) | ||
check waitFor client.waitForNotification( | ||
"$/progress", (json: JsonNode) => json["value"]["kind"].getStr == "begin" | ||
) | ||
check waitFor client.waitForNotification( | ||
"$/progress", (json: JsonNode) => json["value"]["kind"].getStr == "end" | ||
) | ||
|
||
client.notify( | ||
"textDocument/didOpen", %createDidOpenParams("projects/hw/useRoot.nim") | ||
) | ||
|
||
client.notify("textDocument/didOpen", | ||
%createDidOpenParams("projects/hw/useRoot.nim")) | ||
|
||
let prevSuggestPid = ls.projectFiles[hwAbsFile].process.pid | ||
let suggestParams = SuggestParams(action: saRestart, projectFile: hwAbsFile) | ||
let suggestRes = client.call("extension/suggest", %suggestParams).waitFor | ||
let suggestPid = ls.projectFiles[hwAbsFile].process.pid | ||
|
||
check prevSuggestPid != suggestPid | ||
|
||
|
||
test "calling extension/tasks should return all existing tasks": | ||
let initParams = | ||
InitializeParams %* { | ||
"processId": %getCurrentProcessId(), | ||
"rootUri": fixtureUri("projects/tasks/"), | ||
"capabilities": | ||
{"window": {"workDoneProgress": true}, "workspace": {"configuration": true}}, | ||
} | ||
let initializeResult = waitFor client.initialize(initParams) | ||
|
||
let tasksFile = "projects/tasks/src/tasks.nim" | ||
let taskAbsFile = uriToPath(tasksFile.fixtureUri()) | ||
client.notify("textDocument/didOpen", %createDidOpenParams(tasksFile)) | ||
|
||
let tasks = client.call("extension/tasks", jsonutils.toJson(())).waitFor().jsonTo( | ||
seq[NimbleTask] | ||
) | ||
|
||
check tasks.len == 2 | ||
check tasks[0].name == "helloWorld" | ||
check tasks[0].description == "hello world" |