Skip to content

Commit

Permalink
lsp: chronos based client (#2195)
Browse files Browse the repository at this point in the history
  • Loading branch information
fox0430 authored Oct 23, 2024
1 parent 9455dce commit 4591c0c
Show file tree
Hide file tree
Showing 18 changed files with 510 additions and 488 deletions.
1 change: 0 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ jobs:
- 'ubuntu-latest'
- 'macOS-latest'
nim-version:
- '1.6.2'
- '1.6.16'
- '2.0.10'
- 'stable'
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ We recommend Linux environments.

### Requires

- [Nim](https://nim-lang.org) 1.6.2 or higher
- [Nim](https://nim-lang.org) 1.6.16 or higher

- [Ncurses](https://invisible-island.net/ncurses) 6.1 or higher

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.. _#2195: https://github.com/fox0430/moe/pull/2195

Changed
.......

- `#2195`_ lsp: chronos based client

2 changes: 1 addition & 1 deletion documents/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Currently you can use normal mode, visual mode, replace mode, insert mode, ex mo
# Install and compile

## Requires
- [Nim](https://nim-lang.org) 1.6.2 or higher
- [Nim](https://nim-lang.org) 1.6.16 or higher
- [Ncurses](https://invisible-island.net/ncurses) 6.1 or higher

### Install
Expand Down
4 changes: 3 additions & 1 deletion moe.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ bin = @["moe"]

# Dependencies

requires "nim >= 1.6.2"
requires "nim >= 1.6.16"
requires "ncurses >= 1.0.2"
requires "unicodedb >= 0.13.0"
requires "parsetoml >= 0.7.1"
requires "regex >= 0.25.0"
requires "results >= 0.4.0"
requires "jsony >= 1.1.5"
requires "chronos >= 4.0.3"
requires "stew >= 0.1.0"

task release, "Build for release":
exec "nimble build -d:release"
Expand Down
4 changes: 2 additions & 2 deletions src/moepkg/callhierarchyviewer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ proc incomingCalls(status: var EditorStatus) =
let infoIndex =
currentMainWindowNode.currentLine - CallHierarchyViewHeaderLength

let r = status.lspClients[langId.get].textDocumentIncomingCalls(
let r = waitFor status.lspClients[langId.get].textDocumentIncomingCalls(
currentBufStatus.id,
currentBufStatus.callHierarchyInfo.items[infoIndex])
if r.isErr:
Expand All @@ -109,7 +109,7 @@ proc outgoingCalls(status: var EditorStatus) =
let infoIndex =
currentMainWindowNode.currentLine - CallHierarchyViewHeaderLength

let r = status.lspClients[langId.get].textDocumentOutgoingCalls(
let r = waitFor status.lspClients[langId.get].textDocumentOutgoingCalls(
currentBufStatus.id,
currentBufStatus.callHierarchyInfo.items[infoIndex])
if r.isErr:
Expand Down
26 changes: 13 additions & 13 deletions src/moepkg/editorstatus.nim
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ proc cancelLspForegroundRequest*(
if c.isInitialized:
let fgRes = c.getForegroundWaitingResponse(bufferId)
if fgRes.isSome:
let err = c.cancelForegroundRequest(bufferId)
let err = waitFor c.cancelForegroundRequest(bufferId)
if err.isOk:
return Result[LspMethod, string].ok fgRes.get.lspMethod
else:
Expand Down Expand Up @@ -342,15 +342,15 @@ proc lspInitialize*(

if not status.lspClients.contains(langId):
# Init a LSP client and start a LSP server.
var c = initLspClient(
var c = waitFor initLspClient(
$status.settings.lsp.languages[langId].command)
if c.isErr:
return Result[(), string].err c.error

status.lspClients[langId] = c.get

# Initialize request
let err = status.lspClients[langId].initialize(
let err = waitFor status.lspClients[langId].initialize(
status.bufStatus[^1].id,
initInitializeParams(
status.lspClients[langId].serverName,
Expand Down Expand Up @@ -446,7 +446,7 @@ proc addNewBuffer*(
status.settings.lsp.languages.contains(newBufStatus.langId):
if status.lspClients.contains(newBufStatus.langId):
# textDocument/didOpen notification
let err = lspClient.textDocumentDidOpen(
let err = waitFor lspClient.textDocumentDidOpen(
$newBufStatus.path.absolutePath,
newBufStatus.langId,
newBufStatus.buffer.toString)
Expand Down Expand Up @@ -689,15 +689,15 @@ proc sendLspSemanticTokenRequest*(c: var LspClient, b: BufferStatus) =

block:
# Cancel before completion request.
let err = c.cancelRequest(
let err = waitFor c.cancelRequest(
b.id,
LspMethod.textDocumentSemanticTokensFull)
if err.isErr:
error fmt"lsp: {err.error}"

block:
# Send a textDocument/semanticTokens request to the LSP server.
let err = c.textDocumentSemanticTokens(b.id, $b.absolutePath)
let err = waitFor c.textDocumentSemanticTokens(b.id, $b.absolutePath)
if err.isErr:
error fmt"lsp: {err.error}"

Expand All @@ -710,7 +710,7 @@ proc sendLspInlayHintRequest*(

block:
# Cancel before inlayHint request.
let err = c.cancelRequest(b.id, LspMethod.textDocumentInlayHint)
let err = waitFor c.cancelRequest(b.id, LspMethod.textDocumentInlayHint)
if err.isErr: error fmt"lsp: {err.error}"

# Calc range from all views.
Expand All @@ -731,7 +731,7 @@ proc sendLspInlayHintRequest*(
if b.buffer[last].high >= 0: b.buffer[last].high
else: 0

let err = c.textDocumentInlayHint(b.id, $b.absolutePath, hintRange)
let err = waitFor c.textDocumentInlayHint(b.id, $b.absolutePath, hintRange)
if err.isErr: error fmt"lsp: {err.error}"

b.inlayHints.range = Range(
Expand All @@ -747,7 +747,7 @@ proc sendLspInlineValueRequest*(

block:
# Cancel before inlineValue request.
let err = c.cancelRequest(b.id, LspMethod.textDocumentInlineValue)
let err = waitFor c.cancelRequest(b.id, LspMethod.textDocumentInlineValue)
if err.isErr: error fmt"lsp: {err.error}"

# Calc range from all views.
Expand All @@ -768,7 +768,7 @@ proc sendLspInlineValueRequest*(
if b.buffer[last].high >= 0: b.buffer[last].high
else: 0

let err = c.textDocumentInlineValue(b.id, $b.absolutePath, valueRange)
let err = waitFor c.textDocumentInlineValue(b.id, $b.absolutePath, valueRange)
if err.isErr: error fmt"lsp: {err.error}"

b.inlineValues.range = Range(
Expand All @@ -778,7 +778,7 @@ proc sendLspInlineValueRequest*(
proc sendLspCodeLens*(c: var LspClient, b: BufferStatus) =
## Send textDocument/codeLens requests to the LSP server.

let err = c.textDocumentCodeLens(b.id, $b.absolutePath)
let err = waitFor c.textDocumentCodeLens(b.id, $b.absolutePath)
if err.isErr:
error fmt"lsp: {err.error}"

Expand Down Expand Up @@ -832,7 +832,7 @@ proc updateSyntaxHighlightings(status: EditorStatus) =

if isSendDidChange():
# Send a textDocument/didChange notification to the LSP server.
let err = client.textDocumentDidChange(
let err = waitFor client.textDocumentDidChange(
b.version,
absPath,
b.buffer.toString)
Expand Down Expand Up @@ -1527,7 +1527,7 @@ proc autoSave(status: var EditorStatus) =

if bufStatus.isEditMode and status.lspClients.contains(bufStatus.langId):
# Send textDocument/didSave notify to the LSP server.
let err = status.lspClients[bufStatus.langId].textDocumentDidSave(
let err = waitFor status.lspClients[bufStatus.langId].textDocumentDidSave(
bufStatus.version,
$bufStatus.path.absolutePath,
$bufStatus.buffer)
Expand Down
14 changes: 7 additions & 7 deletions src/moepkg/exmode.nim
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ proc writeCommand(status: var EditorStatus, path: Runes) =

if status.lspClients.contains(currentBufStatus.langId):
# Send textDocument/didSave notify to the LSP server.
let err = lspClient.textDocumentDidSave(
let err = waitFor lspClient.textDocumentDidSave(
currentBufStatus.version,
$currentBufStatus.path.absolutePath,
$currentBufStatus.buffer)
Expand Down Expand Up @@ -874,7 +874,7 @@ proc writeAndQuitCommand(status: var EditorStatus) =

if status.lspClients.contains(currentBufStatus.langId):
# Send textDocument/didSave notify to the LSP server.
let err = lspClient.textDocumentDidSave(
let err = waitFor lspClient.textDocumentDidSave(
currentBufStatus.version,
$currentBufStatus.path.absolutePath,
$currentBufStatus.buffer)
Expand Down Expand Up @@ -1133,7 +1133,7 @@ proc lspExecuteCommand(status: var EditorStatus, command: seq[Runes]) =
status.commandLine.writeLspExecuteCommandError("unknow command")
return

let r = lspClient.workspaceExecuteCommand(
let r = waitFor lspClient.workspaceExecuteCommand(
currentBufStatus.id,
lspCommand,
%*command[1 .. ^1].mapIt($it))
Expand All @@ -1154,7 +1154,7 @@ proc lspFoldingRange(status: var EditorStatus) =
"folding range is unavailable")
return

let r = lspClient.textDocumentFoldingRange(
let r = waitFor lspClient.textDocumentFoldingRange(
currentBufStatus.id,
$currentBufStatus.absolutePath)
if r.isErr:
Expand All @@ -1167,7 +1167,7 @@ proc lspRestartClient(status: var EditorStatus) =
status.commandLine.writeLspError("Client not found")
return

let r = lspClient.restart
let r = waitFor lspClient.restart
if r.isOk:
status.commandLine.writeStandard(fmt"lsp: restarted client: {lspClient.serverName}")
else:
Expand All @@ -1176,7 +1176,7 @@ proc lspRestartClient(status: var EditorStatus) =
let langId = currentBufStatus.langId
for b in status.bufStatus:
if b.langId == langId:
let r = lspClient.initialize(
let r = waitFor lspClient.initialize(
status.bufStatus[^1].id,
initInitializeParams(
lspClient.serverName,
Expand All @@ -1200,7 +1200,7 @@ proc lspDocumentFormatting(status: var EditorStatus) =
insertSpaces: true,
insertFinalNewline: some(true))

let r = lspClient.textDocumentFormatting(
let r = waitFor lspClient.textDocumentFormatting(
currentBufStatus.id,
$currentBufStatus.absolutePath,
options)
Expand Down
6 changes: 3 additions & 3 deletions src/moepkg/insertmode.nim
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ proc sendDidChangeNotify(status: var EditorStatus): Result[(), string] =
first: currentMainWindowNode.bufferPosition,
last: currentMainWindowNode.bufferPosition)

let err = lspClient.textDocumentDidChange(
let err = waitFor lspClient.textDocumentDidChange(
currentBufStatus.version,
$currentBufStatus.path.absolutePath,
currentBufStatus.buffer.toString,
Expand All @@ -111,7 +111,7 @@ proc sendCompletionRequest(
block:
let isIncompleteTrigger = status.completionWindow.isSome

let err = lspClient.textDocumentCompletion(
let err = waitFor lspClient.textDocumentCompletion(
currentBufStatus.id,
$currentBufStatus.path.absolutePath,
currentMainWindowNode.bufferPosition,
Expand Down Expand Up @@ -141,7 +141,7 @@ proc sendSignatureHelpRequest(
if r.isSome: SignatureHelpTriggerKind.TriggerCharacter
else: SignatureHelpTriggerKind.Invoked

let err = lspClient.textDocumentSignatureHelp(
let err = waitFor lspClient.textDocumentSignatureHelp(
currentBufStatus.id,
$currentBufStatus.path.absolutePath,
currentMainWindowNode.bufferPosition,
Expand Down
Loading

0 comments on commit 4591c0c

Please sign in to comment.