|
47 | 47 | mkdir -p $out/lib |
48 | 48 | cp target/${buildTarget}/release/*.wasm $out/lib/ |
49 | 49 | ''; |
50 | | - # Disable checks if they only work for WASM |
51 | | - # doCheck = false; |
| 50 | + }; |
| 51 | + mkRustellNvim = exe: |
| 52 | + pkgs.vimUtils.buildVimPlugin { |
| 53 | + name = "rustell-nvim"; |
| 54 | + src = pkgs.writeTextDir "plugin/rustell.vim" '' |
| 55 | + augroup rust.vim.PreWrite |
| 56 | + autocmd! |
| 57 | + augroup END |
| 58 | +
|
| 59 | + augroup rustell_PreWrite |
| 60 | + autocmd! |
| 61 | + autocmd BufWritePre *.rs call s:RustellPreWrite() |
| 62 | + augroup END |
| 63 | +
|
| 64 | + function! s:RustellPreWrite() |
| 65 | + if !filereadable(expand('%')) |
| 66 | + return |
| 67 | + endif |
| 68 | +
|
| 69 | + " Read buffer |
| 70 | + let l:input = join(getline(1, '$'), "\n") |
| 71 | +
|
| 72 | + " --- run rustell first --- |
| 73 | + let l:rustell_out = system('${exe}', l:input) |
| 74 | + if v:shell_error |
| 75 | + echohl ErrorMsg | echom 'rustell failed: ' . l:rustell_out | echohl None |
| 76 | + return |
| 77 | + endif |
| 78 | +
|
| 79 | + " --- now feed result into rustfmt --- |
| 80 | + let l:rustfmt_cmd = 'rustfmt' |
| 81 | + if exists('g:rustfmt_command') |
| 82 | + let l:rustfmt_cmd = g:rustfmt_command |
| 83 | + endif |
| 84 | + if exists('g:rustfmt_options') |
| 85 | + let l:rustfmt_cmd .= ' ' . g:rustfmt_options |
| 86 | + endif |
| 87 | +
|
| 88 | + let l:rustfmt_out = system(l:rustfmt_cmd, l:rustell_out) |
| 89 | + if v:shell_error |
| 90 | + echohl ErrorMsg | echom 'rustfmt failed: ' . l:rustfmt_out | echohl None |
| 91 | + return |
| 92 | + endif |
| 93 | +
|
| 94 | + " Replace buffer with formatted output |
| 95 | + let l:out_lines = split(l:rustfmt_out, "\n") |
| 96 | + call setline(1, l:out_lines) |
| 97 | + if line('$') > len(l:out_lines) |
| 98 | + execute len(l:out_lines)+1 . ',$delete _' |
| 99 | + endif |
| 100 | + endfunction |
| 101 | + ''; |
52 | 102 | }; |
53 | 103 | in { |
54 | 104 | devShells.default = pkgs.mkShell { |
|
64 | 114 | wasmtime |
65 | 115 | ]; |
66 | 116 | }; |
67 | | - packages = { |
| 117 | + packages = rec { |
68 | 118 | rustell = mkRustPkg "rustell"; |
| 119 | + rustell-nvim = mkRustellNvim "${rustell}/bin/rustell"; |
69 | 120 | rustell-wasm = mkRustPkgWasm "rustell"; |
| 121 | + rustell-wasm-nvim = mkRustellNvim "${ |
| 122 | + pkgs.wasmtime |
| 123 | + }/bin/wasmtime ${rustell-wasm}/bin/rustell.wasm"; |
70 | 124 | default = self.packages.${system}.rustell; |
71 | 125 | }; |
72 | 126 | } |
|
0 commit comments