Giter Club home page Giter Club logo

Comments (6)

VonHeikemen avatar VonHeikemen commented on May 25, 2024

The way you add options to a language server is by using .configure() function.

local lsp = require('lsp-zero')
lsp.preset('recommended')

lsp.configure('ansiblels', {
  settings = {
    ansible = {
      ansibleLint = {
        arguments = "-x risky-shell-pipe,package-latest,meta-no-info,role-name,yaml[line-length],no-changed-when,fqcn-builtins,name[casing]",
      },
    },
  },
})

lsp.setup()

If you have ansiblels installed globally in your system, add force_setup = true in configure.

lsp.configure('ansiblels', {
  force_setup = true,
  settings = {
    --- your settings....
  },
})

from lsp-zero.nvim.

d-vb avatar d-vb commented on May 25, 2024

That's strange, that's exactly what I tried earlier, however it then ignores the config of ansiblels.

  use({
    "VonHeikemen/lsp-zero.nvim",
    requires = {
      -- lsp
      { "neovim/nvim-lspconfig" },
      { "williamboman/mason.nvim" },
      { "williamboman/mason-lspconfig.nvim" },

      -- autocomplete
      { "hrsh7th/nvim-cmp" },
      { "hrsh7th/cmp-buffer" },
      { "hrsh7th/cmp-path" },
      { "saadparwaiz1/cmp_luasnip" },
      { "hrsh7th/cmp-nvim-lsp" },
      { "hrsh7th/cmp-nvim-lua" },

      -- snippets
      { "L3MON4D3/LuaSnip" },
      { "rafamadriz/friendly-snippets" },
    },
    config = function()
      local lsp = require("lsp-zero")
      lsp.preset("recommended")
      lsp.configure("ansiblels", {
        settings = {
          ansible = {
            ansibleLint = {
              arguments = "-x risky-shell-pipe,package-latest,meta-no-info,role-name,yaml[line-length],no-changed-when,fqcn-builtins,name[casing]",
            },
          },
        },
      })
      lsp.setup()
    end,
  })

I have installed ansiblels via mason and ansible-lint globally in my system. I have tried with and without force_setup = true.

from lsp-zero.nvim.

VonHeikemen avatar VonHeikemen commented on May 25, 2024

Does the command :LspInfo shows the language server is attached to the buffer?

Edit:
You can use the id of the language server to inspect the settings. Use this command.

:lua = vim.lsp.get_client_by_id(<lsp-server-id>).config.settings

from lsp-zero.nvim.

d-vb avatar d-vb commented on May 25, 2024

With lsp-zero config:

    config = function()
      local lsp = require("lsp-zero")
      lsp.preset("recommended")
      lsp.configure("ansiblels", {
        settings = {
          ansible = {
            ansibleLint = {
              arguments = "-x risky-shell-pipe,package-latest,meta-no-info,role-name,yaml[line-length],no-changed-when,fqcn-builtins,name[casing]",
            },
          },
        },
      })
      lsp.setup()
    end,

:LspInfo

 Use [q] or [Esc] to quit the window
 
 Language client log: /home/dvb/.cache/nvim/lsp.log
 Detected filetype:   yaml.ansible
 
 2 client(s) attached to this buffer: 
 
 Client: ansiblels (id: 1, pid: 40857, bufnr: [1, 3])
 	filetypes:       yaml.ansible
 	autostart:       true
 	root directory:  /home/dvb/git/infrastructure/ansible
 	cmd:             ansible-language-server --stdio
 
 Client: null-ls (id: 2, pid: 5001, bufnr: [1, 3])
 	filetypes:       lua, typescript, javascriptreact, typescriptreact, javascript, vue
 	autostart:       false
 	root directory:  /home/dvb/git/infrastructure
 	cmd:             nvim
 
 Configured servers list: sumneko_lua, dockerls, eslint, clangd, rust_analyzer, cmake, jsonls, ansiblels, pyright, html, marksman, gopls, sqlls, tsserver, bashls, asm_lsp

:lua = vim.lsp.get_client_by_id(1).config.settings

{
  ansible = {
    ansible = {
      path = "ansible"
    },
    ansibleLint = {
      enabled = true,
      path = "ansible-lint"
    },
    executionEnvironment = {
      enabled = false
    },
    python = {
      interpreterPath = "python"
    }
  }
}

With lspconfig config:

    config = function()
      require("lspconfig").ansiblels.setup({
        settings = {
          ansible = {
            ansibleLint = {
              arguments = "-x risky-shell-pipe,package-latest,meta-no-info,role-name,yaml[line-length],no-changed-when,fqcn-builtins,name[casing]",
            },
          },
        },
      })

    end,

:LspInfo

 Use [q] or [Esc] to quit the window
 
 Language client log: /home/dvb/.cache/nvim/lsp.log
 Detected filetype:   yaml.ansible
 
 2 client(s) attached to this buffer: 
 
 Client: ansiblels (id: 1, pid: 42737, bufnr: [1])
 	filetypes:       yaml.ansible
 	autostart:       true
 	root directory:  /home/dvb/git/infrastructure/ansible
 	cmd:             ansible-language-server --stdio
 
 Client: null-ls (id: 2, pid: 5001, bufnr: [1])
 	filetypes:       lua, vue, javascript, typescriptreact, javascriptreact, typescript
 	autostart:       false
 	root directory:  /home/dvb/git/infrastructure
 	cmd:             nvim
 
 Configured servers list: sumneko_lua, ansiblels, cmake, html, sqlls, pyright, gopls, eslint, marksman, asm_lsp, bashls, clangd, tsserver, dockerls, jsonls, rust_analyzer

:lua = vim.lsp.get_client_by_id(1).config.settings

{
  ansible = {
    ansible = {
      path = "ansible"
    },
    ansibleLint = {
      arguments = "-x risky-shell-pipe,package-latest,meta-no-info,role-name,yaml[line-length],no-changed-when,fqcn-builtins,name[casing]",
      enabled = true,
      path = "ansible-lint"
    },
    executionEnvironment = {
      enabled = false
    },
    python = {
      interpreterPath = "python"
    }
  }
}

from lsp-zero.nvim.

VonHeikemen avatar VonHeikemen commented on May 25, 2024

I tested in a docker container with a minimal config, everything seems fine.

There is something else going on in your config. I'm actually surprised lspconfig works on its own without calling mason.nvim, it should raise an error.

Anyway, if lspconfig works, you should be able to use it like this.

local lsp = require('lsp-zero')
lsp.preset('recommended')

local ansible_opts = lsp.build_options('ansiblels', {
  settings = {
    ansible = {
      ansibleLint = {
        arguments = "-x risky-shell-pipe,package-latest,meta-no-info,role-name,yaml[line-length],no-changed-when,fqcn-builtins,name[casing]",
      },
    },
  },
})

require('lspconfig').ansiblels.setup(ansible_opts)

lsp.setup()

from lsp-zero.nvim.

d-vb avatar d-vb commented on May 25, 2024

Thank you so much! This finally works. ❤️

from lsp-zero.nvim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.