Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: .vscode/settings.json not over-riding clangd settings #40

Open
3 tasks done
srinathava opened this issue Aug 21, 2023 · 1 comment
Open
3 tasks done
Labels
bug Something isn't working

Comments

@srinathava
Copy link

Did you check docs and existing issues?

  • I have read all the neoconf.nvim docs
  • I have searched the existing issues of neoconf.nvim
  • I have searched the existing issues of plugins related to this issue

Neovim version (nvim -v)

0.9.1

Operating system/version

Ubuntu 20.04

Describe the bug

I'm trying to use neoconf to pick up the custom clangd settings from our company provided .vscode/settings.json file at the root of our project directory.

I see that Neoconf show does show the custom clangd settings. I see something like this:

    clangd = {
      arguments = { "--malloc-trim", "--pretty", "--pch-storage=disk", "--background-index", "--compile-commands-dir=${workspaceFolder}", "-j=8", "-log=verbose" },
      detectExtensionConflicts = true,
      onConfigChanged = "restart",
      path = "/path/to/company/provided/clangd",
      restartAfterCrash = true
    },

However Neoconf lsp just shows an empty directory:

* /path/to/root/.vscode/settings.json
```lua
vim.empty_dict()

I verified that neoconf is sourced before lspconfig by putting print statements.

Steps To Reproduce

  1. Create a directory (say /tmp/repro)

  2. Create a file /tmp/repro/init.lua with contents as shown in the minimal repro box below

  3. Create a file .vscode/settings.json with contents below:

{
  "clangd.detectExtensionConflicts": true,
  "clangd.arguments": [
    "--malloc-trim",
    "--pretty",
    "--pch-storage=disk",
    "--background-index",
    "--compile-commands-dir=${workspaceFolder}",
    "-j=8",
    "-log=verbose"
  ],
  "clangd.restartAfterCrash": true,
  "clangd.onConfigChanged": "restart",
  "clangd.path": "/tmp/repro/tools/clangd",
}
  1. You'll need to manually copy over a working clangd into the tools subdirectory.

  2. Now open neovim by doing

nvim -u init.lua foo.cpp

Expected Behavior

When the C++ file is opened, LspInfo should show the path to the clangd in the tools subdirectory. However, it will probably error out.

Repro

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
    vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
    vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath, })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
    {
        -- allows for project specific settings for clangd etc.
        -- Automatically picks up .vscode/settings.json etc.
        "folke/neoconf.nvim",
        config = function()
            require('neoconf').setup()
        end,
    },

    {
        "neovim/nvim-lspconfig", -- enable LSP
        event = { "BufReadPre", "BufNewFile" },
        dependencies = {
            "folke/neoconf.nvim", -- neoconf needs to be setup before lspconfig
        },
        config = function()
            local lspconfig = require('lspconfig')
            -- lspconfig.clangd.setup({
            --     cmd = { "/tmp/repro_neconf/proj/tools/clangd" }
            -- })
            lspconfig.clangd.setup({})
        end
    },
    -- add any other plugins here
}
require("lazy").setup(plugins, {
    root = root .. "/plugins",
})
@srinathava srinathava added the bug Something isn't working label Aug 21, 2023
@sarmong
Copy link

sarmong commented Apr 22, 2024

The problem is that for .neoconf.json the settings are specified as lspconfig[servername][key] = value, whereas in .vscode/settings.json they are in a form of [namespace][key] (not always, but most of the time).

The namespace can be the same as the server name (e.g. eslint, clangd), but not always (typescript. for tsserver).
The config options with namespaces are defined in language servers schemas (listed at the bottom of neoconf readme).

Vscode passes these these directly to settings field of the nameserver. (E.g. settings.clangd.restartAfterCrash).

If you define them in .neoconf.json, they will be passed as settings.restartAfterCrash because neoconf will treat clangd as server name and not part of the config option name.

For servers where the server name is the same as the namespace name, you can change this line in neoconf

- options.import.vscode and Settings.get_local(root_dir):get("vscode") or {},
+ options.import.vscode and Settings.get_local(root_dir):get("vscode." .. config.name) or {},

The problem arises for the stuff like tsserver. For some reason, neither tsserver, nor eslint ls want to accept settings options in a form of { settings = { eslint = { nodePath = "foo" } } }, even though this is what schema says.

@folke , do you know why this is happening? Apparently, the same servers accept it in vscode, but not in neovim via lspconfig. I am not sure where the problem lies exactly. I thought it was neoconf, but it may be lspconfig or neovim, or the servers themselves.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants