• Stars
    star
    605
  • Rank 71,419 (Top 2 %)
  • Language
    Lua
  • License
    Apache License 2.0
  • Created over 1 year ago
  • Updated 16 days ago

Reviews

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

Repository Details

๐Ÿ’ผ Neovim plugin to manage global and project-local settings

๐Ÿ’ผ neoconf.nvim

neoconf.nvim is a Neovim plugin to manage global and project-local settings.

image

โœจ Features

  • configure Neovim using JSON files (can have comments)
    • global settings: ~/.config/nvim/neoconf.json
    • local settings: ~/projects/foobar/.neoconf.json
  • live reload of your lsp settings
  • import existing settings from vscode, coc.nvim and nlsp-settings.nvim
  • auto-completion of all the settings in the Json config files
  • auto-completion of all LSP settings in your Neovim Lua config files
  • integrates with neodev.nvim. See .neoconf.json in this repo.

โšก๏ธ Requirements

  • Neovim >= 0.7.2

๐Ÿ“ฆ Installation

Install the plugin with your preferred package manager:

packer

-- Lua
use({
  "folke/neoconf.nvim",
})

๐Ÿš€ Setup

It's important that you set up neoconf.nvim BEFORE nvim-lspconfig.

require("neoconf").setup({
  -- override any of the default settings here
})

-- setup your lsp servers as usual
require("lspconfig").lua_ls.setup(...)

โš™๏ธ Configuration

neoconf.nvim comes with the following defaults:

{

  -- name of the local settings files
  local_settings = ".neoconf.json",
  -- name of the global settings file in your Neovim config directory
  global_settings = "neoconf.json",
  -- import existing settings from other plugins
  import = {
    vscode = true, -- local .vscode/settings.json
    coc = true, -- global/local coc-settings.json
    nlsp = true, -- global/local nlsp-settings.nvim json settings
  },
  -- send new configuration to lsp clients when changing json settings
  live_reload = true,
  -- set the filetype to jsonc for settings files, so you can use comments
  -- make sure you have the jsonc treesitter parser installed!
  filetype_jsonc = true,
  plugins = {
    -- configures lsp clients with settings in the following order:
    -- - lua settings passed in lspconfig setup
    -- - global json settings
    -- - local json settings
    lspconfig = {
      enabled = true,
    },
    -- configures jsonls to get completion in .nvim.settings.json files
    jsonls = {
      enabled = true,
      -- only show completion in json settings for configured lsp servers
      configured_servers_only = true,
    },
    -- configures lua_ls to get completion of lspconfig server settings
    lua_ls = {
      -- by default, lua_ls annotations are only enabled in your neovim config directory
      enabled_for_neovim_config = true,
      -- explicitely enable adding annotations. Mostly relevant to put in your local .nvim.settings.json file
      enabled = false,
    },
  },

}

๐Ÿš€ Usage

The :Neoconf Command

  • :Neoconf: will show a ui to select one of the local/global json config files to edit
  • :Neoconf local: will show a ui to select one of the local json config files to edit
  • :Neoconf global: will show a ui to select one of the global json config files to edit
  • :Neoconf show: opens a floating window with the merged config
  • :Neoconf lsp: opens a floating window with your merged lsp config

image

Completion and Validation for your Json Settings Files

image

Completion and Validation for your Lua Settings Files

Completion of your lua settings should work out of the box.

image

You can additionally use the exported types in other places.

Example with a table containing LSP server settings
  ---@type lspconfig.options
  local servers = {
    ansiblels = {},
    bashls = {},
    clangd = {},
    cssls = {},
    dockerls = {},
    tsserver = {},
    svelte = {},
    eslint = {},
    html = {},
    jsonls = {
      settings = {
        json = {
          format = {
            enable = true,
          },
          schemas = require("schemastore").json.schemas(),
          validate = { enable = true },
        },
      },
    },
  }

๐Ÿ“ฆ API

Neodev comes with an API that can be used by plugin developers to load global/local settings for their plugin.

---@class SettingsPlugin
---@field name string
---@field setup fun()|nil
---@field on_update fun(event)|nil
---@field on_schema fun(schema: Schema)

-- Registers a plugin. Biggest use-case is to get auto-completion for your plugin in the json settings files
---@param plugin SettingsPlugin
function Neodev.register(plugin) end

---@class WorkspaceOptions
---@field file? string File will be used to determine the root_dir
---@field buffer? buffer Buffer will be used to find the root_dir
---@field lsp? boolean LSP root_dir will be used to determine the root_dir
---@field local? boolean defaults to true. Merge local settings
---@field global? boolean defaults to true. Merge global settings

-- Returns the requested settings
---@generic T : table
---@param key? string Optional key to get settings for
---@param defaults? T Optional table of defaults that will be merged in the result
---@param opts? WorkspaceOptions options to determine the root_dir and what settings to merge
---@return T
function Neoconf.get(key, defaults, opts) end
API Example
-- default config for your plugin
local defaults = {
  doit = true,
  count = 1,
  array = {},
}

