neovim / nvim-lspconfig

Quickstart configs for Nvim LSP
Apache License 2.0
10.7k stars 2.08k forks source link

Don`t work for .jsx and .js #2075

Closed dimameln closed 2 years ago

dimameln commented 2 years ago

Description

Tsserver doesn`t work for .jsx and .js

Neovim version

NVIM v0.8.0-dev Build type: RelWithDebInfo LuaJIT 2.1.0-beta3

Nvim-lspconfig version

No response

Operating system and version

Ubuntu 22.04.1 LTS

Affected language servers

tsserver

Steps to reproduce

lspconfig.rc.lua

Actual behavior

Only works for files .tsx .ts

Expected behavior

workd for files .jsx .js .ts. tsx

Minimal config

local nvim_lsp = pcall('lspconfig')
nvim_lsp.tsserver.setup {
  on_attach = on_attach,
  filetypes = {"typescript", "typescriptreact", "typescript.tsx", "javascript", "javascriptreact", "javascript.jsx"},
  cmd = {"typescript-language-server", "--stdio"}
}

LSP log

https://github.com/dimameln/nvim_log/blob/main/lsp.log

glepnir commented 2 years ago

pcall function return two value one is status two is nvim_lsp so it should be

local ok,nvim_lsp = pcall('lspconfig')

if not ok then
  do something stuff
end
nvim_lsp.tsserver.setup({})
dimameln commented 2 years ago

I tried your advice, but still in tsserver not working autocomplete and codehighlight for .jsx, .js, unfortunately(

dimameln commented 2 years ago

My full lspconfig.rc.lua:

local status, nvim_lsp = pcall(require, 'lspconfig') if (not status) then return end

local protocol = require('vim.lsp.protocol')

local on_attach = function(client, bufnr) --formating if client.server_capabilities.documentFormattingProvider then vim.api.nvim_command [[augroup Fromat]] vim.api.nvim_command [[autocmd! * ]] vim.api.nvim_command [[autocmd BufWritePre lua vim.lsp.buf.formatting_seq_sync()]] vim.api.nvim_command [[augroup END]] end end

nvim_lsp.tsserver.setup { on_attach = on_attach, filetypes = { "typescript", "typescriptreact", "typescript.tsx", "javascript", "javascriptreact", "javascript.jsx" }, cmd = { "typescript-language-server", "--stdio" } }

nvim_lsp.sumneko_lua.setup { on_attach = on_attach, settings = { Lua = { diagnostics = { -- Get the language server to recognize the 'vim' global globals = { 'vim' } },

  workspace = {
    --Make the server aware of NeoVim runtime files
    library = vim.api.nvim_get_runtime_file("", true)
  }
}

} }

glepnir commented 2 years ago

this is no need to config the filetypes. these filetype support by default. try the :LspInfo