Skip to content

Commit

Permalink
Fixed some todos
Browse files Browse the repository at this point in the history
  • Loading branch information
Nimaoth committed Oct 25, 2024
1 parent 7e952f1 commit 661be06
Show file tree
Hide file tree
Showing 11 changed files with 135 additions and 123 deletions.
Binary file modified config/wasm/harpoon.wasm
Binary file not shown.
Binary file modified config/wasm/keybindings_plugin.wasm
Binary file not shown.
Binary file modified config/wasm/vscode_config_plugin.wasm
Binary file not shown.
14 changes: 0 additions & 14 deletions scripting/editor_api_wasm.nim
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,6 @@ proc getHostOs*(): string {.gcsafe, raises: [].} =
raiseAssert(getCurrentExceptionMsg())


proc editor_loadApplicationFile_Option_string_App_string_wasm(arg: cstring): cstring {.
importc.}
proc loadApplicationFile*(path: string): Option[string] {.gcsafe, raises: [].} =
var argsJson = newJArray()
argsJson.add path.toJson()
let argsJsonString = $argsJson
let res {.used.} = editor_loadApplicationFile_Option_string_App_string_wasm(
argsJsonString.cstring)
try:
result = parseJson($res).jsonTo(typeof(result))
except:
raiseAssert(getCurrentExceptionMsg())


proc editor_toggleShowDrawnNodes_void_App_wasm(arg: cstring): cstring {.importc.}
proc toggleShowDrawnNodes*() {.gcsafe, raises: [].} =
var argsJson = newJArray()
Expand Down
38 changes: 12 additions & 26 deletions src/app.nim
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import text/language/language_server_base, language_server_command_line
import input, events, document, document_editor, popup, dispatch_tables, theme, app_options, view, register
import text/[custom_treesitter]
import finder/[finder, previewer]
import compilation_config, vfs, vfs_service, vfs_local
import compilation_config, vfs, vfs_service
import service, layout, session

import nimsumtree/[rope]
Expand Down Expand Up @@ -937,12 +937,6 @@ proc getHostOs*(self: App): string {.expose("editor").} =
else:
return "unknown"

proc loadApplicationFile*(self: App, path: string): Option[string] {.expose("editor").} =
## Load a file from the application directory (path is relative to the executable)
# return self.vfs.read("app://" & path).some
# todo
return string.none

proc toggleShowDrawnNodes*(self: App) {.expose("editor").} =
self.platform.showDrawnNodes = not self.platform.showDrawnNodes

Expand Down Expand Up @@ -1435,7 +1429,7 @@ proc browseKeybinds*(self: App, preview: bool = true, scaleX: float = 0.9, scale
return items

let previewer = if preview:
newWorkspaceFilePreviewer(self.vfs, self.services, reuseExistingDocuments = false).Previewer.toDisposableRef.some
newFilePreviewer(self.vfs, self.services, reuseExistingDocuments = false).Previewer.toDisposableRef.some
else:
DisposableRef[Previewer].none

Expand Down Expand Up @@ -1475,7 +1469,7 @@ proc chooseFile*(self: App, preview: bool = true, scaleX: float = 0.8, scaleY: f
self.platform.requestRender()

let previewer = if preview:
newWorkspaceFilePreviewer(self.vfs, self.services).Previewer.toDisposableRef.some
newFilePreviewer(self.vfs, self.services).Previewer.toDisposableRef.some
else:
DisposableRef[Previewer].none

Expand Down Expand Up @@ -1588,19 +1582,14 @@ proc chooseOpenDocument*(self: App) {.expose("editor").} =
let path = document.filename
let isDirty = document.lastSavedRevision != document.revision
let dirtyMarker = if isDirty: "*" else: " "

let (directory, name) = path.splitPath
let relativeDirectory = self.workspace.getRelativePathSync(directory).get(directory)
let data = path

# todo
let infoText = "workspace"

items.add FinderItem(
displayName: dirtyMarker & name,
filterText: name,
data: data,
detail: &"{relativeDirectory}\t{infoText}",
data: path,
detail: relativeDirectory,
)

return items
Expand Down Expand Up @@ -1772,7 +1761,7 @@ proc searchGlobalInteractive*(self: App) {.expose("editor").} =
var finder = newFinder(source, filterAndSort=true)

var popup = newSelectorPopup(self.services, "search".some, finder.some,
newWorkspaceFilePreviewer(self.vfs, self.services).Previewer.toDisposableRef.some)
newFilePreviewer(self.vfs, self.services).Previewer.toDisposableRef.some)
popup.scale.x = 0.85
popup.scale.y = 0.85

Expand Down Expand Up @@ -1806,7 +1795,7 @@ proc searchGlobal*(self: App, query: string) {.expose("editor").} =
var finder = newFinder(source, filterAndSort=true)

var popup = newSelectorPopup(self.services, "search".some, finder.some,
newWorkspaceFilePreviewer(self.vfs, self.services).Previewer.toDisposableRef.some)
newFilePreviewer(self.vfs, self.services).Previewer.toDisposableRef.some)
popup.scale.x = 0.85
popup.scale.y = 0.85

