Compare commits

...

38 Commits

Author SHA1 Message Date
Blaž Hrastnik
cbb3ebafdc Support ctrl-f and ctrl-b to page up/down, fixes #41 2021-06-02 13:20:36 +09:00
Blaž Hrastnik
0851110d10 f/t: Check if at bounds before searching, refs #43, closes #37 2021-06-02 13:20:27 +09:00
Blaž Hrastnik
3ace581191 Fix panics when triggering w or e on the last char of the line
Closes #32
2021-06-02 13:19:40 +09:00
Blaž Hrastnik
c0264b9f7f fix: Don't allow moving past last line, fixes #30, #24
Off by 1 error
2021-06-02 13:19:40 +09:00
Blaž Hrastnik
22dad592b8 Merge pull request #40 from data0x200/fix-empty-command
Fix empty command cause panic
2021-06-02 13:06:57 +09:00
Blaž Hrastnik
67b1cd32c7 Update install notes 2021-06-02 11:14:46 +09:00
Daichi Takamiya
4d12c7c3cf Fix empty command cause panic 2021-06-02 10:55:32 +09:00
Blaž Hrastnik
4f56a8e248 book: Always generate the CNAME file 2021-06-02 10:24:00 +09:00
Blaž Hrastnik
dbc392d92c Run fmt 2021-06-02 09:56:50 +09:00
Blaž Hrastnik
7967d312c0 Merge pull request #38 from nathom/master
Add .DS_Store to ignored directories
2021-06-02 09:37:09 +09:00
Blaž Hrastnik
db48d22384 Merge pull request #19 from wojciechkepka/archinstall
Add Arch Linux installation instructions to README
2021-06-02 09:30:41 +09:00
Blaž Hrastnik
533ff61d0e Merge pull request #34 from DanySpin97/improve-error
Improve errors handling in main by adding context
2021-06-02 09:30:16 +09:00
nathom
b1ce969d80 Add .DS_Store to ignored directories 2021-06-01 17:29:37 -07:00
Blaž Hrastnik
01bf363446 Merge pull request #31 from wullewutz/patch-1
Fixed c/p error in keymap doc
2021-06-02 09:26:29 +09:00
Blaž Hrastnik
cc323f7665 Merge pull request #36 from swdunlop/patch-1
Make HELIX_RUNTIME depend on pwd, not speed's HOME
2021-06-02 09:26:04 +09:00
Scott Dunlop
60caaf7fc4 Make HELIX_RUNTIME depend on pwd, not speed's HOME 2021-06-01 15:03:57 -07:00
Danilo Spinella
ea824ed05d Improve errors handling in main by adding context
Return a anyhow::Result in main function so that Context can be used
there too.
2021-06-01 23:27:16 +02:00
wullewutz
cfae07e7ba Fixed c/p error in keymap doc
Go to definition mapping is "gd" not "ge"
2021-06-01 22:36:42 +02:00
wojciechkepka
56dbc60840 Add Arch Linux installation instructions to README 2021-06-01 21:08:09 +02:00
Blaž Hrastnik
c2e6b9f506 Add typescript support & ts/js indentation queries 2021-06-01 17:55:11 +09:00
Blaž Hrastnik
8fd8006043 Golang indent queries 2021-06-01 17:26:10 +09:00
Blaž Hrastnik
ce25aa951e Allow setting a filepath on :write 2021-06-01 17:26:03 +09:00
Blaž Hrastnik
a2147fc7d5 Change help prompt styling 2021-06-01 12:00:25 +09:00
Blaž Hrastnik
d8e16554bf Don't crash if no filename specified on open 2021-06-01 11:59:59 +09:00
Blaž Hrastnik
2cc30cd07c Categorize _ as a word char, not punctuation 2021-05-31 21:09:17 +09:00
Blaž Hrastnik
0dde5f2cae Fix badge 2021-05-31 21:09:07 +09:00
Blaž Hrastnik
b8d6e6ad28 Allow setting verbosity to info again 2021-05-31 17:14:49 +09:00
Blaž Hrastnik
5825bce0e4 Link to install/keymap docs, fix build status badge 2021-05-31 17:12:09 +09:00
Blaž Hrastnik
aeabfc55a8 Adjust golang indents yet again 2021-05-31 17:09:19 +09:00
Blaž Hrastnik
17e9386388 Allow moving to EOL byte, also fixes #15 2021-05-31 17:08:19 +09:00
Blaž Hrastnik
138787f76e Drop clap for pico-args
We barely have any flags so it's not worth the compilation time or
binary size to use clap.
2021-05-31 17:07:43 +09:00
Blaž Hrastnik
1132c5122f Update mdbook styling, add link to AUR 2021-05-31 00:32:21 +09:00
Blaž Hrastnik
4a8053e832 Merge pull request #13 from helix-editor/dependabot/cargo/tokio-1.6.1
Bump tokio from 1.6.0 to 1.6.1
2021-05-30 18:02:52 +09:00
Blaž Hrastnik
e033a4b8ac Merge pull request #11 from helix-editor/dependabot/github_actions/actions/upload-artifact-2.2.3
Bump actions/upload-artifact from 1 to 2.2.3
2021-05-30 17:58:43 +09:00
Blaž Hrastnik
acbcd758bd Merge pull request #12 from helix-editor/dependabot/github_actions/actions/cache-2.1.6
Bump actions/cache from 1 to 2.1.6
2021-05-30 17:58:21 +09:00
dependabot[bot]
76eed4caad Bump tokio from 1.6.0 to 1.6.1
Bumps [tokio](https://github.com/tokio-rs/tokio) from 1.6.0 to 1.6.1.
- [Release notes](https://github.com/tokio-rs/tokio/releases)
- [Commits](https://github.com/tokio-rs/tokio/compare/tokio-1.6.0...tokio-1.6.1)

Signed-off-by: dependabot[bot] <support@github.com>
2021-05-30 08:54:43 +00:00
dependabot[bot]
3170c49be8 Bump actions/cache from 1 to 2.1.6
Bumps [actions/cache](https://github.com/actions/cache) from 1 to 2.1.6.
- [Release notes](https://github.com/actions/cache/releases)
- [Commits](https://github.com/actions/cache/compare/v1...v2.1.6)

Signed-off-by: dependabot[bot] <support@github.com>
2021-05-30 08:54:19 +00:00
dependabot[bot]
0327d66653 Bump actions/upload-artifact from 1 to 2.2.3
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 1 to 2.2.3.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v1...v2.2.3)

Signed-off-by: dependabot[bot] <support@github.com>
2021-05-30 08:54:15 +00:00
29 changed files with 320 additions and 149 deletions

View File

@@ -25,19 +25,19 @@ jobs:
override: true
- name: Cache cargo registry
uses: actions/cache@v1
uses: actions/cache@v2.1.6
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-v1-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v1
uses: actions/cache@v2.1.6
with:
path: ~/.cargo/git
key: ${{ runner.os }}-v1-cargo-index-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo target dir
uses: actions/cache@v1
uses: actions/cache@v2.1.6
with:
path: target
key: ${{ runner.os }}-v1-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
@@ -64,19 +64,19 @@ jobs:
override: true
- name: Cache cargo registry
uses: actions/cache@v1
uses: actions/cache@v2.1.6
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-v1-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v1
uses: actions/cache@v2.1.6
with:
path: ~/.cargo/git
key: ${{ runner.os }}-v1-cargo-index-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo target dir
uses: actions/cache@v1
uses: actions/cache@v2.1.6
with:
path: target
key: ${{ runner.os }}-v1-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
@@ -104,19 +104,19 @@ jobs:
components: rustfmt, clippy
- name: Cache cargo registry
uses: actions/cache@v1
uses: actions/cache@v2.1.6
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-v1-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v1
uses: actions/cache@v2.1.6
with:
path: ~/.cargo/git
key: ${{ runner.os }}-v1-cargo-index-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo target dir
uses: actions/cache@v1
uses: actions/cache@v2.1.6
with:
path: target
key: ${{ runner.os }}-v1-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}

View File

@@ -96,7 +96,7 @@ jobs:
cp "target/${{ matrix.target }}/release/hx" "dist/"
fi
- uses: actions/upload-artifact@v1
- uses: actions/upload-artifact@v2.2.3
with:
name: bins-${{ matrix.build }}
path: dist

65
Cargo.lock generated
View File

@@ -77,21 +77,6 @@ dependencies = [
"winapi",
]
[[package]]
name = "clap"
version = "3.0.0-beta.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4bd1061998a501ee7d4b6d449020df3266ca3124b941ec56cf2005c3779ca142"
dependencies = [
"bitflags",
"indexmap",
"lazy_static",
"os_str_bytes",
"textwrap",
"unicode-width",
"vec_map",
]
[[package]]
name = "crossbeam-utils"
version = "0.8.4"
@@ -272,17 +257,10 @@ dependencies = [
"regex",
]
[[package]]
name = "hashbrown"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04"
[[package]]
name = "helix-core"
version = "0.1.0"
dependencies = [
"anyhow",
"etcetera",
"helix-syntax",
"once_cell",
@@ -335,7 +313,6 @@ version = "0.1.0"
dependencies = [
"anyhow",
"chrono",
"clap",
"crossterm",
"dirs-next",
"fern",
@@ -349,6 +326,7 @@ dependencies = [
"log",
"num_cpus",
"once_cell",
"pico-args",
"pulldown-cmark",
"serde",
"serde_json",
@@ -423,16 +401,6 @@ dependencies = [
"winapi-util",
]
[[package]]
name = "indexmap"
version = "1.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "824845a0bf897a9042383849b02c1bc219c2383772efcd5c6f9766fa4b81aef3"
dependencies = [
"autocfg",
"hashbrown",
]
[[package]]
name = "instant"
version = "0.1.9"
@@ -602,12 +570,6 @@ version = "1.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af8b08b04175473088b46763e51ee54da5f9a164bc162f615b91bc179dbf15a3"
[[package]]
name = "os_str_bytes"
version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "afb2e1c3ee07430c2cf76151675e583e0f19985fa6efae47d6848a3e2c824f85"
[[package]]
name = "parking_lot"
version = "0.11.1"
@@ -645,6 +607,12 @@ version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e"
[[package]]
name = "pico-args"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d7afeb98c5a10e0bffcc7fc16e105b04d06729fac5fd6384aebf7ff5cb5a67d"
[[package]]
name = "pin-project-lite"
version = "0.2.6"
@@ -857,15 +825,6 @@ dependencies = [
"utf-8",
]
[[package]]
name = "textwrap"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "203008d98caf094106cfaba70acfed15e18ed3ddb7d94e49baec153a2b462789"
dependencies = [
"unicode-width",
]
[[package]]
name = "thiserror"
version = "1.0.25"
@@ -921,9 +880,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
[[package]]
name = "tokio"
version = "1.6.0"
version = "1.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd3076b5c8cc18138b8f8814895c11eb4de37114a5d127bafdc5e55798ceef37"
checksum = "0a38d31d7831c6ed7aad00aa4c12d9375fd225a6dd77da1d25b707346319a975"
dependencies = [
"autocfg",
"bytes",
@@ -1044,12 +1003,6 @@ version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"
[[package]]
name = "vec_map"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
[[package]]
name = "version_check"
version = "0.9.3"

View File

@@ -1,7 +1,7 @@
# Helix
[![Build status](https://github.com/helix-editor/helix/workflows/ci/badge.svg)](https://github.com/helix-editor/helix/actions)
[![Build status](https://github.com/helix-editor/helix/actions/workflows/build.yml/badge.svg)](https://github.com/helix-editor/helix/actions)
![Screenshot](./screenshot.png)
@@ -10,7 +10,8 @@ A kakoune / neovim inspired editor, written in Rust.
The editing model is very heavily based on kakoune; during development I found
myself agreeing with most of kakoune's design decisions.
For more information, see the [website](https://helix-editor.com).
For more information, see the [website](https://helix-editor.com) or
[documentation](https://docs.helix-editor.com/).
# Features
@@ -41,6 +42,14 @@ Now copy the `runtime/` directory somewhere. Helix will by default look for the
runtime inside the same folder as the executable, but that can be overriden via
the `HELIX_RUNTIME` environment variable.
> NOTE: You should set this to <path to repository>/runtime in development (if
> running via cargo).
## Arch Linux
There are two packages available from AUR:
- `helix-bin`: contains prebuilt binary from GitHub releases
- `helix-git`: builds the master branch of this repository
# Contributing
Contributors are very welcome! **No contribution is too small and all contributions are valued.**

View File

@@ -4,3 +4,6 @@ language = "en"
multilingual = false
src = "src"
theme = "colibri"
[output.html]
cname = "docs.helix-editor.com"

View File

@@ -6,10 +6,7 @@ We provide pre-built binaries on the [GitHub Releases page](https://github.com/h
TODO: brew tap
```
$ brew tap helix-editor/helix
$ brew install helix
```
Please use a pre-built binary release for the time being.
## Linux
@@ -21,7 +18,9 @@ shell for working on Helix.
### Arch Linux
TODO: AUR
Binary packages are available on AUR:
- [helix-bin](https://aur.archlinux.org/packages/helix-bin/) contains the pre-built release
- [helix-git](https://aur.archlinux.org/packages/helix-git/) builds the master branch
## Build from source

View File

@@ -118,7 +118,7 @@ Jumps to various locations.
|-----|-----------|
| g | Go to the start of the file |
| e | Go to the end of the file |
| e | Go to definition |
| d | Go to definition |
| t | Go to type definition |
| r | Go to references |
| i | Go to implementation |

View File

@@ -109,7 +109,7 @@ h6:target::before {
margin-top: 1.275em;
margin-bottom: .875em;
}
.content p, .content ol, .content ul, .content table, .content blockquote {
.content p, .content ol, .content ul, .content table {
margin-top: 0;
margin-bottom: .875em;
}
@@ -123,8 +123,7 @@ h6:target::before {
.content .header:link,
.content .header:visited {
color: var(--fg);
/* color: white; */
color: #281733;
color: var(--heading-fg);
}
.content .header:link,
.content .header:visited:hover {
@@ -168,12 +167,15 @@ table tbody tr:nth-child(2n) {
blockquote {
margin: 20px 0;
padding: 0 20px;
margin: 1.5rem 0;
padding: 1rem 1.5rem;
color: var(--fg);
opacity: .9;
background-color: var(--quote-bg);
border-top: .1em solid var(--quote-border);
border-bottom: .1em solid var(--quote-border);
border-left: 4px solid var(--quote-border);
}
blockquote *:last-child {
margin-bottom: 0;
}

View File

@@ -13,6 +13,7 @@
.ayu {
--bg: hsl(210, 25%, 8%);
--fg: #c5c5c5;
--heading-fg: #c5c5c5;
--sidebar-bg: #14191f;
--sidebar-fg: #c8c9db;
@@ -53,6 +54,7 @@
.coal {
--bg: hsl(200, 7%, 8%);
--fg: #98a3ad;
--heading-fg: #98a3ad;
--sidebar-bg: #292c2f;
--sidebar-fg: #a1adb8;
@@ -93,6 +95,7 @@
.light {
--bg: hsl(0, 0%, 100%);
--fg: hsl(0, 0%, 0%);
--heading-fg: hsl(0, 0%, 0%);
--sidebar-bg: #fafafa;
--sidebar-fg: hsl(0, 0%, 0%);
@@ -133,6 +136,7 @@
.navy {
--bg: hsl(226, 23%, 11%);
--fg: #bcbdd0;
--heading-fg: #bcbdd0;
--sidebar-bg: #282d3f;
--sidebar-fg: #c8c9db;
@@ -173,6 +177,7 @@
.rust {
--bg: hsl(60, 9%, 87%);
--fg: #262625;
--heading-fg: #262625;
--sidebar-bg: #3b2e2a;
--sidebar-fg: #c8c9db;
@@ -214,6 +219,7 @@
.light.no-js {
--bg: hsl(200, 7%, 8%);
--fg: #ebeafa;
--heading-fg: #ebeafa;
--sidebar-bg: #292c2f;
--sidebar-fg: #a1adb8;
@@ -297,6 +303,7 @@
--bg: #ffffff;
--fg: #452859;
--fg: #5a5977;
--heading-fg: #281733;
--sidebar-bg: #281733;
--sidebar-fg: #c8c9db;
@@ -317,8 +324,8 @@
--theme-popup-border: #737480;
--theme-hover: rgba(0,0,0, .2);
--quote-bg: hsl(226, 15%, 17%);
--quote-border: hsl(226, 15%, 22%);
--quote-bg: rgba(0, 0, 0, 0);
--quote-border: hsl(226, 15%, 75%);
--table-border-color: #5a5977;
--table-border-color: hsl(201deg 10% 67%);

View File

@@ -11,7 +11,6 @@ license = "MPL-2.0"
helix-syntax = { path = "../helix-syntax" }
ropey = "1.2"
anyhow = "1"
smallvec = "1.4"
tendril = "0.4.2"
unicode-segmentation = "1.6"

View File

@@ -25,8 +25,7 @@ pub fn move_horizontally(
}
Direction::Forward => {
// Line end is pos at the start of next line - 1
// subtract another 1 because the line ends with \n
let end = text.line_to_char(line + 1).saturating_sub(2);
let end = text.line_to_char(line + 1).saturating_sub(1);
nth_next_grapheme_boundary(text, pos, count).min(end)
}
};
@@ -46,7 +45,7 @@ pub fn move_vertically(
let new_line = match dir {
Direction::Backward => row.saturating_sub(count),
Direction::Forward => std::cmp::min(row.saturating_add(count), text.len_lines() - 1),
Direction::Forward => std::cmp::min(row.saturating_add(count), text.len_lines() - 2),
};
// convert to 0-indexed, subtract another 1 because len_chars() counts \n
@@ -65,7 +64,7 @@ pub fn move_next_word_start(slice: RopeSlice, mut begin: usize, count: usize) ->
let mut end = begin;
for _ in 0..count {
if begin + 1 == slice.len_chars() {
if begin + 2 > slice.len_chars() {
return None;
}
@@ -135,7 +134,7 @@ pub fn move_next_word_end(slice: RopeSlice, mut begin: usize, count: usize) -> O
let mut end = begin;
for _ in 0..count {
if begin + 1 == slice.len_chars() {
if begin + 2 > slice.len_chars() {
return None;
}
@@ -190,10 +189,10 @@ fn categorize(ch: char) -> Category {
Category::Eol
} else if ch.is_ascii_whitespace() {
Category::Whitespace
} else if is_word(ch) {
Category::Word
} else if ch.is_ascii_punctuation() {
Category::Punctuation
} else if ch.is_ascii_alphanumeric() {
Category::Word
} else {
unreachable!()
}

View File

@@ -7,6 +7,10 @@ pub fn find_nth_next(
n: usize,
inclusive: bool,
) -> Option<usize> {
if pos >= text.len_chars() {
return None;
}
// start searching right after pos
let mut chars = text.chars_at(pos + 1);

View File

@@ -107,7 +107,10 @@ fn build_dir(dir: &str, language: &str) {
}
fn main() {
let ignore = vec!["tree-sitter-typescript".to_string()];
let ignore = vec![
"tree-sitter-typescript".to_string(),
".DS_Store".to_string(),
];
let dirs = collect_tree_sitter_dirs(&ignore);
let mut n_jobs = 0;

View File

@@ -24,7 +24,7 @@ tokio = { version = "1", features = ["full"] }
num_cpus = "1"
tui = { path = "../helix-tui", package = "helix-tui", default-features = false, features = ["crossterm"] }
crossterm = { version = "0.19", features = ["event-stream"] }
clap = { version = "3.0.0-beta.2 ", default-features = false, features = ["std", "cargo"] }
pico-args = "0.4"
futures-util = { version = "0.3", features = ["std", "async-await"], default-features = false }

View File

@@ -1,8 +1,6 @@
use clap::ArgMatches as Args;
use helix_view::{document::Mode, Document, Editor, Theme, View};
use crate::{compositor::Compositor, ui};
use crate::{compositor::Compositor, ui, Args};
use log::{error, info};
@@ -47,8 +45,8 @@ impl Application {
let size = compositor.size();
let mut editor = Editor::new(size);
if let Ok(files) = args.values_of_t::<PathBuf>("files") {
for file in files {
if !args.files.is_empty() {
for file in args.files {
editor.open(file, Action::VerticalSplit)?;
}
} else {

View File

@@ -473,10 +473,10 @@ fn scroll(cx: &mut Context, offset: usize, direction: Direction) {
let last_line = view.last_line(doc);
// clamp into viewport
let line = cursor.row.clamp(
view.first_line + scrolloff,
last_line.saturating_sub(scrolloff),
);
let line = cursor
.row
.min(view.first_line + scrolloff)
.max(last_line.saturating_sub(scrolloff));
let text = doc.text().slice(..);
let pos = pos_at_coords(text, Position::new(line, cursor.col)); // this func will properly truncate to line end
@@ -885,12 +885,25 @@ mod cmd {
}
fn open(editor: &mut Editor, args: &[&str], event: PromptEvent) {
let path = args[0];
editor.open(path.into(), Action::Replace);
match args.get(0) {
Some(path) => {
// TODO: handle error
editor.open(path.into(), Action::Replace);
}
None => {
editor.set_error("wrong argument count".to_string());
}
};
}
fn write(editor: &mut Editor, args: &[&str], event: PromptEvent) {
let (view, doc) = editor.current();
if let Some(path) = args.get(0) {
if let Err(err) = doc.set_path(Path::new(path)) {
editor.set_error(format!("invalid filepath: {}", err));
return;
};
}
if doc.path().is_none() {
editor.set_error("cannot write a buffer without a filename".to_string());
return;
@@ -934,7 +947,7 @@ mod cmd {
Command {
name: "write",
alias: Some("w"),
doc: "Write changes to disk.",
doc: "Write changes to disk. Accepts an optional path (:write some/path.txt)",
fun: write,
completer: Some(completers::filename),
},
@@ -1018,6 +1031,9 @@ pub fn command_mode(cx: &mut Context) {
}
let parts = input.split_ascii_whitespace().collect::<Vec<&str>>();
if parts.is_empty() {
return;
}
if let Some(cmd) = cmd::COMMANDS.get(parts[0]) {
(cmd.fun)(editor, &parts[1..], event);

View File

@@ -240,10 +240,12 @@ pub fn default() -> Keymaps {
code: KeyCode::PageUp,
modifiers: KeyModifiers::NONE
} => commands::page_up,
ctrl!('b') => commands::page_up,
KeyEvent {
code: KeyCode::PageDown,
modifiers: KeyModifiers::NONE
} => commands::page_down,
ctrl!('f') => commands::page_down,
ctrl!('u') => commands::half_page_up,
ctrl!('d') => commands::half_page_down,

View File

@@ -8,12 +8,11 @@ mod ui;
use application::Application;
use clap::{App, Arg};
use std::path::PathBuf;
use anyhow::Error;
use anyhow::{Context, Result};
fn setup_logging(verbosity: u64) -> Result<(), fern::InitError> {
fn setup_logging(verbosity: u64) -> Result<()> {
let mut base_config = fern::Dispatch::new();
// Let's say we depend on something which whose "info" level messages are too
@@ -28,7 +27,7 @@ fn setup_logging(verbosity: u64) -> Result<(), fern::InitError> {
_3_or_more => base_config.level(log::LevelFilter::Trace),
};
let home = dirs_next::home_dir().expect("can't find the home directory");
let home = dirs_next::home_dir().context("can't find the home directory")?;
// Separate file config so we can include year, month and day in file logs
let file_config = fern::Dispatch::new()
@@ -48,27 +47,53 @@ fn setup_logging(verbosity: u64) -> Result<(), fern::InitError> {
Ok(())
}
fn main() {
let args = clap::app_from_crate!()
.arg(
Arg::new("files")
.about("Sets the input file to use")
.required(false)
.multiple(true)
.index(1),
)
.arg(
Arg::new("verbose")
.about("Increases logging verbosity each use for up to 3 times")
.short('v')
.takes_value(false)
.multiple_occurrences(true),
)
.get_matches();
pub struct Args {
files: Vec<PathBuf>,
}
let verbosity: u64 = args.occurrences_of("verbose");
fn main() -> Result<()> {
let help = format!(
"\
{} {}
{}
{}
setup_logging(verbosity).expect("failed to initialize logging.");
USAGE:
hx [FLAGS] [files]...
ARGS:
<files>... Sets the input file to use
FLAGS:
-h, --help Prints help information
-v Increases logging verbosity each use for up to 3 times
-V, --version Prints version information
",
env!("CARGO_PKG_NAME"),
env!("CARGO_PKG_VERSION"),
env!("CARGO_PKG_AUTHORS"),
env!("CARGO_PKG_DESCRIPTION"),
);
let mut pargs = pico_args::Arguments::from_env();
// Help has a higher priority and should be handled separately.
if pargs.contains(["-h", "--help"]) {
print!("{}", help);
std::process::exit(0);
}
let mut verbosity: u64 = 0;
if pargs.contains("-v") {
verbosity = 1;
}
setup_logging(verbosity).context("failed to initialize logging")?;
let args = Args {
files: pargs.finish().into_iter().map(|arg| arg.into()).collect(),
};
// initialize language registry
use helix_core::config_dir;
@@ -80,17 +105,16 @@ fn main() {
.as_deref()
.unwrap_or(include_bytes!("../../languages.toml"));
LOADER.get_or_init(|| {
let config = toml::from_slice(toml).expect("Could not parse languages.toml");
Loader::new(config)
});
let config = toml::from_slice(toml).context("Could not parse languages.toml")?;
LOADER.get_or_init(|| Loader::new(config));
let runtime = tokio::runtime::Runtime::new().unwrap();
let runtime = tokio::runtime::Runtime::new().context("unable to start tokio runtime")?;
// TODO: use the thread local executor to spawn the application task separately from the work pool
let mut app = Application::new(args).context("unable to create new appliction")?;
runtime.block_on(async move {
let mut app = Application::new(args).unwrap();
app.run().await;
});
Ok(())
}

View File

@@ -111,6 +111,7 @@ impl Prompt {
pub fn render_prompt(&self, area: Rect, surface: &mut Surface, cx: &mut Context) {
let theme = &cx.editor.theme;
let text_color = theme.get("ui.text.focus");
let selected_color = theme.get("ui.menu.selected");
// completion
let max_col = area.width / BASE_WIDTH;
@@ -133,7 +134,8 @@ impl Prompt {
for (i, (_range, completion)) in self.completion.iter().enumerate() {
let color = if Some(i) == self.selection {
Style::default().bg(Color::Rgb(104, 60, 232))
// Style::default().bg(Color::Rgb(104, 60, 232))
selected_color // TODO: just invert bg
} else {
text_color
};
@@ -158,14 +160,9 @@ impl Prompt {
if let Some(doc) = (self.doc_fn)(&self.line) {
let text = ui::Text::new(doc.to_string());
let area = Rect::new(
completion_area.x,
completion_area.y - 3,
completion_area.width,
3,
);
let area = Rect::new(completion_area.x, completion_area.y - 3, BASE_WIDTH * 3, 3);
let background = theme.get("ui.window");
let background = theme.get("ui.help");
surface.clear_with(area, background);
use tui::layout::Margin;

View File

@@ -1,6 +1,6 @@
use anyhow::{Context, Error};
use std::future::Future;
use std::path::{Path, PathBuf};
use std::path::{Component, Path, PathBuf};
use std::sync::Arc;
use helix_core::{
@@ -64,6 +64,42 @@ where
}
}
/// Normalize a path, removing things like `.` and `..`.
///
/// CAUTION: This does not resolve symlinks (unlike
/// [`std::fs::canonicalize`]). This may cause incorrect or surprising
/// behavior at times. This should be used carefully. Unfortunately,
/// [`std::fs::canonicalize`] can be hard to use correctly, since it can often
/// fail, or on Windows returns annoying device paths. This is a problem Cargo
/// needs to improve on.
/// Copied from cargo: https://github.com/rust-lang/cargo/blob/070e459c2d8b79c5b2ac5218064e7603329c92ae/crates/cargo-util/src/paths.rs#L81
pub fn normalize_path(path: &Path) -> PathBuf {
let mut components = path.components().peekable();
let mut ret = if let Some(c @ Component::Prefix(..)) = components.peek().cloned() {
components.next();
PathBuf::from(c.as_os_str())
} else {
PathBuf::new()
};
for component in components {
match component {
Component::Prefix(..) => unreachable!(),
Component::RootDir => {
ret.push(component.as_os_str());
}
Component::CurDir => {}
Component::ParentDir => {
ret.pop();
}
Component::Normal(c) => {
ret.push(c);
}
}
}
ret
}
use helix_lsp::lsp;
use url::Url;
@@ -176,6 +212,20 @@ impl Document {
}
}
pub fn set_path(&mut self, path: &Path) -> Result<(), std::io::Error> {
// canonicalize path to absolute value
let current_dir = std::env::current_dir()?;
let path = normalize_path(&current_dir.join(path));
if let Some(parent) = path.parent() {
// TODO: return error as necessary
if parent.exists() {
self.path = Some(path);
}
}
Ok(())
}
pub fn set_language(
&mut self,
language_config: Option<Arc<helix_core::syntax::LanguageConfiguration>>,

View File

@@ -65,6 +65,17 @@ roots = []
indent = { tab-width = 2, unit = " " }
[[language]]
name = "typescript"
scope = "source.ts"
injection-regex = "^(ts|typescript)$"
file-types = ["ts"]
roots = []
# TODO: highlights-jsx, highlights-params
language-server = { command = "typescript-language-server", args = ["--stdio"] }
indent = { tab-width = 2, unit = " " }
[[language]]
name = "css"
scope = "source.css"

View File

@@ -12,8 +12,10 @@ indent = [
"literal_value",
"expression_case",
"default_case",
"type_case",
"communication_case",
"argument_list",
"block"
"block",
]
outdent = [

View File

@@ -0,0 +1,28 @@
indent = [
"array",
"object",
"arguments",
"formal_parameters",
"statement_block",
"object_pattern",
"class_body",
"named_imports",
"binary_expression",
"return_statement",
"template_substitution",
# (expression_statement (call_expression))
"export_clause",
# typescript
"enum_declaration",
"interface_declaration",
"object_type",
]
outdent = [
"}",
"]",
")"
]

View File

@@ -0,0 +1,36 @@
; inherits: javascript
; Types
(type_identifier) @type
(predefined_type) @type.builtin
((identifier) @type
(#match? @type "^[A-Z]"))
(type_arguments
"<" @punctuation.bracket
">" @punctuation.bracket)
; Variables
(required_parameter (identifier) @variable.parameter)
(optional_parameter (identifier) @variable.parameter)
; Keywords
[
"abstract"
"declare"
"enum"
"export"
"implements"
"interface"
"keyof"
"namespace"
"private"
"protected"
"public"
"type"
"readonly"
] @keyword

View File

@@ -0,0 +1 @@
../javascript/indents.toml

View File

@@ -0,0 +1,2 @@
(required_parameter (identifier) @local.definition)
(optional_parameter (identifier) @local.definition)

View File

@@ -0,0 +1,23 @@
(function_signature
name: (identifier) @name) @definition.function
(method_signature
name: (property_identifier) @name) @definition.method
(abstract_method_signature
name: (property_identifier) @name) @definition.method
(abstract_class_declaration
name: (type_identifier) @name) @definition.class
(module
name: (identifier) @name) @definition.module
(interface_declaration
name: (type_identifier) @name) @definition.interface
(type_annotation
(type_identifier) @name) @reference.type
(new_expression
constructor: (identifier) @name) @reference.class

View File

@@ -12,7 +12,7 @@ pkgs.mkShell {
# https://github.com/rust-lang/rust/issues/55979
LD_LIBRARY_PATH="${stdenv.cc.cc.lib}/lib64:$LD_LIBRARY_PATH";
# HELIX_RUNTIME=./runtime;
HELIX_RUNTIME="/home/speed/src/helix/runtime";
shellHook = ''
export HELIX_RUNTIME=$PWD/runtime
'';
}

View File

@@ -43,8 +43,11 @@
"ui.statusline" = { bg = "#281733" } # revolver
"ui.popup" = { bg = "#281733" } # revolver
"ui.window" = { bg = "#452859" } # bossa nova
"ui.window" = { bg = "#452859" } # bossa nova
"ui.help" = { bg = "#6F44F0", fg = "#a4a0e8" }
"ui.help" = { bg = "#7958DC", fg = "#171452" }
"ui.text" = { fg = "#a4a0e8"} # lavender
"ui.text" = { fg = "#a4a0e8" } # lavender
"ui.text.focus" = { fg = "#dbbfef"} # lilac
"ui.menu.selected" = { fg = "#281733", bg = "#ffffff" } # revolver