simrat39 / rust-tools.nvim

Tools for better development in rust using neovim's builtin lsp
MIT License
2.17k stars 160 forks source link

edition error when running RustEmitIr or Rust EmitAsm #400

Open salimp2009 opened 1 year ago

salimp2009 commented 1 year ago

Hi I have been using rust-tool for a while and it is awesome. However some of the commands (that use rustc; e.g RustEmitIr, RustEmitAsm) gives error due to edtion issue if there is an item that is not included in edtion 2015. Is it possible to read the edition from Cargo.toml file and pass that as an argument to rustc to avoid those errors. Cargo is currently uses edition 2021 as default ; image image

salimp2009 commented 1 year ago

I believe checking edition can be done in a similar way to the example below for rustfmt as explained in null-ls wiki but use it for RustEmitIr or RustEmitAsm functions ( I believe edition can be passed as an argument to rustc )

null_ls.builtins.formatting.rustfmt.with({
    extra_args = function(params)
        local Path = require("plenary.path")
        local cargo_toml = Path:new(params.root .. "/" .. "Cargo.toml")

        if cargo_toml:exists() and cargo_toml:is_file() then
            for _, line in ipairs(cargo_toml:readlines()) do
                local edition = line:match([[^edition%s*=%s*%"(%d+)%"]])
                if edition then
                    return { "--edition=" .. edition }
                end
            end
        end
        -- default edition when we don't find `Cargo.toml` or the `edition` in it.
        return { "--edition=2021" }
    end,
})
roberte777 commented 9 months ago

Any progress on this?

salimp2009 commented 9 months ago

Any progress on this?

not that I know off. No body even responded yet :(

roberte777 commented 9 months ago

Any progress on this?

not that I know off. No body even responded yet :(

I do know that you're right about setting the edition. I'm not even sure how to pass it to the rust tools commands, though. I tried to pass it directly in the language server command, still getting the edition errors.

salimp2009 commented 9 months ago

Any progress on this?

not that I know off. No body even responded yet :(

I do know that you're right about setting the edition. I'm not even sure how to pass it to the rust tools commands, though. I tried to pass it directly in the language server command, still getting the edition errors.

I have not looked at how rust-tools implemented . it can be either hard coded or can be read from toml file as in the example how null-ls does.