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

Differentiate assembler and opcode completions #20

Merged
merged 1 commit into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions src/spinasm_lsp/docs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
class DocumentationManager:
"""A manager for case-insensitive documentation lookups."""

_instructions = INSTRUCTIONS
instructions = INSTRUCTIONS
assemblers = ASSEMBLERS
data: dict[str, MarkdownGenerator] = {**INSTRUCTIONS, **ASSEMBLERS}

def __getitem__(self, key: str) -> str:
Expand All @@ -22,7 +23,7 @@ def get_markdown(self, key: str, default: str = "") -> str:
return str(self.data.get(key.upper(), default))

def get_instruction(self, key: str) -> Instruction | None:
return self._instructions.get(key.upper(), None)
return self.instructions.get(key.upper(), None)

def __contains__(self, key: str) -> bool:
return self.data.__contains__(key.upper())
Expand Down
17 changes: 15 additions & 2 deletions src/spinasm_lsp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,25 @@ async def completions(
value=ls.documentation.get_markdown(opcode),
),
)
for opcode in [k.upper() for k in ls.documentation]
for opcode in [k.upper() for k in ls.documentation.instructions]
]

assembler_completions = [
lsp.CompletionItem(
label=assembler,
kind=lsp.CompletionItemKind.Operator,
detail="(assembler)",
documentation=lsp.MarkupContent(
kind=lsp.MarkupKind.Markdown,
value=ls.documentation.get_markdown(assembler),
),
)
for assembler in [k.upper() for k in ls.documentation.assemblers]
]

return lsp.CompletionList(
is_incomplete=False,
items=symbol_completions + opcode_completions,
items=symbol_completions + opcode_completions + assembler_completions,
)


Expand Down
4 changes: 2 additions & 2 deletions tests/server_tests/test_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class CompletionTestCase(TestCase):
{
"name": "EQU",
"label": "EQU",
"detail": "(opcode)",
"kind": lsp.CompletionItemKind.Function,
"detail": "(assembler)",
"kind": lsp.CompletionItemKind.Operator,
"doc_contains": "**`EQU`** allows one to define symbolic operands",
"uri": f"file:///{PATCH_DIR / 'Basic.spn'}",
},
Expand Down
Loading