y@
y@8mo ago

Neovim setup with LSP formatting & linting

hello, I am trying to set up the fmt & linting using nvim-lspconfig with neovim Anyone know how i set it so that I format using the deno.json file? here is a link to my dotfiles
GitHub
dotfiles/environments/WyatSoule/common/nvim at master · DustinMEast...
Files used to set a system up with my preferred applications and configuration. - DustinMEastway/dotfiles
10 Replies
Deno AI Helper
Deno AI Helper8mo ago
I wasn't able to find the answer to your question in the official Deno documentation. However, based on your message, I can provide some general advice on setting up formatting with Deno in Neovim using nvim-lspconfig. To configure Neovim to format your code using the settings from a deno.json file, you would typically need to ensure that the Deno language server is properly set up in your Neovim configuration. This usually involves adding a configuration block for Deno in your init.vim or init.lua file, depending on which configuration language you are using. Here's an example of how you might set up the Deno language server in Lua:
require'lspconfig'.denols.setup {
-- Add your configuration settings here
init_options = {
lint = true,
unstable = true,
},
root_dir = require'lspconfig'.util.root_pattern("deno.json", "deno.jsonc"),
}
require'lspconfig'.denols.setup {
-- Add your configuration settings here
init_options = {
lint = true,
unstable = true,
},
root_dir = require'lspconfig'.util.root_pattern("deno.json", "deno.jsonc"),
}
This configuration tells the Deno language server to use the deno.json or deno.jsonc file in the root of your project to configure the Deno runtime. Please note that this advice is not based on the Deno documentation, and you should double-check the accuracy of this advice. Additionally, since I don't have access to external links, I cannot review your dotfiles directly. Make sure to consult the nvim-lspconfig documentation and the Deno manual for more detailed instructions on integrating Deno with Neovim's LSP.
suresh
suresh8mo ago
I find the setup easy with coc.nvim along with coc-deno extension. I Personally found it a bit challenging, so I skipped nvim-lspconfig. But if you want to try coc, here's a short reference on how to set it up ->.
GitHub
GitHub - neoclide/coc.nvim: Nodejs extension host for vim & neovim,...
Nodejs extension host for vim & neovim, load extensions like VSCode and host language servers. - neoclide/coc.nvim
GitHub
GitHub - fannheyward/coc-deno: Deno extension for coc.nvim
Deno extension for coc.nvim. Contribute to fannheyward/coc-deno development by creating an account on GitHub.
y@
y@OP7mo ago
awesome! thank you. I was able to get it with my nvim-lspconfig but it is still giving some issues so i will probably either convert over to coc, or I will check out biomejs
Chiezo
Chiezo7mo ago
GitHub
dotlua/lua/rc/lspconfig/init.lua at main · hasundue/dotlua
Chiezo's Neovim configuration. Contribute to hasundue/dotlua development by creating an account on GitHub.
rowvir
rowvir2mo ago
I'm currently going through the same process of trying to figure out why deno isn't formatting with lspconfig. What was your solution?
y@
y@OP2mo ago
I will send it to in here this afternoon. Works well now.
beerman
beerman2mo ago
Install conform then add your deno formatter to ft by file type and enable format on save
rowvir
rowvir2mo ago
I guess I need to learn the overlap between NVIM's LSP and it's ability to format (like with ESLint) and trying to minimize the number of plugins I need to have installed and configured when they do much the same thing
beerman
beerman2mo ago
What are you talking about? It appears that you don't even know how neovim works. Listen to me, do yourself a favour and start reading documentation :h lspconfig is a good start. ESLint is not a formatter - it's a linter. If you just want to quickly get up and running, add denols to your list of servers in your lspconfig, making sure that deno.enable and deno.lint are both set to true. Next, add this plugin https://github.com/stevearc/conform.nvim and include the following in its setup options:
local options = {
formatters_by_ft = {
lua = { "stylua" },
css = { "deno_fmt" },
html = { "deno_fmt" },
javascript = { "deno_fmt" },
typescript = { "deno_fmt" },
json = { "deno_fmt" },
jsonc = { "deno_fmt" },
javascriptreact = { "deno_fmt" },
typescriptreact = { "deno_fmt" },
markdown = { "deno_fmt" },
},

format_on_save = {
enabled = true,
timeout_ms = 2000,
lsp_fallback = true,
},
}
local options = {
formatters_by_ft = {
lua = { "stylua" },
css = { "deno_fmt" },
html = { "deno_fmt" },
javascript = { "deno_fmt" },
typescript = { "deno_fmt" },
json = { "deno_fmt" },
jsonc = { "deno_fmt" },
javascriptreact = { "deno_fmt" },
typescriptreact = { "deno_fmt" },
markdown = { "deno_fmt" },
},

format_on_save = {
enabled = true,
timeout_ms = 2000,
lsp_fallback = true,
},
}
Actually, I don't even think you need to include the configuration for js and ts since denols will run those for you and conform automatically handles lsp formatters if you have lsp_fallback enabled.
y@
y@OP4w ago
GitHub
GitHub - wsoule/config.nvim
Contribute to wsoule/config.nvim development by creating an account on GitHub.
GitHub
config.nvim/lua/custom/plugins/lsp.lua at main · wsoule/config.nvim
Contribute to wsoule/config.nvim development by creating an account on GitHub.
GitHub
config.nvim/lua/custom/plugins/format.lua at main · wsoule/config.n...
Contribute to wsoule/config.nvim development by creating an account on GitHub.
GitHub
config.nvim/lua/custom/plugins/lint.lua at main · wsoule/config.nvim
Contribute to wsoule/config.nvim development by creating an account on GitHub.