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

+ if nimlangserver is not found, ask the user before attempting to 'nimble install' it. #46

Merged
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
33 changes: 25 additions & 8 deletions src/nimLsp.nim
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,31 @@ proc startLanguageServer(tryInstall: bool, state: ExtensionState) {.async.} =
if tryInstall and not state.installPerformed:
let command = getNimbleExecPath() & " install nimlangserver --accept"
vscode.window.showInformationMessage(
cstring(fmt "Unable to find nimlangserver, trying to install it via '{command}'"))
state.installPerformed = true
discard cp.exec(
command,
ExecOptions{},
proc(err: ExecError, stdout: cstring, stderr: cstring): void {.async.} =
console.log("Nimble install finished, validating by checking if nimlangserver is present.")
await startLanguageServer(false, state))
cstring(fmt "Unable to find nimlangserver. Do you want me to attempt to install it via '{command}'?"),
VscodeMessageOptions(
detail: cstring(""),
modal: false
),
VscodeMessageItem(title: cstring("Yes"), isCloseAffordance: false),
VscodeMessageItem(title: cstring("No"), isCloseAffordance: true))
.then(
onfulfilled = proc(value: JsRoot): JsRoot =
if value.JsObject.to(VscodeMessageItem).title == "Yes":
if not state.installPerformed:
state.installPerformed = true
vscode.window.showInformationMessage(
cstring(fmt "Trying to install nimlangserver via '{command}'"))
discard cp.exec(
command,
ExecOptions{},
proc(err: ExecError, stdout: cstring, stderr: cstring): void {.async.} =
console.log("Nimble install finished, validating by checking if nimlangserver is present.")
await startLanguageServer(false, state))
value
,
onrejected = proc(reason: JsRoot): JsRoot =
reason
)
else:
let cantInstallInfoMesssage: cstring = "Unable to find/install `nimlangserver`. You can attempt to install it by running `nimble install nimlangserver` or downloading the binaries from https://github.com/nim-lang/langserver/releases."
vscode.window.showInformationMessage(cantInstallInfoMesssage)
Expand Down
16 changes: 16 additions & 0 deletions src/platform/vscodeApi.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ export jsffi, jsPromise, jsNode
## TODO: Move from JsObject to JsRoot for more explict errors

type
VscodeThenable* = ref VscodeThenableObj
VscodeThenableObj {.importc.} = object of JsRoot

VscodeMarkdownString* = ref VscodeMarkdownStringObj
VscodeMarkdownStringObj {.importc.} = object of JsObject
value*: cstring
Expand Down Expand Up @@ -184,6 +187,8 @@ type
VscodeMarkedString* = ref VscodeMarkedStringObj
VscodeMarkedStringObj {.importc.} = object of JsObject

proc then*(self: VscodeThenable, onfulfilled: proc(value: JsRoot): JsRoot, onrejected: proc(reason: JsRoot): JsRoot): VscodeThenable {.importcpp, discardable.}

proc cstringToMarkedString(s: cstring): VscodeMarkedString {.importcpp: "#".}
converter toVscodeMarkedString*(s: cstring): VscodeMarkedString = s.cstringToMarkedString()
proc hoverLabelToMarkedString(s: VscodeHoverLabel): VscodeMarkedString {.
Expand Down Expand Up @@ -492,6 +497,16 @@ type
activeTextEditor*: VscodeTextEditor
visibleTextEditors*: Array[VscodeTextEditor]

VscodeMessageItem* = ref VscodeMessageItemObj
VscodeMessageItemObj {.importc.} = object of JsRoot
isCloseAffordance*: bool
title*: cstring

VscodeMessageOptions* = ref VscodeMessageOptionsObj
VscodeMessageOptionsObj {.importc.} = object of JsRoot
detail*: cstring
modal*: bool

VscodeCommands* = ref VscodeCommandsObj
VscodeCommandsObj {.importc.} = object of JsObject

Expand Down Expand Up @@ -622,6 +637,7 @@ proc with*(uri: VscodeUri, change: VscodeUriChange): VscodeUri {.importcpp.}

# Output
proc showInformationMessage*(win: VscodeWindow, msg: cstring) {.importcpp.}
proc showInformationMessage*(win: VscodeWindow, message: cstring, options: VscodeMessageOptions): VscodeThenable {.importcpp, varargs, discardable.}
## shows an informational message
proc showErrorMessage*(win: VscodeWindow, message: cstring) {.importcpp.}

Expand Down