GithubHelp home page GithubHelp logo

blz777 / nlsp-settings.nvim Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tamago324/nlsp-settings.nvim

0.0 0.0 0.0 856 KB

A plugin for setting Neovim LSP with JSON or YAML files

License: MIT License

Shell 0.31% Lua 97.89% Makefile 0.19% Vim Script 1.61%

nlsp-settings.nvim's Introduction

nlsp-settings.nvim

gen_schemas

A plugin to configure Neovim LSP using json/yaml 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'

" Recommend
Plug 'williamboman/nvim-lsp-installer'

" Optional
Plug 'rcarriga/nvim-notify'

Getting Started

Step1. Install jsonls with nvim-lsp-installer

:LspInstall jsonls

Step2. Setup LSP servers

Example: Completion using omnifunc

local lsp_installer = require('nvim-lsp-installer')
local lspconfig = require("lspconfig")
local nlspsettings = require("nlspsettings")

nlspsettings.setup({
  config_home = vim.fn.stdpath('config') .. '/nlsp-settings',
  local_settings_dir = ".nlsp-settings",
  local_settings_root_markers_fallback = { '.git' },
  append_default_schemas = true,
  loader = 'json'
})

function on_attach(client, bufnr)
  local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
  buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
end

local global_capabilities = vim.lsp.protocol.make_client_capabilities()
global_capabilities.textDocument.completion.completionItem.snippetSupport = true

lspconfig.util.default_config = vim.tbl_extend("force", lspconfig.util.default_config, {
  capabilities = global_capabilities,
})

lsp_installer.on_server_ready(function(server)
  server:setup({
    on_attach = on_attach
  })
end)

TODO: その他の設定は doc を参照

Step3. Write settings

Execute :LspSettings sumneko_lua.
sumneko_lua.json will be created under the directory set in config_home. Type <C-x><C-o>. You should now have jsonls completion enabled.

Usage

LspSettings command

  • :LspSettings [server_name]: Open the global settings file for the specified {server_name}.
  • :LspSettings buffer: Open the global settings file that matches the current buffer.
  • :LspSettings local [server_name]: Open the local settings file of the specified {server_name} corresponding to the cwd.
  • :LspSettings local buffer or LspSettings buffer local: Open the local settings file of the server corresponding to the current buffer.
  • :LspSettings update [server_name]: Update the setting values for the specified {server_name}.

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

Settings files for each project

You can create a settings file for each project with the following command.

  • :LspSettings local [server_name].
  • :LspSettings update [server_name]

The settings file will be created in {project_path}/.nlsp-settings/{server_name}.json.

Combine with Lua configuration

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

local server_opts = {}

-- lua
server_opts.sumneko_lua = {
  settings = {
    Lua = {
      workspace = {
        library = {
          [vim.fn.expand("$VIMRUNTIME/lua")] = true,
          [vim.fn.stdpath("config") .. '/lua'] = true,
        }
      }
    }
  }
}

local common_setup_opts = {
  -- on_attach = on_attach,
  -- capabilities = require('cmp_nvim_lsp').update_capabilities(
  --   vim.lsp.protocol.make_client_capabilities()
  -- )
}

lsp_installer.on_server_ready(function(server)
  local opts = vim.deepcopy(common_setup_opts)
  if server_opts[server.name] then
      opts = vim.tbl_deep_extend('force', opts, server_opts[server.name])
  end
  server:setup(opts)
end)

Contributing

  • All contributions are welcome.

License

MIT

nlsp-settings.nvim's People

Contributors

blz777 avatar kylo252 avatar lopi-py avatar nymphium avatar shurizzle avatar tamago324 avatar yaegassy avatar yutkat avatar

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.