Skip to content

Commit 0db6eac

Browse files
feat: command completions when using bolt
1 parent 08d5480 commit 0db6eac

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

aegis-server/aegis_server/__main__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ def did_change(ls: AegisServer, params: lsp.DidChangeTextDocumentParams):
3535
def did_open(ls: AegisServer, params: lsp.DidOpenTextDocumentParams):
3636
asyncio.run(publish_diagnostics(ls, params))
3737

38-
3938
@server.thread()
4039
@server.feature(
4140
lsp.TEXT_DOCUMENT_COMPLETION,
@@ -82,7 +81,7 @@ def hover(ls: AegisServer, params: lsp.HoverParams):
8281
@server.feature(lsp.TEXT_DOCUMENT_RENAME)
8382
def rename(ls: AegisServer, params: lsp.RenameParams):
8483
return asyncio.run(rename_variable(ls, params))
85-
84+
8685
@server.command("mecha.server.dumpIndices")
8786
def dump(ls: AegisServer, *args):
8887
for _, i in ls._instances.values():
@@ -117,6 +116,7 @@ def add_arguments(parser: argparse.ArgumentParser):
117116
help="Show the AST node for the hovered token",
118117
)
119118

119+
120120
def main():
121121
print("Starting Aegis Server")
122122
parser = argparse.ArgumentParser()

aegis-server/aegis_server/server/features/completion.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import builtins
2+
import logging
23

34
from aegis_server.providers.variable import add_raw_definition, add_variable_definition
4-
from bolt import Runtime, UndefinedIdentifier
5+
from bolt import Runtime, UnboundLocalIdentifier, UndefinedIdentifier
56
from lsprotocol import types as lsp
67
from mecha import (
78
AstOption,
@@ -133,7 +134,10 @@ def get_diag_completions(
133134
pattern if isinstance(pattern, tuple) else [pattern, None]
134135
)
135136
items += get_token_options(mecha, token_type, value)
136-
break
137+
138+
if isinstance(diagnostic, UnboundLocalIdentifier):
139+
for name in mecha.spec.tree.children.keys(): #type: ignore
140+
items.append(lsp.CompletionItem(name, kind = lsp.CompletionItemKind.Keyword))
137141

138142
if isinstance(diagnostic, UndefinedIdentifier):
139143
for name, variable in diagnostic.lexical_scope.variables.items():
@@ -145,5 +149,4 @@ def get_diag_completions(
145149
for name in runtime.builtins:
146150
add_raw_definition(items, name, getattr(builtins, name))
147151

148-
break
149152
return lsp.CompletionList(False, items)

aegis-server/aegis_server/server/features/validate.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,9 @@ async def parse_function(
223223

224224
# # Parse the stream
225225
mecha = ctx.inject(Mecha)
226-
compilation_unit = mecha.database[file_instance]
227226
runtime = ctx.inject(Runtime)
227+
228+
compilation_unit = mecha.database[file_instance]
228229
compiled_module = runtime.modules.registry.get(file_instance)
229230

230231
return CompiledDocument(
@@ -355,5 +356,5 @@ async def compile(
355356
logging.error("\n".join(traceback.format_tb(cause.__traceback__)))
356357

357358
logging.debug(f"Execution took {time.time() - start}s")
358-
await asyncio.sleep(0)
359+
359360
return indexer.output_ast, diagnostics

0 commit comments

Comments
 (0)