Skip to content

Commit

Permalink
Remove old workarounds (#2196)
Browse files Browse the repository at this point in the history
  • Loading branch information
fox0430 authored Oct 25, 2024
1 parent d1c15ab commit 55c896d
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 106 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.. _#2196: https://github.com/fox0430/moe/pull/2196

Changed
.......

- `#2196`_ Remove old workarounds

91 changes: 29 additions & 62 deletions src/moepkg/exmodeutils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -321,68 +321,35 @@ const
argsType: ArgsType.none)
]

when (NimMajor, NimMinor) >= (1, 9):
# These codes can't compile in Nim 1.6. Maybe compiler bug.

proc noArgsCommandList*(): seq[Runes] {.compileTime.} =
ExCommandInfoList
.filterIt(it.argsType == ArgsType.none)
.mapIt(it.command.toRunes)

proc toggleArgsCommandList*(): seq[Runes] {.compileTime.} =
ExCommandInfoList
.filterIt(it.argsType == ArgsType.toggle)
.mapIt(it.command.toRunes)

proc numberArgsCommandList*(): seq[Runes] {.compileTime.} =
ExCommandInfoList
.filterIt(it.argsType == ArgsType.number)
.mapIt(it.command.toRunes)

proc textArgsCommandList*(): seq[Runes] {.compileTime.} =
ExCommandInfoList
.filterIt(it.argsType == ArgsType.text)
.mapIt(it.command.toRunes)

proc pathArgsCommandList*(): seq[Runes] {.compileTime.} =
ExCommandInfoList
.filterIt(it.argsType == ArgsType.path)
.mapIt(it.command.toRunes)

proc themeArgsCommandList*(): seq[Runes] {.compileTime.} =
ExCommandInfoList
.filterIt(it.argsType == ArgsType.theme)
.mapIt(it.command.toRunes)
else:
proc noArgsCommandList*(): seq[Runes] =
ExCommandInfoList
.filterIt(it.argsType == ArgsType.none)
.mapIt(it.command.toRunes)

proc toggleArgsCommandList*(): seq[Runes] =
ExCommandInfoList
.filterIt(it.argsType == ArgsType.toggle)
.mapIt(it.command.toRunes)

proc numberArgsCommandList*(): seq[Runes] =
ExCommandInfoList
.filterIt(it.argsType == ArgsType.number)
.mapIt(it.command.toRunes)

proc textArgsCommandList*(): seq[Runes] =
ExCommandInfoList
.filterIt(it.argsType == ArgsType.text)
.mapIt(it.command.toRunes)

proc pathArgsCommandList*(): seq[Runes] =
ExCommandInfoList
.filterIt(it.argsType == ArgsType.path)
.mapIt(it.command.toRunes)

proc themeArgsCommandList*(): seq[Runes] =
ExCommandInfoList
.filterIt(it.argsType == ArgsType.theme)
.mapIt(it.command.toRunes)
proc noArgsCommandList*(): seq[Runes] {.compileTime.} =
ExCommandInfoList
.filterIt(it.argsType == ArgsType.none)
.mapIt(it.command.toRunes)

proc toggleArgsCommandList*(): seq[Runes] {.compileTime.} =
ExCommandInfoList
.filterIt(it.argsType == ArgsType.toggle)
.mapIt(it.command.toRunes)

proc numberArgsCommandList*(): seq[Runes] {.compileTime.} =
ExCommandInfoList
.filterIt(it.argsType == ArgsType.number)
.mapIt(it.command.toRunes)

proc textArgsCommandList*(): seq[Runes] {.compileTime.} =
ExCommandInfoList
.filterIt(it.argsType == ArgsType.text)
.mapIt(it.command.toRunes)

proc pathArgsCommandList*(): seq[Runes] {.compileTime.} =
ExCommandInfoList
.filterIt(it.argsType == ArgsType.path)
.mapIt(it.command.toRunes)

proc themeArgsCommandList*(): seq[Runes] {.compileTime.} =
ExCommandInfoList
.filterIt(it.argsType == ArgsType.theme)
.mapIt(it.command.toRunes)

proc exCommandList*(): array[ExCommandInfoList.len, Runes] {.compileTime.} =
for i, info in ExCommandInfoList: result[i] = info.command.toRunes
Expand Down
6 changes: 1 addition & 5 deletions src/moepkg/insertmode.nim
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,9 @@ import std/[options, json, logging, tables]

import pkg/results

import lsp/client

# Workaround for Nim 1.6.2
import lsp/[client, signaturehelp]
import lsp/completion as lspcompletion

import lsp/signaturehelp

import ui, editorstatus, windownode, movement, editor, bufferstatus, settings,
unicodeext, independentutils, gapbuffer, completion, messages

Expand Down
5 changes: 2 additions & 3 deletions src/moepkg/lsp/handler.nim
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,14 @@ import
../statusline,
../visualmode

import completion as lspcompletion

import client, utils, hover, message, diagnostics, semantictoken, progress,
inlayhint, definition, typedefinition, references, rename, declaration,
implementation, callhierarchy, documenthighlight, documentlink,
codelens, executecommand, foldingrange, selectionrange, documentsymbol,
inlinevalue, signaturehelp, formatting

# Workaround for Nim 1.6.2
import completion as lspcompletion

