gobanos/cargo-aoc

rust-analyzer macro-error everywhere

UMR1352 opened this issue · 2 comments

I can't really use rust-analyzer with cargo-aoc since every part of my code get highlighted as a problem by rust-analyzer.

  • The macro call aoc_lib! { year = 2021 } gets marked as: "failed to consume map from lib: AlreadyConsumed"
  • For each generator there's this problem: "generators must be defined before solutions" even though its the first function definition in the file
  • And each solutions has this problem: "A solution is already defined"

cargo check doesn't complain at all and I can run everything just fine with cargo aoc but rust analyzer just throws macro errors everywhere. Is there anything I can do to make rust analyzer work as usual?

As a temporary fix you can disable the diagnostics for proc macros. It's not perfect as it means you won't see macro errors from actual macro usage but it's better than nothing for now.

e.g. in Neovim LSP:

    settings = {
        ["rust-analyzer"] = {
            assist = {
                importGranularity = "module",
                importPrefix = "by_self",
            },
            cargo = {
                loadOutDirsFromCheck = true
            },
            procMacro = {
                enable = false
            },
	    diagnostics = {
		    disabled = {"macro-error", "unresolved-proc-macro"}
	    },
        }
  }

FWIW it seems the error is related to - #8 (and that was with RLS)

As a data point, this occurs only when things are changed, but once it occurs it won't be cleared until the language server is restarted. That suggests some global state pollution occuring somewhere in that process.