Skip to content

Commit

Permalink
✨ Support full features of LSP
Browse files Browse the repository at this point in the history
  • Loading branch information
Freed-Wu committed Dec 10, 2023
1 parent ab3db42 commit 5449ea4
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 18 deletions.
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,24 @@

A language server for zathura's zathurarc.

- [ ] [Diagnostic](https://microsoft.github.io/language-server-protocol/specifications/specification-current#diagnostic):
- [ ] option
- [x] [Diagnostic](https://microsoft.github.io/language-server-protocol/specifications/specification-current#diagnostic):
- [x] option value
- [x] function
- [x] argument
- [x] included paths must be unique
- [x] unmapped keys must be unique
- [x] [Hover](https://microsoft.github.io/language-server-protocol/specifications/specification-current#textDocument_hover)
- [x] option
- [x] keyword
- [x] command
- [x] [Completion](https://microsoft.github.io/language-server-protocol/specifications/specification-current#textDocument_completion)
- [x] option
- [x] keyword
- [x] command
- [x] mode
- [x] function
- [x] argument
- [x] included path

![Diagnostic](https://github.com/Freed-Wu/zathura-language-server/assets/32936898/45b75d73-d8ec-42b6-881e-8255e3a4f6b1)

![Document hover](https://github.com/Freed-Wu/zathura-language-server/assets/32936898/1399c992-9dfc-4b7f-9640-a66f0dff5432)

Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

platformdirs
pygls
# Fix wrong range
tree-sitter-lsp >= 0.0.6
# get_completion_list_by_enum()
tree-sitter-lsp >= 0.0.8
tree-sitter-zathurarc >= 0.0.3
webcolors
8 changes: 4 additions & 4 deletions src/zathura_language_server/assets/json/zathurarc.json
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@
}
]
},
"shortcut": {
"function": {
"type": "string",
"enum": [
"abort",
Expand Down Expand Up @@ -679,7 +679,7 @@
}
]
},
"shortcut": {
"function": {
"type": "string",
"enum": [
"abort",
Expand Down Expand Up @@ -803,7 +803,7 @@
}
]
},
"shortcut": {
"function": {
"type": "string",
"enum": [
"abort",
Expand Down Expand Up @@ -927,7 +927,7 @@
}
]
},
"shortcut": {
"function": {
"type": "string",
"enum": [
"abort",
Expand Down
6 changes: 3 additions & 3 deletions src/zathura_language_server/misc/zathurarc.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def init_schema() -> dict[str, Any]:
indices = []
end_index = len(tokens)
keys = []
shortcuts = []
functions = []
arguments = []
for i, token in enumerate(tokens):
if token.content == "OPTIONS":
Expand Down Expand Up @@ -67,7 +67,7 @@ def init_schema() -> dict[str, Any]:
for line in tokens[k + 5].content.splitlines()
][2:]
if token.content.replace("*", "") == "Shortcut functions":
shortcuts = [
functions = [
line.strip("- :").replace("*", " ").strip(" ")
for line in tokens[k + 5].content.splitlines()
if line.startswith("- ")
Expand Down Expand Up @@ -116,7 +116,7 @@ def init_schema() -> dict[str, Any]:
"additionalProperties": False,
"properties": {
"key": {"anyOf": anyOf},
"shortcut": {"type": "string", "enum": shortcuts},
"function": {"type": "string", "enum": functions},
"argument": {"type": "string", "enum": arguments + [None]},
},
"uniqueItems": True,
Expand Down
8 changes: 4 additions & 4 deletions src/zathura_language_server/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ def from_node(cls, node: Node, parent: "Trie | None") -> "Trie":
key: Node = node.children[1]
if key.type == "mode":
key: Node = key.next_sibling # type: ignore
shortcut: Node = key.next_sibling # type: ignore
argument = shortcut.next_sibling
function: Node = key.next_sibling # type: ignore
argument = function.next_sibling

value: dict[str, Trie] = trie.value # type: ignore
value["key"] = cls(UNI.node2range(key), trie, UNI.node2text(key)) # type: ignore
value["shortcut"] = cls(UNI.node2range(shortcut), trie, UNI.node2text(shortcut)) # type: ignore
if argument := shortcut.next_sibling:
value["function"] = cls(UNI.node2range(function), trie, UNI.node2text(function)) # type: ignore
if argument := function.next_sibling:
value["argument"] = cls(UNI.node2range(argument), trie, UNI.node2text(argument)) # type: ignore
return trie
if node.type == "unmap_directive":
Expand Down
18 changes: 17 additions & 1 deletion src/zathura_language_server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
TextDocumentPositionParams,
)
from pygls.server import LanguageServer
from tree_sitter_lsp.complete import get_completion_list_by_uri
from tree_sitter_lsp.complete import (
get_completion_list_by_enum,
get_completion_list_by_uri,
)
from tree_sitter_lsp.diagnose import get_diagnostics
from tree_sitter_lsp.finders import PositionFinder
from tree_sitter_zathurarc import parser
Expand Down Expand Up @@ -136,6 +139,19 @@ def completions(params: CompletionParams) -> CompletionList:
if x.startswith(text)
],
)
elif uni.node.type == "mode_name":
return get_completion_list_by_enum(
text,
{"enum": get_schema()["properties"]["map"]["properties"]},
)
# FIXME: find key node will get None
elif uni.node.type in {"key", "function", "argument"}:
return get_completion_list_by_enum(
text,
get_schema()["properties"]["map"]["properties"]["normal"][
"items"
]["properties"][uni.node.type],
)
elif uni.node.type == "path":
return get_completion_list_by_uri(
text,
Expand Down

0 comments on commit 5449ea4

Please sign in to comment.