Skip to content

Commit

Permalink
feat: TreeSitter support, closes #10 (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
rbozan authored Jan 18, 2022
1 parent 63c89a6 commit b683390
Show file tree
Hide file tree
Showing 23 changed files with 627 additions and 397 deletions.
18 changes: 14 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,24 @@ jobs:
matrix:
target:
[
x86_64-unknown-linux-musl,
x86_64-unknown-linux-gnu,
x86_64-apple-darwin,
x86_64-pc-windows-gnu,
]
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest

- target: x86_64-pc-windows-gnu
os: windows-2022

- target: x86_64-apple-darwin
os: macos-latest

steps:
- uses: actions/checkout@v2
with:
submodules: true
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
Expand Down Expand Up @@ -70,6 +78,8 @@ jobs:

steps:
- uses: actions/checkout@v2
with:
submodules: true
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
Expand All @@ -93,8 +103,8 @@ jobs:
# Build with fancy params via https://github.com/shepmaster/rust/blob/silicon/silicon/README.md
- if: matrix.target == 'aarch64-apple-darwin'
run: |
SDKROOT=$(xcrun -sdk macosx11.1 --show-sdk-path)
MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx11.1 --show-sdk-platform-version)
SDKROOT=$(xcrun --show-sdk-path)
MACOSX_DEPLOYMENT_TARGET=$(xcrun --show-sdk-platform-version)
- name: Build
uses: actions-rs/cargo@v1
Expand Down Expand Up @@ -130,7 +140,7 @@ jobs:
uses: hennejg/github-tag-action@v4.3.1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
tag_prefix: ''
tag_prefix: ""
release_branches: master
- name: Download artifacts
uses: actions/download-artifact@v2
Expand Down
9 changes: 9 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[submodule "tree-sitter/tree-sitter-json"]
path = tree-sitter/tree-sitter-json
url = https://github.com/tree-sitter/tree-sitter-json.git
[submodule "tree-sitter/tree-sitter-yaml"]
path = tree-sitter/tree-sitter-yaml
url = https://github.com/ikatyang/tree-sitter-yaml.git
[submodule "tree-sitter/tree-sitter-php"]
path = tree-sitter/tree-sitter-php
url = https://github.com/tree-sitter/tree-sitter-php.git
68 changes: 18 additions & 50 deletions Cargo.lock

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

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ tower-lsp = "0.14.1"
tokio = { version = "1.11.0", features = ["macros", "rt-multi-thread", "io-util", "io-std"] }
serde = "1.0.130"
serde_json = "1.0.67"
serde_yaml = "0.8.21"
serde_regex = "1.1.0"
regex = "1.5.4"
futures = "0.3.17"
Expand All @@ -22,8 +21,12 @@ lazy_static = "1.4.0"
country-emoji = "0.1.2"
lsp-document = "0.2.0"
path-clean = "0.1.0"
tree-sitter = "0.20.0"

[dev-dependencies]
tower-test = "0.4.0"
ntest = "0.7.3"
pretty_assertions = "1.0.0"

[build-dependencies]
cc="*"
61 changes: 61 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
use std::path::PathBuf;

fn main() {
build_json();
build_yaml();
build_php();
}

fn build_json() {
let json_dir: PathBuf = ["tree-sitter", "tree-sitter-json", "src"].iter().collect();

cc::Build::new()
.include(&json_dir)
.file(json_dir.join("parser.c"))
.flag_if_supported("-O")
.compile("tree-sitter-json");
}

fn build_yaml() {
let yaml_dir: PathBuf = ["tree-sitter", "tree-sitter-yaml", "src"].iter().collect();

cc::Build::new()
.include(&yaml_dir)
.flag_if_supported("-Wno-unused-parameter")
.flag_if_supported("-Wno-unused-but-set-variable")
.flag_if_supported("-Wno-trigraphs")
.flag_if_supported("-O")
.file(yaml_dir.join("parser.c"))
.compile("tree-sitter-yaml");

cc::Build::new()
.cpp(true)
.include(&yaml_dir)
.flag_if_supported("-Wno-unused-parameter")
.flag_if_supported("-Wno-unused-but-set-variable")
.flag_if_supported("-O")
.file(yaml_dir.join("scanner.cc"))
.compile("tree-sitter-yaml-scanner");
}

fn build_php() {
let php_dir: PathBuf = ["tree-sitter", "tree-sitter-php", "src"].iter().collect();

cc::Build::new()
.include(&php_dir)
.flag_if_supported("-Wno-unused-parameter")
.flag_if_supported("-Wno-unused-but-set-variable")
.flag_if_supported("-Wno-trigraphs")
.flag_if_supported("-O")
.file(php_dir.join("parser.c"))
.compile("tree-sitter-php");

cc::Build::new()
.cpp(true)
.include(&php_dir)
.flag_if_supported("-Wno-unused-parameter")
.flag_if_supported("-Wno-unused-but-set-variable")
.flag_if_supported("-O")
.file(php_dir.join("scanner.cc"))
.compile("tree-sitter-php-scanner");
}
2 changes: 1 addition & 1 deletion src/full_text_document.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use lsp_document::{TextMap, TextAdapter, Pos, IndexedText};
use lsp_document::IndexedText;
use tower_lsp::lsp_types::Url;

#[derive(Clone)]
Expand Down
Loading

0 comments on commit b683390

Please sign in to comment.