Skip to content

Commit

Permalink
overhaul ZLS documentation
Browse files Browse the repository at this point in the history
- split documentation into separate pages
- update editor configuration (every single one, no exceptions)
- add documentation for zls.json JSON Schema
- add documentation for Zed
- add documentation for Code Actions
- add "Build-On-Save" Guide
- add "View Logs" Guide
- add table of contents as a sidebar
- clearly document support for in-editor configuration for each Editor
- mark Emacs Documentation as incomplete #1
- minor styling changes

fixes #6
  • Loading branch information
Techatrix committed Nov 14, 2024
1 parent f32db7e commit 543a7f4
Show file tree
Hide file tree
Showing 30 changed files with 1,467 additions and 650 deletions.
144 changes: 107 additions & 37 deletions assets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,31 @@ header {
flex-direction: column;
}

nav {
#main-nav, .release-nav {
display: flex;
justify-content: center;
gap: 1rem;
padding: 0.75rem 0;
}

@media (max-width: 800px) {
nav {
#content {
display: flex;
flex-direction: column;
flex: 1;
align-self: center;
box-sizing: border-box;
padding: 0 1.5rem;
max-width: min(100%, 800px);
}

#main-nav {
font-size: larger;
border-bottom: thick solid var(--zig-orange);
background-color: var(--nav-background-color);
}

@media (max-width: 600px) {
#main-nav {
flex-direction: column;
}
}
Expand Down Expand Up @@ -47,12 +63,56 @@ pre {
border: 0 dashed;
border-top-width: 1px;
border-bottom-width: 1px;
padding: 0.4rem 0.25rem;
padding: 0;
overflow: auto;
background-color: var(--pre-background-color);
background-color: var(--secondary-background-color);
border-color: var(--border-color);
}


@media (min-width: 600px) {
pre {
margin: 1rem;
}
}

pre code {
background-color: var(--secondary-background-color);
padding: 0.4rem 0.25rem;
display: block;
padding-right: 0;
}

pre::before {
display: block;
font-size: 1.2em;
padding: 0.5rem;
position: sticky;
z-index: 10;
background-color: var(--tertiary-background-color);
color: var(--code-text-color);
}

pre:has(> code.zig):before {
content: "Zig";
}

pre:has(> code.json):before {
content: "JSON";
}

pre:has(> code.lua):before {
content: "Lua";
}

pre:has(> code.vim):before {
content: "Vim";
}

pre:has(> code.toml):before {
content: "TOML";
}

