LuaLS / lua-language-server

A language server that offers Lua language support - programmed in Lua
https://luals.github.io
MIT License
3.39k stars 320 forks source link

PSA: update coc.nvim example in wiki (?) #242

Closed AdamWagner closed 4 years ago

AdamWagner commented 4 years ago

Hi! First, thanks a lot for maintaining this! It's very useful.

I'm posting this in the hope that it'll save someone else from spending an afternoon making (mostly random) changes to their coc-settings.json in the struggle to configure lua-language-server settings in vim using coc.nvim.

Two general rules:

Examples of what NOT to do

This does NOT work

    // coc-settings.json
    "languageserver": {
        "lua": {
            "command": "/path/to/lua-language-server/bin/macOS/lua-language-server",
            "args": ["-E", "/path/to/lua-language-server/main.lua"],
            "filetypes": ["lua"],
            "rootPatterns": [".git/"]
        }
    }

    "Lua.workspace.library":  {  // ← coc.nvim will warn:  "Property Lua.workspace.library is not allowed."
        "/path/to/hammerspoon-completion/build/stubs": true, 
        "/path/to/neovim/runtime/lua": true 
    },

This also does NOT work

    // coc-settings.json
    "languageserver": {
        "lua": {
            "command": "/path/to/lua-language-server/bin/macOS/lua-language-server",
            "args": ["-E", "/path/to/lua-language-server/main.lua"],
            "filetypes": ["lua"],
            "rootPatterns": [".git/"],
            "settings": {
                 "Lua.workspace.library":  {  // ← don't use dot-separated keys, properly nested keys are required.
                     "/path/to/hammerspoon-completion/build/stubs": true, 
                     "/path/to/neovim/runtime/lua": true 
               },
            }
        }
    }

Working example

The following works for me using:

vim version: NVIM v0.5.0-789-gca7449db4 node version: v15.0.1 coc.nvim version: 0.0.79-3e5fbe3a93 term: xterm-kitty platform: darwin

    // coc-settings.json
    "languageserver": {
        "lua": {
            "command": "/path/to/lua-language-server/bin/macOS/lua-language-server",
            "args": ["-E", "/path/to/lua-language-server/main.lua"],
            "filetypes": ["lua"],
            "rootPatterns": [".git/"],
            "settings": {
                "Lua": {
                    "workspace": {
                        "library": {
                            "/path/to/hammerspoon-completion/build/stubs": true,
                            "/path/to/neovim/runtime/lua": true
                        },
                        "maxPreload": 2000,
                        "preloadFileSize": 1000
                    },
                    "runtime": {
                        "version": "5.4.0"
                    },
                    "diagnostics": {
                        "enable": true,
                        "globals": ["hs", "vim", "it", "describe", "before_each", "after_each"],
                        "diable": ["lowercase-global"]
                    },
                    "completion": {
                        "keywordSnippet": "Disable"
                    }
                }
            }
        }
    }
sumneko commented 4 years ago

Thanks you for your advice. These are pretty good! You can update directly to the wiki yourself. I hope that wikis can be jointly maintained by the community, especially those on non Windows Platforms and non vscode environments.

One small problem: Lua.runtime.version should be Lua 5.4 instead of 5.4.0.

AdamWagner commented 4 years ago

@sumneko Thanks, I updated the wiki directly: https://github.com/sumneko/lua-language-server/wiki/Setting-without-VSCode