Expand Down Expand Up @@ -1872,22 +1861,19 @@ proc installTreesitterParserAsync*(self: App, language: string, host: string) {.
block:
log lvlInfo, &"Copy highlight queries"

# todo: don't use VFSLocal directly, move copyFile to VFS
let vfsLocal = self.vfs.getVFS("").vfs.VFSLocal

let queryDirs = if queriesSubDir != "":
@[repoPath // queriesSubDir]
else:
let highlightQueries = await vfsLocal.findFile(repoPath, r"highlights.scm$")
highlightQueries.mapIt(it.splitPath.head)
let highlightQueries = await self.vfs.findFiles(repoPath, r"highlights.scm$")
highlightQueries.mapIt(repoPath // it.splitPath.head)

for path in queryDirs:
let list = await self.vfs.getDirectoryListing(path)
for f in list.files:
if f.endsWith(".scm"):
let fileName = f.splitPath.tail
log lvlInfo, &"Copy '{f}' to '{queryDir}'"
discard await vfsLocal.copyFile(path // f, queryDir // fileName)
await self.vfs.copyFile(path // f, queryDir // fileName)

block:
let (output, err) = await runProcessAsyncOutput("tree-sitter", @["build", "--wasm", grammarPath],
Expand Down Expand Up @@ -1988,7 +1974,7 @@ proc exploreFiles*(self: App, root: string = "", showVFS: bool = false, normaliz
finder.filterThreshold = float.low

var popup = newSelectorPopup(self.services, "file-explorer".some, finder.some,
newWorkspaceFilePreviewer(self.vfs, self.services).Previewer.toDisposableRef.some)
newFilePreviewer(self.vfs, self.services).Previewer.toDisposableRef.some)
popup.scale.x = 0.85
popup.scale.y = 0.85

Expand Down Expand Up @@ -2145,7 +2131,7 @@ proc dumpKeymapGraphViz*(self: App, context: string = "") {.expose("editor").} =
for handler in self.currentEventHandlers():
if context == "" or handler.config.context == context:
try:
waitFor self.vfs.write(handler.config.context & ".dot", handler.dfa.dumpGraphViz)
waitFor self.vfs.write("app://input_dots" // handler.config.context & ".dot", handler.dfa.dumpGraphViz)
except IOError as e:
log lvlError, &"Failed to dump keymap graph: {e.msg}\n{e.getStackTrace()}"

Expand Down
14 changes: 7 additions & 7 deletions src/finder/workspace_file_previewer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import nimsumtree/[rope]
logCategory "file-previewer"

type
WorkspaceFilePreviewer* = ref object of Previewer
FilePreviewer* = ref object of Previewer
services*: Services
editors*: DocumentEditorService
vfs: VFS
Expand All @@ -27,8 +27,8 @@ type
currentStaged: bool
currentDiff: bool

proc newWorkspaceFilePreviewer*(vfs: VFS, services: Services,
openNewDocuments: bool = false, reuseExistingDocuments: bool = true): WorkspaceFilePreviewer =
proc newFilePreviewer*(vfs: VFS, services: Services,
openNewDocuments: bool = false, reuseExistingDocuments: bool = true): FilePreviewer =
new result
result.services = services
result.editors = services.getService(DocumentEditorService).get
Expand All @@ -39,7 +39,7 @@ proc newWorkspaceFilePreviewer*(vfs: VFS, services: Services,
result.tempDocument = newTextDocument(services, createLanguageServer=false)
result.tempDocument.readOnly = true

method deinit*(self: WorkspaceFilePreviewer) =
method deinit*(self: FilePreviewer) =
logScope lvlInfo, &"[deinit] Destroying file previewer"
if self.triggerLoadTask.isNotNil:
self.triggerLoadTask.deinit()
Expand Down Expand Up @@ -86,7 +86,7 @@ proc parsePathAndLocationFromItemData*(item: FinderItem):
except:
return

proc loadAsync(self: WorkspaceFilePreviewer): Future[void] {.async.} =
proc loadAsync(self: FilePreviewer): Future[void] {.async.} =
let revision = self.revision
let path = self.currentPath
let location = self.currentLocation
Expand Down Expand Up @@ -181,11 +181,11 @@ proc loadAsync(self: WorkspaceFilePreviewer): Future[void] {.async.} =

editor.markDirty()

method delayPreview*(self: WorkspaceFilePreviewer) =
method delayPreview*(self: FilePreviewer) =
if self.triggerLoadTask.isNotNil and self.triggerLoadTask.isActive:
self.triggerLoadTask.reschedule()

method previewItem*(self: WorkspaceFilePreviewer, item: FinderItem, editor: DocumentEditor) =
method previewItem*(self: FilePreviewer, item: FinderItem, editor: DocumentEditor) =
if not (editor of TextDocumentEditor):
return

Expand Down
13 changes: 7 additions & 6 deletions src/text/text_document.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1307,12 +1307,13 @@ proc enableAutoReload*(self: TextDocument, enabled: bool) =

proc setFileReadOnlyAsync*(self: TextDocument, readOnly: bool): Future[bool] {.async.} =
## Tries to set the underlying file permissions
# todo
# if self.vfs.setFileReadOnly(self.filename, readOnly).await:
# self.readOnly = readOnly
# return true

return false
try:
await self.vfs.setFileAttributes(self.filename, FileAttributes(writable: not readOnly, readable: true))
self.readOnly = readOnly
return true
except IOError as e:
log lvlError, &"Failed to change file permissions of '{self.filename}': {e.msg}"
return false

proc setFileAndContent*[S: string | Rope](self: TextDocument, filename: string, content: sink S) =
let filename = if filename.len > 0: filename else: self.filename
Expand Down
11 changes: 5 additions & 6 deletions src/text/text_editor.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1904,8 +1904,7 @@ proc checkoutFileAsync*(self: TextDocumentEditor) {.async.} =

log lvlInfo, &"Checkout result: {res}"

# todo
# self.document.setReadOnly(self.workspace.isFileReadOnly(path).await)
self.document.setReadOnly(self.vfs.getFileAttributes(path).await.mapIt(not it.writable).get(false))
self.markDirty()

proc checkoutFile*(self: TextDocumentEditor) {.expose("editor.text").} =
Expand Down Expand Up @@ -2501,7 +2500,7 @@ proc gotoLocationAsync(self: TextDocumentEditor, definitions: seq[Definition]):
data: encodeFileLocationForFinderItem(definition.filename, definition.location.some),
)

builder.previewer = newWorkspaceFilePreviewer(self.vfs, self.services).Previewer.some
builder.previewer = newFilePreviewer(self.vfs, self.services).Previewer.some

let finder = newFinder(newStaticDataSource(res), filterAndSort=true)
builder.finder = finder.some
Expand Down Expand Up @@ -2651,7 +2650,7 @@ proc openLineSelectorPopup(self: TextDocumentEditor, minScore: float, sort: bool
data: encodeFileLocationForFinderItem(self.document.filename, (i, 0).some),
)

builder.previewer = newWorkspaceFilePreviewer(self.vfs, self.services).Previewer.some
builder.previewer = newFilePreviewer(self.vfs, self.services).Previewer.some
let finder = newFinder(newStaticDataSource(res), filterAndSort=true, minScore=minScore, sort=sort)
builder.finder = finder.some

Expand All @@ -2675,7 +2674,7 @@ proc openSymbolSelectorPopup(self: TextDocumentEditor, symbols: seq[Symbol], nav
data: encodeFileLocationForFinderItem(symbol.filename, symbol.location.some),
)

builder.previewer = newWorkspaceFilePreviewer(self.vfs, self.services).Previewer.some
builder.previewer = newFilePreviewer(self.vfs, self.services).Previewer.some
let finder = newFinder(newStaticDataSource(res), filterAndSort=true)
builder.finder = finder.some

Expand Down Expand Up @@ -2756,7 +2755,7 @@ proc gotoWorkspaceSymbolAsync(self: TextDocumentEditor, query: string = ""): Fut
builder.scaleX = 0.85
builder.scaleY = 0.8

builder.previewer = newWorkspaceFilePreviewer(self.vfs, self.services).Previewer.some
builder.previewer = newFilePreviewer(self.vfs, self.services).Previewer.some
let finder = newFinder(newLspWorkspaceSymbolsDataSource(ls, self.workspace), filterAndSort=true)
builder.finder = finder.some

Expand Down
2 changes: 1 addition & 1 deletion src/vcs/vcs_api.nim
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ proc chooseGitActiveFiles*(self: VCSService, all: bool = false) {.expose("vcs").
let source = newAsyncCallbackDataSource () => self.getChangedFilesFromGitAsync(workspace, all)
var finder = newFinder(source, filterAndSort=true)

let previewer = newWorkspaceFilePreviewer(self.vfs, self.services,
let previewer = newFilePreviewer(self.vfs, self.services,
openNewDocuments=true)

var popup = newSelectorPopup(self.services, "git".some, finder.some, previewer.Previewer.toDisposableRef.some)
Expand Down
Loading

0 comments on commit 661be06

Please sign in to comment.