Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: reintroduce raw-strings #117

Draft
wants to merge 32 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ba78ff2
feat: reintroduce changes
mrdgo Sep 25, 2024
c6c753c
tmp: point to current parser and scanner
mrdgo Sep 25, 2024
5ed23d2
chore: declare scanner in necessary places
mrdgo Sep 25, 2024
f57e8e5
chore: do what fdncred did
mrdgo Sep 25, 2024
1963437
ci: I don't know what I am doing
mrdgo Sep 25, 2024
1fb1416
merge
mrdgo Sep 25, 2024
3861ad1
ci: experiments
mrdgo Sep 26, 2024
94d2877
ci: remove make
mrdgo Sep 27, 2024
532d46e
ci: provide init.lua
mrdgo Sep 27, 2024
bd9a128
ci: update lazy synchronosly
mrdgo Sep 30, 2024
443b241
ci: npm update
mrdgo Sep 30, 2024
dd33553
ci: npm update, again
mrdgo Oct 2, 2024
161aeec
ci: use . for tree-sitter-nu
mrdgo Oct 2, 2024
7b7cc09
ci: still try to repro bug
mrdgo Oct 4, 2024
88d2016
ci: add latest release
mrdgo Oct 4, 2024
3999d31
ci: synchronously install ts-nu
mrdgo Oct 4, 2024
0591a27
ci: desperate experiment to repro
mrdgo Oct 4, 2024
b238630
ci: try to fix path
mrdgo Oct 10, 2024
2895807
ci: change sed delimiters to path-proof '#'
mrdgo Oct 10, 2024
aee0cb1
ci: update, not sync
mrdgo Oct 10, 2024
70909bd
ci: + -> -c
mrdgo Oct 11, 2024
73a92e8
ci: force reinstall (no prompt)
mrdgo Oct 11, 2024
43e22df
ci: sed needs input.
mrdgo Oct 11, 2024
ccd0a5b
nvim: revert path
mrdgo Oct 11, 2024
2079cb1
ci: more assertion that local parser is used
mrdgo Oct 11, 2024
2bcaf9e
ci: terminate sed's 's' command
mrdgo Oct 11, 2024
68af951
ci: maybe TSInstall is unneeded
mrdgo Oct 11, 2024
a3cef41
ci: even less interaction with plugins
mrdgo Oct 11, 2024
a474565
ci: experiment
mrdgo Oct 11, 2024
c7b8dfb
scanner: fix logic precedence
mrdgo Oct 11, 2024
da3c7b9
scanner: rename lua module
mrdgo Oct 31, 2024
bb51a54
revert: rename init.lua
mrdgo Oct 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/neovim/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
-- Bootstrap lazy.nvim
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
local lazyrepo = "https://github.com/folke/lazy.nvim.git"
local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath })
if vim.v.shell_error ~= 0 then
vim.api.nvim_echo({
{ "Failed to clone lazy.nvim:\n", "ErrorMsg" },
{ out, "WarningMsg" },
{ "\nPress any key to exit..." },
}, true, {})
vim.fn.getchar()
os.exit(1)
end
end
vim.opt.rtp:prepend(lazypath)

vim.g.mapleader = " "
vim.g.maplocalleader = "\\"

-- Setup lazy.nvim
require("lazy").setup({
spec = {
{
"nvim-treesitter/nvim-treesitter",
config = function()
require("nvim-treesitter.configs").setup({
highlight = { enable = true },
})
end,
dependencies = {
{ dir = "TS_NU_PATH", build = ":TSUpdate nu" },
},
build = ":TSUpdate",
},
},
})
8 changes: 7 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
- main
jobs:
main:
name: install
name: setup, lint, test

runs-on: ${{ matrix.os }}
strategy:
Expand All @@ -30,3 +30,9 @@ jobs:

- name: test
run: npx tree-sitter test

tests:
uses: ./.github/workflows/nvim-tests.yml
with:
neovim_versions: |
[ "nightly", "v0.10.2", "v0.10.1", "v0.9.5" ]
39 changes: 39 additions & 0 deletions .github/workflows/nvim-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Run tests

on:
workflow_call:
inputs:
neovim_versions:
required: true
type: string

jobs:
tests:
name: unit tests
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
rev: ${{ fromJson(inputs.neovim_versions) }}
steps:
- uses: actions/checkout@v3
- run: date +%F > todays-date
- name: Restore cache for Neovim
uses: actions/cache@v3
with:
path: .ci/neovim
key: ${{ matrix.rev }}-${{ hashFiles('todays-date') }}
- name: Prepare
run: |
test -d .ci/neovim || {
mkdir -p .ci/neovim
curl -sL "https://github.com/neovim/neovim/releases/download/${{ matrix.rev }}/nvim-linux64.tar.gz" | tar xzf - --strip-components=1 -C "${PWD}/.ci/neovim"
}

- name: Run tests
run: |
export PATH="${PWD}/.ci/neovim/bin:${PATH}"
export VIM="${PWD}/.ci/neovim/share/nvim/runtime"
sed "s#TS_NU_PATH#${PWD}#" .github/neovim/init.lua > .ci/init.lua
sed -i "s#https://github.com/nushell/tree-sitter-nu#${PWD}#" ${PWD}/plugin/init.lua
nvim --headless -c "sleep | q" -u .ci/init.lua ts.nu
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ path = "bindings/rust/lib.rs"
# path = "src/main.rs"

[dev-dependencies]
tree-sitter-language = "0.1.0"
cc = "1.0"

