Skip to content

Commit

Permalink
🍱 Update json schema
Browse files Browse the repository at this point in the history
  • Loading branch information
Freed-Wu committed Dec 9, 2023
1 parent cdf6049 commit a8ab9ba
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
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 @@ -6,8 +6,8 @@
"additionalProperties": false,
"properties": {
"set": {
"description": "Changing options\nIn addition to the built-in **:set** command zathura offers more options to be changed and makes those changes permanent. To overwrite an option you just have to add a line structured like the following\nset <option> <new value> \nThe **option** field has to be replaced with the name of the option that should be changed and the **new value** field has to be replaced with the new value the option should get. The type of the value can be one of the following:\nINT - An integer number\nFLOAT - A floating point number\nSTRING - A character string\nBOOL - A boolean value (\\\"true\\\" for true, \\\"false\\\" for false)\nIn addition we advice you to check the options to get a more detailed view of the options that can be changed and which values they should be set to.\nThe following example should give some deeper insight of how the **set** command can be used\nset option1 5 set option2 2.0 set option3 hello set option4 hello\\ world set option5 \"hello world\" \nEspecially for options with strings as values, note that escaping of special characters and white spaces is necessary. In the above example, **option4** and **option5** are both set to **hello** world, but **set option6 hello world** would set **option6** only to **hello**.\nFor colors, zathura supports HTML color codes and CSS3-style **rgb(r,g,b)** and **rgba(r,g,b,a)** values. If you want to use color codes for some options, make sure to quote them accordingly or to escape the hash symbol.\nset default-fg \"#CCBBCC\" set default-fg \\#CCBBCC \nFor **rgba**, note that it parses the color components as integers between 0 and 255 and the alpha component as float between 0 and 1.",
"type": "object",
"description": "# Changing options\nIn addition to the built-in **:set** command zathura offers more options\nto be changed and makes those changes permanent. To overwrite an option\nyou just have to add a line structured like the following\n```zathurarc\nset <option> <new value>\n\n```",
"properties": {
"n-completion-items": {
"description": "Defines the maximum number of displayed completion entries.",
Expand Down Expand Up @@ -496,13 +496,13 @@
"additionalProperties": false
},
"include": {
"description": "Including another config file\nThis commands allows one to include other configuration files. If a relative path is given, the path will be resolved relative to the configuration file that is currently processed.\ninclude another-config ",
"type": "array",
"description": "# Including another config file\nThis commands allows one to include other configuration files. If a\nrelative path is given, the path will be resolved relative to the\nconfiguration file that is currently processed.\n```zathurarc\ninclude another-config\n\n```",
"uniqueItems": true
},
"map": {
"description": "Mapping a shortcut\nIt is possible to map or remap new key bindings to shortcut functions which allows a high level of customization. The **:map** command can also be used in the *zathurarc* file to make those changes permanent:\nmap [mode] <binding> <shortcut function> <argument> \n***Mode***\n: The **map** command expects several arguments where only the **binding** as well as the **shortcut-function** argument is required. Since zathura uses several modes it is possible to map bindings only for a specific mode by passing the **mode** argument which can take one of the following values:\n- normal (default) - fullscreen - presentation - index \nThe brackets around the value are mandatory.\n***Single* key binding**\n: The (possible) second argument defines the used key binding that should be mapped to the shortcut function and is structured like the following. On the one hand it is possible to just assign single letters, numbers or signs to it:\n> map a shortcut_function optional_argument > map b shortcut_function optional_argument > map c shortcut_function optional_argument > map 1 shortcut_function optional_argument > map 2 shortcut_function optional_argument > map 3 shortcut_function optional_argument > map ! shortcut_function optional_argument > map ? shortcut_function optional_argument \n***Using* modifiers**\n: It is also possible to use modifiers like the Control or Alt button on the keyboard. It is possible to use the following modifiers:\n- A - Alt - C - Control - S - Shift \nIf any of the modifiers should be used for a binding, it is required to define the **binding** with the following structure:\nmap <A-a> shortcut_function map <C-a> shortcut_function \n***Special* keys**\n: zathura allows it also to assign keys like the space bar or the tab button which also have to be written in between angle brackets. The following special keys are currently available:\n> Identifier Description > > BackSpace Back space > CapsLock Caps lock > Esc Escape > Down Arrow down > Up Arrow up > Left Arrow left > Right Arrow right > F1 F1 > F2 F2 > F3 F3 > F4 F4 > F5 F5 > F6 F6 > F7 F7 > F8 F8 > F9 F9 > F10 F10 > F11 F11 > F12 F12 > PageDown Page Down > PageUp Page Up > Return Return > Space Space > Super Windows key > Tab Tab > Print Print key \nOf course it is possible to combine those special keys with a modifier. The usage of those keys should be explained by the following examples:\nmap <Space> shortcut_function map <C-Space> shortcut_function \n***Mouse* buttons**\n: It is also possible to map mouse buttons to shortcuts by using the following special keys:\n> Identifier Description > > Button1 Mouse button 1 > Button2 Mouse button 2 > Button3 Mouse button 3 > Button4 Mouse button 4 > Button5 Mouse button 5 \nThey can also be combined with modifiers:\nmap <Button1> shortcut_function map <C-Button1> shortcut_function \n***Buffer* commands**\n: If a mapping does not match one of the previous definition but is still a valid mapping it will be mapped as a buffer command:\n> map abc quit > map test quit \n***Shortcut* functions**\n: The following shortcut functions can be mapped:\n- **abort** Switch back to normal mode. - **adjust_window** Adjust page width. Possible arguments are **best-fit** and **width**. - **change_mode** Change current mode. Pass the desired mode as argument. - **display_link**: Display link target. - **exec**: Execute an external command. **\\$FILE** expands to the current document path, and **\\$PAGE** to the current page number. - **focus_inputbar** Focus inputbar. - **follow** Follow a link. - **goto** Go to a certain page. - **jumplist** Move forwards/backwards in the jumplist. Pass **forward** as argument to move to the next entry and **backward** to move to the previous one. - **navigate** Navigate to the next/previous page. - **navigate_index** Navigate through the index. - **print** Show the print dialog. - **quit** Quit zathura. - **recolor** Recolor pages. - **reload** Reload the document. - **rotate** Rotate the page. Pass **rotate-ccw** as argument for counterclockwise rotation and **rotate-cw** for clockwise rotation. - **scroll** Scroll. - **search** Search next/previous item. Pass **forward** as argument to search for the next hit and **backward** to search for the previous hit. - **set** Set an option. - **snap_to_page** Snaps to the current page. Equivalent to **goto \\<current_page\\>** - **toggle_fullscreen** Toggle fullscreen. - **toggle_index** Show or hide index. - **toggle_inputbar** Show or hide inputbar. - **toggle_page_mode** Toggle between one and multiple pages per row. - **toggle_statusbar** Show or hide statusbar. - **zoom** Zoom in or out. - **mark_add** Set a quickmark. - **mark_evaluate** Go to a quickmark. - **feedkeys** Simulate key presses. Note that all keys will be interpreted as if pressing a key on the keyboard. To input uppercase letters, follow the same convention as for key bindings, i.e. for **X**, use **\\<S-X\\>**. \n***Pass* arguments**\n: Some shortcut function require or have optional arguments which influence the behaviour of them. Those can be passed as the last argument:\n> map <C-i> zoom in > map <C-o> zoom out \nPossible arguments are:\nbest-fit\nbottom\nbackward\ncollapse\ncollapse-all\ndefault\ndown\nexpand\nexpand-all\nforward\nfull-down\nfull-up\nhalf-down\nhalf-up\nin\nleft\nnext\nout\npage-bottom\npage-top\nprevious\nright\nrotate-ccw\nrotate-cw\nselect\nspecific\ntoggle\ntop\nup\nwidth",
"type": "object",
"description": "# Mapping a shortcut\nIt is possible to map or remap new key bindings to shortcut functions\nwhich allows a high level of customization. The **:map** command can\nalso be used in the *zathurarc* file to make those changes permanent:\n```zathurarc\nmap [mode] <binding> <shortcut function> <argument>\n\n```",
"additionalProperties": false,
"properties": {
"normal": {
Expand Down Expand Up @@ -592,8 +592,8 @@
}
},
"unmap": {
"description": "Removing a shortcut\nIn addition to mapping or remaping custom key bindings it is possible to remove existing ones by using the **:unmap** command. The command is used in the following way (the explanation of the parameters is described in the **map** section of this document\nunmap [mode] <binding> ",
"type": "object",
"description": "# Removing a shortcut\nIn addition to mapping or remaping custom key bindings it is possible to\nremove existing ones by using the **:unmap** command. The command is\nused in the following way (the explanation of the parameters is\ndescribed in the **map** section of this document\n```zathurarc\nunmap [mode] <binding>\n\n```",
"additionalProperties": false,
"properties": {
"normal": {
Expand Down
22 changes: 17 additions & 5 deletions src/zathura_language_server/misc/zathurarc.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,30 @@ def init_schema() -> dict[str, Any]:
for i, index in enumerate(indices):
keyword, _, description = tokens[index].content.partition(" - ")
schemas[filetype]["properties"][keyword] = {
"description": description,
"type": "object",
}
if len(indices) - 1 == i:
index2 = end_index
else:
index2 = indices[i + 1]
data = []
for token in tokens[index + 1 : index2]:
if token.content != "" and not token.content.startswith("<!--"):
schemas[filetype]["properties"][keyword][
"description"
] += "\n" + re.sub(r"\n\s*", " ", token.content)
if len(data) == 2:
break
if token.content == "" or token.content.startswith("<!--"):
continue
data += [token.content]
# TODO: mode, shortcut, argument
# if keyword == "map":
# for k, token in enumerate(tokens[index + 1 : index2]):
# pass
schemas[filetype]["properties"][keyword][
"description"
] = f"""# {description}
{data[0]}
```zathurarc
{data[1]}
```"""
schemas[filetype]["properties"]["include"]["type"] = "array"
schemas[filetype]["properties"]["include"]["uniqueItems"] = True
for key in {"map", "unmap"}:
Expand Down

0 comments on commit a8ab9ba

Please sign in to comment.