Formatting "*.something" after "set filetype=yaml" #769
-
I use the below autocommand to change the filetype of ´something´ to ´yaml´, which works for syntax — but not for formatting with null-ls. vim.api.nvim_create_autocmd('BufRead', 'BufNewFile', { pattern = '*.something', command = 'set filetype=yaml' })
local null_ls = require 'null-ls'
local sources = {
-- other sources
null_ls.builtins.formatting.prettier,
}
null_ls.setup { sources = sources, debug = true } Nothing happens when I try to format the Below are the only real differences in my logs (differences start at 4th line of logs):
For reference, the file I'm trying to format is %YAML 1.2
---
YAML: YAML Ain't Markup Language™
What It Is:
YAML is a human-friendly data serialization
language for all programming languages. which when formatted, looks like: %YAML 1.2
---
YAML: YAML Ain't Markup Language™
What It Is: YAML is a human-friendly data serialization
language for all programming languages. Any clues as to how I can enable this file to be formatted with my prettier source? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
This isn't a null-ls issue–if you run Prettier with the same arguments from the command line, you'll see that it errors out because it can't infer a parser given the filename (the fact that this error is suppressed is a null-ls issue). You can manually specify the parser: local null_ls = require("null-ls")
local sources = {
null_ls.builtins.formatting.prettier.with({
extra_args = function(params)
return { "--parser", params.ft }
end,
}),
}
null_ls.setup({ sources = sources, debug = true }) |
Beta Was this translation helpful? Give feedback.
This isn't a null-ls issue–if you run Prettier with the same arguments from the command line, you'll see that it errors out because it can't infer a parser given the filename (the fact that this error is suppressed is a null-ls issue). You can manually specify the parser: