• Stars
    star
    316
  • Rank 131,823 (Top 3 %)
  • Language
    Lua
  • License
    MIT License
  • Created over 3 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A plugin for setting Neovim LSP with JSON or YAML files

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

More Repositories

1

lir.nvim

Neovim file explorer
Lua
349
star
2

cmp-zsh

nvim-cmp source for zsh
Shell
68
star
3

LeaderF-filer

๐Ÿ“‚ LeaderF file explorer
Python
39
star
4

nowt36

30
star
5

nowt36lp

25
star
6

compe-zsh

zsh completion source for nvim-compe
Shell
21
star
7

lir-git-status.nvim

Git status integration of lir.nvim
Lua
15
star
8

telescope-sonictemplate.nvim

sonictemplate-vim integration
Lua
14
star
9

vimfiles

My vimfiles
Lua
12
star
10

tiknot.nvim

A disposable floating window.
Lua
12
star
11

vim-gaming-line

๐ŸŒˆ Vim Plugin for Gamers!
Vim Script
11
star
12

vim-browsersync

This plugin uses browser-sync from Vim.
Vim Script
10
star
13

lsp-preview-hover-doc.nvim

textDocument/hover plugin
Lua
9
star
14

telescope-openbrowser.nvim

openbrowser.vim integration
Lua
9
star
15

lir-bookmark.nvim

Lua
7
star
16

lir-mmv.nvim

Lua
7
star
17

vim-clap-help

vim-clap help provider
Vim Script
7
star
18

split-mini

36 key split keyboard
7
star
19

dps-gignore

Generating gitignore using gitignore.io
TypeScript
7
star
20

PyTwitcasting

PyTwitcasting is a library for API v2 (ฮฒ) of Twitcasting.
Python
6
star
21

small-keycaps

OpenSCAD
6
star
22

lua-gameoflife.nvim

Lua
6
star
23

gku34

Game Maker Language
5
star
24

LeaderF-bookmark

๐Ÿ“‘ This Plugin use LeaderF to navigate the bookmark.
Python
5
star
25

compe-necosyntax

neco-syntax completion source for nvim-compe
Lua
3
star
26

date_the_image

Python
3
star
27

LeaderF-openbrowser

๐ŸŒ This Plugin use LeaderF to navigate the OpenBrowser url.
Python
2
star
28

LeaderF-sonictemplate

Vim Script
2
star
29

korpo44

่‡ชๅˆ†ใฎใŸใ‚ใฎใ‚ญใƒผใƒœใƒผใƒ‰
Makefile
2
star
30

EvoRoll

Game Maker Language
2
star
31

haqua34

Game Maker Language
2
star
32

LeaderF-neosnippet

Vim Script
1
star
33

LeaderF-packadd

LeaderF :packadd
Vim Script
1
star
34

cmp-deol-history

nvim-cmp source for deol.nvim
Lua
1
star
35

gu34

34 key choc v1 keyboard
1
star
36

keyboard-firmwares

C
1
star
37

post_nanaco_slack

Get nanaco balance info
Python
1
star