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 2, 2023
1 parent 54f52d8 commit 013f99c
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 4 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ Other features:

![completion](https://github.com/Freed-Wu/pkgbuild-language-server/assets/32936898/c060690c-071b-41a0-bde5-dce338f4e779)

![arch](https://github.com/termux/termux-language-server/assets/32936898/e10b40c6-515e-4d50-9526-d32ea26b9238)

![license](https://github.com/termux/termux-language-server/assets/32936898/13109df3-30ba-4371-ad0a-aa7f46c8e80a)

![depends](https://github.com/termux/termux-language-server/assets/32936898/a70b41ae-cf4b-44cc-bb10-a54cb5488f30)

## How Does It Work

For every subtype of bash, there exists one
Expand Down
11 changes: 11 additions & 0 deletions src/termux_language_server/packages/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
"""
from .. import FILETYPE

PACKAGE_VARIABLES = {
"PKGBUILD": {
"depends",
"makedepends",
"optdepends",
"conflicts",
"provides",
"replaces",
}
}


def search_package_document(name: str, filetype: FILETYPE) -> str:
r"""Search package document.
Expand Down
41 changes: 37 additions & 4 deletions src/termux_language_server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@
MinGWFinder,
PackageFinder,
)
from .packages import search_package_document, search_package_names
from .packages import (
PACKAGE_VARIABLES,
search_package_document,
search_package_names,
)
from .utils import get_filetype, get_schema


Expand Down Expand Up @@ -172,8 +176,12 @@ def hover(params: TextDocumentPositionParams) -> Hover | None:
"command_name",
}
):
# or package names (for PKGBUILD)
if parent.type == "array":
if (
parent.type == "array"
and parent.parent is not None
and parent.parent.children[0].text.decode()
in PACKAGE_VARIABLES.get(filetype, set())
):
result = search_package_document(text, filetype)
if result is None:
return None
Expand Down Expand Up @@ -221,7 +229,12 @@ def completions(params: CompletionParams) -> CompletionList:
if parent is None:
return CompletionList(False, [])
text = uni.get_text()
if parent.type == "array":
if (
parent.type == "array"
and parent.parent is not None
and parent.parent.children[0].text.decode()
in PACKAGE_VARIABLES.get(filetype, set())
):
return CompletionList(
False,
[
Expand All @@ -239,6 +252,26 @@ def completions(params: CompletionParams) -> CompletionList:
],
)
schema = get_schema(filetype)
if parent.type == "array" and parent.parent is not None:
items = (
schema["properties"]
.get(parent.parent.children[0].text.decode(), {})
.get("items", {})
)
enum = items.get(
"enum", items.get("oneOf", [{}])[0].get("enum", [])
)
return CompletionList(
False,
[
CompletionItem(
k,
kind=CompletionItemKind.Constant,
insert_text=k,
)
for k in enum
],
)
return CompletionList(
False,
[
Expand Down

0 comments on commit 013f99c

Please sign in to comment.