LSP: tsserver won't start for bare Javascript files

Context: I want to open throw-away files, usually I create them under /tmp but can be any other directory. I want to have tsserver and eslint (maybe others later) LSP servers attached to that buffer.

Current behaviour: LSP doesn’t start if I open a file under a folder that doesn’t have any matching root pattern (package.json, .git, tsconfig.json, jsconfig.json).

Even forcing a start once the file is opened with :LspStart tsserver doesn’t work.

Desired behaviour: I’d like to have tsserver attached based on filetype.

What have I tried:

  1. mkdir /tmp/test && nvim /tmp/test/thingy.js → NO Language Server bound
  2. with that file opened tried :LspStart → NO Language Server bound
  3. touch /tmp/test/package.json & nvim /tmp/test/thingy.jstsserver bound, eslint not bound
  4. created ~/.config/nvim/after/ftplugin/javascript.lua an inside I put:

→ NO Language Server bound

  1. tried with a different command, but same approach:

But still NO Language Server bound

So I read the suggested :h lspconfig-root-detection help, which lead me to :h lspconfig-all help, but that’s a dead end, because I cannot access the tsserver help, it seems it’s not properly linked or maybe there’s nothing to link.

I want to have the proper language server bound to my buffer, regardless if it doesn’t belong to any project. What should I change in order to achieve that?

Feel free to check my Neovim configuration if it helps to answer this. I haven’t committed the after ftplugin yet.

Add this to your tsserver configuraion
single_file_support = true

Thank you @sarmong , I also tried that setting for eslint server, and it worked. Now I’m wondering if I should leave it for any language server instead of conditional:

mason_lspconfig.setup_handlers {
    require('lspconfig')[server_name].setup {
      capabilities = capabilities,
      on_attach = on_attach,
      settings = servers[server_name],
      -- should I set it up for any LS?
      single_file_support = server_name == 'tsserver' or server_name == 'eslint',