p:has(+ pre) {
margin-bottom: 0;
}
Expand Down Expand Up @@ -92,6 +152,7 @@ h6 {

h1 {
font-size: 2.75rem;
text-align: center;
}

h2 {
Expand Down Expand Up @@ -131,7 +192,7 @@ td {
}

tr:nth-child(2n) > td {
background-color: var(--pre-background-color);
background-color: var(--secondary-background-color);
}

/* Figure */
Expand All @@ -143,6 +204,11 @@ figure {

figure img {
max-width: 100%;
height: auto;
}

figure figcaption {
text-align: center;
}

/* Lists */
Expand All @@ -151,53 +217,56 @@ ul {
padding-left: 1.5rem;
}

li + li {
margin-top: 0.6rem;
/* Classes */

.centered {
align-items: center;
text-align: center;
}

li a {
padding: 0.4rem 0.4rem 0.4rem 0;
.block {
border-left: 0.3rem solid;
padding: 0.25rem 1rem;
margin: 0.75rem 0;
}

/* Classes */
.block h1 {
font-size: 1em;
position: relative !important;
margin: 0 0.25rem !important;
text-align: left;
border-bottom: 1px dashed var(--border-color);
}

#content {
display: flex;
flex-direction: column;
flex: 1;
align-self: center;
box-sizing: border-box;
padding: 0 1.5rem;
max-width: min(800px, 100vw);
.note {
border-color: #4493F8;
}

#main-nav {
font-size: larger;
border-bottom: thick solid var(--zig-orange);
background-color: var(--nav-background-color);
.tip {
border-color: #3FB950;
}

.centered {
align-items: center;
text-align: center;
.warning {
border-color: #CCCC49;
}

/* Color */

:root {
--zig-orange: #f7a41d;
--border-color: #666;

--background-color: white;
--text-color: #222;
--secondary-background-color: #f5f5f5;
--tertiary-background-color: #eaeaea;
--nav-background-color: white;
--code-text-color: black;
--text-highlight-color: #111;
--text-color: #222;
--link-color: #121212;
--border-color: #666;
--pre-background-color: #f5f5f5;
--pre-foreground-color: black;
--nav-background-color: white;

/**
* The luminance values have carefully choosen to fufill the WCAG Minimum
* The luminance values have carefully chosen to fulfill the WCAG Minimum
* Contrast Criterion (AA)
*/
--comment: hsl(270, 10%, 40%);
Expand All @@ -213,12 +282,13 @@ li a {
@media (prefers-color-scheme: dark) {
:root {
--background-color: #121212;
--secondary-background-color: #191919;
--tertiary-background-color: #242424;
--nav-background-color: #242424;
--code-text-color: #c8c8c8;
--text-highlight-color: #fafafa;
--text-color: #ccc;
--text-highlight-color: #eee;
--link-color: #eee;
--pre-background-color: #191919;
--pre-foreground-color: #c8c8c8;
--nav-background-color: #242424;

--comment: hsl(270, 10%, 55%);
--orange: hsl(35, 70%, 50%);
Expand Down Expand Up @@ -279,6 +349,6 @@ li a {

@media (prefers-color-scheme: dark) {
.variable {
color: var(--pre-foreground-color);
color: var(--code-text-color);
}
}
34 changes: 34 additions & 0 deletions content/zls/configure/in-editor.smd
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
{
.title = "In-Editor Config",
.date = @date("2020-03-02T00:00:00"),
.author = "Sample Author",
.layout = "zls-docs.shtml",
}
---

In-Editor Config (or Workspace Config) will integrate with the config system of you editor to configure ZLS on a per-editor basis.

Some editors (like VS Code) also allow workspace-specific configuration. If you want to share the same configuration across multiple editors, please refer to the [zls.json]($link.page('zls/configure/zls-json')) alternative.

## Supported Editors

| Editor | in-editor config support |
| ------------------------------------------------------------- | ------------------------- |
| [VS Code](/zls/editors/vscode) | Yes |
| [Sublime Text](/zls/editors/sublime-text) | Yes |
| [ZigBrains for JetBrains](/zls/editors/jetbrains) | Limited\* |
| [Helix](/zls/editors/helix) | Yes |
| [Zed](/zls/editors/zed) | Yes\*\* |
| [Neovim with nvim-lspconfig](/zls/editors/vim/nvim-lspconfig) | Yes |
| [Vim/Neovim with CoC](/zls/editors/vim/coc) | Yes |
| [Vim/Neovim with YCM](/zls/editors/vim/ycm) | Yes\*\*\* |
| [Emacs with eglot](/zls/editors/emacs) | Yes |
| [Emacs with lsp-mode](/zls/editors/emacs) | Yes |
| [Kate](/zls/editors/kate) | Yes\*\* |

\* Only a subset of config options are available.

\*\* In-Editor configuration for these editors requires at least ZLS `0.14.0-dev.22+a263b8dc6`.

\*\*\* In-Editor configuration is somewhat tedious to setup for this Editor. You may favor the [zls.json]($link.page('zls/configure/zls-json')) alternative.
12 changes: 12 additions & 0 deletions content/zls/configure/index.smd
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
{
.title = "Configuration",
.date = @date("2020-03-01T00:00:00"),
.author = "Sample Author",
.layout = "zls-docs.shtml",
}
---

- [In-Editor Configuration](./in-editor) (recommended)
- [zls.json](./zls-json)
- [Per-build Configuration](./per-build) (advanced)
28 changes: 28 additions & 0 deletions content/zls/configure/per-build.smd
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
{
.title = "Per-Build Config",
.date = @date("2020-03-04T00:00:00"),
.author = "Sample Author",
.layout = "zls-docs.shtml",
}
---

The following options can be set on a per-project basis by placing `zls.build.json` in the project root directory next to `build.zig`.

| Option | Type | Default value | What it Does |
| ----------------------- | ---------------- | ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `relative_builtin_path` | `?[]const u8` | `null` | If present, this path is used to resolve `@import("builtin")` |
| `build_options` | `?[]BuildOption` | `null` | If present, this contains a list of user options to pass to the build. This is useful when options are used to conditionally add packages in `build.zig`. |

#### `BuildOption`

`BuildOption` is defined as follows:

```zig
const BuildOption = struct {
name: []const u8,
value: ?[]const u8 = null,
};
```

When `value` is present, the option will be passed the same as in `zig build -Dname=value`. When `value` is `null`, the option will be passed as a flag instead as in `zig build -Dflag`.
85 changes: 85 additions & 0 deletions content/zls/configure/zls-json.smd
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
---
{
.title = "zls.json Config",
.date = @date("2020-03-03T00:00:00"),
.author = "Sample Author",
.layout = "zls-docs.shtml",
}
---

You can configure ZLS by creating a `zls.json` configuration file. This config will apply to **all** editors that use ZLS.

Here is an example of how a `zls.json` _could_ look like:

```json
{
"zig_exe_path": "/path/to/zig_executable",
"semantic_tokens": "partial",
"enable_build_on_save": true
}
```

The file must be valid JSON which cannot contain comments or trailing commas.

## Where should the zls.json be created?

### ZLS since 0.14.0-dev.50+3354fdcb

Running `zls env` will show you where ZLS will look for the `zls.json` file:

```json
{
"version": "0.14.0-dev.50+3354fdcb",
"global_cache_dir": "/home/anon/.cache/zls",
"global_config_dir": "/etc/xdg",
"local_config_dir": "/home/anon/.config",
"config_file": null,
"log_file": "/home/anon/.cache/zls/zls.log"
}
```

ZLS will look for a `zls.json` in the `local_config_dir` directory and then fallback to `global_config_dir`.

After creating the configuration file at `$local_config_dir/zls.json`, `zls env` should output the following:

```json
{
"version": "0.14.0-dev.50+3354fdcb",
"global_cache_dir": "/home/anon/.cache/zls",
"global_config_dir": "/etc/xdg",
"local_config_dir": "/home/anon/.config",
"config_file": "/home/anon/.config/zls.json",
"log_file": "/home/anon/.cache/zls/zls.log"
}
```

### ZLS before 0.14.0-dev.50+3354fdcb (like ZLS 0.13.0)

Running `zls --show-config-path` will show a path to an already existing `zls.json` or a path to the local configuration folder instead.

```
> zls --show-config-path
info ( main ): No config file zls.json found.
info ( main ): A path to the local configuration folder will be printed instead.
/home/anon/.config/zls.json
```

## JSON Schema

ZLS provides a [JSON Schema](https://github.com/zigtools/zls/blob/master/schema.json) to validate the configuration file. It can be used to validate the configuration file and provide IntelliSense features to editors. Further information about JSON Schemas can be found at https://json-schema.org.

You can add a mapping to `zls.json` that can be used by *some* editors:

```json
{
"$schema": "https://raw.githubusercontent.com/zigtools/zls/refs/heads/master/schema.json",
"zig_exe_path": "/path/to/zig_executable",
"semantic_tokens": "partial",
"enable_build_on_save": true
}
```

Please refer to your Editor's Documentation to find out if and how they support JSON Schemas.

Be aware that configuration options change over time. The example above assumes that you are using ZLS nightly/master. If you use a tagged release of ZLS, you will need to the JSON Schema of the respective version:
`https://raw.githubusercontent.com/zigtools/zls/refs/tags/<ZLS_VERSION_HERE>/schema.json`.
Loading

0 comments on commit 543a7f4

Please sign in to comment.