Skip to content

Commit

Permalink
feat(rustc): do not require a main function + support 2024 edition (#225
Browse files Browse the repository at this point in the history
)

Co-authored-by: saying121 <saying121@example.com>
Co-authored-by: Marc Jakobi <mrcjkb89@outlook.com>
  • Loading branch information
3 people authored Feb 11, 2024
1 parent 042d333 commit 19e7a9a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
12 changes: 10 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- Rustc: Do not require a main function,
and support the 2024 edition
via `unstable-options`.

## [4.6.0] - 2024-02-07

### Added
Expand Down Expand Up @@ -93,7 +101,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
Used by default in Neovim >= 0.10.
- LSP: `:RustLsp testables` command, which is equivalent
to `:RustLsp runnables`, but filters the runnables for tests only,

> [!IMPORTANT]
>
> In Neovim < 0.10, `'background'` executor blocks the UI while running tests.
Expand All @@ -107,7 +115,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
and achieve an experience similar to Rust Playground.
(currently requires a nightly compiler).
Thanks [saying121](https://github.com/saying121)!
- Config: `tools.rustc_unpretty` arguments for `rustc`.
- Config: `tools.rustc` arguments for `rustc`.

### Changed

Expand Down
24 changes: 13 additions & 11 deletions lua/rustaceanvim/commands/rustc_unpretty.lua
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function M.rustc_unpretty(level)
local pos = { math.max(cursor[1] - 1, 0), cursor[2] }

local cline = api.nvim_get_current_line()
if not string.find(cline, 'fn%s*') then
if not string.find(cline, 'fn%s+') then
local temp = vim.fn.searchpos('fn ', 'bcn', vim.fn.line('w0'))
pos = { math.max(temp[1] - 1, 0), temp[2] }
end
Expand All @@ -129,16 +129,18 @@ function M.rustc_unpretty(level)
end
text = table.concat(b, '\n')

-- rustc need a main function for `-Z unpretty`
if not string.find(text, 'fn%s*main') then
text = text .. 'fn main() {}'
end

compat.system(
{ rustc, '--edition', config.tools.rustc.edition, '-Z', 'unpretty=' .. level, '-' },
{ stdin = text },
vim.schedule_wrap(handler)
)
compat.system({
rustc,
'--crate-type',
'lib',
'--edition',
config.tools.rustc.edition,
'-Z',
'unstable-options',
'-Z',
'unpretty=' .. level,
'-',
}, { stdin = text }, vim.schedule_wrap(handler))
end

return M

0 comments on commit 19e7a9a

Please sign in to comment.