ayamir / nvimdots

A well configured and structured Neovim.
BSD 3-Clause "New" or "Revised" License
2.91k stars 458 forks source link

How to config language servers like `glsl-analyzer` which is not managed by `mason.nvim`? #1149

Closed Penguin-SAMA closed 8 months ago

Penguin-SAMA commented 8 months ago

Version confirmation

Following prerequisites

Neovim version

NVIM v0.9.5

Branch info

main (Default/Latest)

Minimal (user) folder structure required to reproduce the issue

user/configs/lsp-servers/glsl-analyzer.lua
user/configs/lsp-servers/glslls.lua

Minimal config with steps on how to reproduce the issue

this the config on user/configs/lsp-servers/glsl-analyzer.lua image

this the config on user/configs/lsp-servers/glslls.lua image

Expected behavior

the config file seem not to be loaded

Additional information

this is :LspInfo image

Penguin-SAMA commented 8 months ago

and when i use TSUninstall glsl

image

CharlesChiuGit commented 8 months ago

bruh, TSUninstall is for treesitter parsers. glsl-analyzer and glslls are language servers.

did u state those LS in the config or install them manually yet?

Penguin-SAMA commented 8 months ago

did u state those LS in the config or install them manually yet?

i only use :TSInstall glsl, and created the two files mentioned above. Is there anything else that needs to be stated?

CharlesChiuGit commented 8 months ago

i not familiar with glslls or glsl-analyzer, but i think :TSInstall glsl can only give u syntax highlighting, not the LS itself. check this: https://github.com/nvim-treesitter/nvim-treesitter#supported-languages https://github.com/theHamsta/tree-sitter-glsl glsl from :TSInstall glsl:

This is a extension of tree-sitter-c to support the syntax of GLSL (https://www.khronos.org/opengl/wiki/Core_Language_(GLSL)).

Since Mason doesn't have glslls and glsl-analyzer, u need to download/compile them by yourself and add them to your PATH. https://github.com/nolanderc/glsl_analyzer#installation https://github.com/svenstaro/glsl-language-server#compile

Penguin-SAMA commented 8 months ago

I found this in the README of glsl_analyzer, but I don't know how to add it to nvimdots. I don't want to modify the default init.lua

I have installed glsl-analyzer and confirmed that it is functional. Also, I added the 'glsl_analyzer' option to ['lsp_deps'] in settings.lua.

CharlesChiuGit commented 8 months ago

Since glsl_analyzer is not in mason-registry, u dont need to add it to [lsp_deps].

u also need to make a custom lspconfig entry for glsl_analuzer like this: https://github.com/ayamir/nvimdots/blob/b0513aadaba9aead3cba940237a092538d2d2a26/lua/modules/configs/completion/lsp.lua#L9-L17

Penguin-SAMA commented 8 months ago

like this?

if vim.fn.executable("glsl-analyzer") == 1 then
        local glsl_opts = {
            -- 在这里放置 glsl-analyzer 的特定配置选项
        }
        local final_glsl_opts = vim.tbl_deep_extend("keep", glsl_opts, opts)
        nvim_lsp.glsl_analyzer.setup(final_glsl_opts)
    end
CharlesChiuGit commented 8 months ago

yeap

Penguin-SAMA commented 8 months ago

But it still doesn't work, the .vert files don't have any language server functionality. image image

CharlesChiuGit commented 8 months ago

can u call glsl-analyzer from any path? or just the folder where u installed it?

or can u show us your whole config?

Penguin-SAMA commented 8 months ago

i can call glsl-analyzer any path. What configuration files do I need to send?

Penguin-SAMA commented 8 months ago

Also, I found that glsl-analyzer seems to require the vim-glsl plugin, but even after installing the vim-glsl plugin, it's not effective.

Penguin-SAMA commented 8 months ago

Oh, I think I understand now. vim-glsl is written in Vimscript, and it requires running the following statement:path

" Language: OpenGL Shading Language
" Maintainer: Sergii Tykhomyrov <sergii@tykhomyrov.net>

" Extensions supported by Khronos reference compiler (with one exception, ".glsl")
" https://github.com/KhronosGroup/glslang
autocmd! BufNewFile,BufRead *.vert,*.tesc,*.tese,*.glsl,*.geom,*.frag,*.comp,*.rgen,*.rmiss,*.rchit,*.rahit,*.rint,*.rcall set filetype=glsl

" vim:set sts=2 sw=2 :

And my user/plugins/vim-glsl.lua is as follows: image If I use :set=glsl in any file, both vim-glsl and glsl-analyzer work fine. But I don't know how to modify my vim-glsl.lua. Please help me.

ayamir commented 8 months ago
  1. Create lua/user/configs/lsp.lua:
    local nvim_lsp = require("lspconfig")
    local opts = {
    capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities()),
    }
    -- Setup lsps that are not supported by `mason.nvim` but supported by `nvim-lspconfig` here.
    if vim.fn.executable("glsl_analyzer") == 1 then
    local ok, _opts = pcall(require, "user.configs.lsp-servers.glsl_analyzer")
    if ok then
        local final_opts = vim.tbl_deep_extend("keep", _opts, opts)
        nvim_lsp.glsl_analyzer.setup(final_opts)
    end
    end
  2. Create lua/user/configs/lsp-servers/glsl_analyzer.lua
    
    return {
    default_config = {
        cmd = { "glsl_analyzer" },
        filetypes = { "glsl", "vert", "tesc", "tese", "frag", "geom", "comp" },
        single_file_support = true,
    },
    docs = {
        description = [[
    https://github.com/nolanderc/glsl_analyzer

Language server for GLSL ]], }, }

3. create file `lua/user/plugins/lang.lua`.
```lua
local lang = {}

lang["tikhomirov/vim-glsl"] = {
    lazy = true,
    ft = { "glsl", "vert", "tesc", "tese", "frag", "geom", "comp" },
}

return lang

then all be fine.

  1. Open a glsl or vert file:

image

image

CharlesChiuGit commented 8 months ago

damn @ayamir that's what i'm drafting lol.

Penguin-SAMA commented 8 months ago

This is so cool! Thank you for your help!