proc applyTextEdit(b: var BufferStatus, edit: TextEdit): Result[(), string] =
let
startLine = edit.range.start.line
Expand Down
57 changes: 21 additions & 36 deletions src/moepkg/normalmode.nim
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,16 @@ template removeAllFoldingRange(status: var EditorStatus, first, last: int) =
proc changeModeToInsertMode(
status: var EditorStatus,
removeFoldingRange: bool = true) {.inline.} =
if currentBufStatus.isReadonly:
status.commandLine.writeReadonlyModeWarning
return

if removeFoldingRange:
status.removeAllFoldingRange
if currentBufStatus.isReadonly:
status.commandLine.writeReadonlyModeWarning
return

if removeFoldingRange:
status.removeAllFoldingRange

changeCursorType(status.settings.standard.insertModeCursor)
status.changeMode(Mode.insert)
changeCursorType(status.settings.standard.insertModeCursor)
status.changeMode(Mode.insert)

proc changeModeToReplaceMode(status: var EditorStatus) {.inline.} =
if currentBufStatus.isReadonly:
Expand All @@ -57,30 +58,30 @@ proc changeModeToReplaceMode(status: var EditorStatus) {.inline.} =

status.changeMode(Mode.replace)

proc changeModeToVisualMode(status: var EditorStatus) {.inline.} =
template changeModeToVisualMode(status: var EditorStatus) =
status.changeMode(Mode.visual)
currentBufStatus.selectedArea = initSelectedArea(
currentMainWindowNode.currentLine,
currentMainWindowNode.currentColumn)
.some

proc changeModeToVisualBlockMode(status: var EditorStatus) {.inline.} =
template changeModeToVisualBlockMode(status: var EditorStatus) =
status.changeMode(Mode.visualBlock)
currentBufStatus.selectedArea = initSelectedArea(
currentMainWindowNode.currentLine,
currentMainWindowNode.currentColumn)
.some

proc changeModeToVisualLineMode(status: var EditorStatus) {.inline.} =
template changeModeToVisualLineMode(status: var EditorStatus) =
status.changeMode(Mode.visualLine)
currentBufStatus.selectedArea = initSelectedArea(
currentMainWindowNode.currentLine,
currentMainWindowNode.currentColumn)
.some

proc changeModeToExMode*(
template changeModeToExMode*(
bufStatus: var BufferStatus,
commandLine: var CommandLine) {.inline.} =
commandLine: var CommandLine) =

bufStatus.changeMode(Mode.ex)
commandLine.clear
Expand All @@ -90,21 +91,15 @@ template moveCursorLeft(status: var EditorStatus) =
for i in 0 ..< currentBufStatus.cmdLoop:
currentMainWindowNode.keyLeft

proc moveCursorRight(status: var EditorStatus) {.inline.} =
## Use proc not template for a workaround for Nim 1.6.2.

template moveCursorRight(status: var EditorStatus) =
for i in 0 ..< currentBufStatus.cmdLoop:
currentBufStatus.keyRight(currentMainWindowNode)

proc moveCursorUp(status: var EditorStatus) {.inline.} =
## Use proc not template for a workaround for Nim 1.6.2.

template moveCursorUp(status: var EditorStatus) =
for i in 0 ..< currentBufStatus.cmdLoop:
currentBufStatus.keyUp(currentMainWindowNode)

proc moveCursorDwon(status: var EditorStatus) {.inline.} =
## Use proc not template for a workaround for Nim 1.6.2.

template moveCursorDwon(status: var EditorStatus) =
for i in 0 ..< currentBufStatus.cmdLoop:
currentBufStatus.keyDown(currentMainWindowNode)

Expand Down Expand Up @@ -327,34 +322,24 @@ proc moveToFirstLine(status: var EditorStatus) =
let dest = currentBufStatus.cmdLoop - 1
currentBufStatus.jumpLine(currentMainWindowNode, dest)

proc moveToForwardWord(status: var EditorStatus) {.inline.} =
## Use proc for workaround for Nim 1.6.2.

template moveToForwardWord(status: var EditorStatus) =
for i in 0 ..< currentBufStatus.cmdLoop:
currentBufStatus.moveToForwardWord(currentMainWindowNode)

proc moveToBackwardWord(status: var EditorStatus) {.inline.} =
## Use proc for workaround for Nim 1.6.2.

template moveToBackwardWord(status: var EditorStatus) =
for i in 0 ..< currentBufStatus.cmdLoop:
currentBufStatus.moveToBackwardWord(currentMainWindowNode)

proc moveToForwardEndOfWord(status: var EditorStatus) {.inline.} =
## Use proc for workaround for Nim 1.6.2.

template moveToForwardEndOfWord(status: var EditorStatus) =
for i in 0 ..< currentBufStatus.cmdLoop:
currentBufStatus.moveToForwardEndOfWord(currentMainWindowNode)

proc incNumberTextUnderCurosr(status: var EditorStatus) {.inline.} =
## Use proc for workaround for Nim 1.6.2.

template incNumberTextUnderCurosr(status: var EditorStatus) =
currentBufStatus.modifyNumberTextUnderCurosr(
currentMainWindowNode,
currentBufStatus.cmdLoop)

proc decNumberTextUnderCurosr(status: var EditorStatus) {.inline.} =
## Use proc for workaround for Nim 1.6.2.

template decNumberTextUnderCurosr(status: var EditorStatus) =
currentBufStatus.modifyNumberTextUnderCurosr(
currentMainWindowNode,
-currentBufStatus.cmdLoop)
Expand Down

0 comments on commit 55c896d

Please sign in to comment.