-- register your settings schema with Neodev, so auto-completion will work in the json files
require("neoconf.plugins").register({
    on_schema = function(schema)
    -- this call will create a json schema based on the lua types of your default settings
    schema:import("myplugin", defaults)
    -- Optionally update some of the json schema
    schema:set("myplugin.array", {
        description = "Special array containg booleans or numbers",
        anyOf = {
        { type = "boolean" },
        { type = "integer" },
        },
        })
    end,
    })

local my_settings = Neoconf.get("neodev", defaults)

โญ Acknowledgment

  • json.lua a pure-lua JSON library for parsing jsonc files

๐Ÿ’ป Supported Language Servers

More Repositories

1

lazy.nvim

๐Ÿ’ค A modern plugin manager for Neovim
Lua
11,777
star
2

tokyonight.nvim

๐Ÿ™ A clean, dark Neovim theme written in Lua, with support for lsp, treesitter and lots of plugins. Includes additional themes for Kitty, Alacritty, iTerm and Fish.
Lua
5,173
star
3

trouble.nvim

๐Ÿšฆ A pretty diagnostics, references, telescope results, quickfix and location list to help you solve all the trouble your code is causing.
Lua
4,726
star
4

which-key.nvim

๐Ÿ’ฅ Create key bindings that stick. WhichKey is a lua plugin for Neovim 0.5 that displays a popup with possible keybindings of the command you started typing.
Lua
4,441
star
5

noice.nvim

๐Ÿ’ฅ Highly experimental plugin that completely replaces the UI for messages, cmdline and the popupmenu.
Lua
3,677
star
6

todo-comments.nvim

โœ… Highlight, list and search todo comments in your projects
Lua
2,711
star
7

flash.nvim

Navigate your code with search labels, enhanced character motions and Treesitter integration
Lua
1,965
star
8

neodev.nvim

๐Ÿ’ป Neovim setup for init.lua and plugin development with full signature help, docs and completion for the nvim lua API.
Lua
1,935
star
9

zen-mode.nvim

๐Ÿง˜ Distraction-free coding for Neovim
Lua
1,442
star
10

ultra-runner

๐Ÿƒโ›ฐ Ultra fast monorepo script runner and build tool
TypeScript
1,188
star
11

twilight.nvim

๐ŸŒ… Twilight is a Lua plugin for Neovim 0.5 that dims inactive portions of the code you're editing using TreeSitter.
Lua
1,130
star
12

esbuild-runner

โšก๏ธ Super-fast on-the-fly transpilation of modern JS, TypeScript and JSX using esbuild
TypeScript
701
star
13

dot

โ˜•๏ธ My Dot Files
Lua
670
star
14

edgy.nvim

Easily create and manage predefined window layouts, bringing a new edge to your workflow
Lua
665
star
15

persistence.nvim

๐Ÿ’พ Simple session management for Neovim
Lua
533
star
16

lsp-colors.nvim

๐ŸŒˆ Plugin that creates missing LSP diagnostics highlight groups for color schemes that don't yet support the Neovim 0.5 builtin LSP client.
Lua
434
star
17

devmoji

๐Ÿค– ๐Ÿš€ โœจ Emojify your conventional commits with Devmoji
TypeScript
286
star
18

styler.nvim

Simple Neovim plugin to set a different colorscheme per filetype.
Lua
247
star
19

drop.nvim

๐Ÿ Fun little plugin that can be used as a screensaver and on your dashboard
Lua
190
star
20

polydock

โœจ A shiny and hackable application dock
TypeScript
179
star
21

paint.nvim

Easily add additional highlights to your buffers
Lua
152
star
22

vscode-monorepo-workspace

๐Ÿ“ฆโœจManage monorepos with multi-root workspaces. Supports Lerna, Yarn, Pnpm, Rushjs and recursive package directories.
TypeScript
138
star
23

splashcii

Simple cli tool that shows a random ascii art from https://www.asciiur.com/
TypeScript
35
star
24

semantic-release-commit-filter

๐Ÿ“ฆ๐Ÿ•ต๏ธโ€โ™€๏ธ Semantic-release plugin that filters git commits based on the current working directory
JavaScript
25
star
25

zmk-config

Folke's ZMK config
C++
21
star
26

lovelace-styler

Custom styling for lovelace cards
TypeScript
18
star
27

folke

7
star
28

lualine.nvim

A blazing fast and easy to configure neovim statusline plugin written in pure lua.
Lua
4
star
29

phpintel

Accurate autocompletion / code checking / .... framework for PHP
PHP
3
star
30

adventofcode

๐ŸŽ… ๐ŸŽ„ โ›„ โœจ Solutions for Advent of Code 2020 in TypeScript
TypeScript
2
star
31

chess

C#
2
star
32

adventofcode2019

Advent of Code 2019 in TypeScript
TypeScript
2
star