How to enable tsserver in `.html` file?

As title. I’m asking this because I just found that I cannot complete this document.querySelector when it is embedded in the <script> tag of the .html file.

I have tried modifying the settings.filetypes of tsserver.setup, but it doesn’t work.

Don’t think tsserver would work on html files. You’ll have to use a html language server like the one provided here: https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#html

[…] You’ll have to use a html language server like […]

I have tried this lsp, but it will NOT show querySelector…

Don’t think tsserver would work on html files. […]

But it did. I loaded two lsp and it works correctly with some tuning about the diagnostics.

Yup, unfortunately it won’t show that because the html lsp server does not have support for completion. I’ve checked the lsp server and looks like I do get some syntax diagnostics within the <script> tags but I guess that’s not what you want.

It’s true you could set a different filetype for tsserver to bind to a html file, but again it will think the file is a js/ts file because that’s what tsserver is made for and not html files.

Honestly, it’s best to just write your js code separately (where tsserver will work) and just include the file with <script src="...">, if code diagnostics and completions are important for your purpose.

I would like to do the same without being forced into an external file. I’d normally use an external file but for demos and small tests it would be really nice to have completion inside the tags.

Looking into WIP: HTML support by KostkaBrukowa · Pull Request #43 · pmizio/typescript-tools.nvim · GitHub and GitHub - jmbuhr/otter.nvim: Just ask an otter! 🦦