Skip to content

Commit

Permalink
Fixed some issues and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Nimaoth committed Oct 12, 2024
1 parent c68a377 commit 32e0ba2
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 16 deletions.
8 changes: 8 additions & 0 deletions src/app.nim
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ proc registerEditor*(self: App, editor: DocumentEditor): void
proc unregisterEditor*(self: App, editor: DocumentEditor): void
proc tryActivateEditor*(self: App, editor: DocumentEditor): void
proc getActiveEditor*(self: App): Option[DocumentEditor]
proc getActiveViewEditor*(self: App): Option[DocumentEditor]
proc getEditorForId*(self: App, id: EditorId): Option[DocumentEditor]
proc getEditorForPath*(self: App, path: string): Option[DocumentEditor]
proc getPopupForId*(self: App, id: EditorId): Option[Popup]
Expand Down Expand Up @@ -319,6 +320,7 @@ implTrait AppInterface, App:
registerEditor(void, App, DocumentEditor)
tryActivateEditor(void, App, DocumentEditor)
getActiveEditor(Option[DocumentEditor], App)
getActiveViewEditor(Option[DocumentEditor], App)
unregisterEditor(void, App, DocumentEditor)
getEditorForId(Option[DocumentEditor], App, EditorId)
getEditorForPath(Option[DocumentEditor], App, string)
Expand Down Expand Up @@ -3736,6 +3738,12 @@ proc getActiveEditor*(self: App): Option[DocumentEditor] =

return DocumentEditor.none

proc getActiveViewEditor*(self: App): Option[DocumentEditor] =
if self.tryGetCurrentEditorView().getSome(view):
return view.editor.some

return DocumentEditor.none

proc logRootNode*(self: App) {.expose("editor").} =
let str = self.platform.builder.root.dump(true)
debug "logRootNode: ", str
Expand Down
1 change: 1 addition & 0 deletions src/app_interface.nim
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ traitRef AppInterface:
method unregisterEditor*(self: AppInterface, editor: DocumentEditor): void {.gcsafe, raises: [].}
method tryActivateEditor*(self: AppInterface, editor: DocumentEditor) {.gcsafe, raises: [].}
method getActiveEditor*(self: AppInterface): Option[DocumentEditor] {.gcsafe, raises: [].}
method getActiveViewEditor*(self: AppInterface): Option[DocumentEditor] {.gcsafe, raises: [].}
method getEditorForId*(self: AppInterface, id: EditorId): Option[DocumentEditor] {.gcsafe, raises: [].}
method getEditorForPath*(self: AppInterface, path: string): Option[DocumentEditor] {.gcsafe, raises: [].}
method getPopupForId*(self: AppInterface, id: EditorId): Option[Popup] {.gcsafe, raises: [].}
Expand Down
2 changes: 1 addition & 1 deletion src/dispatch_tables.nim
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ proc extendActiveDispatchTable*(namespace: string, function: ExposedFunction) =
if table.namespace == namespace:
table.functions[function.name] = function
return
addActiveDispatchTable(namespace, [function])
addActiveDispatchTable(namespace, [function])
2 changes: 1 addition & 1 deletion src/language_server_command_line.nim
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ method getCompletions*(self: LanguageServerCommandLine, filename: string, locati

var completions: seq[CompletionItem]
if useActive:
let currentNamespace = self.app.getActiveEditor().mapIt(it.getNamespace)
let currentNamespace = self.app.getActiveViewEditor().mapIt(it.getNamespace)
{.gcsafe.}:
for table in activeDispatchTables.mitems:
if not table.global and table.namespace.some != currentNamespace:
Expand Down
27 changes: 13 additions & 14 deletions src/service.nim
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,21 @@ proc initService(self: Services, name: string) {.async.} =
service.state = Failed

proc addService*(self: Services, name: string, service: Service, dependencies: seq[string] = @[]) =
log lvlInfo, &"addService {name}"
log lvlInfo, &"addService {name}, dependencies: {dependencies}"
service.services = self
self.registered[name] = service
service.state = Registered

var dependencies = dependencies
for name in self.running.keys:
let idx = dependencies.find(name)
if idx != -1:
dependencies.removeSwap(idx)

if dependencies.len == 0:
asyncSpawn self.initService(name)
else:
log lvlInfo, &"addService {name}, remaining dependencies: {dependencies}"
self.dependencies[name] = dependencies

proc getService*(self: Services, T: typedesc): Option[T] {.gcsafe, raises: [].} =
Expand All @@ -96,26 +103,19 @@ proc getServiceAsync*(self: Services, T: typedesc): Future[Option[T]] {.gcsafe,
proc addService*[T: Service](self: Services, service: T) {.gcsafe, raises: [].} =
self.addService(T.serviceName, service)

# func addBuiltinServiceImpl(T: NimNode, name: static string, names: static seq[string], dependencies: varargs[typed]) =
# echo "addBuiltinService ", T.treeRepr, ", ", dependencies.treeRepr
# builtinServices.add nnkTupleExpr.newTree(T, genAst(T, T.serviceName))

macro addBuiltinServiceImpl(T: typed, name: static string, names: static seq[string], dependencies: varargs[typed]) =
echo "addBuiltinService ", T.treeRepr, ", ", dependencies.treeRepr
macro addBuiltinServiceImpl(T: typed, name: static string, dependencies: static seq[string]) =
var dependencyNames = nnkBracket.newTree()
for n in names:
for n in dependencies:
dependencyNames.add n.newLit

builtinServices.add nnkBracket.newTree(T, newLit(name), nnkPrefix.newTree(ident"@", dependencyNames))

macro addBuiltinService*(T: typed, dependencies: varargs[typed]) =
echo "addBuiltinService ", T.treeRepr, ", ", dependencies.treeRepr
var dependencyNames = nnkPrefix.newTree(ident"@", nnkBracket.newTree())
for d in dependencies:
dependencyNames.add genAst(d, d.serviceName)
echo dependencyNames.treeRepr
result = genAst(T, dependencies):
addBuiltinServiceImpl(T, T.serviceName, @[], dependencies)
dependencyNames[1].add genAst(d, d.serviceName)
result = genAst(T, dependencyNames):
addBuiltinServiceImpl(T, T.serviceName, dependencyNames)

macro addBuiltinServices*(services: Services) =
result = nnkStmtList.newTree()
Expand All @@ -124,7 +124,6 @@ macro addBuiltinServices*(services: Services) =
let T = serviceInfo[0]
let name = serviceInfo[1]
let dependencies = serviceInfo[2]
echo serviceInfo.treeRepr
result.add genAst(services, T, name, dependencies, services.addService(name, T(), dependencies))

echo result.repr
10 changes: 10 additions & 0 deletions src/text/language/debugger.nim
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ type
scopes*: Table[(ThreadId, FrameId), Scopes]
variables*: Table[(ThreadId, FrameId, VariablesReference), Variables]

type
DebuggerService = ref object of Service

func serviceName*(_: typedesc[DebuggerService]): string = "DebuggerService"
addBuiltinService(DebuggerService)

method init*(self: DebuggerService): Future[Result[void, ref CatchableError]] {.async: (raises: []).} =
log lvlInfo, &"DebuggerService.init"
return ok()

proc applyBreakpointSignsToEditor(self: Debugger, editor: TextDocumentEditor)
proc handleAction(self: Debugger, action: string, arg: string): EventResponse
proc updateVariables(self: Debugger, variablesReference: VariablesReference, maxDepth: int) {.async.}
Expand Down

0 comments on commit 32e0ba2

Please sign in to comment.