Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into typst-support
Browse files Browse the repository at this point in the history
  • Loading branch information
grantlemons committed Dec 30, 2024
2 parents 83789eb + ace693c commit e66ec68
Show file tree
Hide file tree
Showing 70 changed files with 6,222 additions and 1,507 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/precommit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- uses: extractions/setup-just@v2
- uses: actions/setup-node@v4
with:
node-version: 20
node-version: 23
- name: Install `wasm-pack`
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- name: Precommit
Expand Down
44 changes: 1 addition & 43 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,3 @@
# Harper's Architecture

This document seeks to solve one simple problem:

> "Roughly, it takes 2x more time to write a patch if you are unfamiliar with the project, but it takes 10x more time to figure out **where** you should change the code." - [Alex Kladov](https://matklad.github.io/2021/02/06/ARCHITECTURE.md.html)
This document is meant to serve as a kind of table of contents for the Harper project.
Hopefully, we can reduce that 10x down to something a little more reasonable.

## What does Harper do?

Harper tries to do one thing well: find grammatical and spelling errors in English text.
If possible, provide suggestions to correct those errors.
An error and it's possible corrections together form what we call a lint.

In this vein, Harper serves the role of a [Linter](<https://en.wikipedia.org/wiki/Lint_(software)>) for English.

## `harper-core`

`harper-core` is where all the magic happens.
It contains the code need to tokenize, parse, analyze and lint English text.

At a high level, there are just a couple types you need to worry about.

- [Document](https://docs.rs/harper-core/latest/harper_core/struct.Document.html): A representation of an English document. Implements [`TokenStringExt`](https://docs.rs/harper-core/latest/harper_core/trait.TokenStringExt.html) to make it easier to query.
- [Parser](https://docs.rs/harper-core/latest/harper_core/parsers/trait.Parser.html): A trait that describes an object that consumes text and emits tokens. The name is somewhat of a misnomer since it is supposed to only lex English (and emit [Tokens](https://docs.rs/harper-core/latest/harper_core/struct.Token.html)), not parse it. It is called a parser since most types that implement this trait parse _other_ languages (JavaScript) to extract the English text.
- The [Markdown parser](https://docs.rs/harper-core/latest/harper_core/parsers/struct.Markdown.html) is a great example.
- [Linter](https://docs.rs/harper-core/latest/harper_core/linting/trait.Linter.html): A trait that, provided a document, will produce zero or more [Lints](https://docs.rs/harper-core/latest/harper_core/linting/struct.Lint.html#). This is usually done using direct queries on the document or by implementing a [`PatternLinter`](https://docs.rs/harper-core/latest/harper_core/linting/trait.PatternLinter.html).

If you want to add a linter to Harper, create a new file under the `linters` module in `harper-core` and create a public struct that implements the `Linter` trait.
There are a couple places in other parts of the codebase you'll need to update before it will show up in editors and have persistent settings, but that's a problem for after you've opened your pull request.

## `harper-ls`

`harper-ls` is a language server that wraps around `harper-core`.
In essence, it enables text editors and IDEs to access the capabilities of Harper over a network or via standard input/output.

If you aren't familiar with what a language server does, I would suggest reading [this](https://tamerlan.dev/an-introduction-to-the-language-server-protocol/) or the [official language server protocol documentation](https://microsoft.github.io/language-server-protocol/).

When Harper is used through Neovim, Visual Studio Code, Helix or Emacs, `harper-ls` is the interface.

## `harper-wasm`

`harper-wasm` is a small library that wraps `harper-core` and compiles to WebAssembly with [`wasm-bindgen`](https://github.com/rustwasm/wasm-bindgen).
This allows web applications (like the [Harper](https://writewithharper.com) and the [Obsidian Plugin](https://github.com/automattic/harper-obsidian-plugin) to run Harper without downloading any additional executables. It all runs inside the JavaScript engine.
This document has been moved to the [online documentation](https://writewithharper.com/docs/contributors/architecture).
40 changes: 1 addition & 39 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,3 @@
# Contributing

Harper is completely open to outside contributors of any kind.

If you have a feature request or bug to report, please [create an issue](https://github.com/automattic/harper/issues).

## Setup Your Environment

To use the tooling required to build and debug Harper, you'll need to the following programs available in your `PATH`.

- [`just`](https://github.com/casey/just)
- `bash`
- [`cargo`](https://www.rust-lang.org/) (we develop against the latest version of Rust)
- `yarn`
- `node`
- `grep`
- [`wasm-pack`](https://rustwasm.github.io/wasm-pack/installer/)

To list out the various tools for development, run:

```bash
just --list
```

I would highly recommend that you run `just setup` to populate your build caches and install the necessary build-tools.

## Committing

Harper follows [conventional commit practices](https://www.conventionalcommits.org/en/v1.0.0/).
Before creating a pull request, please make sure all your commits follow the linked conventions.

Additionally, to minimize the labor required to review your commit, we run a relatively strict suite of formatting and linting programs.
We highly recommend that you run both `just format` and `just precommit` before submitting a pull request.
If those scripts don't work in your environment, we run `just precommit` through GitHub actions inside of pull requests, so you may make modifications and push until the checks pass.

If this sounds intimidating, don't worry.
We are entirely willing to work with you to make sure your code can make it into Harper, just know it might take a little longer.

## How does it work?

Please take a read of the [architecture document](./ARCHITECTURE.md).
This page has been moved to [the main documentation](https://writewithharper.com/docs/contributors/introduction).
21 changes: 16 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ RUN wasm-pack build --release --target web

FROM node:slim AS node-build

RUN apt-get update && apt-get install git -y

RUN mkdir -p /usr/build/
WORKDIR /usr/build/

Expand Down
17 changes: 0 additions & 17 deletions fly.toml

This file was deleted.

4 changes: 2 additions & 2 deletions harper-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ repository = "https://github.com/automattic/harper"
anyhow = "1.0.95"
ariadne = "0.4.1"
clap = { version = "4.5.23", features = ["derive"] }
harper-core = { path = "../harper-core", version = "0.12.0" }
harper-comments = { path = "../harper-comments", version = "0.12.0" }
harper-core = { path = "../harper-core", version = "0.13.0" }
harper-comments = { path = "../harper-comments", version = "0.13.0" }
serde_json = "1.0.133"
9 changes: 5 additions & 4 deletions harper-comments/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
[package]
name = "harper-comments"
version = "0.12.0"
version = "0.13.0"
edition = "2021"
description = "The language checker for developers."
license = "Apache-2.0"
readme = "README.md"
repository = "https://github.com/automattic/harper"

[dependencies]
harper-core = { path = "../harper-core", version = "0.12.0" }
harper-html = { path = "../harper-html", version = "0.12.0" }
harper-tree-sitter = { path = "../harper-tree-sitter", version = "0.12.0" }
harper-core = { path = "../harper-core", version = "0.13.0" }
harper-html = { path = "../harper-html", version = "0.13.0" }
harper-tree-sitter = { path = "../harper-tree-sitter", version = "0.13.0" }
tree-sitter = "0.20.10"
tree-sitter-rust = "0.20.4"
tree-sitter-typescript = "0.20.3"
Expand All @@ -28,6 +28,7 @@ tree-sitter-bash = "0.20.0"
tree-sitter-java = "0.20.0"
tree-sitter-nix = "0.0.1"
itertools = "0.13.0"
tree-sitter-haskell = "0.15.0"

[dev-dependencies]
paste = "1.0.15"
2 changes: 2 additions & 0 deletions harper-comments/src/comment_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ impl CommentParser {
"lua" => tree_sitter_lua::language(),
"shellscript" => tree_sitter_bash::language(),
"java" => tree_sitter_java::language(),
"haskell" => tree_sitter_haskell::language(),
_ => return None,
};

Expand Down Expand Up @@ -85,6 +86,7 @@ impl CommentParser {
"sh" => "shellscript",
"bash" => "shellscript",
"java" => "java",
"hs" => "haskell",
_ => return None,
})
}
Expand Down
2 changes: 1 addition & 1 deletion harper-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "harper-core"
version = "0.12.0"
version = "0.13.0"
edition = "2021"
description = "The language checker for developers."
license = "Apache-2.0"
Expand Down
Loading

0 comments on commit e66ec68

Please sign in to comment.