Skip to content

Commit

Permalink
🚸 Improve completion
Browse files Browse the repository at this point in the history
  • Loading branch information
Freed-Wu committed Dec 21, 2023
1 parent 0891b6a commit de669ab
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/mutt_language_server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,15 @@ def hover(params: TextDocumentPositionParams) -> Hover | None:
word, _range = self._cursor_word(
params.text_document.uri, params.position, True
)
result = get_schema().get(word)
if not result:
properties = get_schema().get("properties", {})
if _range.start.character != 0:
properties = properties.get("set", {}).get("properties", {})
description = properties.get(word, {}).get("description", {})
if not description:
return None
return Hover(MarkupContent(MarkupKind.Markdown, result), _range)
return Hover(
MarkupContent(MarkupKind.Markdown, description), _range
)

@self.feature(TEXT_DOCUMENT_COMPLETION)
def completions(params: CompletionParams) -> CompletionList:
Expand All @@ -89,21 +94,26 @@ def completions(params: CompletionParams) -> CompletionList:
:type params: CompletionParams
:rtype: CompletionList
"""
word, _ = self._cursor_word(
word, _range = self._cursor_word(
params.text_document.uri, params.position, False
)
properties = get_schema().get("properties", {})
if _range.start.character != 0:
properties = properties.get("set", {}).get("properties", {})
items = [
CompletionItem(
x,
kind=(
CompletionItemKind.Constant
if doc.startswith("Type:")
if property.get("description", "").startswith("Type:")
else CompletionItemKind.Function
),
documentation=MarkupContent(MarkupKind.Markdown, doc),
documentation=MarkupContent(
MarkupKind.Markdown, property.get("description", "")
),
insert_text=x,
)
for x, doc in get_schema().items()
for x, property in properties.items()
if x.startswith(word)
]
return CompletionList(False, items)
Expand Down

0 comments on commit de669ab

Please sign in to comment.