a-h / templ

A language for writing HTML user interfaces in Go.
https://templ.guide/
MIT License
8.22k stars 269 forks source link

LazyVim LSP example? #160

Closed ezynda3 closed 1 year ago

ezynda3 commented 1 year ago

I'm trying to use the builtin LSP but since it's not supported by Mason, I'm not sure how to use it with my LazyVim setup. Would it be possible to add an example for how to add this as a custom LSP using LazyVim?

evanlurvey commented 1 year ago

TL;DR; install templ with go and make sure your go bin is on your path then you can do your lsp config.

local lspconfig = require("lspconfig")
local configs = require("lspconfig.configs")
local util = require("lspconfig.util")

-- add custom templ lsp
configs .templ = {
  default_config = {
    cmd = { "templ", "lsp", },
    filetypes = { "templ" },
    root_dir = util.root_pattern("go.mod", ".git"),
    settings = {},
  }
}

-- setup same way you do with other lsp configs
-- assumes you have an on_attach and capabilities generation of some sort already. 
lspconfig["templ"].setup({ on_attach = on_attach, capabilities = capabilities })

If you have questions post your config.

zbindenren commented 1 year ago

My PR to add it to mason.nvim got accepted: https://github.com/mason-org/mason-registry/pull/2832

I plan to create a PR for the lspconfig and conform.nvim repo.

ezynda3 commented 1 year ago

TL;DR; install templ with go and make sure your go bin is on your path then you can do your lsp config.

local lspconfig = require("lspconfig")
local configs = require("lspconfig.configs")
local util = require("lspconfig.util")

-- add custom templ lsp
configs .templ = {
  default_config = {
    cmd = { "templ", "lsp", },
    filetypes = { "templ" },
    root_dir = util.root_pattern("go.mod", ".git"),
    settings = {},
  }
}

-- setup same way you do with other lsp configs
-- assumes you have an on_attach and capabilities generation of some sort already. 
lspconfig["templ"].setup({ on_attach = on_attach, capabilities = capabilities })

If you have questions post your config.

Thanks!

a-h commented 1 year ago

That's really cool.

Do the docs need updating to explain how to get the templ LSP working with Mason, or will it be automatic since @zbindenren's PR?

evanlurvey commented 1 year ago

Should be automatic with mason if you add to your install list. The custom LSP config will be required until someone makes a pr there. Then for most depending on what your config looks like it would be adding a single item to a table and the rest is all automatic.

zbindenren commented 1 year ago

That's really cool.

Do the docs need updating to explain how to get the templ LSP working with Mason, or will it be automatic since @zbindenren's PR?

When everything is done I will make a PR here to update the templ doc.

zbindenren commented 1 year ago

Let's see how it goes:

a-h commented 1 year ago

Great work, those two PRs are merged. Just a docs PR to go, I've just signed up to Hacktoberfest, so now's a great time to update the docs. 😁