nvim-lua / kickstart.nvim

A launch point for your personal nvim configuration
MIT License
16.77k stars 16.76k forks source link

LSP for html config #921

Closed damccull closed 1 month ago

damccull commented 1 month ago

Hello. I love Kickstart and am really trying to figure out most of this stuff through research and documentation, but I am stuck on this issue I have formatting html.

I used :Mason to install the html-lsp (turns out to be vscode-html-language-server), and when it formats my files it's using 8-space-width tabs for everything, which is highly annoying.

Where would I find the documentation to configure this? I assume it's a config in the language server itself but there is no docs I can find explaining it, and further, I'd like to configure it right there in init.lua rather than in a separate file, if possible.

How do I figure this out?

saysora commented 1 month ago

What's worked for me is adding in a .editorconfig file. Generally that helps with most of the formatting issues that aren't being applied in real-time with an LSP from Mason.

https://editorconfig.org/

Hopefully that helps!

damccull commented 1 month ago

You know, I have never heard of this, but I'm already in love with it. Though I'd still like to know if it's possible to do it in lua.

saysora commented 1 month ago

Neovim wise, you typically will just do the vim settings within your init.lua

vim.opt.tabstop = 2
vim.opt.shiftwidth = 2

Link here: https://neovim.io/doc/user/options.html#'shiftwidth'

damccull commented 1 month ago

Oh, and this should affect the formatting of the html-lsp? I must be doing it wrong then. Mine is unaffected by those.

dam9000 commented 1 month ago

I suspect you have a problem with the vim-sleuth plugin:

  'tpope/vim-sleuth', -- Detect tabstop and shiftwidth automatically

I frequently find that it does not guess the right parameters so in my config I disable this and set them manually. Try this:

diff --git a/init.lua b/init.lua
index 88658ef..17efddb 100644
--- a/init.lua
+++ b/init.lua
@@ -154,6 +154,10 @@ vim.opt.cursorline = true
 -- Minimal number of screen lines to keep above and below the cursor.
 vim.opt.scrolloff = 10

+vim.opt.expandtab = true
+vim.opt.shiftwidth = 4
+vim.opt.tabstop = 4
+
 -- [[ Basic Keymaps ]]
 --  See `:help vim.keymap.set()`

@@ -226,7 +230,7 @@ vim.opt.rtp:prepend(lazypath)
 -- NOTE: Here is where you install your plugins.
 require('lazy').setup({
   -- NOTE: Plugins can be added with a link (or for a github repo: 'owner/repo' link).
-  'tpope/vim-sleuth', -- Detect tabstop and shiftwidth automatically
+  --  'tpope/vim-sleuth', -- Detect tabstop and shiftwidth automatically

   -- NOTE: Plugins can also be added by using a table,
   -- with the first argument being the link and the following
feoh commented 1 month ago

@damccull Did @dam9000's suggested work around work for you?

damccull commented 1 month ago

Yes. A combination of the two makes my life easier. I relieved sleuth and that's what solved it. Then I added an editor config for great success.

feoh commented 1 month ago

Super glad to hear! Closing this for now. Thanks!