[dependencies]
tree-sitter-language = "0.1.0"
tree-sitter = "~0.20.3"

[build-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ let package = Package(
],
sources: [
"src/parser.c",
// NOTE: if your language has an external scanner, add it here.
"src/scanner.c",
],
resources: [
.copy("queries")
Expand Down
2 changes: 1 addition & 1 deletion binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"sources": [
"bindings/node/binding.cc",
"src/parser.c",
# NOTE: if your language has an external scanner, add it here.
"src/scanner.c",
],
"conditions": [
["OS!='win'", {
Expand Down
2 changes: 1 addition & 1 deletion bindings/go/binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package tree_sitter_nu

// #cgo CFLAGS: -std=c11 -fPIC
// #include "../../src/parser.c"
// // NOTE: if your language has an external scanner, add it here.
// #include "../../src/scanner.c"
import "C"

import "unsafe"
Expand Down
2 changes: 0 additions & 2 deletions bindings/rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ fn main() {
// If your language uses an external scanner written in C,
// then include this block of code:

/*
let scanner_path = src_dir.join("scanner.c");
c_config.file(&scanner_path);
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
*/

c_config.compile("parser");
println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap());
Expand Down
19 changes: 15 additions & 4 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ module.exports = grammar({

extras: ($) => [/\s/, $.comment],

// externals: $ => [
// $.long_flag_equals_value
// ],
externals: ($) => [
$.raw_string_begin,
$.raw_string_content,
$.raw_string_end,
],

conflicts: ($) => [
[$._declaration, $._declaration_last],
Expand Down Expand Up @@ -428,6 +430,7 @@ module.exports = grammar({

match_pattern: ($) =>
choice(
seq(PUNC().underscore, $.match_guard),
seq($._match_pattern, optional($.match_guard)),
seq($._match_pattern, repeat(seq(PUNC().pipe, $._match_pattern))),
),
Expand Down Expand Up @@ -1009,7 +1012,15 @@ module.exports = grammar({
),

val_string: ($) =>
choice($._str_double_quotes, $._str_single_quotes, $._str_back_ticks),
choice(
$._str_double_quotes,
$._str_single_quotes,
$._str_back_ticks,
$._raw_str,
),

_raw_str: ($) =>
seq($.raw_string_begin, $.raw_string_content, $.raw_string_end),

_str_double_quotes: ($) =>
seq(
Expand Down
4 changes: 3 additions & 1 deletion installation/neovim.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ local parser_config = require("nvim-treesitter.parsers").get_parser_configs()
parser_config.nu = {
install_info = {
url = "https://github.com/nushell/tree-sitter-nu",
files = { "src/parser.c" },
files = { "src/parser.c", "src/scanner.c" },
branch = "main",
},
filetype = "nu",
Expand Down Expand Up @@ -63,6 +63,8 @@ mkdir $local
http get ([$remote $file] | str join "/") | save --force ($local | path join $file)
```

You need to run this snippet whenever the highlights change and `:TSUpdate nu` whenever there is a new version of the parser.

[tree-sitter]: https://tree-sitter.github.io/tree-sitter/
[nvim-treesitter]: https://github.com/nvim-treesitter/nvim-treesitter
[nvim-treesitter/playground]: https://github.com/nvim-treesitter/playground
Expand Down
53 changes: 28 additions & 25 deletions package-lock.json

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

20 changes: 5 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"author": "The Nushell Contributors",
"license": "MIT",
"dependencies": {
"node-addon-api": "^8.0.0",
"node-gyp-build": "^4.8.0"
"node-addon-api": "^8.1.0",
"node-gyp-build": "^4.8.2"
},
"peerDependencies": {
"tree-sitter": "^0.21.0"
Expand All @@ -25,20 +25,10 @@
}
},
"devDependencies": {
"prettier": "3.2.5",
"tree-sitter-cli": "^0.22.5",
"prettier": "3.3.3",
"tree-sitter-cli": "^0.23.0",
"prebuildify": "^6.0.0"
},
"tree-sitter": [
{
"scope": "source.nu",
"file-types": [
"nu"
],
"highlights": "queries/nu/highlights.scm",
"injections": "queries/nu/injections.scm"
}
],
"files": [
"grammar.js",
"binding.gyp",
Expand All @@ -47,4 +37,4 @@
"queries/*",
"src/**"
]
}
}
18 changes: 10 additions & 8 deletions plugin/init.lua
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
vim.filetype.add({ extension = { nu = "nu" }, filename = { ["nurfile"] = "nu" } })

vim.api.nvim_create_autocmd("FileType", {
pattern = "nu",
callback = function(event) vim.bo[event.buf].commentstring = "# %s" end,
pattern = "nu",
callback = function(event)
vim.bo[event.buf].commentstring = "# %s"
end,
})

require("nvim-treesitter.parsers").get_parser_configs().nu = {
install_info = {
url = "https://github.com/nushell/tree-sitter-nu",
files = { "src/parser.c" },
branch = "main",
},
filetype = "nu",
install_info = {
url = "https://github.com/mrdgo/tree-sitter-nu",
files = { "src/parser.c", "src/scanner.c" },
branch = "raw-strings-pt2",
},
filetype = "nu",
}
4 changes: 4 additions & 0 deletions queries/nu/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ file_path: (val_string) @variable.parameter
(escaped_interpolated_content) @string
(expr_interpolated ["(" ")"] @variable.parameter)

(raw_string_begin) @string
(raw_string_content) @string
(raw_string_end) @string

;;; ---
;;; operators
(expr_binary [
Expand Down
Loading