nix-community / nixvim

Configure Neovim with Nix! [maintainer=@GaetanLepage, @traxys, @mattsturgeon, @khaneliman]
https://nix-community.github.io/nixvim
MIT License
1.59k stars 251 forks source link

[BUG] `templ` files handled as plaintext files when templ LSP is enabled #1971

Open JeroenoBoy opened 1 month ago

JeroenoBoy commented 1 month ago
Field Description
Plugin 'LSP'
Nixpkgs 24.05
Home Manager not used

Description

When enabling the templ LSP in the nix config, switching, opening a .templ file, it only shows white text, I'm not sure why this happens since everything else just works after enabling the LSP

Minimal, Reproducible Example (MRE)

Enable the Templ LSP server, then open a .templ file in a go project with templ installed

# see https://github.com/JeroenoBoy/Nix-framework/blob/main/modules/nvim for full nixvim config
programs.nixvim.plugins = {
  treesitter.enable = true;  

  lsp-format.enable = true;
  lsp = {
    enable = true;
    html.enable = true;
    htmx.enable = true;
    templ.enable = true;
    tailwindcss.enable = true;

    go.enable = true;
  };
}
MattSturgeon commented 1 month ago

I'm not familiar with this LS, but have you referenced their docs?

Syntax highlighting is usually a joint effort between treesitter and the LSP, however it's usually treesitter doing the heavy lifting; so this may not be an issue at all with your LSP config.

JeroenoBoy commented 1 month ago

The issue isn't that there is no syntax highlighting, it seems like nvim handles it as a normal text file even though templ is enabled. No completions, no errors, nothing

MattSturgeon commented 1 month ago

Does the filetype in the status line show as "plain text" then?

It's possible you need to manually configure the filetype for neovim to recognise it.

I'd check if the LS's docs talk about doing that. I'd also reference neovim's filetype docs and our docs for the filetype option.

JeroenoBoy commented 1 month ago

Thank you for the help!

It seems like adding these 2 lines did the trick. Is it possible to add these by default when enabling templ to avoid future confusion?

filetype.extension.templ = "templ";
plugins.lsp.servers.templ.filetypes = ["templ"];
MattSturgeon commented 1 month ago

Unlike home-manager and nixos, we try not to configure things by default. Instead we follow the principle that only what is explicitly configured will end up in init.lua.

Ideally, the upstream plugins would resolve these issues, not nixvim.

Googling around, it seems tj has an example config/plugin for templ here: https://github.com/tjdevries/templ.nvim/blob/master/plugin/templ.lua

@traxys what're your thoughts? Can we add warnings/docs for this? Or maybe should we consider having an option to configure some of this automatically?

Or is there a plugin we could package that sets up a basic stuff like the filetype? If we had a plugins.templ then we could recommend using that when using this LSP.

GaetanLepage commented 1 month ago

@traxys what're your thoughts? Can we add warnings/docs for this? Or maybe should we consider having an option to configure some of this automatically?

Do we have a hook to add some general info about a LS in the documentation ? I don't think to... I was thinking of something like meta.description for plugins.

MattSturgeon commented 1 month ago

I was thinking of something like meta.description for plugins.

This may work. We refactored how the docs handles meta a while back to allow setting a URL for language-servers: https://github.com/nix-community/nixvim/pull/1646

If it doesn't work, the change needed in the docs should be trivial.

traxys commented 1 month ago

I think this should indeed belong to documentation of the LSP (in nixvim)