LazyVim:如何使 erb 格式化程序工作?

问题描述 投票:0回答:1

我希望不要那么菜鸟,但我无法让它发挥作用。我是 LazyVim 的新手,阅读文档我了解到它使用 Conform 进行格式化,然后我转到 Conform 的文档,那里有可用的 erb-formatter,我安装了这个 gem,我可以在终端中运行它。但是,如果我在缓冲区中运行

:ConformInfo
,则没有可用的格式化程序:

Log file: /home/andres/.local/state/nvim/conform.log
          additional information: leftover token
          
          15:52:50[ERROR] Formatter 'stylua' error: error: could not format from stdin: failed to format from stdin: error parsing: error occurred while creating ast: unexpected token `{`. (starting from line 4, character 2 and ending on line 4, character 3)
          additional information: leftover token
          
          16:03:00[WARN] No formatters found for /home/andres/Documentos/Proyectos/opina/app/views/sites/index.html.erb
          16:03:10[WARN] No formatters found for /home/andres/Documentos/Proyectos/opina/app/views/sites/index.html.erb
          16:09:09[ERROR] Formatter 'stylua' error: error: could not format from stdin: failed to format from stdin: error parsing: error occurred while creating ast: unexpected token `=`. (starting from line 5, character 18 and ending on line 5, character 19)
          additional information: expected '}'

Formatters for this buffer:
<none>

Other formatters:
erb_format ready (erb) /home/andres/.local/share/nvim/mason/bin/erb-format
fish_indent ready (fish) /usr/bin/fish_indent
shfmt ready (sh) /home/andres/.local/share/nvim/mason/bin/shfmt
stylua ready (lua) /home/andres/.local/share/nvim/mason/bin/stylua

现在,它出现在“其他格式化程序”中,因为我添加了一个配置文件,试图使其在给出文件格式的情况下工作:

return {
  "stevearc/conform.nvim",
  opts = {
    formatters_by_ft = {
      erb = { "erb_format" },
    },
  },
}

但是还是不行。

我也尝试使用 mason.nvim 安装它:

 Installed
    ◍ erb-formatter
    ◍ htmlbeautifier
    ◍ markdownlint
    ◍ shfmt
    ◍ stylua

有人可以帮助我了解我的设置有什么问题吗?

ruby-on-rails neovim lazyvim
1个回答
1
投票

我正在写这个问题,我注意到 :LspInfo 命令显示检测到的文件类型“eruby”,所以我再次尝试使用 eruby doctype 进行符合配置,它有效!

最后看起来像:

return {
  "stevearc/conform.nvim",
  opts = {
    formatters_by_ft = {
      eruby = { "erb_format" },
    },
  },
}
© www.soinside.com 2019 - 2024. All rights reserved.