Skip to content

Commit

Permalink
📝 Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Freed-Wu committed Dec 23, 2023
1 parent 2c34b04 commit 1acb761
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 8 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
patreon: user?u=83975719
custom:
- "https://user-images.githubusercontent.com/32936898/199681341-1c5cfa61-4411-4b67-b268-7cd87c5867bb.png"
- "https://user-images.githubusercontent.com/32936898/199681363-1094a0be-85ca-49cf-a410-19b3d7965120.png"
Expand Down
122 changes: 114 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,132 @@
[![pypi/implementation](https://shields.io/pypi/implementation/tree-sitter-lsp)](https://pypi.org/project/tree-sitter-lsp/#files)
[![pypi/pyversions](https://shields.io/pypi/pyversions/tree-sitter-lsp)](https://pypi.org/project/tree-sitter-lsp/#files)

A core library to support many language servers:
A core library to support language servers.

I write many language servers and they share some same code so I extract the
shared code to this library.

I've had enough of writing many DSLs in my editor without any LSP support
(completion, hover, ...). So I decide to sacrifice my time to do this work.
Some [Chinese blogs](https://freed-wu.github.io/tag/lsp/) about how I write
these language servers.

## Language servers

### Use tree-sitter and json schema

- [termux-language-server](https://github.com/termux/termux-language-server/):
for some specific bash scripts:
- [`build.sh`](https://github.com/termux/termux-packages/wiki/Creating-new-package)
- [`PKGBUILD`](https://wiki.archlinux.org/title/PKGBUILD)
- [`*.ebuild`](https://dev.gentoo.org/~zmedico/portage/doc/man/ebuild.5.html)
- ...
- [mutt-language-server](https://github.com/neomutt/mutt-language-server):
for [(neo)mutt](https://github.com/neomutt/neomutt)'s (neo)muttrc
- [autotools-language-server](https://github.com/Freed-Wu/autotools-language-server/):
for `Makefile`
- [requirements-language-server](https://github.com/Freed-Wu/requirements-language-server/):
for `requirements.txt`
- [zathura-language-server](https://github.com/Freed-Wu/zathura-language-server):
for [zathura](https://github.com/pwmt/zathura)'s zathurarc

### Use tree-sitter

- [requirements-language-server](https://github.com/Freed-Wu/requirements-language-server/):
for `requirements.txt`
- [autotools-language-server](https://github.com/Freed-Wu/autotools-language-server/):
for `Makefile`

### Don't use tree-sitter

- [mutt-language-server](https://github.com/neomutt/mutt-language-server):
for [(neo)mutt](https://github.com/neomutt/neomutt)'s (neo)muttrc
- [bitbake-language-server](https://github.com/Freed-Wu/bitbake-language-server):
for [bitbake](https://docs.yoctoproject.org/bitbake/index.html)
- [tmux-language-server](https://github.com/Freed-Wu/tmux-language-server):
for [tmux](https://github.com/tmux/tmux)'s `tmux.conf`
- [sublime-syntax-language-server](https://github.com/Freed-Wu/sublime-syntax-language-server):
for sublime syntax's test file `syntax_test_*`
- [expect-language-server](https://github.com/Freed-Wu/expect-language-server):
for [expect](https://wiki.tcl-lang.org/page/Expect)
- [xilinx-language-server](https://github.com/Freed-Wu/xilinx-language-server):
for xilinx's xsdb, xsct
- [translate-shell](https://github.com/Freed-Wu/translate-shell):
translate the word under the cursor

## What does this library provide

### Finders

Some finders to find the required node in tree-sitter's AST.
Such as, if you want to get the node under the cursor:

```python
@self.feature(TEXT_DOCUMENT_COMPLETION)
def completions(params: CompletionParams) -> CompletionList:
document = self.workspace.get_document(params.text_document.uri)
uni = PositionFinder(params.position, right_equal=True).find(
document.uri, self.trees[document.uri]
)
# ...
```

UNI (Universal Node Identifier) is URI + node.

### Schema

A `Trie` to convert a file to a json, then you can use json schema to validate
it to get diagnostics.

Take
[termux-language-server](https://github.com/termux/termux-language-server/) as
an example. This is a `PKGBUILD`:

```sh
pkgname=hello
pkgver=0.0.1
pkgrel=1
pkgdesc="hello"
arch=(any)
license=(GPL3)

build() {
cat <<EOF > hello
#!/usr/bin/env sh
echo hello
EOF
}

package() {
install -D hello -t $pkgdir/usr/bin
}
```

```sh
termux-language-server --convert PKGBUILD
```

```json
{
"pkgname": "hello",
"pkgver": "0.0.1",
"pkgrel": "1",
"pkgdesc": "hello",
"arch": [
"any"
],
"license": [
"GPL3"
],
"build": 0,
"package": 0
}
```

So, we can validate the json by a json schema. For termux-language-server,
these json schemas are
[here](https://github.com/termux/termux-language-server/tree/main/src/termux_language_server/assets/json).

### Utilities

This library still provide many utility functions. Such as convert man page to
markdown and tokenize it in order to generate the json schema.

which connect:
## References

- [tree-sitter](https://tree-sitter.github.io/tree-sitter/)
- [language server protocol](https://microsoft.github.io/language-server-protocol/specifications/specification-current)
Expand Down

0 comments on commit 1acb761

Please sign in to comment.