Skip to content

Commit

Permalink
🧑‍💻 Improve generated schema
Browse files Browse the repository at this point in the history
  • Loading branch information
Freed-Wu committed Dec 4, 2023
1 parent ef82233 commit 8b436ba
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 35 deletions.
24 changes: 12 additions & 12 deletions src/zathura_language_server/assets/json/zathurarc.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,12 @@
},
"adjust-open": {
"description": "Defines which auto adjustment mode should be used if a document is loaded. Possible options are \\\"best-fit\\\" and \\\"width\\\".",
"type": "string",
"default": "best-fit",
"enum": [
"best-fit",
"width"
]
],
"type": "string",
"default": "best-fit"
},
"advance-pages-per-row": {
"description": "Defines if the number of pages per row should be honored when advancing a page.",
Expand All @@ -186,13 +186,13 @@
},
"database": {
"description": "Defines the database backend to use for bookmarks and input history. Possible values are \\\"plain\\\", \\\"sqlite\\\" (if built with sqlite support) and \\\"null\\\". If \\\"null\\\" is used, bookmarks and input history will not be stored.",
"type": "string",
"default": "plain",
"enum": [
"plain",
"sqlite",
"null"
]
],
"type": "string",
"default": "plain"
},
"dbus-service": {
"description": "En/Disables the D-Bus service. If the services is disabled, SyncTeX forward synchronization is not available.",
Expand All @@ -206,13 +206,13 @@
},
"filemonitor": {
"description": "Defines the file monitor backend used to check for changes in files. Possible values are \\\"glib\\\", \\\"signal\\\" (if signal handling is supported), and \\\"noop\\\". The \\\"noop\\\" file monitor does not trigger reloads.",
"type": "string",
"default": "glib",
"enum": [
"glib",
"signal",
"noop"
]
],
"type": "string",
"default": "glib"
},
"incremental-search": {
"description": "En/Disables incremental search (search while typing).",
Expand Down Expand Up @@ -473,13 +473,13 @@
},
"sandbox": {
"description": "Defines the sandbox mode to use for the seccomp syscall filter. Possible values are \\\"none\\\", \\\"normal\\\" and \\\"strict\\\". If \\\"none\\\" is used, the sandbox will be disabled. The use of \\\"normal\\\" will provide minimal protection and allow normal use of zathura with support for all features. The \\\"strict\\\" mode is a read only sandbox that is intended for viewing documents only.",
"type": "string",
"default": "normal",
"enum": [
"none",
"normal",
"strict"
]
],
"type": "string",
"default": "normal"
},
"window-icon-document": {
"description": "Defines whether the window document should be updated based on the first page of a dcument.",
Expand Down
51 changes: 28 additions & 23 deletions src/zathura_language_server/misc/zathurarc.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,31 @@ def init_schema() -> dict[str, Any]:
.get("description")
is None
):
description = " ".join(
line.strip()
for line in token.content.lstrip(": ").splitlines()
)
schemas[filetype]["properties"]["set"]["properties"][
keyword
] = {
"description": " ".join(
line.strip()
for line in token.content.lstrip(": ").splitlines()
)
}
] = {"description": description}
if (
description.find("Possible values are ")
== description.find("Possible options are ")
== -1
):
continue
schemas[filetype]["properties"]["set"]["properties"][
keyword
]["enum"] = [
value.split(" ")[0].replace('\\"', "")
for value in description.rpartition(
"Possible values are "
)[2]
.rpartition("Possible options are ")[2]
.partition(".")[0]
.replace(" and ", ", ")
.split(", ")
]
continue
for line in token.content.splitlines():
if line.find("Value type: ") != -1:
Expand Down Expand Up @@ -127,31 +144,19 @@ def init_schema() -> dict[str, Any]:
schemas[filetype]["properties"]["set"][
"properties"
][keyword]["format"] = "color"
schemas[filetype]["properties"]["set"]["properties"]["guioptions"][
"pattern"
] = r"[cshv]*"
schemas[filetype]["properties"]["set"]["properties"]["database"][
"enum"
] = ["plain", "sqlite", "null"]
schemas[filetype]["properties"]["set"]["properties"]["adjust-open"][
"enum"
] = ["best-fit", "width"]
schemas[filetype]["properties"]["set"]["properties"]["filemonitor"][
"enum"
] = ["glib", "signal", "noop"]

schemas[filetype]["properties"]["set"]["properties"][
"highlight-transparency"
] |= {"minimum": 0, "maximum": 1}

schemas[filetype]["properties"]["set"]["properties"]["guioptions"][
"pattern"
] = r"[cshv]*"
schemas[filetype]["properties"]["set"]["properties"]["first-page-column"][
"pattern"
] = r"\d+(:\d+)*"
schemas[filetype]["properties"]["set"]["properties"][
"selection-clipboard"
]["enum"] = ["clipboard", "primary"]
schemas[filetype]["properties"]["set"]["properties"]["sandbox"]["enum"] = [
"none",
"normal",
"strict",
]

return schemas

0 comments on commit 8b436ba

Please sign in to comment.