Skip to content

Commit 2a84440

Browse files
Merge pull request #29 from DrKJeff16/patch/documentation
2 parents d5fdd79 + 6aa4019 commit 2a84440

8 files changed

Lines changed: 190 additions & 31 deletions

File tree

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
<div align="center">
2+
13
# wezterm-types
24

3-
Wezterm config types for Lua Language Server
5+
[Wezterm](https://github.com/wezterm/wezterm) config types for Lua Language Server
6+
7+
</div>
8+
9+
---
410

511
## Installation
612

@@ -74,7 +80,7 @@ local wezterm = require("wezterm")
7480
local config = wezterm.config_builder()
7581

7682
-- Your configuration here with full type support
77-
config.window_decorations = "RESIZE | MACOS_FORCE_DISABLE_SHADOW"
83+
config.window_decorations = "RESIZE|MACOS_FORCE_DISABLE_SHADOW"
7884

7985
return config
8086
```

lua/types/config/init.lua

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,33 @@
104104
---|"WindowsSymbols" like WindowsLong but using a logo for the Win key
105105

106106
---@class Config
107+
-- TODO: Finish
108+
---@field cell_widths? table
109+
---@field char_select_font? FontAttributes|FontFamilyAttributes
110+
---@field command_palette_font? any
111+
---@field command_palette_rows? any
112+
---@field cursor_thickness? any
113+
---@field default_ssh_auth_sock? any
114+
---@field font_antialias? any
115+
---@field font_hinting? any
116+
---@field font_rules? any
117+
---@field macos_fullscreen_extend_behind_notch? any
118+
---@field mux_enable_ssh_agent? any
119+
---@field notification_handling? any
120+
---@field pane_select_font? any
121+
---@field quick_select_remove_styling? any
122+
---@field reverse_video_cursor_min_contrast? any
123+
---@field show_close_tab_button_in_tabs? any
124+
---@field text_min_contrast_ratio? any
125+
---@field window_content_alignment? any
107126
-- When combined with `window_background_opacity`, enables background blur
108127
-- using the KDE Wayland blur protocol.
109128
--
110129
-- This can be used to produce a translucent window effect rather than
111130
-- a crystal clear transparent window effect
112131
---@field kde_window_background_blur? bool
113132
-- The baseline font to use
114-
---@field font? FontAttributes
133+
---@field font? FontAttributes|FontFamilyAttributes
115134
---@field dpi_by_screen? { [string]: f64 }
116135
-- The color palette
117136
---@field colors? Palette

lua/types/enum/key-assignment.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,4 +256,8 @@
256256
---@field ToggleFullScreen any
257257
---@field TogglePaneZoomState any
258258

259+
-- Helper for defining key assignment actions in your configuration file.
260+
-- This is really just sugar for the underlying Lua -> Rust deserialation mapping
261+
-- that makes it a bit easier to identify where syntax errors may exist
262+
-- in your configuration file
259263
---@alias Action ActionFuncClass|fun(action: ActionClass)

lua/types/init.lua

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@
470470
---|"MONOCHROME"
471471
---|"NO_AUTOHINT"
472472

473+
-- TODO: Find out what do the undocumented options do
473474
---@alias HarfbuzzFeatures
474475
---|"calt=0"
475476
---|"clig=0"
@@ -522,24 +523,31 @@
522523
---|"ss09" -- `>>=`, `<<=`, `||=`, `|=`
523524
---|"ss10"
524525

525-
---@alias Fonts { fonts: FontAttributes[] }
526-
527526
---@class FontAttributes
528-
---@field family? string
529527
-- Whether the font should be a bold variant
530528
---@field weight? FontWeight
531529
---@field stretch? FontStretch
532530
-- Whether the font should be an italic variant
533531
---@field style? FontStyle
532+
---@field is_fallback? bool
533+
---@field is_synthetic? bool
534+
---@field scale? number
535+
536+
-- `FontAttributes`-like class but with font family specified
537+
---@class FontFamilyAttributes: FontAttributes
538+
---@field family string
539+
540+
---@class FontFamilyExtendedAttributes: FontFamilyAttributes
541+
---@field harfbuzz_features? HarfbuzzFeatures[]
534542
---@field freetype_load_target? FreeTypeLoadTarget
535543
---@field freetype_render_target? FreeTypeLoadTarget
536544
-- you can combine the flags like `"NO_HINTING|MONOCHROME"`
537545
-- **(you probably wouldn't want to do this)**
538546
---@field freetype_load_flags? FreeTypeLoadFlags
539-
---@field is_fallback? bool
540-
---@field is_synthetic? bool
541547
---@field assume_emoji_presentation? bool
542-
---@field scale? number
548+
549+
---@class Fonts
550+
---@field fonts FontAttributes[]
543551

544552
---@class WindowFrameConfig
545553
---@field inactive_titlebar_bg? RgbColor
@@ -936,7 +944,7 @@
936944
---@field wezterm_version? string
937945
---@field aliases? string[]
938946

939-
---@alias ActionCallback fun(win: Window, pane: Pane, ...: any): (nil|false)
947+
---@alias ActionCallback fun(win: Window, pane: Pane, ...: any): false?
940948

941949
-- - `"Light"`: The normal appearance, with dark text on a light background
942950
-- - `"Dark"`: Dark mode with predominantly dark colors and probably a lighter,

lua/types/objects/ssh-domain.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
---@meta
22

3+
---@class SshHost
4+
---@field hostname string
5+
---@field identityagent string
6+
---@field identityfile string
7+
---@field port string
8+
---@field user string
9+
---@field userknownhostsfile string
10+
311
-- The `SshDomain` struct specifies information
412
-- about an individual [SSH Domain](https://wezterm.org/multiplexing.html#ssh-domains)
513
---@class SshDomain

lua/types/wezterm/gui/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
---@alias KeyDefaultTables Key[]|KeyDefault
77

8-
-- The `wezterm.gui` module exposes functions that operate on the gui layer.
8+
-- The `wezterm.gui` module exposes functions that operate on the GUI layer.
99
--
1010
-- The multiplexer may not be connected to a GUI, so attempting to
1111
-- resolve this module from the mux server will return `nil`

lua/types/wezterm/init.lua

Lines changed: 132 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,144 @@
1515
---@alias PathBuf string
1616

1717
---@class Wezterm: ExecDomain
18-
---@field GLOBAL table<string, ANY>
18+
-- Provides global, in-process, in-memory, data storage for JSON-like variables
19+
-- that persists across config reloads.
20+
--
21+
-- WezTerm's Lua files may be re-loaded and re-evaluated multiple times in different contexts
22+
-- or in different threads.
23+
-- If you'd like to keep track of state that lasts for the lifetime
24+
-- of your wezterm process then you cannot simply use
25+
-- global variables in the Lua script.
26+
--
27+
-- `wezterm.GLOBAL` is a special `userdata` value that acts like a table.
28+
-- Writing to keys will copy the data that you assign into a global in-memory table
29+
-- and allow it to be read back later.
30+
--
31+
-- Reads and writes from/to `wezterm.GLOBAL` are thread-safe but don't currently provide
32+
-- synchronization primitives for managing read-modify-write operations.
33+
--
34+
-- You may store values with the following types:
35+
--
36+
-- - `string`
37+
-- - `number`
38+
-- - `table`
39+
-- - `boolean`
40+
--
41+
-- **Attempting to assign other types will raise an error**
42+
---@field GLOBAL userdata
43+
-- The `wezterm.color` module exposes functions that work with colors
1944
---@field color Wezterm.Color
45+
-- The `wezterm.gui` module exposes functions that operate on the GUI layer.
46+
--
47+
-- The multiplexer may not be connected to a GUI, so attempting to
48+
-- resolve this module from the mux server will return `nil`
2049
---@field gui? Wezterm.Gui
2150
---@field mux Wezterm.Mux
2251
---@field nerdfonts Wezterm.NerdFont
52+
-- The `wezterm.plugin` module provides functions to manage Wezterm plugins
2353
---@field plugin Wezterm.Plugin
54+
-- The `wezterm.procinfo` module exposes functions that allow querying information
55+
-- about processes that are running on the local system
2456
---@field procinfo Wezterm.ProcInfo
57+
-- The `wezterm.serde` module provides functions for parsing the given string as
58+
-- JSON, YAML, or TOML, returning the corresponding Lua values, and vice versa
2559
---@field serde Wezterm.Serde
60+
-- The `wezterm.time` module exposes functions that allow working with time
2661
---@field time Wezterm.Time
62+
-- The `wezterm.url` module exposes functions that allow working with URLs
2763
---@field url Wezterm.Url
64+
-- Helper for defining key assignment actions in your configuration file.
65+
-- This is really just sugar for the underlying Lua -> Rust deserialation mapping
66+
-- that makes it a bit easier to identify where syntax errors may exist
67+
-- in your configuration file
2868
---@field action Action
29-
---@field action_callback (fun(win: Window, pane: Pane, ...: any): (nil|false))|(fun(callback: ActionCallback):Action)
30-
---@field add_to_config_reload_watch_list fun(path: string): nil Adds path to the list of files that are watched for config changes. If `automatically_reload_config` is enabled, then the config will be reloaded when any of the files that have been added to the watch list have changed.
31-
---@field background_child_process fun(args: string[]): nil Accepts an argument list; it will attempt to spawn that command in the background.
32-
---@field battery_info fun(): BatteryInfo[] Returns battery information for each of the installed batteries on the system. This is useful for example to assemble status information for the status bar.
33-
---@field column_width fun(string): number Given a string parameter, returns the number of columns that that text occupies in the terminal, which is useful together with format-tab-title and update-right-status to compute/layout tabs and status information.
34-
---@field config_builder fun(): Config Returns a config builder object that can be used to define your configuration.
35-
---@field config_dir string This constant is set to the path to the directory in which your wezterm.lua configuration file was found.
36-
---@field config_file string This constant is set to the path to the wezterm.lua that is in use.
69+
-- This function is a helper to register a custom event
70+
-- and return an action triggering it.
71+
--
72+
-- It is helpful to write custom key bindings directly,
73+
-- without having to declare the event and use it in a different place.
74+
--
75+
-- The implementation is essentially the same as:
76+
--
77+
-- ```lua
78+
-- function wezterm.action_callback(callback)
79+
-- local event_id = '...' -- the function generates a unique event id
80+
-- wezterm.on(event_id, callback)
81+
-- return wezterm.action.EmitEvent(event_id)
82+
-- end
83+
-- ```
84+
---@field action_callback fun(callback: ActionCallback): Action
85+
-- Adds path to the list of files that are watched for config changes.
86+
--
87+
-- If `automatically_reload_config` is enabled, then the config will be reloaded
88+
-- when any of the files that have been added to the watch list have changed
89+
---@field add_to_config_reload_watch_list fun(path: string)
90+
-- Accepts an argument list; it will attempt to spawn that command in the background
91+
---@field background_child_process fun(args: string[])
92+
-- Returns the battery information for each of the installed batteries on the system.
93+
--
94+
-- This is useful for example to assemble status information for the status bar
95+
---@field battery_info fun(): BatteryInfo[]
96+
-- Given a `string` parameter, returns the number of columns
97+
-- that text occupies in the terminal,
98+
-- which is useful together with `format-tab-title` and `update-right-status`
99+
-- to compute/layout tabs and status information
100+
---@field column_width fun(value: string): number
101+
-- Returns a `Config` object that can be used to define your configuration
102+
---@field config_builder fun(): Config
103+
-- This constant is set to the path to the directory
104+
-- in which your `wezterm.lua` configuration file was found
105+
---@field config_dir string
106+
-- This constant is set to the path to the `wezterm.lua` that is in use
107+
---@field config_file string
37108
---@field default_hyperlink_rules fun(): HyperLinkRule[] Returns the compiled-in default values for hyperlink_rules.
38-
---@field default_ssh_domains fun(): SshDomain[] Computes a list of SshDomain objects based on the set of hosts discovered in your ~/.ssh/config. Each host will have both a plain SSH and a multiplexing SSH domain generated and returned in the list of domains. The former don't require wezterm to be installed on the remote host, while the latter do require it. The intended purpose of this function is to allow you the opportunity to edit/adjust the returned information before assigning it to your config.
39-
---@field default_wsl_domains fun(): { name: string, distribution: string }[] Computes a list of WslDomain objects, each one representing an installed WSL distribution on your system. This list is the same as the default value for the wsl_domains configuration option, which is to make a WslDomain with the distribution field set to the name of WSL distro and the name field set to name of the distro but with "WSL:" prefixed to it.
40-
---@field emit fun(event: string, ...)
41-
---@field enumerate_ssh_hosts fun(ssh_config_file_name: string?): { [string] : { hostname: string, identityagent: string, identityfile: string, port: string, user: string, userknownhostsfile: string } } This function will parse your ssh configuration file(s) and extract from them the set of literal (non-pattern, non-negated) host names that are specified in Host and Match stanzas contained in those configuration files and return a mapping from the hostname to the effective ssh config options for that host. You may optionally pass a list of ssh configuration files that should be read, in case you have a special configuration.
42-
---@field executable_dir string This constant is set to the directory containing the wezterm executable file.
43-
---@field font (fun(font_attributes: FontAttributes): Fonts)|(fun(name: string, font_attributes: FontAttributes?): Fonts) https://wezfurlong.org/wezterm/config/lua/wezterm/font.html
44-
---@field font_with_fallback fun(fonts: string[]|FontAttributes[]): Fonts https://wezfurlong.org/wezterm/config/lua/wezterm/font_with_fallback.html
45-
---@field format fun(...: FormatItem[]): string Can be used to produce a formatted string with terminal graphic attributes such as bold, italic and colors. The resultant string is rendered into a string with wezterm compatible escape sequences embedded.
46-
---@field get_builtin_color_schemes any #TODO
47-
---@field glob fun(pattern: string, relative_to: string?): string[] This function evalutes the glob pattern and returns an array containing the absolute file names of the matching results. Due to limitations in the lua bindings, all of the paths must be able to be represented as UTF-8 or this function will generate an error.
109+
-- Computes a list of `SshDomain` objects based on the set of hosts
110+
-- discovered in `~/.ssh/config`.
111+
--
112+
-- Each host will have both a plain SSH and a multiplexing SSH domain
113+
-- generated and returned in the list of domains.
114+
-- The former don't require wezterm to be installed on the remote host,
115+
-- while the latter do require it.
116+
--
117+
-- The intended purpose of this function is to give you the opportunity
118+
-- to edit/adjust the returned information before assigning it to your config
119+
---@field default_ssh_domains fun(): SshDomain[]
120+
-- Computes a list of `WslDomain` objects, each one representing
121+
-- an installed WSL distribution on your system.
122+
--
123+
-- This list is the same as the default value for the `wsl_domains` configuration option,
124+
-- which is to make a `WslDomain` with the `distribution` field set to the name
125+
-- of the WSL distro and the `name` field set to name of the distro
126+
-- but with `"WSL:"` prefixed to it
127+
---@field default_wsl_domains fun(): WslDomain[]
128+
---@field emit fun(event: string, ...: any)
129+
-- This function will parse your ssh configuration file(s) and extract from them
130+
-- the set of literal (non-pattern, non-negated) host names that are specified
131+
-- in `Host` and `Match` stanzas contained in those configuration files
132+
-- and return a mapping from the hostname to the effective ssh config options for that host.
133+
--
134+
-- You may optionally pass a list of ssh configuration files that should be read
135+
-- in case you have a special configuration
136+
---@field enumerate_ssh_hosts fun(ssh_config_file_name: (string[]|string)?): table<string, SshHost>
137+
-- This constant is set to the directory containing the wezterm executable file
138+
---@field executable_dir string
139+
-- [Info](https://wezfurlong.org/wezterm/config/lua/wezterm/font.html)
140+
---@field font (fun(attributes: FontFamilyAttributes|FontFamilyExtendedAttributes): FontFamilyAttributes)|(fun(name: string, attributes: FontAttributes?): FontFamilyAttributes)
141+
-- [Info](https://wezfurlong.org/wezterm/config/lua/wezterm/font_with_fallback.html)
142+
---@field font_with_fallback fun(fonts: (string|FontAttributes)[]): Fonts
143+
--- Can be used to produce a formatted string with terminal graphic attributes
144+
--- such as `bold`, `italic` and `colors`.
145+
---
146+
--- The result is a string with wezterm-compatible escape sequences embedded
147+
---@field format fun(...: FormatItem[]): string
148+
---@field get_builtin_color_schemes any
149+
-- This function evalutes the glob pattern and returns an array
150+
-- containing the absolute file names of the matching results.
151+
--
152+
-- Due to limitations in the Lua bindings,
153+
-- all of the paths must be able to be represented as `UTF-8`
154+
-- or this function will generate an error
155+
---@field glob fun(pattern: string, relative_to: string?): string[]
48156
---@field has_action fun(action: string): boolean
49157
---@field home_dir string This constant is set to the home directory of the user running wezterm.
50158
---@field hostname fun(): string This function returns the current hostname of the system that is running wezterm. This can be useful to adjust configuration based on the host.
@@ -74,5 +182,9 @@
74182
---@field truncate_left fun(string: string, max_width: number): string Returns a copy of string that is no longer than max_width columns (as measured by wezterm.column_width). Truncation occurs by reemoving excess characters from the left end of the string.
75183
---@field truncate_right fun(string: string, max_width: number): string Returns a copy of string that is no longer than max_width columns (as measured by wezterm.column_width). Truncation occurs by reemoving excess characters from the right end of the string.
76184
---@field utf16_to_utf8 fun(string: string): string Overly specific and exists primarily to workaround this wsl.exe issue. It takes as input a string and attempts to convert it from utf16 to utf8.
77-
---@field version string This constant is set to the wezterm version string that is also reported by running wezterm -V. This can potentially be used to adjust configuration according to the installed version.
185+
-- This constant is set to the wezterm version string that is also reported
186+
-- by running `wezterm -V`.
187+
--
188+
-- This can potentially be used to adjust configuration according to the installed version
189+
---@field version string
78190
---@field gradient_colors fun(gradient: Gradient, num_colors: number): Color[]

lua/types/wezterm/nerdfonts/init.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
---@meta
22

3+
-- NOTE: (DrKJeff16) I am not touching this file ever again
4+
35
---@class (exact) Wezterm.NerdFont
46
---@field cod_account string
57
---@field cod_activate_breakpoints string

0 commit comments

Comments
 (0)