kickstart.nvim icon indicating copy to clipboard operation
kickstart.nvim copied to clipboard

LSP for html config

Open damccull opened this issue 9 months ago • 5 comments

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?

damccull avatar May 10 '24 00:05 damccull

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!

saysora avatar May 10 '24 06:05 saysora

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.

damccull avatar May 10 '24 06:05 damccull

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'

saysora avatar May 10 '24 07:05 saysora

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

damccull avatar May 10 '24 07:05 damccull

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

dam9000 avatar May 10 '24 08:05 dam9000

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

feoh avatar May 13 '24 16:05 feoh

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.

damccull avatar May 13 '24 16:05 damccull

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

feoh avatar May 13 '24 16:05 feoh