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

Replace file content representation with rope crdt #26

Merged
merged 31 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
3ade96e
Added nimsumtree and first implementation of synching
Nimaoth Sep 12, 2024
bfcfa50
Progress
Nimaoth Sep 13, 2024
44960da
Removed some debug code
Nimaoth Sep 13, 2024
53a2ba7
Merge branch 'main' into rope-crdt
Nimaoth Sep 13, 2024
f489c22
more progress
Nimaoth Sep 14, 2024
4c30b84
progress
Nimaoth Sep 14, 2024
4a073ba
progress
Nimaoth Sep 15, 2024
9b38663
add basic bench mark tool
Nimaoth Sep 15, 2024
81cc643
made reduced fps mode more configurable
Nimaoth Sep 15, 2024
12ff165
progress
Nimaoth Sep 15, 2024
af6b6a2
Moved treesitter parsing to separate thread, fixed bugs
Nimaoth Sep 16, 2024
c90a027
Progress
Nimaoth Sep 17, 2024
129fd57
progress
Nimaoth Sep 17, 2024
a0b349c
Use anchors for diagnostics, fixed some other issues
Nimaoth Sep 19, 2024
a7c0c6d
Added compile option to debug break on sysFatal
Nimaoth Sep 19, 2024
b4a162c
Added back undo checkpoints, fixed reloading
Nimaoth Sep 19, 2024
c49bd43
Cleaned up some warnings
Nimaoth Sep 19, 2024
d27e33c
Updated nimsumtree version
Nimaoth Sep 19, 2024
92ee263
progress
Nimaoth Sep 19, 2024
640cdee
Moved collab stuff to separate file, fixed reversed selections crashing
Nimaoth Sep 20, 2024
74761d8
Update main.yml (#27)
Nimaoth Sep 20, 2024
238761c
Fixed weird compile errors
Nimaoth Sep 20, 2024
ec9adc7
Progress
Nimaoth Sep 20, 2024
5c1bd53
Updated dependency
Nimaoth Sep 20, 2024
ec3782f
Fixed performance issue, small cleanup
Nimaoth Sep 21, 2024
994187c
Reenabled log document
Nimaoth Sep 21, 2024
811b5b8
Some cleanup, added treesitter mem tracking
Nimaoth Sep 22, 2024
3ed5e61
Add cli option to enable treesitter mem tracking
Nimaoth Sep 22, 2024
64f94c8
A bunch of fixes, perf improvements
Nimaoth Sep 22, 2024
2e07585
Big refactor
Nimaoth Sep 24, 2024
6782aa6
Updated nimsumtree
Nimaoth Sep 24, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Build and test the editor
on:
# Runs on pushes targeting the default branch
push:
branches: ["main"]
branches: ["main", "rope-crdt"]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
Expand Down
1 change: 1 addition & 0 deletions config/default_config.nim
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ proc loadDefaultKeybindings*(clearExisting: bool = false) {.expose("load-default
addCommand "editor", "<LEADER>gp", "explore-current-file-directory"
addCommand "editor", "<LEADER>gs", "search-global-interactive"
addCommand "editor", "<LEADER>gk", "browse-keybinds"
addCommand "editor", "<LEADER>gn", "open-last-editor"
addCommandBlock "editor", "<LEADER>log":
logs(scrollToBottom = true)
nextView()
Expand Down
1 change: 1 addition & 0 deletions nev.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ requires "https://github.com/Nimaoth/boxy >= 0.4.2"
requires "https://github.com/Nimaoth/nimscripter >= 1.0.21"
requires "https://github.com/Nimaoth/nimtreesitter-api >= 0.1.15"
requires "https://github.com/Nimaoth/nimwasmtime >= 0.1.7"
requires "https://github.com/Nimaoth/nimsumtree >= 0.3.1"

# Use this to include all treesitter languages (takes longer to download)
requires "https://github.com/Nimaoth/nimtreesitter >= 0.1.6"
Expand Down
10 changes: 10 additions & 0 deletions nimble.lock
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,16 @@
"sha1": "dfe09fbcf8040027630301c43b4dbe9d9f0fab4d"
}
},
"nimsumtree": {
"version": "0.3.1",
"vcsRevision": "3c03f938668a57ed568944116aceecacc24f24be",
"url": "https://github.com/Nimaoth/nimsumtree",
"downloadMethod": "git",
"dependencies": [],
"checksums": {
"sha1": "c4c9d1f4116afdfdb5fbfea06302d79e7ae957d6"
}
},
"nimtreesitter": {
"version": "0.1.6",
"vcsRevision": "8e0af3c1efecfd624a169790d29a8b5e0b11edd6",
Expand Down
4 changes: 4 additions & 0 deletions patches/fatal.nim
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,17 @@ else:
when defined(enableSysFatalStackTrace) and not defined(wasm):
writeStackTrace2()
##### patch end
when defined(sysFatalInt3):
asm "int3"
raise (ref exceptn)(msg: message)

func sysFatal(exceptn: typedesc[Defect], message, arg: string) {.inline, noreturn.} =
##### patch begin - I want that stacktrace
when defined(enableSysFatalStackTrace) and not defined(wasm):
writeStackTrace2()
##### patch end
when defined(sysFatalInt3):
asm "int3"
raise (ref exceptn)(msg: message & arg)

{.pop.}
31 changes: 31 additions & 0 deletions scripting/collab_api_wasm.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import std/[json, options]
import scripting_api, misc/myjsonutils

## This file is auto generated, don't modify.


proc collab_connectCollaborator_void_int_wasm(arg: cstring): cstring {.importc.}
proc connectCollaborator*(port: int = 6969) =
var argsJson = newJArray()
argsJson.add block:
when int is JsonNode:
port
else:
port.toJson()
let argsJsonString = $argsJson
let res {.used.} = collab_connectCollaborator_void_int_wasm(
argsJsonString.cstring)


proc collab_hostCollaborator_void_int_wasm(arg: cstring): cstring {.importc.}
proc hostCollaborator*(port: int = 6969) =
var argsJson = newJArray()
argsJson.add block:
when int is JsonNode:
port
else:
port.toJson()
let argsJsonString = $argsJson
let res {.used.} = collab_hostCollaborator_void_int_wasm(
argsJsonString.cstring)

4 changes: 4 additions & 0 deletions scripting/editor_api.nim
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ proc browseKeybinds*(preview: bool = true; scaleX: float = 0.9;
scaleY: float = 0.8; previewScale: float = 0.4) =
editor_browseKeybinds_void_App_bool_float_float_float_impl(preview, scaleX,
scaleY, previewScale)
proc connectCollaborator*(port: int = 6969) =
editor_connectCollaborator_void_App_int_impl(port)
proc hostCollaborator*(port: int = 6969) =
editor_hostCollaborator_void_App_int_impl(port)
proc chooseFile*(preview: bool = true; scaleX: float = 0.8; scaleY: float = 0.8;
previewScale: float = 0.5) =
## Opens a file dialog which shows all files in the currently open workspaces
Expand Down
47 changes: 0 additions & 47 deletions scripting/editor_text_api_wasm.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1392,25 +1392,6 @@ proc addNextCheckpoint*(self: TextDocumentEditor; checkpoint: string) =
argsJsonString.cstring)


proc editor_text_printUndoHistory_void_TextDocumentEditor_int_wasm(arg: cstring): cstring {.
importc.}
proc printUndoHistory*(self: TextDocumentEditor; max: int = 50) =
var argsJson = newJArray()
argsJson.add block:
when TextDocumentEditor is JsonNode:
self
else:
self.toJson()
argsJson.add block:
when int is JsonNode:
max
else:
max.toJson()
let argsJsonString = $argsJson
let res {.used.} = editor_text_printUndoHistory_void_TextDocumentEditor_int_wasm(
argsJsonString.cstring)


proc editor_text_copy_void_TextDocumentEditor_string_bool_wasm(arg: cstring): cstring {.
importc.}
proc copy*(self: TextDocumentEditor; register: string = "";
Expand Down Expand Up @@ -3441,34 +3422,6 @@ proc clearDiagnostics*(self: TextDocumentEditor) =
argsJsonString.cstring)


proc editor_text_updateDiagnosticsForCurrent_void_TextDocumentEditor_wasm(
arg: cstring): cstring {.importc.}
proc updateDiagnosticsForCurrent*(self: TextDocumentEditor) =
var argsJson = newJArray()
argsJson.add block:
when TextDocumentEditor is JsonNode:
self
else:
self.toJson()
let argsJsonString = $argsJson
let res {.used.} = editor_text_updateDiagnosticsForCurrent_void_TextDocumentEditor_wasm(
argsJsonString.cstring)


proc editor_text_showDiagnosticsForCurrent_void_TextDocumentEditor_wasm(
arg: cstring): cstring {.importc.}
proc showDiagnosticsForCurrent*(self: TextDocumentEditor) =
var argsJson = newJArray()
argsJson.add block:
when TextDocumentEditor is JsonNode:
self
else:
self.toJson()
let argsJsonString = $argsJson
let res {.used.} = editor_text_showDiagnosticsForCurrent_void_TextDocumentEditor_wasm(
argsJsonString.cstring)


proc editor_text_setReadOnly_void_TextDocumentEditor_bool_wasm(arg: cstring): cstring {.
importc.}
proc setReadOnly*(self: TextDocumentEditor; readOnly: bool) =
Expand Down
6 changes: 6 additions & 0 deletions scripting/plugin_api.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ export scripting_api

## This file is auto generated, don't modify.

when defined(wasm):
import collab_api_wasm
export collab_api_wasm
else:
import collab_api
export collab_api
when defined(wasm):
import debugger_api_wasm
export debugger_api_wasm
Expand Down
4 changes: 4 additions & 0 deletions scripting/plugin_api_internal.nim
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,10 @@ proc editor_browseKeybinds_void_App_bool_float_float_float_impl*(
preview: bool = true; scaleX: float = 0.9; scaleY: float = 0.8;
previewScale: float = 0.4) =
discard
proc editor_connectCollaborator_void_App_int_impl*(port: int = 6969) =
discard
proc editor_hostCollaborator_void_App_int_impl*(port: int = 6969) =
discard
proc editor_chooseFile_void_App_bool_float_float_float_impl*(
preview: bool = true; scaleX: float = 0.8; scaleY: float = 0.8;
previewScale: float = 0.5) =
Expand Down
31 changes: 18 additions & 13 deletions src/app.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import std/[sequtils, strformat, strutils, tables, unicode, options, os, json, macros, macrocache, sugar, streams, deques]
import std/[sequtils, strformat, strutils, tables, unicode, options, os, json, macros, macrocache, sugar, streams, deques, algorithm]
import asynctools/asyncipc
import misc/[id, util, timer, event, myjsonutils, traits, rect_utils, custom_logger, custom_async,
array_set, delayed_task, regex, disposable_ref]
Expand All @@ -14,6 +14,8 @@ import finder/[finder, previewer]
import compilation_config, vfs
import vcs/vcs

import nimsumtree/[buffer, clock, rope]

when not defined(js):
import misc/async_process

Expand Down Expand Up @@ -707,6 +709,7 @@ when enableAst:
import ast/[model_document]
import selector_popup
import finder/[workspace_file_previewer, open_editor_previewer]
import collab

# todo: remove this function
proc setLocationList(self: App, list: seq[FinderItem], previewer: Option[Previewer] = Previewer.none) =
Expand Down Expand Up @@ -1159,8 +1162,8 @@ proc listenForIpc(self: App, id: int) {.async.} =
try:
if message.startsWith("-r:") or message.startsWith("-R:"):
let (action, arg) = parseAction(message[3..^1])
let response = self.handleAction(action, arg, record=true)
# todo: send response
discard self.handleAction(action, arg, record=true)
elif message.startsWith("-p:"):
let setting = message[3..^1]
let i = setting.find("=")
Expand Down Expand Up @@ -1492,7 +1495,8 @@ proc handleLog(self: App, level: Level, args: openArray[string]) =
let str = substituteLog(defaultFmtStr, level, args) & "\n"
if self.logDocument.isNotNil:
let selection = self.logDocument.TextDocument.lastCursor.toSelection
discard self.logDocument.TextDocument.insert([selection], [selection], [logBuffer & str])
# todo: reenable and make sure performance is good
# discard self.logDocument.TextDocument.edit([selection], [selection], [logBuffer & str])
logBuffer = ""
Nimaoth marked this conversation as resolved.
Show resolved Hide resolved

for view in self.views:
Expand Down Expand Up @@ -1625,10 +1629,8 @@ proc openDocument*(self: App, path: string, appFile = false, load = true): Optio
return Document.none

proc getDocument*(self: App, path: string, appFile = false): Option[Document] =

for document in self.documents:
if document.workspace == self.workspace.some and document.appFile == appFile and document.filename == path:
log lvlInfo, &"Get existing document '{path}'"
return document.some

return Document.none
Expand Down Expand Up @@ -2282,7 +2284,7 @@ proc setLayout*(self: App, layout: string) {.expose("editor").} =
self.platform.requestRender()

proc commandLine*(self: App, initialValue: string = "") {.expose("editor").} =
self.getCommandLineTextEditor.document.content = @[initialValue]
self.getCommandLineTextEditor.document.content = initialValue
if self.commandHistory.len == 0:
self.commandHistory.add ""
self.commandHistory[0] = ""
Expand All @@ -2293,7 +2295,7 @@ proc commandLine*(self: App, initialValue: string = "") {.expose("editor").} =
self.platform.requestRender()

proc exitCommandLine*(self: App) {.expose("editor").} =
self.getCommandLineTextEditor.document.content = @[""]
self.getCommandLineTextEditor.document.content = ""
self.getCommandLineTextEditor.hideCompletions()
self.commandLineMode = false
self.platform.requestRender()
Expand Down Expand Up @@ -2336,7 +2338,7 @@ proc executeCommandLine*(self: App): bool {.expose("editor").} =
defer:
self.platform.requestRender()
self.commandLineMode = false
let command = self.getCommandLineTextEditor.document.content.join("")
let command = self.getCommandLineTextEditor.document.contentString.replace("\n", "")

if (let i = self.commandHistory.find(command); i >= 0):
self.commandHistory.delete i
Expand All @@ -2351,7 +2353,7 @@ proc executeCommandLine*(self: App): bool {.expose("editor").} =
self.commandHistory.setLen maxHistorySize

var (action, arg) = command.parseAction
self.getCommandLineTextEditor.document.content = @[""]
self.getCommandLineTextEditor.document.content = ""

if arg.startsWith("\\"):
arg = $newJString(arg[1..^1])
Expand Down Expand Up @@ -2707,7 +2709,6 @@ proc browseKeybinds*(self: App, preview: bool = true, scaleX: float = 0.9, scale
if popup.getPreviewSelection().getSome(selection):
targetSelection = selection.some

let (vfs, relPath) = self.vfs.getVFS(path)
let pathNorm = self.vfs.normalize(path)

let editor = self.openWorkspaceFile(pathNorm)
Expand Down Expand Up @@ -3952,8 +3953,8 @@ proc scriptGetTextEditorLine*(editorId: EditorId, line: int): string {.expose("e
if gEditor.getEditorForId(editorId).getSome(editor):
if editor of TextDocumentEditor:
let editor = TextDocumentEditor(editor)
if line >= 0 and line < editor.document.content.len:
return editor.document.content[line]
if line >= 0 and line < editor.document.numLines:
return editor.document.getLine(line)
return ""

proc scriptGetTextEditorLineCount*(editorId: EditorId): int {.expose("editor").} =
Expand All @@ -3962,7 +3963,7 @@ proc scriptGetTextEditorLineCount*(editorId: EditorId): int {.expose("editor").}
if gEditor.getEditorForId(editorId).getSome(editor):
if editor of TextDocumentEditor:
let editor = TextDocumentEditor(editor)
return editor.document.content.len
return editor.document.numLines
return 0

template createScriptGetOption(path, default, accessor: untyped): untyped =
Expand Down Expand Up @@ -4249,6 +4250,10 @@ proc handleAction(self: App, action: string, arg: string, record: bool): Option[
log lvlError, fmt"No current view"
return JsonNode.none

# todo: there's got to be better way than putting all these here manually
if collab.dispatchEvent(action, args).getSome(r):
return r.some

if debugger.dispatchEvent(action, args).getSome(r):
return r.some

Expand Down
Loading
Loading