Giter VIP home page Giter VIP logo

nlsp-settings.nvim's Introduction

nlsp-settings.nvim

A plugin to configure Neovim LSP using json files like coc-settings.json.

sumneko_lua_completion.gif

Using nlsp-settings.nvim and lspconfig and jsonls and nvim-compe and vim-vsnip

Using nlsp-settings.nvim, you can write some of the settings to be passed to lspconfig.xxx.setup() in a json file. You can also use it with jsonls to complete the configuration values.

Requirements

Installation

Plug 'neovim/nvim-lspconfig'
Plug 'tamago324/nlsp-settings.nvim'

Usage

Step1. Configure jsonls.

jsonls allows for configuration value completion.

require"lspconfig".jsonls.setup {
  cmd = { '/path/to/json-languageserver', '--stdio' },

  -- Set the schema so that it can be completed in settings json file.
  -- The schemas defined in `jsonls.json` will be merged with the list configured here.
  settings = {
    json = {
      schemas = require'nlspsettings.jsonls'.get_default_schemas()
    }
  }
}

Step2. Write settings.

For a list of language servers that have JSON Schema, see here.

Example) Settings the sumneko_lua settings:

:NlspConfig sumneko_lua

Create a settings file in ~/.config/nvim/nlsp-settings/sumneko_lua.json.

{
  "Lua.runtime.version": "LuaJIT",
  "Lua.diagnostics.enable": true,
  "Lua.diagnostics.globals": [
    "vim", "describe", "it", "before_each", "after_each"
  ],
  "Lua.diagnostics.disable": [
    "unused-local", "unused-vararg", "lowercase-global", "undefined-field"
  ],
  "Lua.completion.callSnippet": "Both",
  "Lua.completion.keywordSnippet": "Both"
}

NOTE: The path where settings json file is stored can be changed by the config_home argument of nlspsettings.setup().

require'nlspsettings'.setup {
  config_home = vim.fn.stdpath('config') .. '/lspsettings'
}

Step 3. Load settings.

By calling nlspsettings.setup(), you can use on_new_config to automatically load JSON files on all language servers.

-- You need to call lspconfig.*.setup().
require'nlspsettings'.setup()

It is still possible to write settings in lua. However, if you have the same key, the value in the JSON file will take precedence.

Example) Write sumneko_lua settings in Lua

lspconfig.sumneko_lua.setup{
  cmd = { '/path/to/bin/Linux/lua-language-server', '-E', '/path/to/main.lua', },

  -- You can also specify a value in settings, but if it is the same key,
  -- it will be overwritten by the value in the JSON file.
  settings = {
    Lua = {
      workspace = {
        library = {
          [vim.fn.expand("$VIMRUNTIME/lua")] = true,
          [vim.fn.stdpath("config") .. '/lua'] = true,
        }
      }
    }
  }
}

Contributing

  • If your language server lacks support, please feel free to make a pull request or issue.
  • All contributions are welcome.

License

MIT

nlsp-settings.nvim's People

Contributors

tamago324 avatar yaegassy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

yididiel7

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.