sveltejs / language-tools

The Svelte Language Server, and official extensions which use it
MIT License
1.23k stars 196 forks source link

bug(nvim/svelte-language-server): root dir not found on folder with square brackets #2530

Closed vipexv closed 1 week ago

vipexv commented 1 week ago

Describe the bug

So i'm using neovim development build due to the fact that it allows me to use Netrw to access directories that have brackets around them, so everything works fine, in React/Lua and every other language server, but in svelte it just throws an error saying not found, more info will be found below.

Reproduction

Try to access a directory that's wrapped with square brackets, and the Lsp doesn't start up.

Expected behaviour

The Lsp is expected to start and work normally.

System Info

Which package is the issue about?

svelte-language-server

Additional Information, eg. Screenshots

==============================================================================

lspconfig:                                 require("lspconfig.health").check()

LSP configs active in this session (globally) ~
- Configured servers: svelte, tailwindcss, lua_ls, ts_ls
- OK Deprecated servers: (none)

LSP configs active in this buffer (id=13) ~
- Language client log: ~\AppData\Local\nvim-data\lsp.log
- Detected filetype: `svelte`
- 1 client(s) attached to this buffer
- Client: tailwindcss (id: 1, bufnr: [13])
  filetypes:       aspnetcorerazor, astro, astro-markdown, blade, clojure, django-html, htmldjango, edge, eelixir, elixir, ejs, erb, eruby, gohtml, gohtmltmpl, haml, handlebars, hbs, html, htmlangular, html-eex, heex, jade, leaf, liquid, markdown, mdx, mustache, njk, nunjucks, php, razor, slim, twig, css, less, postcss, sass, scss, stylus, sugarss, javascript, javascriptreact, reason, rescript, typescript, typescriptreact, vue, svelte, templ
  root directory:  Running in single file mode.
  cmd:             ~\AppData\Local\nvim-data\mason\bin\tailwindcss-language-server.CMD --stdio
  autostart:       true
- Other clients that match the "svelte" filetype: 
- Config: svelte
  filetypes:         svelte
  root directory:    ~\Desktop\test-server-ox\data\resources\[cfx]\[gameplay]\new_chat\Not found.
  cmd:               ~\AppData\Local\nvim-data\mason\bin\svelteserver.CMD --stdio
  cmd is executable: true
  autostart:         true
  custom handlers:   
jasonlyu123 commented 1 week ago

I don't think this is an issue on our side. It might be a problem with how nvim-lspconfig searches for the root directory.

If I set the command config for svelte lsp to a non-existent path. The "not found" problem still exists even though the server is not even running.

lspconfig.svelte.setup {
    cmd = { "node", "--inspect", "/path/to/language-tools/packages/language-server/bin/server.js", "--stdio" },
    capabilities = lsp_capabilities,
}

And if I change the directory from [cfx] to [cfx. Neovim now shows an error with the "wrong config" because the language server failed to start. And it works if I remove the wrong config.

vipexv commented 1 week ago

Generally speaking i'm really new to Neovim still and have no idea how allot of customization works, this is my LSP Config tho, i'm really unsure as to what the issue might be because i don't really remember specifically configuring the svelte LSP, and i installed it through Mason.

You can also find my whole Neovim config here

local telescopeBuiltIn = require("telescope.builtin")

vim.api.nvim_create_autocmd("LspAttach", {
    group = vim.api.nvim_create_augroup("user_lsp_attach", { clear = true }),
    callback = function(event)
        local opts = { buffer = event.buf }

        vim.keymap.set("n", "gd", function()
            telescopeBuiltIn.lsp_definitions()
        end, opts)
        vim.keymap.set("n", "K", function()
            vim.lsp.buf.hover()
        end, opts)
        vim.keymap.set("n", "<leader>vws", function()
            vim.lsp.buf.workspace_symbol()
        end, opts)
        vim.keymap.set("n", "<leader>vd", function()
            vim.diagnostic.open_float()
        end, opts)
        vim.keymap.set("n", "[d", function()
            vim.diagnostic.goto_next()
        end, opts)
        vim.keymap.set("n", "]d", function()
            vim.diagnostic.goto_prev()
        end, opts)
        vim.keymap.set("n", "<leader>vca", function()
            vim.lsp.buf.code_action()
        end, opts)
        vim.keymap.set("n", "<leader>fr", function()
            telescopeBuiltIn.lsp_references()
        end, opts)
        vim.keymap.set("n", "<leader>vrn", function()
            vim.lsp.buf.rename()
        end, opts)
        vim.keymap.set("i", "<C-h>", function()
            vim.lsp.buf.signature_help()
        end, opts)
        vim.keymap.set("n", "<leader>ve", function()
            vim.diagnostic.setloclist()
        end, opts)
    end,
})

local lsp_capabilities = require("cmp_nvim_lsp").default_capabilities()

require("mason").setup({})
require("mason-lspconfig").setup({
    ensure_installed = { "ts_ls" },
    handlers = {
        function(server_name)
            require("lspconfig")[server_name].setup({
                capabilities = lsp_capabilities,
            })
        end,
        lua_ls = function()
            require("lspconfig").lua_ls.setup({
                capabilities = lsp_capabilities,
                settings = {
                    Lua = {
                        runtime = {
                            version = "LuaJIT",
                        },
                        diagnostics = {
                            globals = { "vim" },
                        },
                        workspace = {
                            library = {
                                vim.env.VIMRUNTIME,
                                [vim.fn.expand(vim.fn.stdpath("config") .. "/fivem-library/")] = true,
                            },
                        },
                    },
                },
                { "hrsh7th/cmp-buffer" },
            })
        end,
    },
})

local cmp = require("cmp")
local cmp_select = { behavior = cmp.SelectBehavior.Select }

cmp.setup({
    sources = cmp.config.sources({
        { name = "nvim_lsp" },
        { name = "luasnip" },
    }, {
        { name = "buffer" },
    }),
    mapping = cmp.mapping.preset.insert({
        ["<C-n>"] = cmp.mapping.confirm({ select = true }),
        ["<C-y>"] = cmp.mapping.complete(),
    }),
    snippet = {
        expand = function(args)
            require("luasnip").lsp_expand(args.body)
        end,
    },
})
jasonlyu123 commented 1 week ago

From my understanding, neovim/vim doesn't open a directory like most text editor/IDE. However, root directories are required for a language server. So the root directory search is a way to emulate opening a directory. nvim-lspconfig maintains a list of default configs for different language servers depending on the different project structures. The problem is likely how they turn the file path into a regex or glob pattern. You can try opening an issue on nvim-lspconfig

vipexv commented 1 week ago

Weird, i'll see what i can do, because generally any other files/lsps work perfectly fine, confusing bug, could also be neovim honestly, thank you tho!