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

Adds a restart nimsuggest button per nimsuggest instance #99

Merged
merged 2 commits into from
Sep 11, 2024
Merged
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
43 changes: 37 additions & 6 deletions src/nimLsp.nim
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ proc handleLspVersion(nimlangserver: cstring, latestVersion: LSPVersion, state:
else:
state.lspVersion = ver.get()
notifyOrUpdateOnTheLSPVersion(ver.get, latestVersion, state)
console.log("Blab la")
if state.onLspVersionLoaded != nil:
discard state.onLspVersionLoaded()
else:
Expand Down Expand Up @@ -438,6 +437,18 @@ proc newLspItem*(label: cstring, description: cstring = "", tooltip: cstring = "
statusItem.notification = notification
cast[LspItem](statusItem)

proc onLspSuggest*(action, projectFile: cstring) {.async.} =
#Handles extension/suggest calls
#(right now only from the restart button in the suggest instance from the nim panel)
case action:
of "restart":
let suggestParams = JsObject()
suggestParams.action = action
suggestParams.projectFile = projectFile
let response = await fetchLsp[JsObject, JsObject](ext, "extension/suggest", suggestParams)
console.log(response)
else:
console.error("Action not supported")

proc onShowNotification*(args: JsObject) =
let message = args.to(cstring)
Expand Down Expand Up @@ -528,20 +539,40 @@ proc getChildrenImpl(self: NimLangServerStatusProvider, element: LspItem = nil):
] & self.status.get.openFiles.mapIt(newLspItem("OpenFile:", it))
elif element.label == "NimSuggest Instances":
# Children of Nim Suggest Instances
return self.status.get.nimsuggestInstances.mapIt(newLspItem(it.projectFile, "", "", TreeItemCollapsibleState_Collapsed, some it))
var instances = self.status.get.nimsuggestInstances.mapIt(newLspItem(it.projectFile, "", "", TreeItemCollapsibleState_Collapsed, some it))
if excRestartSuggest in ext.lspExtensionCapabilities:
let restartItem = vscode.newTreeItem("Restart All", TreeItemCollapsibleState_None)
restartItem.command = newJsObject()
restartItem.command.command = "nim.onLspSuggest".cstring
restartItem.command.title = "Restart All Nimsuggests".cstring
#Notice the actions here corresponds to SuggestAction in the lsp rathen than capabilities
restartItem.command.arguments = @[cstring("restart"), "*".cstring] #Restart all
restartItem.iconPath = vscode.themeIcon("debug-restart", vscode.themeColor("notificationsWarningIcon.foreground"))
instances.add(cast[LspItem](restartItem))
return instances
elif not element.instance.isNone:
# Children of a specific instance
let instance = element.instance.get
return @[
var nsItems = @[
newLspItem("Project File", instance.projectFile),
newLspItem("Capabilities", instance.capabilities.join(", ").cstring),
newLspItem("Version", instance.version),
newLspItem("Path", instance.path),
newLspItem("Port", cstring($instance.port)),
newLspItem("Open Files", instance.openFiles.join(", ").cstring),
newLspItem("Unknown Files", instance.unknownFiles.join(", ").cstring)
]

]
if excRestartSuggest in ext.lspExtensionCapabilities:
let restartItem = vscode.newTreeItem("Restart", TreeItemCollapsibleState_None)
restartItem.command = newJsObject()
restartItem.command.command = "nim.onLspSuggest".cstring
restartItem.command.title = "Restart Nimsuggest".cstring
#Notice the actions here corresponds to SuggestAction in the lsp rathen than capabilities
restartItem.command.arguments = @[cstring("restart"), instance.projectFile]

restartItem.iconPath = vscode.themeIcon("debug-restart", vscode.themeColor("notificationsWarningIcon.foreground"))
nsItems.insert(cast[LspItem](restartItem), 0)
return nsItems
return @[]

proc getTreeItemImpl(self: NimLangServerStatusProvider, element: TreeItem): Future[TreeItem] {.async.}=
Expand Down Expand Up @@ -570,4 +601,4 @@ proc refreshNotifications*(self: NimLangServerStatusProvider, notifications: seq
self.notifications = notifications
self.emitter.fire(nil)

export stopLanguageServer
export stopLanguageServer
1 change: 1 addition & 0 deletions src/nimvscode.nim
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ proc activate*(ctx: VscodeExtensionContext): void {.async.} =
vscode.commands.registerCommand("nim.showNotification", onShowNotification)
vscode.commands.registerCommand("nim.onDeleteNotification", onDeleteNotification)
vscode.commands.registerCommand("nim.onClearAllNotifications", onClearAllNotifications)
vscode.commands.registerCommand("nim.onLspSuggest", onLspSuggest)



Expand Down
2 changes: 1 addition & 1 deletion src/spec.nim
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type
LSPVersion* = tuple[major: int, minor: int, patch: int]

LspExtensionCapability* = enum #List of extensions the lsp server support.
excNone
excNone = "None", excRestartSuggest = "RestartSuggest"

ExtensionState* = ref object
ctx*: VscodeExtensionContext
Expand Down