mirror of https://github.com/helix-editor/helix
Merge branch 'master' into magopian:6045-expand-word-boundary-on-search
commit
109ede2e4b
@ -1,3 +1,17 @@
|
||||
# we use tokio_unstable to enable runtime::Handle::id so we can separate
|
||||
# globals from multiple parallel tests. If that function ever does get removed
|
||||
# its possible to replace (with some additional overhead and effort)
|
||||
# Annoyingly build.rustflags doesn't work here because it gets overwritten
|
||||
# if people have their own global target.<..> config (for example to enable mold)
|
||||
# specifying flags this way is more robust as they get merged
|
||||
# This still gets overwritten by RUST_FLAGS though, luckily it shouldn't be necessary
|
||||
# to set those most of the time. If downstream does overwrite this its not a huge
|
||||
# deal since it will only break tests anyway
|
||||
[target."cfg(all())"]
|
||||
rustflags = ["--cfg", "tokio_unstable", "-C", "target-feature=-crt-static"]
|
||||
|
||||
|
||||
[alias]
|
||||
xtask = "run --package xtask --"
|
||||
integration-test = "test --features integration --profile integration --workspace --test integration"
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
watch_file shell.nix
|
||||
watch_file flake.lock
|
||||
watch_file rust-toolchain.toml
|
||||
|
||||
# try to use flakes, if it fails use normal nix (ie. shell.nix)
|
||||
use flake || use nix
|
||||
|
@ -1,5 +0,0 @@
|
||||
# Things that we don't want ripgrep to search that we do want in git
|
||||
# https://github.com/BurntSushi/ripgrep/blob/master/GUIDE.md#automatic-filtering
|
||||
|
||||
# Minified JS vendored from mdbook
|
||||
book/theme/highlight.js
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,231 @@
|
||||
html {
|
||||
font-family: "Inter", sans-serif;
|
||||
}
|
||||
|
||||
.sidebar .sidebar-scrollbox {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.chapter {
|
||||
margin: 0.25rem 0;
|
||||
}
|
||||
|
||||
.chapter li.chapter-item {
|
||||
line-height: initial;
|
||||
margin: 0;
|
||||
padding: 1rem 1.5rem;
|
||||
}
|
||||
|
||||
.chapter .section li.chapter-item {
|
||||
line-height: inherit;
|
||||
padding: .5rem .5rem 0 .5rem;
|
||||
}
|
||||
|
||||
.content {
|
||||
overflow-y: auto;
|
||||
padding: 0 15px;
|
||||
padding-bottom: 50px;
|
||||
}
|
||||
|
||||
/* 2 1.75 1.5 1.25 1 .875 */
|
||||
.content h1 { font-size: 2em }
|
||||
.content h2 { font-size: 1.75em }
|
||||
.content h3 { font-size: 1.5em }
|
||||
.content h4 { font-size: 1.25em }
|
||||
.content h5 { font-size: 1em }
|
||||
.content h6 { font-size: .875em }
|
||||
|
||||
.content h1,
|
||||
.content h2,
|
||||
.content h3,
|
||||
.content h4 {
|
||||
font-weight: 500;
|
||||
margin-top: 1.275em;
|
||||
margin-bottom: .875em;
|
||||
}
|
||||
|
||||
.content p,
|
||||
.content ol,
|
||||
.content ul,
|
||||
.content table {
|
||||
margin-top: 0;
|
||||
margin-bottom: .875em;
|
||||
}
|
||||
|
||||
.content ul li {
|
||||
margin-bottom: .25rem;
|
||||
}
|
||||
|
||||
.content ul {
|
||||
list-style-type: square;
|
||||
}
|
||||
|
||||
.content ul ul,
|
||||
.content ol ul {
|
||||
margin-bottom: .5rem;
|
||||
}
|
||||
|
||||
.content li p {
|
||||
margin-bottom: .5em;
|
||||
}
|
||||
|
||||
blockquote {
|
||||
margin: 1.5rem 0;
|
||||
padding: 1rem 1.5rem;
|
||||
color: var(--fg);
|
||||
opacity: .9;
|
||||
background-color: var(--quote-bg);
|
||||
border-left: 4px solid var(--quote-border);
|
||||
border-top: none;
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
blockquote *:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
table {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
table thead th {
|
||||
padding: .75rem;
|
||||
text-align: left;
|
||||
font-weight: 500;
|
||||
line-height: 1.5;
|
||||
width: auto;
|
||||
}
|
||||
|
||||
table td {
|
||||
padding: .75rem;
|
||||
border: none;
|
||||
}
|
||||
|
||||
table thead tr {
|
||||
border: none;
|
||||
border-bottom: 2px var(--table-border-color) solid;
|
||||
}
|
||||
|
||||
table tbody tr {
|
||||
border-bottom: 1px var(--table-border-line) solid;
|
||||
}
|
||||
|
||||
table tbody tr:nth-child(2n) {
|
||||
background: unset;
|
||||
}
|
||||
|
||||
pre code.hljs {
|
||||
display: block;
|
||||
overflow-x: auto;
|
||||
padding: 1em;
|
||||
}
|
||||
|
||||
code.hljs {
|
||||
padding: 3px 5px;
|
||||
}
|
||||
|
||||
.colibri {
|
||||
--bg: #3b224c;
|
||||
--fg: #bcbdd0;
|
||||
--heading-fg: #fff;
|
||||
|
||||
--sidebar-bg: #281733;
|
||||
--sidebar-fg: #c8c9db;
|
||||
--sidebar-non-existent: #505274;
|
||||
--sidebar-active: #a4a0e8;
|
||||
--sidebar-spacer: #2d334f;
|
||||
|
||||
--scrollbar: var(--sidebar-fg);
|
||||
|
||||
--icons: #737480;
|
||||
--icons-hover: #b7b9cc;
|
||||
|
||||
/* --links: #a4a0e8; */
|
||||
--links: #ECCDBA;
|
||||
|
||||
--inline-code-color: hsl(48.7, 7.8%, 70%);
|
||||
|
||||
--theme-popup-bg: #161923;
|
||||
--theme-popup-border: #737480;
|
||||
--theme-hover: rgba(0, 0, 0, .2);
|
||||
|
||||
--quote-bg: #281733;
|
||||
--quote-border: hsl(226, 15%, 22%);
|
||||
|
||||
--table-border-color: hsl(226, 23%, 76%);
|
||||
--table-header-bg: hsla(226, 23%, 31%, 0);
|
||||
--table-alternate-bg: hsl(226, 23%, 14%);
|
||||
--table-border-line: hsla(201deg, 20%, 92%, 0.2);
|
||||
|
||||
--searchbar-border-color: #aaa;
|
||||
--searchbar-bg: #aeaec6;
|
||||
--searchbar-fg: #000;
|
||||
--searchbar-shadow-color: #aaa;
|
||||
--searchresults-header-fg: #5f5f71;
|
||||
--searchresults-border-color: #5c5c68;
|
||||
--searchresults-li-bg: #242430;
|
||||
--search-mark-bg: #a2cff5;
|
||||
}
|
||||
|
||||
.colibri .content .header {
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
/* highlight.js theme, :where() is used to avoid increasing specificity */
|
||||
|
||||
:where(.colibri) .hljs {
|
||||
background: #2f1e2e;
|
||||
color: #a39e9b;
|
||||
}
|
||||
|
||||
:where(.colibri) .hljs-comment,
|
||||
:where(.colibri) .hljs-quote {
|
||||
color: #8d8687;
|
||||
}
|
||||
|
||||
:where(.colibri) .hljs-link,
|
||||
:where(.colibri) .hljs-meta,
|
||||
:where(.colibri) .hljs-name,
|
||||
:where(.colibri) .hljs-regexp,
|
||||
:where(.colibri) .hljs-selector-class,
|
||||
:where(.colibri) .hljs-selector-id,
|
||||
:where(.colibri) .hljs-tag,
|
||||
:where(.colibri) .hljs-template-variable,
|
||||
:where(.colibri) .hljs-variable {
|
||||
color: #ef6155;
|
||||
}
|
||||
|
||||
:where(.colibri) .hljs-built_in,
|
||||
:where(.colibri) .hljs-deletion,
|
||||
:where(.colibri) .hljs-literal,
|
||||
:where(.colibri) .hljs-number,
|
||||
:where(.colibri) .hljs-params,
|
||||
:where(.colibri) .hljs-type {
|
||||
color: #f99b15;
|
||||
}
|
||||
|
||||
:where(.colibri) .hljs-attribute,
|
||||
:where(.colibri) .hljs-section,
|
||||
:where(.colibri) .hljs-title {
|
||||
color: #fec418;
|
||||
}
|
||||
|
||||
:where(.colibri) .hljs-addition,
|
||||
:where(.colibri) .hljs-bullet,
|
||||
:where(.colibri) .hljs-string,
|
||||
:where(.colibri) .hljs-symbol {
|
||||
color: #48b685;
|
||||
}
|
||||
|
||||
:where(.colibri) .hljs-keyword,
|
||||
:where(.colibri) .hljs-selector-tag {
|
||||
color: #815ba4;
|
||||
}
|
||||
|
||||
:where(.colibri) .hljs-emphasis {
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
:where(.colibri) .hljs-strong {
|
||||
font-weight: 700;
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
# Commands
|
||||
|
||||
Command mode can be activated by pressing `:`, similar to Vim. Built-in commands:
|
||||
Command mode can be activated by pressing `:`. The built-in commands are:
|
||||
|
||||
{{#include ./generated/typable-cmd.md}}
|
||||
|
@ -1,4 +1,4 @@
|
||||
# Guides
|
||||
|
||||
This section contains guides for adding new language server configurations,
|
||||
tree-sitter grammars, textobject queries, etc.
|
||||
tree-sitter grammars, textobject queries, and other similar items.
|
||||
|
@ -1,45 +1,55 @@
|
||||
# Adding languages
|
||||
# Adding new languages to Helix
|
||||
|
||||
In order to add a new language to Helix, you will need to follow the steps
|
||||
below.
|
||||
|
||||
## Language configuration
|
||||
|
||||
To add a new language, you need to add a `[[language]]` entry to the
|
||||
`languages.toml` (see the [language configuration section]).
|
||||
1. Add a new `[[language]]` entry in the `languages.toml` file and provide the
|
||||
necessary configuration for the new language. For more information on
|
||||
language configuration, refer to the
|
||||
[language configuration section](../languages.md) of the documentation.
|
||||
A new language server can be added by extending the `[language-server]` table in the same file.
|
||||
2. If you are adding a new language or updating an existing language server
|
||||
configuration, run the command `cargo xtask docgen` to update the
|
||||
[Language Support](../lang-support.md) documentation.
|
||||
|
||||
When adding a new language or Language Server configuration for an existing
|
||||
language, run `cargo xtask docgen` to add the new configuration to the
|
||||
[Language Support][lang-support] docs before creating a pull request.
|
||||
When adding a Language Server configuration, be sure to update the
|
||||
[Language Server Wiki][install-lsp-wiki] with installation notes.
|
||||
> 💡 If you are adding a new Language Server configuration, make sure to update
|
||||
> the
|
||||
> [Language Server Wiki](https://github.com/helix-editor/helix/wiki/How-to-install-the-default-language-servers)
|
||||
> with the installation instructions.
|
||||
|
||||
## Grammar configuration
|
||||
|
||||
If a tree-sitter grammar is available for the language, add a new `[[grammar]]`
|
||||
entry to `languages.toml`.
|
||||
|
||||
You may use the `source.path` key rather than `source.git` with an absolute path
|
||||
to a locally available grammar for testing, but switch to `source.git` before
|
||||
submitting a pull request.
|
||||
1. If a tree-sitter grammar is available for the new language, add a new
|
||||
`[[grammar]]` entry to the `languages.toml` file.
|
||||
2. If you are testing the grammar locally, you can use the `source.path` key
|
||||
with an absolute path to the grammar. However, before submitting a pull
|
||||
request, make sure to switch to using `source.git`.
|
||||
|
||||
## Queries
|
||||
|
||||
For a language to have syntax-highlighting and indentation among
|
||||
other things, you have to add queries. Add a directory for your
|
||||
language with the path `runtime/queries/<name>/`. The tree-sitter
|
||||
[website](https://tree-sitter.github.io/tree-sitter/syntax-highlighting#queries)
|
||||
gives more info on how to write queries.
|
||||
|
||||
> NOTE: When evaluating queries, the first matching query takes
|
||||
precedence, which is different from other editors like Neovim where
|
||||
the last matching query supersedes the ones before it. See
|
||||
[this issue][neovim-query-precedence] for an example.
|
||||
|
||||
## Common Issues
|
||||
|
||||
- If you get errors when running after switching branches, you may have to update the tree-sitter grammars. Run `hx --grammar fetch` to fetch the grammars and `hx --grammar build` to build any out-of-date grammars.
|
||||
|
||||
- If a parser is segfaulting or you want to remove the parser, make sure to remove the compiled parser in `runtime/grammar/<name>.so`
|
||||
|
||||
[language configuration section]: ../languages.md
|
||||
[neovim-query-precedence]: https://github.com/helix-editor/helix/pull/1170#issuecomment-997294090
|
||||
[install-lsp-wiki]: https://github.com/helix-editor/helix/wiki/How-to-install-the-default-language-servers
|
||||
[lang-support]: ../lang-support.md
|
||||
1. In order to provide syntax highlighting and indentation for the new language,
|
||||
you will need to add queries.
|
||||
2. Create a new directory for the language with the path
|
||||
`runtime/queries/<name>/`.
|
||||
3. Refer to the
|
||||
[tree-sitter website](https://tree-sitter.github.io/tree-sitter/syntax-highlighting#queries)
|
||||
for more information on writing queries.
|
||||
4. A list of highlight captures can be found [on the themes page](https://docs.helix-editor.com/themes.html#scopes).
|
||||
|
||||
> 💡 In Helix, the first matching query takes precedence when evaluating
|
||||
> queries, which is different from other editors such as Neovim where the last
|
||||
> matching query supersedes the ones before it. See
|
||||
> [this issue](https://github.com/helix-editor/helix/pull/1170#issuecomment-997294090)
|
||||
> for an example.
|
||||
|
||||
## Common issues
|
||||
|
||||
- If you encounter errors when running Helix after switching branches, you may
|
||||
need to update the tree-sitter grammars. Run the command `hx --grammar fetch`
|
||||
to fetch the grammars and `hx --grammar build` to build any out-of-date
|
||||
grammars.
|
||||
- If a parser is causing a segfault, or you want to remove it, make sure to
|
||||
remove the compiled parser located at `runtime/grammars/<name>.so`.
|
||||
- If you are attempting to add queries and Helix is unable to locate them, ensure that the environment variable `HELIX_RUNTIME` is set to the location of the `runtime` folder you're developing in.
|
||||
|
@ -1,180 +1,331 @@
|
||||
# Installation
|
||||
|
||||
We provide pre-built binaries on the [GitHub Releases page](https://github.com/helix-editor/helix/releases).
|
||||
# Installing Helix
|
||||
|
||||
<!--toc:start-->
|
||||
- [Pre-built binaries](#pre-built-binaries)
|
||||
- [Linux, macOS, Windows and OpenBSD packaging status](#linux-macos-windows-and-openbsd-packaging-status)
|
||||
- [Linux](#linux)
|
||||
- [Ubuntu](#ubuntu)
|
||||
- [Fedora/RHEL](#fedorarhel)
|
||||
- [Arch Linux extra](#arch-linux-extra)
|
||||
- [NixOS](#nixos)
|
||||
- [Flatpak](#flatpak)
|
||||
- [Snap](#snap)
|
||||
- [AppImage](#appimage)
|
||||
- [macOS](#macos)
|
||||
- [Homebrew Core](#homebrew-core)
|
||||
- [MacPorts](#macports)
|
||||
- [Windows](#windows)
|
||||
- [Winget](#winget)
|
||||
- [Scoop](#scoop)
|
||||
- [Chocolatey](#chocolatey)
|
||||
- [MSYS2](#msys2)
|
||||
- [Building from source](#building-from-source)
|
||||
- [Configuring Helix's runtime files](#configuring-helixs-runtime-files)
|
||||
- [Linux and macOS](#linux-and-macos)
|
||||
- [Windows](#windows)
|
||||
- [Multiple runtime directories](#multiple-runtime-directories)
|
||||
- [Validating the installation](#validating-the-installation)
|
||||
- [Configure the desktop shortcut](#configure-the-desktop-shortcut)
|
||||
<!--toc:end-->
|
||||
|
||||
To install Helix, follow the instructions specific to your operating system.
|
||||
Note that:
|
||||
|
||||
- To get the latest nightly version of Helix, you need to
|
||||
[build from source](#building-from-source).
|
||||
|
||||
- To take full advantage of Helix, install the language servers for your
|
||||
preferred programming languages. See the
|
||||
[wiki](https://github.com/helix-editor/helix/wiki/How-to-install-the-default-language-servers)
|
||||
for instructions.
|
||||
|
||||
## Pre-built binaries
|
||||
|
||||
Download pre-built binaries from the
|
||||
[GitHub Releases page](https://github.com/helix-editor/helix/releases). Add the binary to your system's `$PATH` to use it from the command
|
||||
line.
|
||||
|
||||
## Linux, macOS, Windows and OpenBSD packaging status
|
||||
|
||||
[![Packaging status](https://repology.org/badge/vertical-allrepos/helix.svg)](https://repology.org/project/helix/versions)
|
||||
|
||||
## OSX
|
||||
## Linux
|
||||
|
||||
The following third party repositories are available:
|
||||
|
||||
### Ubuntu
|
||||
|
||||
Helix is available in homebrew-core:
|
||||
Add the `PPA` for Helix:
|
||||
|
||||
```sh
|
||||
sudo add-apt-repository ppa:maveonair/helix-editor
|
||||
sudo apt update
|
||||
sudo apt install helix
|
||||
```
|
||||
brew install helix
|
||||
|
||||
### Fedora/RHEL
|
||||
|
||||
```sh
|
||||
sudo dnf install helix
|
||||
```
|
||||
|
||||
## Linux
|
||||
### Arch Linux extra
|
||||
|
||||
Releases are available in the `extra` repository:
|
||||
|
||||
```sh
|
||||
sudo pacman -S helix
|
||||
```
|
||||
|
||||
> 💡 When installed from the `extra` repository, run Helix with `helix` instead of `hx`.
|
||||
>
|
||||
> For example:
|
||||
> ```sh
|
||||
> helix --health
|
||||
> ```
|
||||
> to check health
|
||||
|
||||
Additionally, a [helix-git](https://aur.archlinux.org/packages/helix-git/) package is available
|
||||
in the AUR, which builds the master branch.
|
||||
|
||||
### NixOS
|
||||
|
||||
A [flake](https://nixos.wiki/wiki/Flakes) containing the package is available in
|
||||
the project root. The flake can also be used to spin up a reproducible development
|
||||
shell for working on Helix with `nix develop`.
|
||||
Helix is available in [nixpkgs](https://github.com/nixos/nixpkgs) through the `helix` attribute,
|
||||
the unstable channel usually carries the latest release.
|
||||
|
||||
Flake outputs are cached for each push to master using
|
||||
[Cachix](https://www.cachix.org/). The flake is configured to
|
||||
automatically make use of this cache assuming the user accepts
|
||||
the new settings on first use.
|
||||
Helix is also available as a [flake](https://nixos.wiki/wiki/Flakes) in the project
|
||||
root. Use `nix develop` to spin up a reproducible development shell. Outputs are
|
||||
cached for each push to master using [Cachix](https://www.cachix.org/). The
|
||||
flake is configured to automatically make use of this cache assuming the user
|
||||
accepts the new settings on first use.
|
||||
|
||||
If you are using a version of Nix without flakes enabled you can
|
||||
[install Cachix cli](https://docs.cachix.org/installation); `cachix use helix` will
|
||||
configure Nix to use cached outputs when possible.
|
||||
If you are using a version of Nix without flakes enabled,
|
||||
[install Cachix CLI](https://docs.cachix.org/installation) and use
|
||||
`cachix use helix` to configure Nix to use cached outputs when possible.
|
||||
|
||||
### Arch Linux
|
||||
### Flatpak
|
||||
|
||||
Releases are available in the `community` repository.
|
||||
Helix is available on [Flathub](https://flathub.org/en-GB/apps/com.helix_editor.Helix):
|
||||
|
||||
A [helix-git](https://aur.archlinux.org/packages/helix-git/) package is also available on the AUR, which builds the master branch.
|
||||
```sh
|
||||
flatpak install flathub com.helix_editor.Helix
|
||||
flatpak run com.helix_editor.Helix
|
||||
```
|
||||
|
||||
### Fedora Linux
|
||||
### Snap
|
||||
|
||||
You can install the COPR package for Helix via
|
||||
Helix is available on [Snapcraft](https://snapcraft.io/helix) and can be installed with:
|
||||
|
||||
```sh
|
||||
snap install --classic helix
|
||||
```
|
||||
sudo dnf copr enable varlad/helix
|
||||
sudo dnf install helix
|
||||
|
||||
This will install Helix as both `/snap/bin/helix` and `/snap/bin/hx`, so make sure `/snap/bin` is in your `PATH`.
|
||||
|
||||
### AppImage
|
||||
|
||||
Install Helix using the Linux [AppImage](https://appimage.org/) format.
|
||||
Download the official Helix AppImage from the [latest releases](https://github.com/helix-editor/helix/releases/latest) page.
|
||||
|
||||
```sh
|
||||
chmod +x helix-*.AppImage # change permission for executable mode
|
||||
./helix-*.AppImage # run helix
|
||||
```
|
||||
|
||||
## macOS
|
||||
|
||||
### Void Linux
|
||||
### Homebrew Core
|
||||
|
||||
```sh
|
||||
brew install helix
|
||||
```
|
||||
sudo xbps-install helix
|
||||
|
||||
### MacPorts
|
||||
|
||||
```sh
|
||||
port install helix
|
||||
```
|
||||
|
||||
## Windows
|
||||
|
||||
Helix can be installed using [Scoop](https://scoop.sh/), [Chocolatey](https://chocolatey.org/)
|
||||
Install on Windows using [Winget](https://learn.microsoft.com/en-us/windows/package-manager/winget/), [Scoop](https://scoop.sh/), [Chocolatey](https://chocolatey.org/)
|
||||
or [MSYS2](https://msys2.org/).
|
||||
|
||||
**Scoop:**
|
||||
### Winget
|
||||
Windows Package Manager winget command-line tool is by default available on Windows 11 and modern versions of Windows 10 as a part of the App Installer.
|
||||
You can get [App Installer from the Microsoft Store](https://www.microsoft.com/p/app-installer/9nblggh4nns1#activetab=pivot:overviewtab). If it's already installed, make sure it is updated with the latest version.
|
||||
|
||||
```sh
|
||||
winget install Helix.Helix
|
||||
```
|
||||
|
||||
### Scoop
|
||||
|
||||
```sh
|
||||
scoop install helix
|
||||
```
|
||||
|
||||
**Chocolatey:**
|
||||
### Chocolatey
|
||||
|
||||
```
|
||||
```sh
|
||||
choco install helix
|
||||
```
|
||||
|
||||
**MSYS2:**
|
||||
### MSYS2
|
||||
|
||||
Choose the [proper command](https://www.msys2.org/docs/package-naming/) for your system from below:
|
||||
For 64-bit Windows 8.1 or above:
|
||||
|
||||
- For 32 bit Windows 7 or above:
|
||||
|
||||
```
|
||||
pacman -S mingw-w64-i686-helix
|
||||
```sh
|
||||
pacman -S mingw-w64-ucrt-x86_64-helix
|
||||
```
|
||||
|
||||
- For 64 bit Windows 7 or above:
|
||||
## Building from source
|
||||
|
||||
```
|
||||
pacman -S mingw-w64-x86_64-helix
|
||||
```
|
||||
Requirements:
|
||||
|
||||
- For 64 bit Windows 8.1 or above:
|
||||
Clone the Helix GitHub repository into a directory of your choice. The
|
||||
examples in this documentation assume installation into either `~/src/` on
|
||||
Linux and macOS, or `%userprofile%\src\` on Windows.
|
||||
|
||||
```
|
||||
pacman -S mingw-w64-ucrt-x86_64-helix
|
||||
```
|
||||
- The [Rust toolchain](https://www.rust-lang.org/tools/install)
|
||||
- The [Git version control system](https://git-scm.com/)
|
||||
- A C++14 compatible compiler to build the tree-sitter grammars, for example GCC or Clang
|
||||
|
||||
## Build from source
|
||||
If you are using the `musl-libc` standard library instead of `glibc` the following environment variable must be set during the build to ensure tree-sitter grammars can be loaded correctly:
|
||||
|
||||
```
|
||||
git clone https://github.com/helix-editor/helix
|
||||
cd helix
|
||||
cargo install --path helix-term --locked
|
||||
```sh
|
||||
RUSTFLAGS="-C target-feature=-crt-static"
|
||||
```
|
||||
|
||||
This will install the `hx` binary to `$HOME/.cargo/bin` and build tree-sitter grammars in `./runtime/grammars`.
|
||||
1. Clone the repository:
|
||||
|
||||
If you are using the musl-libc instead of glibc the following environment variable must be set during the build
|
||||
to ensure tree sitter grammars can be loaded correctly:
|
||||
```sh
|
||||
git clone https://github.com/helix-editor/helix
|
||||
cd helix
|
||||
```
|
||||
|
||||
```
|
||||
RUSTFLAGS="-C target-feature=-crt-static"
|
||||
```
|
||||
2. Compile from source:
|
||||
|
||||
```sh
|
||||
cargo install --path helix-term --locked
|
||||
```
|
||||
|
||||
Helix also needs its runtime files so make sure to copy/symlink the `runtime/` directory into the
|
||||
config directory (for example `~/.config/helix/runtime` on Linux/macOS). This location can be overridden
|
||||
via the `HELIX_RUNTIME` environment variable.
|
||||
This command will create the `hx` executable and construct the tree-sitter
|
||||
grammars in the local `runtime` folder.
|
||||
|
||||
| OS | Command |
|
||||
| -------------------- | ------------------------------------------------ |
|
||||
| Windows (Cmd) | `xcopy /e /i runtime %AppData%\helix\runtime` |
|
||||
| Windows (PowerShell) | `xcopy /e /i runtime $Env:AppData\helix\runtime` |
|
||||
| Linux / macOS | `ln -s $PWD/runtime ~/.config/helix/runtime` |
|
||||
> 💡 If you do not want to fetch or build grammars, set an environment variable `HELIX_DISABLE_AUTO_GRAMMAR_BUILD`
|
||||
|
||||
Starting with Windows Vista you can also create symbolic links on Windows. Note that this requires
|
||||
elevated privileges - i.e. PowerShell or Cmd must be run as administrator.
|
||||
> 💡 Tree-sitter grammars can be fetched and compiled if not pre-packaged. Fetch
|
||||
> grammars with `hx --grammar fetch` and compile them with
|
||||
> `hx --grammar build`. This will install them in
|
||||
> the `runtime` directory within the user's helix config directory (more
|
||||
> [details below](#multiple-runtime-directories)).
|
||||
|
||||
**PowerShell:**
|
||||
### Configuring Helix's runtime files
|
||||
|
||||
```powershell
|
||||
New-Item -ItemType Junction -Target "runtime" -Path "$Env:AppData\helix\runtime"
|
||||
```
|
||||
Note: "runtime" must be the absolute path to the runtime directory.
|
||||
#### Linux and macOS
|
||||
|
||||
**Cmd:**
|
||||
The **runtime** directory is one below the Helix source, so either export a
|
||||
`HELIX_RUNTIME` environment variable to point to that directory and add it to
|
||||
your `~/.bashrc` or equivalent:
|
||||
|
||||
```cmd
|
||||
cd %appdata%\helix
|
||||
mklink /D runtime "<helix-repo>\runtime"
|
||||
```sh
|
||||
export HELIX_RUNTIME=~/src/helix/runtime
|
||||
```
|
||||
|
||||
The runtime location can be overridden via the `HELIX_RUNTIME` environment variable.
|
||||
Or, create a symbolic link:
|
||||
|
||||
```sh
|
||||
ln -Ts $PWD/runtime ~/.config/helix/runtime
|
||||
```
|
||||
|
||||
> NOTE: if `HELIX_RUNTIME` is set prior to calling `cargo install --path helix-term --locked`,
|
||||
> tree-sitter grammars will be built in `$HELIX_RUNTIME/grammars`.
|
||||
If the above command fails to create a symbolic link because the file exists either move `~/.config/helix/runtime` to a new location or delete it, then run the symlink command above again.
|
||||
|
||||
If you plan on keeping the repo locally, an alternative to copying/symlinking
|
||||
runtime files is to set `HELIX_RUNTIME=/path/to/helix/runtime`
|
||||
(`HELIX_RUNTIME=$PWD/runtime` if you're in the helix repo directory).
|
||||
#### Windows
|
||||
|
||||
To use Helix in desktop environments that supports [XDG desktop menu](https://specifications.freedesktop.org/menu-spec/menu-spec-latest.html), including Gnome and KDE, copy the provided `.desktop` file to the correct folder:
|
||||
Either set the `HELIX_RUNTIME` environment variable to point to the runtime files using the Windows setting (search for
|
||||
`Edit environment variables for your account`) or use the `setx` command in
|
||||
Cmd:
|
||||
|
||||
```bash
|
||||
cp contrib/Helix.desktop ~/.local/share/applications
|
||||
```sh
|
||||
setx HELIX_RUNTIME "%userprofile%\source\repos\helix\runtime"
|
||||
```
|
||||
|
||||
To use another terminal than the default, you will need to modify the `.desktop` file. For example, to use `kitty`:
|
||||
> 💡 `%userprofile%` resolves to your user directory like
|
||||
> `C:\Users\Your-Name\` for example.
|
||||
|
||||
```bash
|
||||
sed -i "s|Exec=hx %F|Exec=kitty hx %F|g" ~/.local/share/applications/Helix.desktop
|
||||
sed -i "s|Terminal=true|Terminal=false|g" ~/.local/share/applications/Helix.desktop
|
||||
```
|
||||
Or, create a symlink in `%appdata%\helix\` that links to the source code directory:
|
||||
|
||||
Please note: there is no icon for Helix yet, so the system default will be used.
|
||||
| Method | Command |
|
||||
| ---------- | -------------------------------------------------------------------------------------- |
|
||||
| PowerShell | `New-Item -ItemType Junction -Target "runtime" -Path "$Env:AppData\helix\runtime"` |
|
||||
| Cmd | `cd %appdata%\helix` <br/> `mklink /D runtime "%userprofile%\src\helix\runtime"` |
|
||||
|
||||
## Finishing up the installation
|
||||
> 💡 On Windows, creating a symbolic link may require running PowerShell or
|
||||
> Cmd as an administrator.
|
||||
|
||||
To make sure everything is set up as expected you should finally run the helix healthcheck via
|
||||
#### Multiple runtime directories
|
||||
|
||||
```
|
||||
When Helix finds multiple runtime directories it will search through them for files in the
|
||||
following order:
|
||||
|
||||
1. `runtime/` sibling directory to `$CARGO_MANIFEST_DIR` directory (this is intended for
|
||||
developing and testing helix only).
|
||||
2. `runtime/` subdirectory of OS-dependent helix user config directory.
|
||||
3. `$HELIX_RUNTIME`
|
||||
4. Distribution-specific fallback directory (set at compile time—not run time—
|
||||
with the `HELIX_DEFAULT_RUNTIME` environment variable)
|
||||
5. `runtime/` subdirectory of path to Helix executable.
|
||||
|
||||
This order also sets the priority for selecting which file will be used if multiple runtime
|
||||
directories have files with the same name.
|
||||
|
||||
#### Note to packagers
|
||||
|
||||
If you are making a package of Helix for end users, to provide a good out of
|
||||
the box experience, you should set the `HELIX_DEFAULT_RUNTIME` environment
|
||||
variable at build time (before invoking `cargo build`) to a directory which
|
||||
will store the final runtime files after installation. For example, say you want
|
||||
to package the runtime into `/usr/lib/helix/runtime`. The rough steps a build
|
||||
script could follow are:
|
||||
|
||||
1. `export HELIX_DEFAULT_RUNTIME=/usr/lib/helix/runtime`
|
||||
1. `cargo build --profile opt --locked --path helix-term`
|
||||
1. `cp -r runtime $BUILD_DIR/usr/lib/helix/`
|
||||
1. `cp target/opt/hx $BUILD_DIR/usr/bin/hx`
|
||||
|
||||
This way the resulting `hx` binary will always look for its runtime directory in
|
||||
`/usr/lib/helix/runtime` if the user has no custom runtime in `~/.config/helix`
|
||||
or `HELIX_RUNTIME`.
|
||||
|
||||
### Validating the installation
|
||||
|
||||
To make sure everything is set up as expected you should run the Helix health
|
||||
check:
|
||||
|
||||
```sh
|
||||
hx --health
|
||||
```
|
||||
|
||||
For more information on the information displayed in the health check results refer to [Healthcheck](https://github.com/helix-editor/helix/wiki/Healthcheck).
|
||||
For more information on the health check results refer to
|
||||
[Health check](https://github.com/helix-editor/helix/wiki/Healthcheck).
|
||||
|
||||
### Configure the desktop shortcut
|
||||
|
||||
### Building tree-sitter grammars
|
||||
If your desktop environment supports the
|
||||
[XDG desktop menu](https://specifications.freedesktop.org/menu-spec/menu-spec-latest.html)
|
||||
you can configure Helix to show up in the application menu by copying the
|
||||
provided `.desktop` and icon files to their correct folders:
|
||||
|
||||
Tree-sitter grammars must be fetched and compiled if not pre-packaged.
|
||||
Fetch grammars with `hx --grammar fetch` (requires `git`) and compile them
|
||||
with `hx --grammar build` (requires a C++ compiler).
|
||||
```sh
|
||||
cp contrib/Helix.desktop ~/.local/share/applications
|
||||
cp contrib/helix.png ~/.icons # or ~/.local/share/icons
|
||||
```
|
||||
|
||||
### Installing language servers
|
||||
To use another terminal than the system default, you can modify the `.desktop`
|
||||
file. For example, to use `kitty`:
|
||||
|
||||
Language servers can optionally be installed if you want their features (auto-complete, diagnostics etc.).
|
||||
Follow the [instructions on the wiki page](https://github.com/helix-editor/helix/wiki/How-to-install-the-default-language-servers) to add your language servers of choice.
|
||||
```sh
|
||||
sed -i "s|Exec=hx %F|Exec=kitty hx %F|g" ~/.local/share/applications/Helix.desktop
|
||||
sed -i "s|Terminal=true|Terminal=false|g" ~/.local/share/applications/Helix.desktop
|
||||
```
|
||||
|
@ -1,660 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
// Fix back button cache problem
|
||||
window.onunload = function () { };
|
||||
|
||||
// Global variable, shared between modules
|
||||
function playground_text(playground) {
|
||||
let code_block = playground.querySelector("code");
|
||||
|
||||
if (window.ace && code_block.classList.contains("editable")) {
|
||||
let editor = window.ace.edit(code_block);
|
||||
return editor.getValue();
|
||||
} else {
|
||||
return code_block.textContent;
|
||||
}
|
||||
}
|
||||
|
||||
(function codeSnippets() {
|
||||
function fetch_with_timeout(url, options, timeout = 6000) {
|
||||
return Promise.race([
|
||||
fetch(url, options),
|
||||
new Promise((_, reject) => setTimeout(() => reject(new Error('timeout')), timeout))
|
||||
]);
|
||||
}
|
||||
|
||||
var playgrounds = Array.from(document.querySelectorAll(".playground"));
|
||||
if (playgrounds.length > 0) {
|
||||
fetch_with_timeout("https://play.rust-lang.org/meta/crates", {
|
||||
headers: {
|
||||
'Content-Type': "application/json",
|
||||
},
|
||||
method: 'POST',
|
||||
mode: 'cors',
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(response => {
|
||||
// get list of crates available in the rust playground
|
||||
let playground_crates = response.crates.map(item => item["id"]);
|
||||
playgrounds.forEach(block => handle_crate_list_update(block, playground_crates));
|
||||
});
|
||||
}
|
||||
|
||||
function handle_crate_list_update(playground_block, playground_crates) {
|
||||
// update the play buttons after receiving the response
|
||||
update_play_button(playground_block, playground_crates);
|
||||
|
||||
// and install on change listener to dynamically update ACE editors
|
||||
if (window.ace) {
|
||||
let code_block = playground_block.querySelector("code");
|
||||
if (code_block.classList.contains("editable")) {
|
||||
let editor = window.ace.edit(code_block);
|
||||
editor.addEventListener("change", function (e) {
|
||||
update_play_button(playground_block, playground_crates);
|
||||
});
|
||||
// add Ctrl-Enter command to execute rust code
|
||||
editor.commands.addCommand({
|
||||
name: "run",
|
||||
bindKey: {
|
||||
win: "Ctrl-Enter",
|
||||
mac: "Ctrl-Enter"
|
||||
},
|
||||
exec: _editor => run_rust_code(playground_block)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// updates the visibility of play button based on `no_run` class and
|
||||
// used crates vs ones available on http://play.rust-lang.org
|
||||
function update_play_button(pre_block, playground_crates) {
|
||||
var play_button = pre_block.querySelector(".play-button");
|
||||
|
||||
// skip if code is `no_run`
|
||||
if (pre_block.querySelector('code').classList.contains("no_run")) {
|
||||
play_button.classList.add("hidden");
|
||||
return;
|
||||
}
|
||||
|
||||
// get list of `extern crate`'s from snippet
|
||||
var txt = playground_text(pre_block);
|
||||
var re = /extern\s+crate\s+([a-zA-Z_0-9]+)\s*;/g;
|
||||
var snippet_crates = [];
|
||||
var item;
|
||||
while (item = re.exec(txt)) {
|
||||
snippet_crates.push(item[1]);
|
||||
}
|
||||
|
||||
// check if all used crates are available on play.rust-lang.org
|
||||
var all_available = snippet_crates.every(function (elem) {
|
||||
return playground_crates.indexOf(elem) > -1;
|
||||
});
|
||||
|
||||
if (all_available) {
|
||||
play_button.classList.remove("hidden");
|
||||
} else {
|
||||
play_button.classList.add("hidden");
|
||||
}
|
||||
}
|
||||
|
||||
function run_rust_code(code_block) {
|
||||
var result_block = code_block.querySelector(".result");
|
||||
if (!result_block) {
|
||||
result_block = document.createElement('code');
|
||||
result_block.className = 'result hljs language-bash';
|
||||
|
||||
code_block.append(result_block);
|
||||
}
|
||||
|
||||
let text = playground_text(code_block);
|
||||
let classes = code_block.querySelector('code').classList;
|
||||
let has_2018 = classes.contains("edition2018");
|
||||
let edition = has_2018 ? "2018" : "2015";
|
||||
|
||||
var params = {
|
||||
version: "stable",
|
||||
optimize: "0",
|
||||
code: text,
|
||||
edition: edition
|
||||
};
|
||||
|
||||
if (text.indexOf("#![feature") !== -1) {
|
||||
params.version = "nightly";
|
||||
}
|
||||
|
||||
result_block.innerText = "Running...";
|
||||
|
||||
fetch_with_timeout("https://play.rust-lang.org/evaluate.json", {
|
||||
headers: {
|
||||
'Content-Type': "application/json",
|
||||
},
|
||||
method: 'POST',
|
||||
mode: 'cors',
|
||||
body: JSON.stringify(params)
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(response => result_block.innerText = response.result)
|
||||
.catch(error => result_block.innerText = "Playground Communication: " + error.message);
|
||||
}
|
||||
|
||||
// Syntax highlighting Configuration
|
||||
hljs.configure({
|
||||
tabReplace: ' ', // 4 spaces
|
||||
languages: [], // Languages used for auto-detection
|
||||
});
|
||||
|
||||
let code_nodes = Array
|
||||
.from(document.querySelectorAll('code'))
|
||||
// Don't highlight `inline code` blocks in headers.
|
||||
.filter(function (node) {return !node.parentElement.classList.contains("header"); });
|
||||
|
||||
if (window.ace) {
|
||||
// language-rust class needs to be removed for editable
|
||||
// blocks or highlightjs will capture events
|
||||
Array
|
||||
.from(document.querySelectorAll('code.editable'))
|
||||
.forEach(function (block) { block.classList.remove('language-rust'); });
|
||||
|
||||
Array
|
||||
.from(document.querySelectorAll('code:not(.editable)'))
|
||||
.forEach(function (block) { hljs.highlightBlock(block); });
|
||||
} else {
|
||||
code_nodes.forEach(function (block) { hljs.highlightBlock(block); });
|
||||
}
|
||||
|
||||
// Adding the hljs class gives code blocks the color css
|
||||
// even if highlighting doesn't apply
|
||||
code_nodes.forEach(function (block) { block.classList.add('hljs'); });
|
||||
|
||||
Array.from(document.querySelectorAll("code.language-rust")).forEach(function (block) {
|
||||
|
||||
var lines = Array.from(block.querySelectorAll('.boring'));
|
||||
// If no lines were hidden, return
|
||||
if (!lines.length) { return; }
|
||||
block.classList.add("hide-boring");
|
||||
|
||||
var buttons = document.createElement('div');
|
||||
buttons.className = 'buttons';
|
||||
buttons.innerHTML = "<button class=\"fa fa-eye\" title=\"Show hidden lines\" aria-label=\"Show hidden lines\"></button>";
|
||||
|
||||
// add expand button
|
||||
var pre_block = block.parentNode;
|
||||
pre_block.insertBefore(buttons, pre_block.firstChild);
|
||||
|
||||
pre_block.querySelector('.buttons').addEventListener('click', function (e) {
|
||||
if (e.target.classList.contains('fa-eye')) {
|
||||
e.target.classList.remove('fa-eye');
|
||||
e.target.classList.add('fa-eye-slash');
|
||||
e.target.title = 'Hide lines';
|
||||
e.target.setAttribute('aria-label', e.target.title);
|
||||
|
||||
block.classList.remove('hide-boring');
|
||||
} else if (e.target.classList.contains('fa-eye-slash')) {
|
||||
e.target.classList.remove('fa-eye-slash');
|
||||
e.target.classList.add('fa-eye');
|
||||
e.target.title = 'Show hidden lines';
|
||||
e.target.setAttribute('aria-label', e.target.title);
|
||||
|
||||
block.classList.add('hide-boring');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
if (window.playground_copyable) {
|
||||
Array.from(document.querySelectorAll('pre code')).forEach(function (block) {
|
||||
var pre_block = block.parentNode;
|
||||
if (!pre_block.classList.contains('playground')) {
|
||||
var buttons = pre_block.querySelector(".buttons");
|
||||
if (!buttons) {
|
||||
buttons = document.createElement('div');
|
||||
buttons.className = 'buttons';
|
||||
pre_block.insertBefore(buttons, pre_block.firstChild);
|
||||
}
|
||||
|
||||
var clipButton = document.createElement('button');
|
||||
clipButton.className = 'fa fa-copy clip-button';
|
||||
clipButton.title = 'Copy to clipboard';
|
||||
clipButton.setAttribute('aria-label', clipButton.title);
|
||||
clipButton.innerHTML = '<i class=\"tooltiptext\"></i>';
|
||||
|
||||
buttons.insertBefore(clipButton, buttons.firstChild);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Process playground code blocks
|
||||
Array.from(document.querySelectorAll(".playground")).forEach(function (pre_block) {
|
||||
// Add play button
|
||||
var buttons = pre_block.querySelector(".buttons");
|
||||
if (!buttons) {
|
||||
buttons = document.createElement('div');
|
||||
buttons.className = 'buttons';
|
||||
pre_block.insertBefore(buttons, pre_block.firstChild);
|
||||
}
|
||||
|
||||
var runCodeButton = document.createElement('button');
|
||||
runCodeButton.className = 'fa fa-play play-button';
|
||||
runCodeButton.hidden = true;
|
||||
runCodeButton.title = 'Run this code';
|
||||
runCodeButton.setAttribute('aria-label', runCodeButton.title);
|
||||
|
||||
buttons.insertBefore(runCodeButton, buttons.firstChild);
|
||||
runCodeButton.addEventListener('click', function (e) {
|
||||
run_rust_code(pre_block);
|
||||
});
|
||||
|
||||
if (window.playground_copyable) {
|
||||
var copyCodeClipboardButton = document.createElement('button');
|
||||
copyCodeClipboardButton.className = 'fa fa-copy clip-button';
|
||||
copyCodeClipboardButton.innerHTML = '<i class="tooltiptext"></i>';
|
||||
copyCodeClipboardButton.title = 'Copy to clipboard';
|
||||
copyCodeClipboardButton.setAttribute('aria-label', copyCodeClipboardButton.title);
|
||||
|
||||
buttons.insertBefore(copyCodeClipboardButton, buttons.firstChild);
|
||||
}
|
||||
|
||||
let code_block = pre_block.querySelector("code");
|
||||
if (window.ace && code_block.classList.contains("editable")) {
|
||||
var undoChangesButton = document.createElement('button');
|
||||
undoChangesButton.className = 'fa fa-history reset-button';
|
||||
undoChangesButton.title = 'Undo changes';
|
||||
undoChangesButton.setAttribute('aria-label', undoChangesButton.title);
|
||||
|
||||
buttons.insertBefore(undoChangesButton, buttons.firstChild);
|
||||
|
||||
undoChangesButton.addEventListener('click', function () {
|
||||
let editor = window.ace.edit(code_block);
|
||||
editor.setValue(editor.originalCode);
|
||||
editor.clearSelection();
|
||||
});
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
||||
(function themes() {
|
||||
var html = document.querySelector('html');
|
||||
var themeToggleButton = document.getElementById('theme-toggle');
|
||||
var themePopup = document.getElementById('theme-list');
|
||||
var themeColorMetaTag = document.querySelector('meta[name="theme-color"]');
|
||||
var stylesheets = {
|
||||
ayuHighlight: document.querySelector("[href$='ayu-highlight.css']"),
|
||||
tomorrowNight: document.querySelector("[href$='tomorrow-night.css']"),
|
||||
highlight: document.querySelector("[href$='highlight.css']"),
|
||||
};
|
||||
|
||||
function showThemes() {
|
||||
themePopup.style.display = 'block';
|
||||
themeToggleButton.setAttribute('aria-expanded', true);
|
||||
themePopup.querySelector("button#" + get_theme()).focus();
|
||||
}
|
||||
|
||||
function hideThemes() {
|
||||
themePopup.style.display = 'none';
|
||||
themeToggleButton.setAttribute('aria-expanded', false);
|
||||
themeToggleButton.focus();
|
||||
}
|
||||
|
||||
function get_theme() {
|
||||
var theme;
|
||||
try { theme = localStorage.getItem('mdbook-theme'); } catch (e) { }
|
||||
if (theme === null || theme === undefined) {
|
||||
return default_theme;
|
||||
} else {
|
||||
return theme;
|
||||
}
|
||||
}
|
||||
|
||||
function set_theme(theme, store = true) {
|
||||
let ace_theme;
|
||||
|
||||
if (theme == 'coal' || theme == 'navy') {
|
||||
stylesheets.ayuHighlight.disabled = true;
|
||||
stylesheets.tomorrowNight.disabled = false;
|
||||
stylesheets.highlight.disabled = true;
|
||||
|
||||
ace_theme = "ace/theme/tomorrow_night";
|
||||
} else if (theme == 'ayu') {
|
||||
stylesheets.ayuHighlight.disabled = false;
|
||||
stylesheets.tomorrowNight.disabled = true;
|
||||
stylesheets.highlight.disabled = true;
|
||||
ace_theme = "ace/theme/tomorrow_night";
|
||||
} else {
|
||||
stylesheets.ayuHighlight.disabled = true;
|
||||
stylesheets.tomorrowNight.disabled = true;
|
||||
stylesheets.highlight.disabled = false;
|
||||
ace_theme = "ace/theme/dawn";
|
||||
}
|
||||
|
||||
setTimeout(function () {
|
||||
themeColorMetaTag.content = getComputedStyle(document.body).backgroundColor;
|
||||
}, 1);
|
||||
|
||||
if (window.ace && window.editors) {
|
||||
window.editors.forEach(function (editor) {
|
||||
editor.setTheme(ace_theme);
|
||||
});
|
||||
}
|
||||
|
||||
var previousTheme = get_theme();
|
||||
|
||||
if (store) {
|
||||
try { localStorage.setItem('mdbook-theme', theme); } catch (e) { }
|
||||
}
|
||||
|
||||
html.classList.remove(previousTheme);
|
||||
html.classList.add(theme);
|
||||
}
|
||||
|
||||
// Set theme
|
||||
var theme = get_theme();
|
||||
|
||||
set_theme(theme, false);
|
||||
|
||||
themeToggleButton.addEventListener('click', function () {
|
||||
if (themePopup.style.display === 'block') {
|
||||
hideThemes();
|
||||
} else {
|
||||
showThemes();
|
||||
}
|
||||
});
|
||||
|
||||
themePopup.addEventListener('click', function (e) {
|
||||
var theme = e.target.id || e.target.parentElement.id;
|
||||
set_theme(theme);
|
||||
});
|
||||
|
||||
themePopup.addEventListener('focusout', function(e) {
|
||||
// e.relatedTarget is null in Safari and Firefox on macOS (see workaround below)
|
||||
if (!!e.relatedTarget && !themeToggleButton.contains(e.relatedTarget) && !themePopup.contains(e.relatedTarget)) {
|
||||
hideThemes();
|
||||
}
|
||||
});
|
||||
|
||||
// Should not be needed, but it works around an issue on macOS & iOS: https://github.com/rust-lang/mdBook/issues/628
|
||||
document.addEventListener('click', function(e) {
|
||||
if (themePopup.style.display === 'block' && !themeToggleButton.contains(e.target) && !themePopup.contains(e.target)) {
|
||||
hideThemes();
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener('keydown', function (e) {
|
||||
if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) { return; }
|
||||
if (!themePopup.contains(e.target)) { return; }
|
||||
|
||||
switch (e.key) {
|
||||
case 'Escape':
|
||||
e.preventDefault();
|
||||
hideThemes();
|
||||
break;
|
||||
case 'ArrowUp':
|
||||
e.preventDefault();
|
||||
var li = document.activeElement.parentElement;
|
||||
if (li && li.previousElementSibling) {
|
||||
li.previousElementSibling.querySelector('button').focus();
|
||||
}
|
||||
break;
|
||||
case 'ArrowDown':
|
||||
e.preventDefault();
|
||||
var li = document.activeElement.parentElement;
|
||||
if (li && li.nextElementSibling) {
|
||||
li.nextElementSibling.querySelector('button').focus();
|
||||
}
|
||||
break;
|
||||
case 'Home':
|
||||
e.preventDefault();
|
||||
themePopup.querySelector('li:first-child button').focus();
|
||||
break;
|
||||
case 'End':
|
||||
e.preventDefault();
|
||||
themePopup.querySelector('li:last-child button').focus();
|
||||
break;
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
||||
(function sidebar() {
|
||||
var html = document.querySelector("html");
|
||||
var sidebar = document.getElementById("sidebar");
|
||||
var sidebarLinks = document.querySelectorAll('#sidebar a');
|
||||
var sidebarToggleButton = document.getElementById("sidebar-toggle");
|
||||
var sidebarResizeHandle = document.getElementById("sidebar-resize-handle");
|
||||
var firstContact = null;
|
||||
|
||||
function showSidebar() {
|
||||
html.classList.remove('sidebar-hidden')
|
||||
html.classList.add('sidebar-visible');
|
||||
Array.from(sidebarLinks).forEach(function (link) {
|
||||
link.setAttribute('tabIndex', 0);
|
||||
});
|
||||
sidebarToggleButton.setAttribute('aria-expanded', true);
|
||||
sidebar.setAttribute('aria-hidden', false);
|
||||
try { localStorage.setItem('mdbook-sidebar', 'visible'); } catch (e) { }
|
||||
}
|
||||
|
||||
|
||||
var sidebarAnchorToggles = document.querySelectorAll('#sidebar a.toggle');
|
||||
|
||||
function toggleSection(ev) {
|
||||
ev.currentTarget.parentElement.classList.toggle('expanded');
|
||||
}
|
||||
|
||||
Array.from(sidebarAnchorToggles).forEach(function (el) {
|
||||
el.addEventListener('click', toggleSection);
|
||||
});
|
||||
|
||||
function hideSidebar() {
|
||||
html.classList.remove('sidebar-visible')
|
||||
html.classList.add('sidebar-hidden');
|
||||
Array.from(sidebarLinks).forEach(function (link) {
|
||||
link.setAttribute('tabIndex', -1);
|
||||
});
|
||||
sidebarToggleButton.setAttribute('aria-expanded', false);
|
||||
sidebar.setAttribute('aria-hidden', true);
|
||||
try { localStorage.setItem('mdbook-sidebar', 'hidden'); } catch (e) { }
|
||||
}
|
||||
|
||||
// Toggle sidebar
|
||||
sidebarToggleButton.addEventListener('click', function sidebarToggle() {
|
||||
if (html.classList.contains("sidebar-hidden")) {
|
||||
var current_width = parseInt(
|
||||
document.documentElement.style.getPropertyValue('--sidebar-width'), 10);
|
||||
if (current_width < 150) {
|
||||
document.documentElement.style.setProperty('--sidebar-width', '150px');
|
||||
}
|
||||
showSidebar();
|
||||
} else if (html.classList.contains("sidebar-visible")) {
|
||||
hideSidebar();
|
||||
} else {
|
||||
if (getComputedStyle(sidebar)['transform'] === 'none') {
|
||||
hideSidebar();
|
||||
} else {
|
||||
showSidebar();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
sidebarResizeHandle.addEventListener('mousedown', initResize, false);
|
||||
|
||||
function initResize(e) {
|
||||
window.addEventListener('mousemove', resize, false);
|
||||
window.addEventListener('mouseup', stopResize, false);
|
||||
html.classList.add('sidebar-resizing');
|
||||
}
|
||||
function resize(e) {
|
||||
var pos = (e.clientX - sidebar.offsetLeft);
|
||||
if (pos < 20) {
|
||||
hideSidebar();
|
||||
} else {
|
||||
if (html.classList.contains("sidebar-hidden")) {
|
||||
showSidebar();
|
||||
}
|
||||
pos = Math.min(pos, window.innerWidth - 100);
|
||||
document.documentElement.style.setProperty('--sidebar-width', pos + 'px');
|
||||
}
|
||||
}
|
||||
//on mouseup remove windows functions mousemove & mouseup
|
||||
function stopResize(e) {
|
||||
html.classList.remove('sidebar-resizing');
|
||||
window.removeEventListener('mousemove', resize, false);
|
||||
window.removeEventListener('mouseup', stopResize, false);
|
||||
}
|
||||
|
||||
document.addEventListener('touchstart', function (e) {
|
||||
firstContact = {
|
||||
x: e.touches[0].clientX,
|
||||
time: Date.now()
|
||||
};
|
||||
}, { passive: true });
|
||||
|
||||
document.addEventListener('touchmove', function (e) {
|
||||
if (!firstContact)
|
||||
return;
|
||||
|
||||
var curX = e.touches[0].clientX;
|
||||
var xDiff = curX - firstContact.x,
|
||||
tDiff = Date.now() - firstContact.time;
|
||||
|
||||
if (tDiff < 250 && Math.abs(xDiff) >= 150) {
|
||||
if (xDiff >= 0 && firstContact.x < Math.min(document.body.clientWidth * 0.25, 300))
|
||||
showSidebar();
|
||||
else if (xDiff < 0 && curX < 300)
|
||||
hideSidebar();
|
||||
|
||||
firstContact = null;
|
||||
}
|
||||
}, { passive: true });
|
||||
|
||||
// Scroll sidebar to current active section
|
||||
var activeSection = document.getElementById("sidebar").querySelector(".active");
|
||||
if (activeSection) {
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView
|
||||
activeSection.scrollIntoView({ block: 'center' });
|
||||
}
|
||||
})();
|
||||
|
||||
(function chapterNavigation() {
|
||||
document.addEventListener('keydown', function (e) {
|
||||
if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) { return; }
|
||||
if (window.search && window.search.hasFocus()) { return; }
|
||||
|
||||
switch (e.key) {
|
||||
case 'ArrowRight':
|
||||
e.preventDefault();
|
||||
var nextButton = document.querySelector('.nav-chapters.next');
|
||||
if (nextButton) {
|
||||
window.location.href = nextButton.href;
|
||||
}
|
||||
break;
|
||||
case 'ArrowLeft':
|
||||
e.preventDefault();
|
||||
var previousButton = document.querySelector('.nav-chapters.previous');
|
||||
if (previousButton) {
|
||||
window.location.href = previousButton.href;
|
||||
}
|
||||
break;
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
||||
(function clipboard() {
|
||||
var clipButtons = document.querySelectorAll('.clip-button');
|
||||
|
||||
function hideTooltip(elem) {
|
||||
elem.firstChild.innerText = "";
|
||||
elem.className = 'fa fa-copy clip-button';
|
||||
}
|
||||
|
||||
function showTooltip(elem, msg) {
|
||||
elem.firstChild.innerText = msg;
|
||||
elem.className = 'fa fa-copy tooltipped';
|
||||
}
|
||||
|
||||
var clipboardSnippets = new ClipboardJS('.clip-button', {
|
||||
text: function (trigger) {
|
||||
hideTooltip(trigger);
|
||||
let playground = trigger.closest("pre");
|
||||
return playground_text(playground);
|
||||
}
|
||||
});
|
||||
|
||||
Array.from(clipButtons).forEach(function (clipButton) {
|
||||
clipButton.addEventListener('mouseout', function (e) {
|
||||
hideTooltip(e.currentTarget);
|
||||
});
|
||||
});
|
||||
|
||||
clipboardSnippets.on('success', function (e) {
|
||||
e.clearSelection();
|
||||
showTooltip(e.trigger, "Copied!");
|
||||
});
|
||||
|
||||
clipboardSnippets.on('error', function (e) {
|
||||
showTooltip(e.trigger, "Clipboard error!");
|
||||
});
|
||||
})();
|
||||
|
||||
(function scrollToTop () {
|
||||
var menuTitle = document.querySelector('.menu-title');
|
||||
|
||||
menuTitle.addEventListener('click', function () {
|
||||
document.scrollingElement.scrollTo({ top: 0, behavior: 'smooth' });
|
||||
});
|
||||
})();
|
||||
|
||||
(function controlMenu() {
|
||||
var menu = document.getElementById('menu-bar');
|
||||
|
||||
(function controlPosition() {
|
||||
var scrollTop = document.scrollingElement.scrollTop;
|
||||
var prevScrollTop = scrollTop;
|
||||
var minMenuY = -menu.clientHeight - 50;
|
||||
// When the script loads, the page can be at any scroll (e.g. if you reforesh it).
|
||||
menu.style.top = scrollTop + 'px';
|
||||
// Same as parseInt(menu.style.top.slice(0, -2), but faster
|
||||
var topCache = menu.style.top.slice(0, -2);
|
||||
menu.classList.remove('sticky');
|
||||
var stickyCache = false; // Same as menu.classList.contains('sticky'), but faster
|
||||
document.addEventListener('scroll', function () {
|
||||
scrollTop = Math.max(document.scrollingElement.scrollTop, 0);
|
||||
// `null` means that it doesn't need to be updated
|
||||
var nextSticky = null;
|
||||
var nextTop = null;
|
||||
var scrollDown = scrollTop > prevScrollTop;
|
||||
var menuPosAbsoluteY = topCache - scrollTop;
|
||||
if (scrollDown) {
|
||||
nextSticky = false;
|
||||
if (menuPosAbsoluteY > 0) {
|
||||
nextTop = prevScrollTop;
|
||||
}
|
||||
} else {
|
||||
if (menuPosAbsoluteY > 0) {
|
||||
nextSticky = true;
|
||||
} else if (menuPosAbsoluteY < minMenuY) {
|
||||
nextTop = prevScrollTop + minMenuY;
|
||||
}
|
||||
}
|
||||
if (nextSticky === true && stickyCache === false) {
|
||||
menu.classList.add('sticky');
|
||||
stickyCache = true;
|
||||
} else if (nextSticky === false && stickyCache === true) {
|
||||
menu.classList.remove('sticky');
|
||||
stickyCache = false;
|
||||
}
|
||||
if (nextTop !== null) {
|
||||
menu.style.top = nextTop + 'px';
|
||||
topCache = nextTop;
|
||||
}
|
||||
prevScrollTop = scrollTop;
|
||||
}, { passive: true });
|
||||
})();
|
||||
(function controlBorder() {
|
||||
menu.classList.remove('bordered');
|
||||
document.addEventListener('scroll', function () {
|
||||
if (menu.offsetTop === 0) {
|
||||
menu.classList.remove('bordered');
|
||||
} else {
|
||||
menu.classList.add('bordered');
|
||||
}
|
||||
}, { passive: true });
|
||||
})();
|
||||
})();
|
@ -1,499 +0,0 @@
|
||||
/* CSS for UI elements (a.k.a. chrome) */
|
||||
|
||||
@import 'variables.css';
|
||||
|
||||
::-webkit-scrollbar {
|
||||
background: var(--bg);
|
||||
}
|
||||
::-webkit-scrollbar-thumb {
|
||||
background: var(--scrollbar);
|
||||
}
|
||||
html {
|
||||
scrollbar-color: var(--scrollbar) var(--bg);
|
||||
}
|
||||
#searchresults a,
|
||||
.content a:link,
|
||||
a:visited,
|
||||
a > .hljs {
|
||||
color: var(--links);
|
||||
}
|
||||
.content a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/* Menu Bar */
|
||||
|
||||
#menu-bar,
|
||||
#menu-bar-hover-placeholder {
|
||||
z-index: 101;
|
||||
margin: auto calc(0px - var(--page-padding));
|
||||
}
|
||||
#menu-bar {
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
background-color: var(--bg);
|
||||
border-bottom-color: var(--bg);
|
||||
border-bottom-width: 1px;
|
||||
border-bottom-style: solid;
|
||||
}
|
||||
#menu-bar.sticky,
|
||||
.js #menu-bar-hover-placeholder:hover + #menu-bar,
|
||||
.js #menu-bar:hover,
|
||||
.js.sidebar-visible #menu-bar {
|
||||
position: -webkit-sticky;
|
||||
position: sticky;
|
||||
top: 0 !important;
|
||||
}
|
||||
#menu-bar-hover-placeholder {
|
||||
position: sticky;
|
||||
position: -webkit-sticky;
|
||||
top: 0;
|
||||
height: var(--menu-bar-height);
|
||||
}
|
||||
#menu-bar.bordered {
|
||||
border-bottom-color: var(--table-border-color);
|
||||
}
|
||||
#menu-bar i, #menu-bar .icon-button {
|
||||
position: relative;
|
||||
padding: 0 8px;
|
||||
z-index: 10;
|
||||
line-height: var(--menu-bar-height);
|
||||
cursor: pointer;
|
||||
transition: color 0.5s;
|
||||
}
|
||||
@media only screen and (max-width: 420px) {
|
||||
#menu-bar i, #menu-bar .icon-button {
|
||||
padding: 0 5px;
|
||||
}
|
||||
}
|
||||
|
||||
.icon-button {
|
||||
border: none;
|
||||
background: none;
|
||||
padding: 0;
|
||||
color: inherit;
|
||||
}
|
||||
.icon-button i {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.right-buttons {
|
||||
margin: 0 15px;
|
||||
}
|
||||
.right-buttons a {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.left-buttons {
|
||||
display: flex;
|
||||
margin: 0 5px;
|
||||
}
|
||||
.no-js .left-buttons {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.menu-title {
|
||||
display: inline-block;
|
||||
font-weight: 200;
|
||||
font-size: 2.4rem;
|
||||
line-height: var(--menu-bar-height);
|
||||
text-align: center;
|
||||
margin: 0;
|
||||
flex: 1;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.js .menu-title {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.menu-bar,
|
||||
.menu-bar:visited,
|
||||
.nav-chapters,
|
||||
.nav-chapters:visited,
|
||||
.mobile-nav-chapters,
|
||||
.mobile-nav-chapters:visited,
|
||||
.menu-bar .icon-button,
|
||||
.menu-bar a i {
|
||||
color: var(--icons);
|
||||
}
|
||||
|
||||
.menu-bar i:hover,
|
||||
.menu-bar .icon-button:hover,
|
||||
.nav-chapters:hover,
|
||||
.mobile-nav-chapters i:hover {
|
||||
color: var(--icons-hover);
|
||||
}
|
||||
|
||||
/* Nav Icons */
|
||||
|
||||
.nav-chapters {
|
||||
font-size: 2.5em;
|
||||
text-align: center;
|
||||
text-decoration: none;
|
||||
|
||||
position: fixed;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
margin: 0;
|
||||
max-width: 150px;
|
||||
min-width: 90px;
|
||||
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-content: center;
|
||||
flex-direction: column;
|
||||
|
||||
transition: color 0.5s, background-color 0.5s;
|
||||
}
|
||||
|
||||
.nav-chapters:hover {
|
||||
text-decoration: none;
|
||||
background-color: var(--theme-hover);
|
||||
transition: background-color 0.15s, color 0.15s;
|
||||
}
|
||||
|
||||
.nav-wrapper {
|
||||
margin-top: 50px;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.mobile-nav-chapters {
|
||||
font-size: 2.5em;
|
||||
text-align: center;
|
||||
text-decoration: none;
|
||||
width: 90px;
|
||||
border-radius: 5px;
|
||||
background-color: var(--sidebar-bg);
|
||||
}
|
||||
|
||||
.previous {
|
||||
float: left;
|
||||
}
|
||||
|
||||
.next {
|
||||
float: right;
|
||||
right: var(--page-padding);
|
||||
}
|
||||
|
||||
@media only screen and (max-width: 1080px) {
|
||||
.nav-wide-wrapper { display: none; }
|
||||
.nav-wrapper { display: block; }
|
||||
}
|
||||
|
||||
@media only screen and (max-width: 1380px) {
|
||||
.sidebar-visible .nav-wide-wrapper { display: none; }
|
||||
.sidebar-visible .nav-wrapper { display: block; }
|
||||
}
|
||||
|
||||
/* Inline code */
|
||||
|
||||
:not(pre) > .hljs {
|
||||
display: inline;
|
||||
padding: 0.1em 0.3em;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
:not(pre):not(a):not(td):not(p) > .hljs {
|
||||
color: var(--inline-code-color);
|
||||
overflow-x: initial;
|
||||
}
|
||||
|
||||
a:hover > .hljs {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
pre {
|
||||
position: relative;
|
||||
}
|
||||
pre > .buttons {
|
||||
position: absolute;
|
||||
z-index: 100;
|
||||
right: 5px;
|
||||
top: 5px;
|
||||
|
||||
color: var(--sidebar-fg);
|
||||
cursor: pointer;
|
||||
}
|
||||
pre > .buttons :hover {
|
||||
color: var(--sidebar-active);
|
||||
}
|
||||
pre > .buttons i {
|
||||
margin-left: 8px;
|
||||
}
|
||||
pre > .buttons button {
|
||||
color: inherit;
|
||||
background: transparent;
|
||||
border: none;
|
||||
cursor: inherit;
|
||||
}
|
||||
pre > .result {
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
/* Search */
|
||||
|
||||
#searchresults a {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
mark {
|
||||
border-radius: 2px;
|
||||
padding: 0 3px 1px 3px;
|
||||
margin: 0 -3px -1px -3px;
|
||||
background-color: var(--search-mark-bg);
|
||||
transition: background-color 300ms linear;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
mark.fade-out {
|
||||
background-color: rgba(0,0,0,0) !important;
|
||||
cursor: auto;
|
||||
}
|
||||
|
||||
.searchbar-outer {
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
max-width: var(--content-max-width);
|
||||
}
|
||||
|
||||
#searchbar {
|
||||
width: 100%;
|
||||
margin: 5px auto 0px auto;
|
||||
padding: 10px 16px;
|
||||
transition: box-shadow 300ms ease-in-out;
|
||||
border: 1px solid var(--searchbar-border-color);
|
||||
border-radius: 3px;
|
||||
background-color: var(--searchbar-bg);
|
||||
color: var(--searchbar-fg);
|
||||
}
|
||||
#searchbar:focus,
|
||||
#searchbar.active {
|
||||
box-shadow: 0 0 3px var(--searchbar-shadow-color);
|
||||
}
|
||||
|
||||
.searchresults-header {
|
||||
font-weight: bold;
|
||||
font-size: 1em;
|
||||
padding: 18px 0 0 5px;
|
||||
color: var(--searchresults-header-fg);
|
||||
}
|
||||
|
||||
.searchresults-outer {
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
max-width: var(--content-max-width);
|
||||
border-bottom: 1px dashed var(--searchresults-border-color);
|
||||
}
|
||||
|
||||
ul#searchresults {
|
||||
list-style: none;
|
||||
padding-left: 20px;
|
||||
}
|
||||
ul#searchresults li {
|
||||
margin: 10px 0px;
|
||||
padding: 2px;
|
||||
border-radius: 2px;
|
||||
}
|
||||
ul#searchresults li.focus {
|
||||
background-color: var(--searchresults-li-bg);
|
||||
}
|
||||
ul#searchresults span.teaser {
|
||||
display: block;
|
||||
clear: both;
|
||||
margin: 5px 0 0 20px;
|
||||
font-size: 0.8em;
|
||||
}
|
||||
ul#searchresults span.teaser em {
|
||||
font-weight: bold;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
/* Sidebar */
|
||||
|
||||
.sidebar {
|
||||
position: fixed;
|
||||
left: 0;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
width: var(--sidebar-width);
|
||||
font-size: 0.875em;
|
||||
box-sizing: border-box;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
overscroll-behavior-y: contain;
|
||||
background-color: var(--sidebar-bg);
|
||||
color: var(--sidebar-fg);
|
||||
}
|
||||
.sidebar-resizing {
|
||||
-moz-user-select: none;
|
||||
-webkit-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
.js:not(.sidebar-resizing) .sidebar {
|
||||
transition: transform 0.3s; /* Animation: slide away */
|
||||
}
|
||||
.sidebar code {
|
||||
line-height: 2em;
|
||||
}
|
||||
.sidebar .sidebar-scrollbox {
|
||||
overflow-y: auto;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
}
|
||||
.sidebar .sidebar-resize-handle {
|
||||
position: absolute;
|
||||
cursor: col-resize;
|
||||
width: 0;
|
||||
right: 0;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
}
|
||||
.js .sidebar .sidebar-resize-handle {
|
||||
cursor: col-resize;
|
||||
width: 5px;
|
||||
}
|
||||
.sidebar-hidden .sidebar {
|
||||
transform: translateX(calc(0px - var(--sidebar-width)));
|
||||
}
|
||||
.sidebar::-webkit-scrollbar {
|
||||
background: var(--sidebar-bg);
|
||||
}
|
||||
.sidebar::-webkit-scrollbar-thumb {
|
||||
background: var(--scrollbar);
|
||||
}
|
||||
|
||||
.sidebar-visible .page-wrapper {
|
||||
transform: translateX(var(--sidebar-width));
|
||||
}
|
||||
@media only screen and (min-width: 620px) {
|
||||
.sidebar-visible .page-wrapper {
|
||||
transform: none;
|
||||
margin-left: var(--sidebar-width);
|
||||
}
|
||||
}
|
||||
|
||||
.chapter {
|
||||
list-style: none outside none;
|
||||
padding-left: 0;
|
||||
margin: .25rem 0;
|
||||
}
|
||||
|
||||
.chapter ol {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.chapter li {
|
||||
display: flex;
|
||||
color: var(--sidebar-non-existent);
|
||||
}
|
||||
.chapter li a {
|
||||
display: block;
|
||||
text-decoration: none;
|
||||
color: var(--sidebar-fg);
|
||||
}
|
||||
|
||||
.chapter li a:hover {
|
||||
color: var(--sidebar-active);
|
||||
}
|
||||
|
||||
.chapter li a.active {
|
||||
color: var(--sidebar-active);
|
||||
}
|
||||
|
||||
.chapter li > a.toggle {
|
||||
cursor: pointer;
|
||||
display: block;
|
||||
margin-left: auto;
|
||||
padding: 0 10px;
|
||||
user-select: none;
|
||||
opacity: 0.68;
|
||||
}
|
||||
|
||||
.chapter li > a.toggle div {
|
||||
transition: transform 0.5s;
|
||||
}
|
||||
|
||||
/* collapse the section */
|
||||
.chapter li:not(.expanded) + li > ol {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.chapter li.chapter-item {
|
||||
padding: 1rem 1.5rem;
|
||||
}
|
||||
|
||||
.chapter .section li.chapter-item {
|
||||
padding: .5rem .5rem 0 .5rem;
|
||||
}
|
||||
|
||||
.chapter li.expanded > a.toggle div {
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
|
||||
.spacer {
|
||||
width: 100%;
|
||||
height: 3px;
|
||||
margin: 5px 0px;
|
||||
}
|
||||
.chapter .spacer {
|
||||
background-color: var(--sidebar-spacer);
|
||||
}
|
||||
|
||||
@media (-moz-touch-enabled: 1), (pointer: coarse) {
|
||||
.chapter li a { padding: 5px 0; }
|
||||
.spacer { margin: 10px 0; }
|
||||
}
|
||||
|
||||
.section {
|
||||
list-style: none outside none;
|
||||
padding-left: 2rem;
|
||||
line-height: 1.9em;
|
||||
}
|
||||
|
||||
/* Theme Menu Popup */
|
||||
|
||||
.theme-popup {
|
||||
position: absolute;
|
||||
left: 10px;
|
||||
top: var(--menu-bar-height);
|
||||
z-index: 1000;
|
||||
border-radius: 4px;
|
||||
font-size: 0.7em;
|
||||
color: var(--fg);
|
||||
background: var(--theme-popup-bg);
|
||||
border: 1px solid var(--theme-popup-border);
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
display: none;
|
||||
}
|
||||
.theme-popup .default {
|
||||
color: var(--icons);
|
||||
}
|
||||
.theme-popup .theme {
|
||||
width: 100%;
|
||||
border: 0;
|
||||
margin: 0;
|
||||
padding: 2px 10px;
|
||||
line-height: 25px;
|
||||
white-space: nowrap;
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
color: inherit;
|
||||
background: inherit;
|
||||
font-size: inherit;
|
||||
}
|
||||
.theme-popup .theme:hover {
|
||||
background-color: var(--theme-hover);
|
||||
}
|
||||
.theme-popup .theme:hover:first-child,
|
||||
.theme-popup .theme:hover:last-child {
|
||||
border-top-left-radius: inherit;
|
||||
border-top-right-radius: inherit;
|
||||
}
|
@ -1,233 +0,0 @@
|
||||
/* Base styles and content styles */
|
||||
|
||||
@import 'variables.css';
|
||||
|
||||
:root {
|
||||
/* Browser default font-size is 16px, this way 1 rem = 10px */
|
||||
font-size: 62.5%;
|
||||
}
|
||||
|
||||
/* TODO: replace with self hosted fonts */
|
||||
|
||||
html {
|
||||
font-family: "Inter", sans-serif;
|
||||
color: var(--fg);
|
||||
background-color: var(--bg);
|
||||
text-size-adjust: none;
|
||||
}
|
||||
|
||||
/* @supports (font-variation-settings: normal) { */
|
||||
/* html { font-family: 'Inter var', sans-serif; } */
|
||||
/* } */
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
font-size: 1.6rem;
|
||||
overflow-x: hidden;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: "Source Code Pro", Consolas, "Ubuntu Mono", Menlo, "DejaVu Sans Mono", monospace, monospace !important;
|
||||
font-size: 0.875em; /* please adjust the ace font size accordingly in editor.js */
|
||||
}
|
||||
|
||||
/* Don't change font size in headers. */
|
||||
h1 code, h2 code, h3 code, h4 code, h5 code, h6 code {
|
||||
font-size: unset;
|
||||
}
|
||||
|
||||
.left { float: left; }
|
||||
.right { float: right; }
|
||||
.boring { opacity: 0.6; }
|
||||
.hide-boring .boring { display: none; }
|
||||
.hidden { display: none !important; }
|
||||
|
||||
h2, h3 { margin-top: 2.5em; }
|
||||
h4, h5 { margin-top: 2em; }
|
||||
|
||||
.header + .header h3,
|
||||
.header + .header h4,
|
||||
.header + .header h5 {
|
||||
margin-top: 1em;
|
||||
}
|
||||
|
||||
h1:target::before,
|
||||
h2:target::before,
|
||||
h3:target::before,
|
||||
h4:target::before,
|
||||
h5:target::before,
|
||||
h6:target::before {
|
||||
display: inline-block;
|
||||
content: "»";
|
||||
margin-left: -30px;
|
||||
width: 30px;
|
||||
}
|
||||
|
||||
/* This is broken on Safari as of version 14, but is fixed
|
||||
in Safari Technology Preview 117 which I think will be Safari 14.2.
|
||||
https://bugs.webkit.org/show_bug.cgi?id=218076
|
||||
*/
|
||||
:target {
|
||||
scroll-margin-top: calc(var(--menu-bar-height) + 0.5em);
|
||||
}
|
||||
|
||||
.page {
|
||||
outline: 0;
|
||||
padding: 0 var(--page-padding);
|
||||
margin-top: calc(0px - var(--menu-bar-height)); /* Compensate for the #menu-bar-hover-placeholder */
|
||||
}
|
||||
.page-wrapper {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.js:not(.sidebar-resizing) .page-wrapper {
|
||||
transition: margin-left 0.3s ease, transform 0.3s ease; /* Animation: slide away */
|
||||
}
|
||||
|
||||
.content {
|
||||
overflow-y: auto;
|
||||
padding: 0 15px;
|
||||
padding-bottom: 50px;
|
||||
}
|
||||
.content main {
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
max-width: var(--content-max-width);
|
||||
}
|
||||
|
||||
|
||||
/* 2 1.75 1.5 1.25 1 .875 */
|
||||
|
||||
.content h1 { font-size: 2em }
|
||||
.content h2 { font-size: 1.75em }
|
||||
.content h3 { font-size: 1.5em }
|
||||
.content h4 { font-size: 1.25em }
|
||||
.content h5 { font-size: 1em }
|
||||
.content h6 { font-size: .875em }
|
||||
|
||||
.content h1, .content h2, .content h3, .content h4 {
|
||||
font-weight: 500;
|
||||
margin-top: 1.275em;
|
||||
margin-bottom: .875em;
|
||||
}
|
||||
.content p, .content ol, .content ul, .content table {
|
||||
margin-top: 0;
|
||||
margin-bottom: .875em;
|
||||
}
|
||||
|
||||
.content ul li {
|
||||
margin-bottom: .25rem;
|
||||
}
|
||||
.content ul {
|
||||
list-style-type: square;
|
||||
}
|
||||
.content ul ul, .content ol ul {
|
||||
margin-bottom: .5rem;
|
||||
}
|
||||
.content li p {
|
||||
margin-bottom: .5em;
|
||||
}
|
||||
|
||||
.content p { line-height: 1.45em; }
|
||||
.content ol { line-height: 1.45em; }
|
||||
.content ul { line-height: 1.45em; }
|
||||
.content a { text-decoration: none; }
|
||||
.content a:hover { text-decoration: underline; }
|
||||
.content img { max-width: 100%; }
|
||||
.content .header:link,
|
||||
.content .header:visited {
|
||||
color: var(--fg);
|
||||
color: var(--heading-fg);
|
||||
}
|
||||
.content .header:link,
|
||||
.content .header:visited:hover {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
table {
|
||||
margin: 0 auto;
|
||||
border-collapse: collapse;
|
||||
width: 100%;
|
||||
}
|
||||
table td {
|
||||
padding: .75rem;
|
||||
width: auto;
|
||||
}
|
||||
table thead {
|
||||
background: var(--table-header-bg);
|
||||
}
|
||||
table thead td {
|
||||
font-weight: 700;
|
||||
border: none;
|
||||
}
|
||||
table thead th {
|
||||
padding: .75rem;
|
||||
text-align: left;
|
||||
font-weight: 500;
|
||||
line-height: 1.5;
|
||||
width: auto;
|
||||
}
|
||||
table thead tr {
|
||||
border-bottom: 2px var(--table-border-color) solid;
|
||||
}
|
||||
table tbody tr {
|
||||
border-bottom: 1px var(--table-border-line) solid;
|
||||
}
|
||||
/* Alternate background colors for rows */
|
||||
table tbody tr:nth-child(2n) {
|
||||
/* background: var(--table-alternate-bg); */
|
||||
}
|
||||
|
||||
|
||||
blockquote {
|
||||
margin: 1.5rem 0;
|
||||
padding: 1rem 1.5rem;
|
||||
color: var(--fg);
|
||||
opacity: .9;
|
||||
background-color: var(--quote-bg);
|
||||
border-left: 4px solid var(--quote-border);
|
||||
}
|
||||
blockquote *:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
|
||||
:not(.footnote-definition) + .footnote-definition,
|
||||
.footnote-definition + :not(.footnote-definition) {
|
||||
margin-top: 2em;
|
||||
}
|
||||
.footnote-definition {
|
||||
font-size: 0.9em;
|
||||
margin: 0.5em 0;
|
||||
}
|
||||
.footnote-definition p {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
.tooltiptext {
|
||||
position: absolute;
|
||||
visibility: hidden;
|
||||
color: #fff;
|
||||
background-color: #333;
|
||||
transform: translateX(-50%); /* Center by moving tooltip 50% of its width left */
|
||||
left: -8px; /* Half of the width of the icon */
|
||||
top: -35px;
|
||||
font-size: 0.8em;
|
||||
text-align: center;
|
||||
border-radius: 6px;
|
||||
padding: 5px 8px;
|
||||
margin: 5px;
|
||||
z-index: 1000;
|
||||
}
|
||||
.tooltipped .tooltiptext {
|
||||
visibility: visible;
|
||||
}
|
||||
|
||||
.chapter li.part-title {
|
||||
color: var(--sidebar-fg);
|
||||
margin: 5px 0px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.result-no-output {
|
||||
font-style: italic;
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
|
||||
#sidebar,
|
||||
#menu-bar,
|
||||
.nav-chapters,
|
||||
.mobile-nav-chapters {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#page-wrapper.page-wrapper {
|
||||
transform: none;
|
||||
margin-left: 0px;
|
||||
overflow-y: initial;
|
||||
}
|
||||
|
||||
#content {
|
||||
max-width: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.page {
|
||||
overflow-y: initial;
|
||||
}
|
||||
|
||||
code {
|
||||
background-color: #666666;
|
||||
border-radius: 5px;
|
||||
|
||||
/* Force background to be printed in Chrome */
|
||||
-webkit-print-color-adjust: exact;
|
||||
}
|
||||
|
||||
pre > .buttons {
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
a, a:visited, a:active, a:hover {
|
||||
color: #4183c4;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
h1, h2, h3, h4, h5, h6 {
|
||||
page-break-inside: avoid;
|
||||
page-break-after: avoid;
|
||||
}
|
||||
|
||||
pre, code {
|
||||
page-break-inside: avoid;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
.fa {
|
||||
display: none !important;
|
||||
}
|
@ -1,411 +0,0 @@
|
||||
|
||||
/* Globals */
|
||||
|
||||
:root {
|
||||
--sidebar-width: 300px;
|
||||
--page-padding: 15px;
|
||||
--content-max-width: 750px;
|
||||
--menu-bar-height: 50px;
|
||||
}
|
||||
|
||||
/* Themes */
|
||||
|
||||
.ayu {
|
||||
--bg: hsl(210, 25%, 8%);
|
||||
--fg: #c5c5c5;
|
||||
|
||||
--sidebar-bg: #14191f;
|
||||
--sidebar-fg: #c8c9db;
|
||||
--sidebar-non-existent: #5c6773;
|
||||
--sidebar-active: #ffb454;
|
||||
--sidebar-spacer: #2d334f;
|
||||
|
||||
--scrollbar: var(--sidebar-fg);
|
||||
|
||||
--icons: #737480;
|
||||
--icons-hover: #b7b9cc;
|
||||
|
||||
--links: #0096cf;
|
||||
|
||||
--inline-code-color: #ffb454;
|
||||
|
||||
--theme-popup-bg: #14191f;
|
||||
--theme-popup-border: #5c6773;
|
||||
--theme-hover: #191f26;
|
||||
|
||||
--quote-bg: hsl(226, 15%, 17%);
|
||||
--quote-border: hsl(226, 15%, 22%);
|
||||
|
||||
--table-border-color: hsl(210, 25%, 13%);
|
||||
--table-header-bg: hsl(210, 25%, 28%);
|
||||
--table-alternate-bg: hsl(210, 25%, 11%);
|
||||
|
||||
--searchbar-border-color: #848484;
|
||||
--searchbar-bg: #424242;
|
||||
--searchbar-fg: #fff;
|
||||
--searchbar-shadow-color: #d4c89f;
|
||||
--searchresults-header-fg: #666;
|
||||
--searchresults-border-color: #888;
|
||||
--searchresults-li-bg: #252932;
|
||||
--search-mark-bg: #e3b171;
|
||||
--hljs-background: #191f26;
|
||||
--hljs-color: #e6e1cf;
|
||||
--hljs-quote: #5c6773;
|
||||
--hljs-variable: #ff7733;
|
||||
--hljs-type: #ffee99;
|
||||
--hljs-title: #b8cc52;
|
||||
--hljs-symbol: #ffb454;
|
||||
--hljs-selector-tag: #ff7733;
|
||||
--hljs-selector-tag: #36a3d9;
|
||||
--hljs-selector-tag: #00568d;
|
||||
--hljs-selector-tag: #91b362;
|
||||
--hljs-selector-tag: #d96c75;
|
||||
}
|
||||
|
||||
.coal {
|
||||
--bg: hsl(200, 7%, 8%);
|
||||
--fg: #98a3ad;
|
||||
|
||||
--sidebar-bg: #292c2f;
|
||||
--sidebar-fg: #a1adb8;
|
||||
--sidebar-non-existent: #505254;
|
||||
--sidebar-active: #3473ad;
|
||||
--sidebar-spacer: #393939;
|
||||
|
||||
--scrollbar: var(--sidebar-fg);
|
||||
|
||||
--icons: #43484d;
|
||||
--icons-hover: #b3c0cc;
|
||||
|
||||
--links: #2b79a2;
|
||||
|
||||
--inline-code-color: #c5c8c6;
|
||||
|
||||
--theme-popup-bg: #141617;
|
||||
--theme-popup-border: #43484d;
|
||||
--theme-hover: #1f2124;
|
||||
|
||||
--quote-bg: hsl(234, 21%, 18%);
|
||||
--quote-border: hsl(234, 21%, 23%);
|
||||
|
||||
--table-border-color: hsl(200, 7%, 13%);
|
||||
--table-header-bg: hsl(200, 7%, 28%);
|
||||
--table-alternate-bg: hsl(200, 7%, 11%);
|
||||
|
||||
--searchbar-border-color: #aaa;
|
||||
--searchbar-bg: #b7b7b7;
|
||||
--searchbar-fg: #000;
|
||||
--searchbar-shadow-color: #aaa;
|
||||
--searchresults-header-fg: #666;
|
||||
--searchresults-border-color: #98a3ad;
|
||||
--searchresults-li-bg: #2b2b2f;
|
||||
--search-mark-bg: #355c7d;
|
||||
--hljs-background: #969896;
|
||||
--hljs-color: #cc6666;
|
||||
--hljs-quote: #de935f;
|
||||
--hljs-variable: #f0c674;
|
||||
--hljs-type: #b5bd68;
|
||||
--hljs-title: #8abeb7;
|
||||
--hljs-symbol: #81a2be;
|
||||
--hljs-selector-tag: #b294bb;
|
||||
--hljs-selector-tag: #1d1f21;
|
||||
--hljs-selector-tag: #c5c8c6;
|
||||
--hljs-selector-tag: #718c00;
|
||||
--hljs-selector-tag: #c82829;
|
||||
}
|
||||
|
||||
.light {
|
||||
--bg: hsl(0, 0%, 100%);
|
||||
--fg: hsl(0, 0%, 0%);
|
||||
|
||||
--sidebar-bg: #fafafa;
|
||||
--sidebar-fg: hsl(0, 0%, 0%);
|
||||
--sidebar-non-existent: #aaaaaa;
|
||||
--sidebar-active: #1f1fff;
|
||||
--sidebar-spacer: #f4f4f4;
|
||||
|
||||
--scrollbar: #8F8F8F;
|
||||
|
||||
--icons: #747474;
|
||||
--icons-hover: #000000;
|
||||
|
||||
--links: #20609f;
|
||||
|
||||
--inline-code-color: #301900;
|
||||
|
||||
--theme-popup-bg: #fafafa;
|
||||
--theme-popup-border: #cccccc;
|
||||
--theme-hover: #e6e6e6;
|
||||
|
||||
--quote-bg: hsl(197, 37%, 96%);
|
||||
--quote-border: hsl(197, 37%, 91%);
|
||||
|
||||
--table-border-color: hsl(0, 0%, 95%);
|
||||
--table-header-bg: hsl(0, 0%, 80%);
|
||||
--table-alternate-bg: hsl(0, 0%, 97%);
|
||||
|
||||
--searchbar-border-color: #aaa;
|
||||
--searchbar-bg: #fafafa;
|
||||
--searchbar-fg: #000;
|
||||
--searchbar-shadow-color: #aaa;
|
||||
--searchresults-header-fg: #666;
|
||||
--searchresults-border-color: #888;
|
||||
--searchresults-li-bg: #e4f2fe;
|
||||
--search-mark-bg: #a2cff5;
|
||||
--hljs-background: #f6f7f6;
|
||||
--hljs-color: #000;
|
||||
--hljs-quote: #575757;
|
||||
--hljs-variable: #d70025;
|
||||
--hljs-type: #b21e00;
|
||||
--hljs-title: #0030f2;
|
||||
--hljs-symbol: #008200;
|
||||
--hljs-selector-tag: #9d00ec;
|
||||
}
|
||||
|
||||
.navy {
|
||||
--bg: hsl(226, 23%, 11%);
|
||||
--fg: #bcbdd0;
|
||||
|
||||
--sidebar-bg: #282d3f;
|
||||
--sidebar-fg: #c8c9db;
|
||||
--sidebar-non-existent: #505274;
|
||||
--sidebar-active: #2b79a2;
|
||||
--sidebar-spacer: #2d334f;
|
||||
|
||||
--scrollbar: var(--sidebar-fg);
|
||||
|
||||
--icons: #737480;
|
||||
--icons-hover: #b7b9cc;
|
||||
|
||||
--links: #2b79a2;
|
||||
|
||||
--inline-code-color: #c5c8c6;
|
||||
|
||||
--theme-popup-bg: #161923;
|
||||
--theme-popup-border: #737480;
|
||||
--theme-hover: #282e40;
|
||||
|
||||
--quote-bg: hsl(226, 15%, 17%);
|
||||
--quote-border: hsl(226, 15%, 22%);
|
||||
|
||||
--table-border-color: hsl(226, 23%, 16%);
|
||||
--table-header-bg: hsl(226, 23%, 31%);
|
||||
--table-alternate-bg: hsl(226, 23%, 14%);
|
||||
|
||||
--searchbar-border-color: #aaa;
|
||||
--searchbar-bg: #aeaec6;
|
||||
--searchbar-fg: #000;
|
||||
--searchbar-shadow-color: #aaa;
|
||||
--searchresults-header-fg: #5f5f71;
|
||||
--searchresults-border-color: #5c5c68;
|
||||
--searchresults-li-bg: #242430;
|
||||
--search-mark-bg: #a2cff5;
|
||||
|
||||
--hljs-background: #969896;
|
||||
--hljs-color: #cc6666;
|
||||
--hljs-quote: #de935f;
|
||||
--hljs-variable: #f0c674;
|
||||
--hljs-type: #b5bd68;
|
||||
--hljs-title: #8abeb7;
|
||||
--hljs-symbol: #81a2be;
|
||||
--hljs-selector-tag: #b294bb;
|
||||
--hljs-selector-tag: #1d1f21;
|
||||
--hljs-selector-tag: #c5c8c6;
|
||||
--hljs-selector-tag: #718c00;
|
||||
--hljs-selector-tag: #c82829;
|
||||
}
|
||||
|
||||
.rust {
|
||||
--bg: hsl(60, 9%, 87%);
|
||||
--fg: #262625;
|
||||
|
||||
--sidebar-bg: #3b2e2a;
|
||||
--sidebar-fg: #c8c9db;
|
||||
--sidebar-non-existent: #505254;
|
||||
--sidebar-active: #e69f67;
|
||||
--sidebar-spacer: #45373a;
|
||||
|
||||
--scrollbar: var(--sidebar-fg);
|
||||
|
||||
--icons: #737480;
|
||||
--icons-hover: #262625;
|
||||
|
||||
--links: #2b79a2;
|
||||
|
||||
--inline-code-color: #6e6b5e;
|
||||
|
||||
--theme-popup-bg: #e1e1db;
|
||||
--theme-popup-border: #b38f6b;
|
||||
--theme-hover: #99908a;
|
||||
|
||||
--quote-bg: hsl(60, 5%, 75%);
|
||||
--quote-border: hsl(60, 5%, 70%);
|
||||
|
||||
--table-border-color: hsl(60, 9%, 82%);
|
||||
--table-header-bg: #b3a497;
|
||||
--table-alternate-bg: hsl(60, 9%, 84%);
|
||||
|
||||
--searchbar-border-color: #aaa;
|
||||
--searchbar-bg: #fafafa;
|
||||
--searchbar-fg: #000;
|
||||
--searchbar-shadow-color: #aaa;
|
||||
--searchresults-header-fg: #666;
|
||||
--searchresults-border-color: #888;
|
||||
--searchresults-li-bg: #dec2a2;
|
||||
--search-mark-bg: #e69f67;
|
||||
--hljs-background: #f6f7f6;
|
||||
--hljs-color: #000;
|
||||
--hljs-quote: #575757;
|
||||
--hljs-variable: #d70025;
|
||||
--hljs-type: #b21e00;
|
||||
--hljs-title: #0030f2;
|
||||
--hljs-symbol: #008200;
|
||||
--hljs-selector-tag: #9d00ec;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
.light.no-js {
|
||||
--bg: hsl(200, 7%, 8%);
|
||||
--fg: #98a3ad;
|
||||
|
||||
--sidebar-bg: #292c2f;
|
||||
--sidebar-fg: #a1adb8;
|
||||
--sidebar-non-existent: #505254;
|
||||
--sidebar-active: #3473ad;
|
||||
--sidebar-spacer: #393939;
|
||||
|
||||
--scrollbar: var(--sidebar-fg);
|
||||
|
||||
--icons: #43484d;
|
||||
--icons-hover: #b3c0cc;
|
||||
|
||||
--links: #2b79a2;
|
||||
|
||||
--inline-code-color: #c5c8c6;
|
||||
|
||||
--theme-popup-bg: #141617;
|
||||
--theme-popup-border: #43484d;
|
||||
--theme-hover: #1f2124;
|
||||
|
||||
--quote-bg: hsl(234, 21%, 18%);
|
||||
--quote-border: hsl(234, 21%, 23%);
|
||||
|
||||
--table-border-color: hsl(200, 7%, 13%);
|
||||
--table-header-bg: hsl(200, 7%, 28%);
|
||||
--table-alternate-bg: hsl(200, 7%, 11%);
|
||||
|
||||
--searchbar-border-color: #aaa;
|
||||
--searchbar-bg: #b7b7b7;
|
||||
--searchbar-fg: #000;
|
||||
--searchbar-shadow-color: #aaa;
|
||||
--searchresults-header-fg: #666;
|
||||
--searchresults-border-color: #98a3ad;
|
||||
--searchresults-li-bg: #2b2b2f;
|
||||
--search-mark-bg: #355c7d;
|
||||
}
|
||||
}
|
||||
|
||||
.colibri {
|
||||
--bg: #3b224c;
|
||||
--fg: #bcbdd0;
|
||||
--heading-fg: #fff;
|
||||
|
||||
--sidebar-bg: #281733;
|
||||
--sidebar-fg: #c8c9db;
|
||||
--sidebar-non-existent: #505274;
|
||||
--sidebar-active: #a4a0e8;
|
||||
--sidebar-spacer: #2d334f;
|
||||
|
||||
--scrollbar: var(--sidebar-fg);
|
||||
|
||||
--icons: #737480;
|
||||
--icons-hover: #b7b9cc;
|
||||
|
||||
/* --links: #a4a0e8; */
|
||||
--links: #ECCDBA;
|
||||
|
||||
--inline-code-color: hsl(48.7, 7.8%, 70%);
|
||||
|
||||
--theme-popup-bg: #161923;
|
||||
--theme-popup-border: #737480;
|
||||
--theme-hover: rgba(0,0,0, .2);
|
||||
|
||||
--quote-bg: #281733;
|
||||
--quote-border: hsl(226, 15%, 22%);
|
||||
|
||||
--table-border-color: hsl(226, 23%, 76%);
|
||||
--table-header-bg: hsla(226, 23%, 31%, 0);
|
||||
--table-alternate-bg: hsl(226, 23%, 14%);
|
||||
--table-border-line: hsla(201deg, 20%, 92%, 0.2);
|
||||
|
||||
--searchbar-border-color: #aaa;
|
||||
--searchbar-bg: #aeaec6;
|
||||
--searchbar-fg: #000;
|
||||
--searchbar-shadow-color: #aaa;
|
||||
--searchresults-header-fg: #5f5f71;
|
||||
--searchresults-border-color: #5c5c68;
|
||||
--searchresults-li-bg: #242430;
|
||||
--search-mark-bg: #acff5;
|
||||
--hljs-background: #2f1e2e;
|
||||
--hljs-color: #a39e9b;
|
||||
--hljs-quote: #8d8687;
|
||||
--hljs-variable: #ef6155;
|
||||
--hljs-type: #f99b15;
|
||||
--hljs-title: #fec418;
|
||||
--hljs-symbol: #48b685;
|
||||
--hljs-selector-tag: #815ba4;
|
||||
}
|
||||
|
||||
.colibri {
|
||||
/*
|
||||
--bg: #ffffff;
|
||||
--fg: #452859;
|
||||
--fg: #5a5977;
|
||||
--heading-fg: #281733;
|
||||
|
||||
--sidebar-bg: #281733;
|
||||
--sidebar-fg: #c8c9db;
|
||||
--sidebar-non-existent: #505274;
|
||||
--sidebar-active: #a4a0e8;
|
||||
--sidebar-spacer: #2d334f;
|
||||
|
||||
--scrollbar: var(--sidebar-fg);
|
||||
|
||||
--icons: #737480;
|
||||
--icons-hover: #b7b9cc;
|
||||
|
||||
--links: #6F44F0;
|
||||
|
||||
--inline-code-color: #a39e9b;
|
||||
|
||||
--theme-popup-bg: #161923;
|
||||
--theme-popup-border: #737480;
|
||||
--theme-hover: rgba(0,0,0, .2);
|
||||
|
||||
--quote-bg: rgba(0, 0, 0, 0);
|
||||
--quote-border: hsl(226, 15%, 75%);
|
||||
|
||||
--table-border-color: #5a5977;
|
||||
--table-border-color: hsl(201deg 10% 67%);
|
||||
--table-header-bg: hsl(0, 0%, 100%);
|
||||
--table-alternate-bg: hsl(0, 0%, 97%);
|
||||
--table-border-line: hsl(201deg, 20%, 92%);
|
||||
|
||||
--searchbar-border-color: #aaa;
|
||||
--searchbar-bg: #aeaec6;
|
||||
--searchbar-fg: #000;
|
||||
--searchbar-shadow-color: #aaa;
|
||||
--searchresults-header-fg: #5f5f71;
|
||||
--searchresults-border-color: #5c5c68;
|
||||
--searchresults-li-bg: #242430;
|
||||
--search-mark-bg: #a2cff5;
|
||||
--hljs-background: #TODO;
|
||||
--hljs-color: #TODO;
|
||||
--hljs-quote: #TODO;
|
||||
--hljs-variable: #TODO;
|
||||
--hljs-type: #TODO;
|
||||
--hljs-title: #TODO;
|
||||
--hljs-symbol: #TODO;
|
||||
--hljs-selector-tag: #TODO;
|
||||
*/
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
pre code.hljs {
|
||||
display:block;
|
||||
overflow-x:auto;
|
||||
padding:1em
|
||||
}
|
||||
code.hljs {
|
||||
padding:3px 5px
|
||||
}
|
||||
.hljs {
|
||||
background: var(--hljs-background);
|
||||
color: var(--hljs-color);
|
||||
}
|
||||
.hljs-comment,
|
||||
.hljs-quote {
|
||||
color: var(--hljs-quote)
|
||||
}
|
||||
.hljs-link,
|
||||
.hljs-meta,
|
||||
.hljs-name,
|
||||
.hljs-regexp,
|
||||
.hljs-selector-class,
|
||||
.hljs-selector-id,
|
||||
.hljs-tag,
|
||||
.hljs-template-variable,
|
||||
.hljs-variable {
|
||||
color: var(--hljs-variable)
|
||||
}
|
||||
.hljs-built_in,
|
||||
.hljs-deletion,
|
||||
.hljs-literal,
|
||||
.hljs-number,
|
||||
.hljs-params,
|
||||
.hljs-type {
|
||||
color: var(--hljs-type)
|
||||
}
|
||||
.hljs-attribute,
|
||||
.hljs-section,
|
||||
.hljs-title {
|
||||
color: var(--hljs-title)
|
||||
}
|
||||
.hljs-addition,
|
||||
.hljs-bullet,
|
||||
.hljs-string,
|
||||
.hljs-symbol {
|
||||
color: var(--hljs-symbol)
|
||||
}
|
||||
.hljs-keyword,
|
||||
.hljs-selector-tag {
|
||||
color: var(--hljs-selector-tag)
|
||||
}
|
||||
.hljs-emphasis {
|
||||
font-style:italic
|
||||
}
|
||||
.hljs-strong {
|
||||
font-weight:700
|
||||
}
|
File diff suppressed because one or more lines are too long
Binary file not shown.
After Width: | Height: | Size: 264 KiB |
@ -0,0 +1,43 @@
|
||||
use std::ops::DerefMut;
|
||||
|
||||
use nucleo::pattern::{Atom, AtomKind, CaseMatching};
|
||||
use nucleo::Config;
|
||||
use parking_lot::Mutex;
|
||||
|
||||
pub struct LazyMutex<T> {
|
||||
inner: Mutex<Option<T>>,
|
||||
init: fn() -> T,
|
||||
}
|
||||
|
||||
impl<T> LazyMutex<T> {
|
||||
pub const fn new(init: fn() -> T) -> Self {
|
||||
Self {
|
||||
inner: Mutex::new(None),
|
||||
init,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn lock(&self) -> impl DerefMut<Target = T> + '_ {
|
||||
parking_lot::MutexGuard::map(self.inner.lock(), |val| val.get_or_insert_with(self.init))
|
||||
}
|
||||
}
|
||||
|
||||
pub static MATCHER: LazyMutex<nucleo::Matcher> = LazyMutex::new(nucleo::Matcher::default);
|
||||
|
||||
/// convenience function to easily fuzzy match
|
||||
/// on a (relatively small list of inputs). This is not recommended for building a full tui
|
||||
/// application that can match large numbers of matches as all matching is done on the current
|
||||
/// thread, effectively blocking the UI
|
||||
pub fn fuzzy_match<T: AsRef<str>>(
|
||||
pattern: &str,
|
||||
items: impl IntoIterator<Item = T>,
|
||||
path: bool,
|
||||
) -> Vec<(T, u16)> {
|
||||
let mut matcher = MATCHER.lock();
|
||||
matcher.config = Config::DEFAULT;
|
||||
if path {
|
||||
matcher.config.set_match_paths();
|
||||
}
|
||||
let pattern = Atom::new(pattern, CaseMatching::Smart, AtomKind::Fuzzy, false);
|
||||
pattern.match_list(items, &mut matcher)
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,81 +0,0 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Register {
|
||||
name: char,
|
||||
values: Vec<String>,
|
||||
}
|
||||
|
||||
impl Register {
|
||||
pub const fn new(name: char) -> Self {
|
||||
Self {
|
||||
name,
|
||||
values: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_with_values(name: char, values: Vec<String>) -> Self {
|
||||
Self { name, values }
|
||||
}
|
||||
|
||||
pub const fn name(&self) -> char {
|
||||
self.name
|
||||
}
|
||||
|
||||
pub fn read(&self) -> &[String] {
|
||||
&self.values
|
||||
}
|
||||
|
||||
pub fn write(&mut self, values: Vec<String>) {
|
||||
self.values = values;
|
||||
}
|
||||
|
||||
pub fn push(&mut self, value: String) {
|
||||
self.values.push(value);
|
||||
}
|
||||
}
|
||||
|
||||
/// Currently just wraps a `HashMap` of `Register`s
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Registers {
|
||||
inner: HashMap<char, Register>,
|
||||
}
|
||||
|
||||
impl Registers {
|
||||
pub fn get(&self, name: char) -> Option<&Register> {
|
||||
self.inner.get(&name)
|
||||
}
|
||||
|
||||
pub fn read(&self, name: char) -> Option<&[String]> {
|
||||
self.get(name).map(|reg| reg.read())
|
||||
}
|
||||
|
||||
pub fn write(&mut self, name: char, values: Vec<String>) {
|
||||
if name != '_' {
|
||||
self.inner
|
||||
.insert(name, Register::new_with_values(name, values));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn push(&mut self, name: char, value: String) {
|
||||
if name != '_' {
|
||||
if let Some(r) = self.inner.get_mut(&name) {
|
||||
r.push(value);
|
||||
} else {
|
||||
self.write(name, vec![value]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn first(&self, name: char) -> Option<&String> {
|
||||
self.read(name).and_then(|entries| entries.first())
|
||||
}
|
||||
|
||||
pub fn last(&self, name: char) -> Option<&String> {
|
||||
self.read(name).and_then(|entries| entries.last())
|
||||
}
|
||||
|
||||
pub fn inner(&self) -> &HashMap<char, Register> {
|
||||
&self.inner
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
use std::io;
|
||||
|
||||
use ropey::iter::Chunks;
|
||||
use ropey::RopeSlice;
|
||||
|
||||
pub struct RopeReader<'a> {
|
||||
current_chunk: &'a [u8],
|
||||
chunks: Chunks<'a>,
|
||||
}
|
||||
|
||||
impl<'a> RopeReader<'a> {
|
||||
pub fn new(rope: RopeSlice<'a>) -> RopeReader<'a> {
|
||||
RopeReader {
|
||||
current_chunk: &[],
|
||||
chunks: rope.chunks(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl io::Read for RopeReader<'_> {
|
||||
fn read(&mut self, mut buf: &mut [u8]) -> io::Result<usize> {
|
||||
let buf_len = buf.len();
|
||||
loop {
|
||||
let read_bytes = self.current_chunk.read(buf)?;
|
||||
buf = &mut buf[read_bytes..];
|
||||
if buf.is_empty() {
|
||||
return Ok(buf_len);
|
||||
}
|
||||
|
||||
if let Some(next_chunk) = self.chunks.next() {
|
||||
self.current_chunk = next_chunk.as_bytes();
|
||||
} else {
|
||||
return Ok(buf_len - buf.len());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,7 +1,9 @@
|
||||
use smartstring::{LazyCompact, SmartString};
|
||||
use textwrap::{Options, WordSplitter::NoHyphenation};
|
||||
|
||||
/// Given a slice of text, return the text re-wrapped to fit it
|
||||
/// within the given width.
|
||||
pub fn reflow_hard_wrap(text: &str, max_line_len: usize) -> SmartString<LazyCompact> {
|
||||
textwrap::refill(text, max_line_len).into()
|
||||
pub fn reflow_hard_wrap(text: &str, text_width: usize) -> SmartString<LazyCompact> {
|
||||
let options = Options::new(text_width).word_splitter(NoHyphenation);
|
||||
textwrap::refill(text, options).into()
|
||||
}
|
||||
|
@ -0,0 +1,48 @@
|
||||
std::vector<std::string>
|
||||
fn_with_many_parameters(int parm1, long parm2, float parm3, double parm4,
|
||||
char* parm5, bool parm6);
|
||||
|
||||
std::vector<std::string>
|
||||
fn_with_many_parameters(int parm1, long parm2, float parm3, double parm4,
|
||||
char* parm5, bool parm6) {
|
||||
auto lambda = []() {
|
||||
return 0;
|
||||
};
|
||||
auto lambda_with_a_really_long_name_that_uses_a_whole_line
|
||||
= [](int some_more_aligned_parameters,
|
||||
std::string parm2) {
|
||||
do_smth();
|
||||
};
|
||||
if (brace_on_same_line) {
|
||||
do_smth();
|
||||
} else if (brace_on_next_line)
|
||||
{
|
||||
do_smth();
|
||||
} else if (another_condition) {
|
||||
do_smth();
|
||||
}
|
||||
else {
|
||||
do_smth();
|
||||
}
|
||||
if (inline_if_statement)
|
||||
do_smth();
|
||||
if (another_inline_if_statement)
|
||||
return [](int parm1, char* parm2) {
|
||||
this_is_a_really_pointless_lambda();
|
||||
};
|
||||
|
||||
switch (var) {
|
||||
case true:
|
||||
return -1;
|
||||
case false:
|
||||
return 42;
|
||||
}
|
||||
}
|
||||
|
||||
class MyClass : public MyBaseClass {
|
||||
public:
|
||||
MyClass();
|
||||
void public_fn();
|
||||
private:
|
||||
super_secret_private_fn();
|
||||
}
|
@ -1 +0,0 @@
|
||||
../../../src/indent.rs
|
@ -1,25 +1,27 @@
|
||||
[package]
|
||||
name = "helix-dap"
|
||||
version = "0.6.0"
|
||||
authors = ["Blaž Hrastnik <blaz@mxxn.io>"]
|
||||
edition = "2018"
|
||||
license = "MPL-2.0"
|
||||
description = "DAP client implementation for Helix project"
|
||||
categories = ["editor"]
|
||||
repository = "https://github.com/helix-editor/helix"
|
||||
homepage = "https://helix-editor.com"
|
||||
version.workspace = true
|
||||
authors.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
rust-version.workspace = true
|
||||
categories.workspace = true
|
||||
repository.workspace = true
|
||||
homepage.workspace = true
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
helix-core = { version = "0.6", path = "../helix-core" }
|
||||
helix-stdx = { path = "../helix-stdx" }
|
||||
helix-core = { path = "../helix-core" }
|
||||
|
||||
anyhow = "1.0"
|
||||
log = "0.4"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
thiserror = "1.0"
|
||||
tokio = { version = "1", features = ["rt", "rt-multi-thread", "io-util", "io-std", "time", "process", "macros", "fs", "parking_lot", "net", "sync"] }
|
||||
which = "4.4"
|
||||
|
||||
[dev-dependencies]
|
||||
fern = "0.6"
|
||||
|
@ -0,0 +1,29 @@
|
||||
[package]
|
||||
name = "helix-event"
|
||||
version.workspace = true
|
||||
authors.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
rust-version.workspace = true
|
||||
categories.workspace = true
|
||||
repository.workspace = true
|
||||
homepage.workspace = true
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
ahash = "0.8.3"
|
||||
hashbrown = "0.14.0"
|
||||
tokio = { version = "1", features = ["rt", "rt-multi-thread", "time", "sync", "parking_lot", "macros"] }
|
||||
# the event registry is essentially read only but must be an rwlock so we can
|
||||
# setup new events on initialization, hardware-lock-elision hugely benefits this case
|
||||
# as it essentially makes the lock entirely free as long as there is no writes
|
||||
parking_lot = { version = "0.12", features = ["hardware-lock-elision"] }
|
||||
once_cell = "1.18"
|
||||
|
||||
anyhow = "1"
|
||||
log = "0.4"
|
||||
futures-executor = "0.3.28"
|
||||
|
||||
[features]
|
||||
integration_test = []
|
@ -0,0 +1,19 @@
|
||||
use std::future::Future;
|
||||
|
||||
pub use oneshot::channel as cancelation;
|
||||
use tokio::sync::oneshot;
|
||||
|
||||
pub type CancelTx = oneshot::Sender<()>;
|
||||
pub type CancelRx = oneshot::Receiver<()>;
|
||||
|
||||
pub async fn cancelable_future<T>(future: impl Future<Output = T>, cancel: CancelRx) -> Option<T> {
|
||||
tokio::select! {
|
||||
biased;
|
||||
_ = cancel => {
|
||||
None
|
||||
}
|
||||
res = future => {
|
||||
Some(res)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
//! Utilities for declaring an async (usually debounced) hook
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
use futures_executor::block_on;
|
||||
use tokio::sync::mpsc::{self, error::TrySendError, Sender};
|
||||
use tokio::time::Instant;
|
||||
|
||||
/// Async hooks provide a convenient framework for implementing (debounced)
|
||||
/// async event handlers. Most synchronous event hooks will likely need to
|
||||
/// debounce their events, coordinate multiple different hooks and potentially
|
||||
/// track some state. `AsyncHooks` facilitate these use cases by running as
|
||||
/// a background tokio task that waits for events (usually an enum) to be
|
||||
/// sent through a channel.
|
||||
pub trait AsyncHook: Sync + Send + 'static + Sized {
|
||||
type Event: Sync + Send + 'static;
|
||||
/// Called immediately whenever an event is received, this function can
|
||||
/// consume the event immediately or debounce it. In case of debouncing,
|
||||
/// it can either define a new debounce timeout or continue the current one
|
||||
fn handle_event(&mut self, event: Self::Event, timeout: Option<Instant>) -> Option<Instant>;
|
||||
|
||||
/// Called whenever the debounce timeline is reached
|
||||
fn finish_debounce(&mut self);
|
||||
|
||||
fn spawn(self) -> mpsc::Sender<Self::Event> {
|
||||
// the capacity doesn't matter too much here, unless the cpu is totally overwhelmed
|
||||
// the cap will never be reached since we always immediately drain the channel
|
||||
// so it should only be reached in case of total CPU overload.
|
||||
// However, a bounded channel is much more efficient so it's nice to use here
|
||||
let (tx, rx) = mpsc::channel(128);
|
||||
tokio::spawn(run(self, rx));
|
||||
tx
|
||||
}
|
||||
}
|
||||
|
||||
async fn run<Hook: AsyncHook>(mut hook: Hook, mut rx: mpsc::Receiver<Hook::Event>) {
|
||||
let mut deadline = None;
|
||||
loop {
|
||||
let event = match deadline {
|
||||
Some(deadline_) => {
|
||||
let res = tokio::time::timeout_at(deadline_, rx.recv()).await;
|
||||
match res {
|
||||
Ok(event) => event,
|
||||
Err(_) => {
|
||||
hook.finish_debounce();
|
||||
deadline = None;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
None => rx.recv().await,
|
||||
};
|
||||
let Some(event) = event else {
|
||||
break;
|
||||
};
|
||||
deadline = hook.handle_event(event, deadline);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn send_blocking<T>(tx: &Sender<T>, data: T) {
|
||||
// block_on has some overhead and in practice the channel should basically
|
||||
// never be full anyway so first try sending without blocking
|
||||
if let Err(TrySendError::Full(data)) = tx.try_send(data) {
|
||||
// set a timeout so that we just drop a message instead of freezing the editor in the worst case
|
||||
let _ = block_on(tx.send_timeout(data, Duration::from_millis(10)));
|
||||
}
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
//! rust dynamic dispatch is extremely limited so we have to build our
|
||||
//! own vtable implementation. Otherwise implementing the event system would not be possible.
|
||||
//! A nice bonus of this approach is that we can optimize the vtable a bit more. Normally
|
||||
//! a dyn Trait fat pointer contains two pointers: A pointer to the data itself and a
|
||||
//! pointer to a global (static) vtable entry which itself contains multiple other pointers
|
||||
//! (the various functions of the trait, drop, size and align). That makes dynamic
|
||||
//! dispatch pretty slow (double pointer indirections). However, we only have a single function
|
||||
//! in the hook trait and don't need a drop implementation (event system is global anyway
|
||||
//! and never dropped) so we can just store the entire vtable inline.
|
||||
|
||||
use anyhow::Result;
|
||||
use std::ptr::{self, NonNull};
|
||||
|
||||
use crate::Event;
|
||||
|
||||
/// Opaque handle type that represents an erased type parameter.
|
||||
///
|
||||
/// If extern types were stable, this could be implemented as `extern { pub type Opaque; }` but
|
||||
/// until then we can use this.
|
||||
///
|
||||
/// Care should be taken that we don't use a concrete instance of this. It should only be used
|
||||
/// through a reference, so we can maintain something else's lifetime.
|
||||
struct Opaque(());
|
||||
|
||||
pub(crate) struct ErasedHook {
|
||||
data: NonNull<Opaque>,
|
||||
call: unsafe fn(NonNull<Opaque>, NonNull<Opaque>, NonNull<Opaque>),
|
||||
}
|
||||
|
||||
impl ErasedHook {
|
||||
pub(crate) fn new_dynamic<H: Fn() -> Result<()> + 'static + Send + Sync>(
|
||||
hook: H,
|
||||
) -> ErasedHook {
|
||||
unsafe fn call<F: Fn() -> Result<()> + 'static + Send + Sync>(
|
||||
hook: NonNull<Opaque>,
|
||||
_event: NonNull<Opaque>,
|
||||
result: NonNull<Opaque>,
|
||||
) {
|
||||
let hook: NonNull<F> = hook.cast();
|
||||
let result: NonNull<Result<()>> = result.cast();
|
||||
let hook: &F = hook.as_ref();
|
||||
let res = hook();
|
||||
ptr::write(result.as_ptr(), res)
|
||||
}
|
||||
|
||||
unsafe {
|
||||
ErasedHook {
|
||||
data: NonNull::new_unchecked(Box::into_raw(Box::new(hook)) as *mut Opaque),
|
||||
call: call::<H>,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn new<E: Event, F: Fn(&mut E) -> Result<()>>(hook: F) -> ErasedHook {
|
||||
unsafe fn call<E: Event, F: Fn(&mut E) -> Result<()>>(
|
||||
hook: NonNull<Opaque>,
|
||||
event: NonNull<Opaque>,
|
||||
result: NonNull<Opaque>,
|
||||
) {
|
||||
let hook: NonNull<F> = hook.cast();
|
||||
let mut event: NonNull<E> = event.cast();
|
||||
let result: NonNull<Result<()>> = result.cast();
|
||||
let hook: &F = hook.as_ref();
|
||||
let res = hook(event.as_mut());
|
||||
ptr::write(result.as_ptr(), res)
|
||||
}
|
||||
|
||||
unsafe {
|
||||
ErasedHook {
|
||||
data: NonNull::new_unchecked(Box::into_raw(Box::new(hook)) as *mut Opaque),
|
||||
call: call::<E, F>,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) unsafe fn call<E: Event>(&self, event: &mut E) -> Result<()> {
|
||||
let mut res = Ok(());
|
||||
|
||||
unsafe {
|
||||
(self.call)(
|
||||
self.data,
|
||||
NonNull::from(event).cast(),
|
||||
NonNull::from(&mut res).cast(),
|
||||
);
|
||||
}
|
||||
res
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Sync for ErasedHook {}
|
||||
unsafe impl Send for ErasedHook {}
|
@ -0,0 +1,203 @@
|
||||
//! `helix-event` contains systems that allow (often async) communication between
|
||||
//! different editor components without strongly coupling them. Specifically
|
||||
//! it allows defining synchronous hooks that run when certain editor events
|
||||
//! occur.
|
||||
//!
|
||||
//! The core of the event system are hook callbacks and the [`Event`] trait. A
|
||||
//! hook is essentially just a closure `Fn(event: &mut impl Event) -> Result<()>`
|
||||
//! that gets called every time an appropriate event is dispatched. The implementation
|
||||
//! details of the [`Event`] trait are considered private. The [`events`] macro is
|
||||
//! provided which automatically declares event types. Similarly the `register_hook`
|
||||
//! macro should be used to (safely) declare event hooks.
|
||||
//!
|
||||
//! Hooks run synchronously which can be advantageous since they can modify the
|
||||
//! current editor state right away (for example to immediately hide the completion
|
||||
//! popup). However, they can not contain their own state without locking since
|
||||
//! they only receive immutable references. For handler that want to track state, do
|
||||
//! expensive background computations or debouncing an [`AsyncHook`] is preferable.
|
||||
//! Async hooks are based around a channels that receive events specific to
|
||||
//! that `AsyncHook` (usually an enum). These events can be sent by synchronous
|
||||
//! hooks. Due to some limitations around tokio channels the [`send_blocking`]
|
||||
//! function exported in this crate should be used instead of the builtin
|
||||
//! `blocking_send`.
|
||||
//!
|
||||
//! In addition to the core event system, this crate contains some message queues
|
||||
//! that allow transfer of data back to the main event loop from async hooks and
|
||||
//! hooks that may not have access to all application data (for example in helix-view).
|
||||
//! This include the ability to control rendering ([`lock_frame`], [`request_redraw`]) and
|
||||
//! display status messages ([`status`]).
|
||||
//!
|
||||
//! Hooks declared in helix-term can furthermore dispatch synchronous jobs to be run on the
|
||||
//! main loop (including access to the compositor). Ideally that queue will be moved
|
||||
//! to helix-view in the future if we manage to detach the compositor from its rendering backend.
|
||||
|
||||
use anyhow::Result;
|
||||
pub use cancel::{cancelable_future, cancelation, CancelRx, CancelTx};
|
||||
pub use debounce::{send_blocking, AsyncHook};
|
||||
pub use redraw::{lock_frame, redraw_requested, request_redraw, start_frame, RenderLockGuard};
|
||||
pub use registry::Event;
|
||||
|
||||
mod cancel;
|
||||
mod debounce;
|
||||
mod hook;
|
||||
mod redraw;
|
||||
mod registry;
|
||||
#[doc(hidden)]
|
||||
pub mod runtime;
|
||||
pub mod status;
|
||||
|
||||
#[cfg(test)]
|
||||
mod test;
|
||||
|
||||
pub fn register_event<E: Event + 'static>() {
|
||||
registry::with_mut(|registry| registry.register_event::<E>())
|
||||
}
|
||||
|
||||
/// Registers a hook that will be called when an event of type `E` is dispatched.
|
||||
/// This function should usually not be used directly, use the [`register_hook`]
|
||||
/// macro instead.
|
||||
///
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// `hook` must be totally generic over all lifetime parameters of `E`. For
|
||||
/// example if `E` was a known type `Foo<'a, 'b>`, then the correct trait bound
|
||||
/// would be `F: for<'a, 'b, 'c> Fn(&'a mut Foo<'b, 'c>)`, but there is no way to
|
||||
/// express that kind of constraint for a generic type with the Rust type system
|
||||
/// as of this writing.
|
||||
pub unsafe fn register_hook_raw<E: Event>(
|
||||
hook: impl Fn(&mut E) -> Result<()> + 'static + Send + Sync,
|
||||
) {
|
||||
registry::with_mut(|registry| registry.register_hook(hook))
|
||||
}
|
||||
|
||||
/// Register a hook solely by event name
|
||||
pub fn register_dynamic_hook(
|
||||
hook: impl Fn() -> Result<()> + 'static + Send + Sync,
|
||||
id: &str,
|
||||
) -> Result<()> {
|
||||
registry::with_mut(|reg| reg.register_dynamic_hook(hook, id))
|
||||
}
|
||||
|
||||
pub fn dispatch(e: impl Event) {
|
||||
registry::with(|registry| registry.dispatch(e));
|
||||
}
|
||||
|
||||
/// Macro to declare events
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ``` no-compile
|
||||
/// events! {
|
||||
/// FileWrite(&Path)
|
||||
/// ViewScrolled{ view: View, new_pos: ViewOffset }
|
||||
/// DocumentChanged<'a> { old_doc: &'a Rope, doc: &'a mut Document, changes: &'a ChangeSet }
|
||||
/// }
|
||||
///
|
||||
/// fn init() {
|
||||
/// register_event::<FileWrite>();
|
||||
/// register_event::<ViewScrolled>();
|
||||
/// register_event::<DocumentChanged>();
|
||||
/// }
|
||||
///
|
||||
/// fn save(path: &Path, content: &str){
|
||||
/// std::fs::write(path, content);
|
||||
/// dispatch(FileWrite(path));
|
||||
/// }
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! events {
|
||||
($name: ident<$($lt: lifetime),*> { $($data:ident : $data_ty:ty),* } $($rem:tt)*) => {
|
||||
pub struct $name<$($lt),*> { $(pub $data: $data_ty),* }
|
||||
unsafe impl<$($lt),*> $crate::Event for $name<$($lt),*> {
|
||||
const ID: &'static str = stringify!($name);
|
||||
const LIFETIMES: usize = $crate::events!(@sum $(1, $lt),*);
|
||||
type Static = $crate::events!(@replace_lt $name, $('static, $lt),*);
|
||||
}
|
||||
$crate::events!{ $($rem)* }
|
||||
};
|
||||
($name: ident { $($data:ident : $data_ty:ty),* } $($rem:tt)*) => {
|
||||
pub struct $name { $(pub $data: $data_ty),* }
|
||||
unsafe impl $crate::Event for $name {
|
||||
const ID: &'static str = stringify!($name);
|
||||
const LIFETIMES: usize = 0;
|
||||
type Static = Self;
|
||||
}
|
||||
$crate::events!{ $($rem)* }
|
||||
};
|
||||
() => {};
|
||||
(@replace_lt $name: ident, $($lt1: lifetime, $lt2: lifetime),* ) => {$name<$($lt1),*>};
|
||||
(@sum $($val: expr, $lt1: lifetime),* ) => {0 $(+ $val)*};
|
||||
}
|
||||
|
||||
/// Safely register statically typed event hooks
|
||||
#[macro_export]
|
||||
macro_rules! register_hook {
|
||||
// Safety: this is safe because we fully control the type of the event here and
|
||||
// ensure all lifetime arguments are fully generic and the correct number of lifetime arguments
|
||||
// is present
|
||||
(move |$event:ident: &mut $event_ty: ident<$($lt: lifetime),*>| $body: expr) => {
|
||||
let val = move |$event: &mut $event_ty<$($lt),*>| $body;
|
||||
unsafe {
|
||||
// Lifetimes are a bit of a pain. We want to allow events being
|
||||
// non-static. Lifetimes don't actually exist at runtime so its
|
||||
// fine to essentially transmute the lifetimes as long as we can
|
||||
// prove soundness. The hook must therefore accept any combination
|
||||
// of lifetimes. In other words fn(&'_ mut Event<'_, '_>) is ok
|
||||
// but examples like fn(&'_ mut Event<'_, 'static>) or fn<'a>(&'a
|
||||
// mut Event<'a, 'a>) are not. To make this safe we use a macro to
|
||||
// forbid the user from specifying lifetimes manually (all lifetimes
|
||||
// specified are always function generics and passed to the event so
|
||||
// lifetimes can't be used multiple times and using 'static causes a
|
||||
// syntax error).
|
||||
//
|
||||
// There is one soundness hole tough: Type Aliases allow
|
||||
// "accidentally" creating these problems. For example:
|
||||
//
|
||||
// type Event2 = Event<'static>.
|
||||
// type Event2<'a> = Event<'a, a>.
|
||||
//
|
||||
// These cases can be caught by counting the number of lifetimes
|
||||
// parameters at the parameter declaration site and then at the hook
|
||||
// declaration site. By asserting the number of lifetime parameters
|
||||
// are equal we can catch all bad type aliases under one assumption:
|
||||
// There are no unused lifetime parameters. Introducing a static
|
||||
// would reduce the number of arguments of the alias by one in the
|
||||
// above example Event2 has zero lifetime arguments while the original
|
||||
// event has one lifetime argument. Similar logic applies to using
|
||||
// a lifetime argument multiple times. The ASSERT below performs a
|
||||
// a compile time assertion to ensure exactly this property.
|
||||
//
|
||||
// With unused lifetime arguments it is still one way to cause unsound code:
|
||||
//
|
||||
// type Event2<'a, 'b> = Event<'a, 'a>;
|
||||
//
|
||||
// However, this case will always emit a compiler warning/cause CI
|
||||
// failures so a user would have to introduce #[allow(unused)] which
|
||||
// is easily caught in review (and a very theoretical case anyway).
|
||||
// If we want to be pedantic we can simply compile helix with
|
||||
// forbid(unused). All of this is just a safety net to prevent
|
||||
// very theoretical misuse. This won't come up in real code (and is
|
||||
// easily caught in review).
|
||||
#[allow(unused)]
|
||||
const ASSERT: () = {
|
||||
if <$event_ty as $crate::Event>::LIFETIMES != 0 + $crate::events!(@sum $(1, $lt),*){
|
||||
panic!("invalid type alias");
|
||||
}
|
||||
};
|
||||
$crate::register_hook_raw::<$crate::events!(@replace_lt $event_ty, $('static, $lt),*)>(val);
|
||||
}
|
||||
};
|
||||
(move |$event:ident: &mut $event_ty: ident| $body: expr) => {
|
||||
let val = move |$event: &mut $event_ty| $body;
|
||||
unsafe {
|
||||
#[allow(unused)]
|
||||
const ASSERT: () = {
|
||||
if <$event_ty as $crate::Event>::LIFETIMES != 0{
|
||||
panic!("invalid type alias");
|
||||
}
|
||||
};
|
||||
$crate::register_hook_raw::<$event_ty>(val);
|
||||
}
|
||||
};
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
//! Signals that control when/if the editor redraws
|
||||
|
||||
use std::future::Future;
|
||||
|
||||
use parking_lot::{RwLock, RwLockReadGuard};
|
||||
use tokio::sync::Notify;
|
||||
|
||||
use crate::runtime_local;
|
||||
|
||||
runtime_local! {
|
||||
/// A `Notify` instance that can be used to (asynchronously) request
|
||||
/// the editor to render a new frame.
|
||||
static REDRAW_NOTIFY: Notify = Notify::const_new();
|
||||
|
||||
/// A `RwLock` that prevents the next frame from being
|
||||
/// drawn until an exclusive (write) lock can be acquired.
|
||||
/// This allows asynchronous tasks to acquire `non-exclusive`
|
||||
/// locks (read) to prevent the next frame from being drawn
|
||||
/// until a certain computation has finished.
|
||||
static RENDER_LOCK: RwLock<()> = RwLock::new(());
|
||||
}
|
||||
|
||||
pub type RenderLockGuard = RwLockReadGuard<'static, ()>;
|
||||
|
||||
/// Requests that the editor is redrawn. The redraws are debounced (currently to
|
||||
/// 30FPS) so this can be called many times without causing a ton of frames to
|
||||
/// be rendered.
|
||||
pub fn request_redraw() {
|
||||
REDRAW_NOTIFY.notify_one();
|
||||
}
|
||||
|
||||
/// Returns a future that will yield once a redraw has been asynchronously
|
||||
/// requested using [`request_redraw`].
|
||||
pub fn redraw_requested() -> impl Future<Output = ()> {
|
||||
REDRAW_NOTIFY.notified()
|
||||
}
|
||||
|
||||
/// Wait until all locks acquired with [`lock_frame`] have been released.
|
||||
/// This function is called before rendering and is intended to allow the frame
|
||||
/// to wait for async computations that should be included in the current frame.
|
||||
pub fn start_frame() {
|
||||
drop(RENDER_LOCK.write());
|
||||
// exhaust any leftover redraw notifications
|
||||
let notify = REDRAW_NOTIFY.notified();
|
||||
tokio::pin!(notify);
|
||||
notify.enable();
|
||||
}
|
||||
|
||||
/// Acquires the render lock which will prevent the next frame from being drawn
|
||||
/// until the returned guard is dropped.
|
||||
pub fn lock_frame() -> RenderLockGuard {
|
||||
RENDER_LOCK.read()
|
||||
}
|
@ -0,0 +1,131 @@
|
||||
//! A global registry where events are registered and can be
|
||||
//! subscribed to by registering hooks. The registry identifies event
|
||||
//! types using their type name so multiple event with the same type name
|
||||
//! may not be registered (will cause a panic to ensure soundness)
|
||||
|
||||
use std::any::TypeId;
|
||||
|
||||
use anyhow::{bail, Result};
|
||||
use hashbrown::hash_map::Entry;
|
||||
use hashbrown::HashMap;
|
||||
use parking_lot::RwLock;
|
||||
|
||||
use crate::hook::ErasedHook;
|
||||
use crate::runtime_local;
|
||||
|
||||
pub struct Registry {
|
||||
events: HashMap<&'static str, TypeId, ahash::RandomState>,
|
||||
handlers: HashMap<&'static str, Vec<ErasedHook>, ahash::RandomState>,
|
||||
}
|
||||
|
||||
impl Registry {
|
||||
pub fn register_event<E: Event + 'static>(&mut self) {
|
||||
let ty = TypeId::of::<E>();
|
||||
assert_eq!(ty, TypeId::of::<E::Static>());
|
||||
match self.events.entry(E::ID) {
|
||||
Entry::Occupied(entry) => {
|
||||
if entry.get() == &ty {
|
||||
// don't warn during tests to avoid log spam
|
||||
#[cfg(not(feature = "integration_test"))]
|
||||
panic!("Event {} was registered multiple times", E::ID);
|
||||
} else {
|
||||
panic!("Multiple events with ID {} were registered", E::ID);
|
||||
}
|
||||
}
|
||||
Entry::Vacant(ent) => {
|
||||
ent.insert(ty);
|
||||
self.handlers.insert(E::ID, Vec::new());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// `hook` must be totally generic over all lifetime parameters of `E`. For
|
||||
/// example if `E` was a known type `Foo<'a, 'b> then the correct trait bound
|
||||
/// would be `F: for<'a, 'b, 'c> Fn(&'a mut Foo<'b, 'c>)` but there is no way to
|
||||
/// express that kind of constraint for a generic type with the rust type system
|
||||
/// right now.
|
||||
pub unsafe fn register_hook<E: Event>(
|
||||
&mut self,
|
||||
hook: impl Fn(&mut E) -> Result<()> + 'static + Send + Sync,
|
||||
) {
|
||||
// ensure event type ids match so we can rely on them always matching
|
||||
let id = E::ID;
|
||||
let Some(&event_id) = self.events.get(id) else {
|
||||
panic!("Tried to register handler for unknown event {id}");
|
||||
};
|
||||
assert!(
|
||||
TypeId::of::<E::Static>() == event_id,
|
||||
"Tried to register invalid hook for event {id}"
|
||||
);
|
||||
let hook = ErasedHook::new(hook);
|
||||
self.handlers.get_mut(id).unwrap().push(hook);
|
||||
}
|
||||
|
||||
pub fn register_dynamic_hook(
|
||||
&mut self,
|
||||
hook: impl Fn() -> Result<()> + 'static + Send + Sync,
|
||||
id: &str,
|
||||
) -> Result<()> {
|
||||
// ensure event type ids match so we can rely on them always matching
|
||||
if self.events.get(id).is_none() {
|
||||
bail!("Tried to register handler for unknown event {id}");
|
||||
};
|
||||
let hook = ErasedHook::new_dynamic(hook);
|
||||
self.handlers.get_mut(id).unwrap().push(hook);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn dispatch<E: Event>(&self, mut event: E) {
|
||||
let Some(hooks) = self.handlers.get(E::ID) else {
|
||||
log::error!("Dispatched unknown event {}", E::ID);
|
||||
return;
|
||||
};
|
||||
let event_id = self.events[E::ID];
|
||||
|
||||
assert_eq!(
|
||||
TypeId::of::<E::Static>(),
|
||||
event_id,
|
||||
"Tried to dispatch invalid event {}",
|
||||
E::ID
|
||||
);
|
||||
|
||||
for hook in hooks {
|
||||
// safety: event type is the same
|
||||
if let Err(err) = unsafe { hook.call(&mut event) } {
|
||||
log::error!("{} hook failed: {err:#?}", E::ID);
|
||||
crate::status::report_blocking(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
runtime_local! {
|
||||
static REGISTRY: RwLock<Registry> = RwLock::new(Registry {
|
||||
// hardcoded random number is good enough here we don't care about DOS resistance
|
||||
// and avoids the additional complexity of `Option<Registry>`
|
||||
events: HashMap::with_hasher(ahash::RandomState::with_seeds(423, 9978, 38322, 3280080)),
|
||||
handlers: HashMap::with_hasher(ahash::RandomState::with_seeds(423, 99078, 382322, 3282938)),
|
||||
});
|
||||
}
|
||||
|
||||
pub(crate) fn with<T>(f: impl FnOnce(&Registry) -> T) -> T {
|
||||
f(®ISTRY.read())
|
||||
}
|
||||
|
||||
pub(crate) fn with_mut<T>(f: impl FnOnce(&mut Registry) -> T) -> T {
|
||||
f(&mut REGISTRY.write())
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
/// The number of specified lifetimes and the static type *must* be correct.
|
||||
/// This is ensured automatically by the [`events`](crate::events)
|
||||
/// macro.
|
||||
pub unsafe trait Event: Sized {
|
||||
/// Globally unique (case sensitive) string that identifies this type.
|
||||
/// A good candidate is the events type name
|
||||
const ID: &'static str;
|
||||
const LIFETIMES: usize;
|
||||
type Static: Event + 'static;
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
//! The event system makes use of global to decouple different systems.
|
||||
//! However, this can cause problems for the integration test system because
|
||||
//! it runs multiple helix applications in parallel. Making the globals
|
||||
//! thread-local does not work because a applications can/does have multiple
|
||||
//! runtime threads. Instead this crate implements a similar notion to a thread
|
||||
//! local but instead of being local to a single thread, the statics are local to
|
||||
//! a single tokio-runtime. The implementation requires locking so it's not exactly efficient.
|
||||
//!
|
||||
//! Therefore this function is only enabled during integration tests and behaves like
|
||||
//! a normal static otherwise. I would prefer this module to be fully private and to only
|
||||
//! export the macro but the macro still need to construct these internals so it's marked
|
||||
//! `doc(hidden)` instead
|
||||
|
||||
use std::ops::Deref;
|
||||
|
||||
#[cfg(not(feature = "integration_test"))]
|
||||
pub struct RuntimeLocal<T: 'static> {
|
||||
/// inner API used in the macro, not part of public API
|
||||
#[doc(hidden)]
|
||||
pub __data: T,
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "integration_test"))]
|
||||
impl<T> Deref for RuntimeLocal<T> {
|
||||
type Target = T;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.__data
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "integration_test"))]
|
||||
#[macro_export]
|
||||
macro_rules! runtime_local {
|
||||
($($(#[$attr:meta])* $vis: vis static $name:ident: $ty: ty = $init: expr;)*) => {
|
||||
$($(#[$attr])* $vis static $name: $crate::runtime::RuntimeLocal<$ty> = $crate::runtime::RuntimeLocal {
|
||||
__data: $init
|
||||
};)*
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(feature = "integration_test")]
|
||||
pub struct RuntimeLocal<T: 'static> {
|
||||
data:
|
||||
parking_lot::RwLock<hashbrown::HashMap<tokio::runtime::Id, &'static T, ahash::RandomState>>,
|
||||
init: fn() -> T,
|
||||
}
|
||||
|
||||
#[cfg(feature = "integration_test")]
|
||||
impl<T> RuntimeLocal<T> {
|
||||
/// inner API used in the macro, not part of public API
|
||||
#[doc(hidden)]
|
||||
pub const fn __new(init: fn() -> T) -> Self {
|
||||
Self {
|
||||
data: parking_lot::RwLock::new(hashbrown::HashMap::with_hasher(
|
||||
ahash::RandomState::with_seeds(423, 9978, 38322, 3280080),
|
||||
)),
|
||||
init,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "integration_test")]
|
||||
impl<T> Deref for RuntimeLocal<T> {
|
||||
type Target = T;
|
||||
fn deref(&self) -> &T {
|
||||
let id = tokio::runtime::Handle::current().id();
|
||||
let guard = self.data.read();
|
||||
match guard.get(&id) {
|
||||
Some(res) => res,
|
||||
None => {
|
||||
drop(guard);
|
||||
let data = Box::leak(Box::new((self.init)()));
|
||||
let mut guard = self.data.write();
|
||||
guard.insert(id, data);
|
||||
data
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "integration_test")]
|
||||
#[macro_export]
|
||||
macro_rules! runtime_local {
|
||||
($($(#[$attr:meta])* $vis: vis static $name:ident: $ty: ty = $init: expr;)*) => {
|
||||
$($(#[$attr])* $vis static $name: $crate::runtime::RuntimeLocal<$ty> = $crate::runtime::RuntimeLocal::__new(|| $init);)*
|
||||
};
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
//! A queue of async messages/errors that will be shown in the editor
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::{runtime_local, send_blocking};
|
||||
use once_cell::sync::OnceCell;
|
||||
use tokio::sync::mpsc::{Receiver, Sender};
|
||||
|
||||
/// Describes the severity level of a [`StatusMessage`].
|
||||
#[derive(Debug, Clone, Copy, Eq, PartialEq, PartialOrd, Ord)]
|
||||
pub enum Severity {
|
||||
Hint,
|
||||
Info,
|
||||
Warning,
|
||||
Error,
|
||||
}
|
||||
|
||||
pub struct StatusMessage {
|
||||
pub severity: Severity,
|
||||
pub message: Cow<'static, str>,
|
||||
}
|
||||
|
||||
impl From<anyhow::Error> for StatusMessage {
|
||||
fn from(err: anyhow::Error) -> Self {
|
||||
StatusMessage {
|
||||
severity: Severity::Error,
|
||||
message: err.to_string().into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&'static str> for StatusMessage {
|
||||
fn from(msg: &'static str) -> Self {
|
||||
StatusMessage {
|
||||
severity: Severity::Info,
|
||||
message: msg.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
runtime_local! {
|
||||
static MESSAGES: OnceCell<Sender<StatusMessage>> = OnceCell::new();
|
||||
}
|
||||
|
||||
pub async fn report(msg: impl Into<StatusMessage>) {
|
||||
// if the error channel overflows just ignore it
|
||||
let _ = MESSAGES
|
||||
.wait()
|
||||
.send_timeout(msg.into(), Duration::from_millis(10))
|
||||
.await;
|
||||
}
|
||||
|
||||
pub fn report_blocking(msg: impl Into<StatusMessage>) {
|
||||
let messages = MESSAGES.wait();
|
||||
send_blocking(messages, msg.into())
|
||||
}
|
||||
|
||||
/// Must be called once during editor startup exactly once
|
||||
/// before any of the messages in this module can be used
|
||||
///
|
||||
/// # Panics
|
||||
/// If called multiple times
|
||||
pub fn setup() -> Receiver<StatusMessage> {
|
||||
let (tx, rx) = tokio::sync::mpsc::channel(128);
|
||||
let _ = MESSAGES.set(tx);
|
||||
rx
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
use parking_lot::Mutex;
|
||||
|
||||
use crate::{dispatch, events, register_dynamic_hook, register_event, register_hook};
|
||||
#[test]
|
||||
fn smoke_test() {
|
||||
events! {
|
||||
Event1 { content: String }
|
||||
Event2 { content: usize }
|
||||
}
|
||||
register_event::<Event1>();
|
||||
register_event::<Event2>();
|
||||
|
||||
// setup hooks
|
||||
let res1: Arc<Mutex<String>> = Arc::default();
|
||||
let acc = Arc::clone(&res1);
|
||||
register_hook!(move |event: &mut Event1| {
|
||||
acc.lock().push_str(&event.content);
|
||||
Ok(())
|
||||
});
|
||||
let res2: Arc<AtomicUsize> = Arc::default();
|
||||
let acc = Arc::clone(&res2);
|
||||
register_hook!(move |event: &mut Event2| {
|
||||
acc.fetch_add(event.content, Ordering::Relaxed);
|
||||
Ok(())
|
||||
});
|
||||
|
||||
// triggers events
|
||||
let thread = std::thread::spawn(|| {
|
||||
for i in 0..1000 {
|
||||
dispatch(Event2 { content: i });
|
||||
}
|
||||
});
|
||||
std::thread::sleep(Duration::from_millis(1));
|
||||
dispatch(Event1 {
|
||||
content: "foo".to_owned(),
|
||||
});
|
||||
dispatch(Event2 { content: 42 });
|
||||
dispatch(Event1 {
|
||||
content: "bar".to_owned(),
|
||||
});
|
||||
dispatch(Event1 {
|
||||
content: "hello world".to_owned(),
|
||||
});
|
||||
thread.join().unwrap();
|
||||
|
||||
// check output
|
||||
assert_eq!(&**res1.lock(), "foobarhello world");
|
||||
assert_eq!(
|
||||
res2.load(Ordering::Relaxed),
|
||||
42 + (0..1000usize).sum::<usize>()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dynamic() {
|
||||
events! {
|
||||
Event3 {}
|
||||
Event4 { count: usize }
|
||||
};
|
||||
register_event::<Event3>();
|
||||
register_event::<Event4>();
|
||||
|
||||
let count = Arc::new(AtomicUsize::new(0));
|
||||
let count1 = count.clone();
|
||||
let count2 = count.clone();
|
||||
register_dynamic_hook(
|
||||
move || {
|
||||
count1.fetch_add(2, Ordering::Relaxed);
|
||||
Ok(())
|
||||
},
|
||||
"Event3",
|
||||
)
|
||||
.unwrap();
|
||||
register_dynamic_hook(
|
||||
move || {
|
||||
count2.fetch_add(3, Ordering::Relaxed);
|
||||
Ok(())
|
||||
},
|
||||
"Event4",
|
||||
)
|
||||
.unwrap();
|
||||
dispatch(Event3 {});
|
||||
dispatch(Event4 { count: 0 });
|
||||
dispatch(Event3 {});
|
||||
assert_eq!(count.load(Ordering::Relaxed), 7)
|
||||
}
|
@ -1,28 +1,32 @@
|
||||
[package]
|
||||
name = "helix-lsp"
|
||||
version = "0.6.0"
|
||||
authors = ["Blaž Hrastnik <blaz@mxxn.io>"]
|
||||
edition = "2021"
|
||||
license = "MPL-2.0"
|
||||
description = "LSP client implementation for Helix project"
|
||||
categories = ["editor"]
|
||||
repository = "https://github.com/helix-editor/helix"
|
||||
homepage = "https://helix-editor.com"
|
||||
version.workspace = true
|
||||
authors.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
rust-version.workspace = true
|
||||
categories.workspace = true
|
||||
repository.workspace = true
|
||||
homepage.workspace = true
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
helix-core = { version = "0.6", path = "../helix-core" }
|
||||
helix-loader = { version = "0.6", path = "../helix-loader" }
|
||||
helix-stdx = { path = "../helix-stdx" }
|
||||
helix-core = { path = "../helix-core" }
|
||||
helix-loader = { path = "../helix-loader" }
|
||||
helix-parsec = { path = "../helix-parsec" }
|
||||
|
||||
anyhow = "1.0"
|
||||
futures-executor = "0.3"
|
||||
futures-util = { version = "0.3", features = ["std", "async-await"], default-features = false }
|
||||
globset = "0.4.14"
|
||||
log = "0.4"
|
||||
lsp-types = { version = "0.94" }
|
||||
lsp-types = { version = "0.95" }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
thiserror = "1.0"
|
||||
tokio = { version = "1.25", features = ["rt", "rt-multi-thread", "io-util", "io-std", "time", "process", "macros", "fs", "parking_lot", "sync"] }
|
||||
tokio-stream = "0.1.11"
|
||||
which = "4.4"
|
||||
tokio = { version = "1.35", features = ["rt", "rt-multi-thread", "io-util", "io-std", "time", "process", "macros", "fs", "parking_lot", "sync"] }
|
||||
tokio-stream = "0.1.14"
|
||||
parking_lot = "0.12.1"
|
||||
|
@ -0,0 +1,193 @@
|
||||
use std::{collections::HashMap, path::PathBuf, sync::Weak};
|
||||
|
||||
use globset::{GlobBuilder, GlobSetBuilder};
|
||||
use tokio::sync::mpsc;
|
||||
|
||||
use crate::{lsp, Client};
|
||||
|
||||
enum Event {
|
||||
FileChanged {
|
||||
path: PathBuf,
|
||||
},
|
||||
Register {
|
||||
client_id: usize,
|
||||
client: Weak<Client>,
|
||||
registration_id: String,
|
||||
options: lsp::DidChangeWatchedFilesRegistrationOptions,
|
||||
},
|
||||
Unregister {
|
||||
client_id: usize,
|
||||
registration_id: String,
|
||||
},
|
||||
RemoveClient {
|
||||
client_id: usize,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct ClientState {
|
||||
client: Weak<Client>,
|
||||
registered: HashMap<String, globset::GlobSet>,
|
||||
}
|
||||
|
||||
/// The Handler uses a dedicated tokio task to respond to file change events by
|
||||
/// forwarding changes to LSPs that have registered for notifications with a
|
||||
/// matching glob.
|
||||
///
|
||||
/// When an LSP registers for the DidChangeWatchedFiles notification, the
|
||||
/// Handler is notified by sending the registration details in addition to a
|
||||
/// weak reference to the LSP client. This is done so that the Handler can have
|
||||
/// access to the client without preventing the client from being dropped if it
|
||||
/// is closed and the Handler isn't properly notified.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Handler {
|
||||
tx: mpsc::UnboundedSender<Event>,
|
||||
}
|
||||
|
||||
impl Default for Handler {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl Handler {
|
||||
pub fn new() -> Self {
|
||||
let (tx, rx) = mpsc::unbounded_channel();
|
||||
tokio::spawn(Self::run(rx));
|
||||
Self { tx }
|
||||
}
|
||||
|
||||
pub fn register(
|
||||
&self,
|
||||
client_id: usize,
|
||||
client: Weak<Client>,
|
||||
registration_id: String,
|
||||
options: lsp::DidChangeWatchedFilesRegistrationOptions,
|
||||
) {
|
||||
let _ = self.tx.send(Event::Register {
|
||||
client_id,
|
||||
client,
|
||||
registration_id,
|
||||
options,
|
||||
});
|
||||
}
|
||||
|
||||
pub fn unregister(&self, client_id: usize, registration_id: String) {
|
||||
let _ = self.tx.send(Event::Unregister {
|
||||
client_id,
|
||||
registration_id,
|
||||
});
|
||||
}
|
||||
|
||||
pub fn file_changed(&self, path: PathBuf) {
|
||||
let _ = self.tx.send(Event::FileChanged { path });
|
||||
}
|
||||
|
||||
pub fn remove_client(&self, client_id: usize) {
|
||||
let _ = self.tx.send(Event::RemoveClient { client_id });
|
||||
}
|
||||
|
||||
async fn run(mut rx: mpsc::UnboundedReceiver<Event>) {
|
||||
let mut state: HashMap<usize, ClientState> = HashMap::new();
|
||||
while let Some(event) = rx.recv().await {
|
||||
match event {
|
||||
Event::FileChanged { path } => {
|
||||
log::debug!("Received file event for {:?}", &path);
|
||||
|
||||
state.retain(|id, client_state| {
|
||||
if !client_state
|
||||
.registered
|
||||
.values()
|
||||
.any(|glob| glob.is_match(&path))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
let Some(client) = client_state.client.upgrade() else {
|
||||
log::warn!("LSP client was dropped: {id}");
|
||||
return false;
|
||||
};
|
||||
let Ok(uri) = lsp::Url::from_file_path(&path) else {
|
||||
return true;
|
||||
};
|
||||
log::debug!(
|
||||
"Sending didChangeWatchedFiles notification to client '{}'",
|
||||
client.name()
|
||||
);
|
||||
if let Err(err) = crate::block_on(client
|
||||
.did_change_watched_files(vec![lsp::FileEvent {
|
||||
uri,
|
||||
// We currently always send the CHANGED state
|
||||
// since we don't actually have more context at
|
||||
// the moment.
|
||||
typ: lsp::FileChangeType::CHANGED,
|
||||
}]))
|
||||
{
|
||||
log::warn!("Failed to send didChangeWatchedFiles notification to client: {err}");
|
||||
}
|
||||
true
|
||||
});
|
||||
}
|
||||
Event::Register {
|
||||
client_id,
|
||||
client,
|
||||
registration_id,
|
||||
options: ops,
|
||||
} => {
|
||||
log::debug!(
|
||||
"Registering didChangeWatchedFiles for client '{}' with id '{}'",
|
||||
client_id,
|
||||
registration_id
|
||||
);
|
||||
|
||||
let entry = state.entry(client_id).or_insert_with(ClientState::default);
|
||||
entry.client = client;
|
||||
|
||||
let mut builder = GlobSetBuilder::new();
|
||||
for watcher in ops.watchers {
|
||||
if let lsp::GlobPattern::String(pattern) = watcher.glob_pattern {
|
||||
if let Ok(glob) = GlobBuilder::new(&pattern).build() {
|
||||
builder.add(glob);
|
||||
}
|
||||
}
|
||||
}
|
||||
match builder.build() {
|
||||
Ok(globset) => {
|
||||
entry.registered.insert(registration_id, globset);
|
||||
}
|
||||
Err(err) => {
|
||||
// Remove any old state for that registration id and
|
||||
// remove the entire client if it's now empty.
|
||||
entry.registered.remove(®istration_id);
|
||||
if entry.registered.is_empty() {
|
||||
state.remove(&client_id);
|
||||
}
|
||||
log::warn!(
|
||||
"Unable to build globset for LSP didChangeWatchedFiles {err}"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
Event::Unregister {
|
||||
client_id,
|
||||
registration_id,
|
||||
} => {
|
||||
log::debug!(
|
||||
"Unregistering didChangeWatchedFiles with id '{}' for client '{}'",
|
||||
registration_id,
|
||||
client_id
|
||||
);
|
||||
if let Some(client_state) = state.get_mut(&client_id) {
|
||||
client_state.registered.remove(®istration_id);
|
||||
if client_state.registered.is_empty() {
|
||||
state.remove(&client_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
Event::RemoveClient { client_id } => {
|
||||
log::debug!("Removing LSP client: {client_id}");
|
||||
state.remove(&client_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue