Skip to content

Commit af7d608

Browse files
authored
better main + ci (#22)
add ci and possibly a release workflow
1 parent 5ac5752 commit af7d608

File tree

16 files changed

+303
-261
lines changed

16 files changed

+303
-261
lines changed

.github/workflows/build-and-test.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
on: [push]
2+
3+
name: build-and-test
4+
5+
jobs:
6+
check:
7+
name: Build and Check
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v2
11+
- uses: actions/cache@v3
12+
with:
13+
path: |
14+
~/.cargo/bin/
15+
~/.cargo/registry/index/
16+
~/.cargo/registry/cache/
17+
~/.cargo/git/db/
18+
target/
19+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
20+
21+
- name: Install Neovim
22+
shell: bash
23+
run: |
24+
wget -q https://github.com/neovim/neovim/releases/download/nightly/nvim-linux64.deb -O /tmp/nvim.deb
25+
sudo dpkg -i /tmp/nvim.deb
26+
27+
- name: Install plenary.nvim (for testing)
28+
run: |
29+
mkdir -p ~/.local/share/nvim/site/pack/vendor/start
30+
git clone --depth 1 https://github.com/nvim-lua/plenary.nvim ~/.local/share/nvim/site/pack/vendor/start/plenary.nvim
31+
32+
- name: Install latest nightly rust
33+
uses: actions-rs/toolchain@v1
34+
with:
35+
toolchain: nightly
36+
override: true
37+
components: rustfmt, clippy
38+
39+
- name: Run cargo clippy (workspace)
40+
uses: actions-rs/cargo@v1
41+
with:
42+
command: clippy
43+
args: --workspace
44+
45+
- name: Run cargo build (workspace)
46+
uses: actions-rs/cargo@v1
47+
with:
48+
command: build
49+
args: --workspace
50+
51+
- name: Run cargo test
52+
uses: actions-rs/cargo@v1
53+
with:
54+
command: test
55+
args: --workspace

.github/workflows/release.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: release-tag
2+
3+
on:
4+
push:
5+
tags:
6+
- v*
7+
8+
9+
jobs:
10+
release-image:
11+
name: Release latest version
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v2
15+
- uses: actions/cache@v3
16+
with:
17+
path: |
18+
~/.cargo/bin/
19+
~/.cargo/registry/index/
20+
~/.cargo/registry/cache/
21+
~/.cargo/git/db/
22+
target/
23+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
24+
25+
- name: Install latest nightly rust
26+
uses: actions-rs/toolchain@v1
27+
with:
28+
toolchain: nightly
29+
override: true
30+
components: rustfmt, clippy
31+
32+
- name: Run cargo build --release (workspace)
33+
uses: actions-rs/cargo@v1
34+
with:
35+
command: build
36+
args: --workspace --release
37+
38+
- uses: "marvinpinto/action-automatic-releases@latest"
39+
with:
40+
repo_token: "${{ secrets.GITHUB_TOKEN }}"
41+
automatic_release_tag: "latest"
42+
prerelease: false
43+
title: "Latest Release"
44+
files: |
45+
./target/release/vim9jit

crates/macros/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ impl VisitMut for ReplaceQuestions {
4040
#[proc_macro_attribute]
4141
pub fn parse_context(_attr: TokenStream, tokens: TokenStream) -> TokenStream {
4242
let mut input = parse_macro_input!(tokens as syn::ItemImpl);
43-
for mut item in input.items.iter_mut() {
43+
for item in input.items.iter_mut() {
4444
match &item {
4545
ImplItem::Const(_) => todo!(),
4646
ImplItem::Method(_) => {
4747
let mut replacer = ReplaceQuestions {
4848
name: *input.self_ty.clone(),
4949
};
5050

51-
replacer.visit_impl_item_mut(&mut item);
51+
replacer.visit_impl_item_mut(item);
5252
}
5353
ImplItem::Type(_) => todo!(),
5454
ImplItem::Macro(_) => todo!(),

crates/vim9-gen/build.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,8 @@ fn main() -> anyhow::Result<()> {
3434

3535
let source_lua = Path::new("src/lua");
3636
let mut entries = Vec::new();
37-
for entry in source_lua.read_dir().unwrap() {
38-
if let Ok(entry) = entry {
39-
entries.push(entry.path());
40-
}
37+
for entry in source_lua.read_dir().unwrap().flatten() {
38+
entries.push(entry.path());
4139
}
4240

4341
// always sort `init` to the top of the list
@@ -68,23 +66,19 @@ fn main() -> anyhow::Result<()> {
6866
let contents = contents.replace("require \"_vim9script\"", "vim9");
6967

7068
if name == "_" {
71-
writeln!(&mut file, "{}\n", contents)?;
69+
writeln!(&mut file, "{contents}\n")?;
7270
} else if name == "init" {
7371
// init.lua declares our base module and it's guaranteed to be first.
74-
writeln!(&mut file, "local vim9 = (function() {} end)()\n", contents)?;
72+
writeln!(&mut file, "local vim9 = (function() {contents} end)()\n")?;
7573
} else {
76-
writeln!(
77-
&mut file,
78-
"vim9['{}'] = (function() {} end)()",
79-
name, contents
80-
)?;
74+
writeln!(&mut file, "vim9['{name}'] = (function() {contents} end)()",)?;
8175
}
8276
}
8377

84-
writeln!(&mut file, "")?;
78+
writeln!(&mut file)?;
8579
writeln!(&mut file, "return vim9")?;
8680

87-
let file = format::lua(&file).expect(&format!("to format code: {}", file));
81+
let file = format::lua(&file).expect("to format the file");
8882

8983
let init_lua = luadir.join("_vim9script.lua");
9084
fs::write(init_lua, file)?;

crates/vim9-gen/src/call_expr.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,8 @@ fn expr_is_func_mutable(arg: &Expression) -> bool {
5050
}
5151
}
5252

53-
pub fn mutates(expr: &CallExpression, data: &FunctionData) -> Option<VimFuncMutability> {
54-
match data {
55-
// FunctionData::VimFunc { .. } => return None,
56-
_ => {}
57-
};
53+
pub fn mutates(expr: &CallExpression, _data: &FunctionData) -> Option<VimFuncMutability> {
54+
{};
5855

5956
// Check if any args can even be mutated
6057
// If there are none, then it doesn't matter if the function
@@ -162,7 +159,7 @@ impl VimFunc {
162159
// })
163160
// .collect::<Vec<_>>();
164161

165-
generate_mutable_fn_call(&name, &args, &replaced)
162+
generate_mutable_fn_call(name, &args, &replaced)
166163
}
167164
}
168165

@@ -230,8 +227,8 @@ impl Generate for Vec<Expression> {
230227
pub fn generate(call: &CallExpression, state: &mut State) -> String {
231228
let func_data: FunctionData = call.into();
232229

233-
match mutates(call, &func_data) {
234-
Some(mutability) => match func_data {
230+
if let Some(mutability) = mutates(call, &func_data) {
231+
match func_data {
235232
FunctionData::ApiFunc { .. } => {}
236233
FunctionData::GeneratedFunc { .. } => {}
237234
FunctionData::VimFuncRef { .. } => todo!(),
@@ -242,8 +239,7 @@ pub fn generate(call: &CallExpression, state: &mut State) -> String {
242239
// but at the same time, it's nice to just assume that functions
243240
// that are expressions are really just generated funcs
244241
FunctionData::ExprFunc { .. } => {}
245-
},
246-
None => {}
242+
}
247243
};
248244

249245
match func_data {
@@ -294,7 +290,7 @@ end
294290
}
295291

296292
fn generate_mutable_fn_call(name: &str, args: &str, replace: &str) -> String {
297-
return format!("vim9.fn_mut('{name}', {{ {args} }}, {{ replace = {replace} }})");
293+
format!("vim9.fn_mut('{name}', {{ {args} }}, {{ replace = {replace} }})")
298294
}
299295

300296
pub fn generate_method(method: &parser::MethodCall, state: &mut State) -> String {
@@ -320,7 +316,7 @@ pub fn generate_method(method: &parser::MethodCall, state: &mut State) -> String
320316
let name = func_data.name();
321317
let args = call.args.gen(state);
322318
let replace = mutability.returned.unwrap().to_string();
323-
return generate_mutable_fn_call(&name, &args, &replace);
319+
return generate_mutable_fn_call(name, &args, &replace);
324320
}
325321
}
326322
}

0 commit comments

Comments
 (0)