Merge pull request #10 from mattleong/feat/config
New Configuration File
This commit is contained in:
commit
be8518df04
13 changed files with 262 additions and 40 deletions
6
init.lua
6
init.lua
|
@ -1 +1,5 @@
|
|||
require('cosmic')
|
||||
local ok, err = pcall(require, 'cosmic')
|
||||
|
||||
if not ok then
|
||||
error(string.format('Error loading core...\n\n%s', err))
|
||||
end
|
||||
|
|
37
lua/cosmic/config/config.lua
Normal file
37
lua/cosmic/config/config.lua
Normal file
|
@ -0,0 +1,37 @@
|
|||
-- Override Cosmic configuration options
|
||||
|
||||
--[[
|
||||
local config = {}
|
||||
|
||||
config.statusline = {
|
||||
main_icon = '★',
|
||||
}
|
||||
|
||||
config.lsp = {
|
||||
|
||||
-- true/false or table of filetypes {'.ts', '.js',}
|
||||
format_on_save = false,
|
||||
|
||||
servers = {
|
||||
|
||||
-- enable/disable server
|
||||
eslint = false,
|
||||
|
||||
-- enable non-default servers (todo: support for custom server configs)
|
||||
rust_analyzer = true,
|
||||
|
||||
efm = {
|
||||
-- specifc to efm, e.g. 'eslint', 'prettier', 'lua'
|
||||
disable_formatters = {},
|
||||
},
|
||||
|
||||
tsserver = {
|
||||
-- disable formatting all together
|
||||
format = false,
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return config
|
||||
]]
|
6
lua/cosmic/config/editor.lua
Normal file
6
lua/cosmic/config/editor.lua
Normal file
|
@ -0,0 +1,6 @@
|
|||
-- Override Cosmic editor options
|
||||
|
||||
--[[ local opt = vim.opt
|
||||
opt.tabstop = 4
|
||||
opt.softtabstop = 4
|
||||
opt.shiftwidth = 4 ]]
|
47
lua/cosmic/config/init.lua
Normal file
47
lua/cosmic/config/init.lua
Normal file
|
@ -0,0 +1,47 @@
|
|||
-- DO NOT TOUCH :)
|
||||
local ok, user_config = pcall(require, 'cosmic.config.config')
|
||||
|
||||
if not ok then
|
||||
error(string.format('Error loading user config...\n\n%s', user_config))
|
||||
error('No user config, using default instead...')
|
||||
end
|
||||
|
||||
if user_config == true then
|
||||
user_config = {}
|
||||
end
|
||||
|
||||
-- these settings will be merged with any settings definined in config.lua
|
||||
local default_config = {
|
||||
statusline = {
|
||||
main_icon = require('cosmic.core.theme.icons').ghost,
|
||||
},
|
||||
lsp = {
|
||||
format_on_save = false, -- true/false or table of filetypes {'.ts', '.js',}
|
||||
servers = {
|
||||
eslint = true, -- enable/disable server
|
||||
-- rust_analyzer = true, -- enable non-default servers (todo: support for custom server configs)
|
||||
efm = {
|
||||
format = true, -- true or false
|
||||
disable_formatters = { 'eslint' }, -- e.g. 'eslint', 'prettier', 'stylua'
|
||||
},
|
||||
tsserver = {
|
||||
format = false, -- disable formatting all together
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
local config = vim.tbl_deep_extend('force', default_config, user_config)
|
||||
-- default servers that can be formatted
|
||||
local formatting_servers = { 'efm', 'eslint', 'tsserver', 'sumneko_lua', 'rust_analyzer', 'gopls', 'pyright' }
|
||||
local user_servers = vim.tbl_keys(config.lsp.servers)
|
||||
|
||||
function config.lsp.can_client_format(client_name)
|
||||
if not user_servers[client_name] or vim.tbl_contains(formatting_servers, client_name) then
|
||||
return false
|
||||
end
|
||||
|
||||
return (user_servers[client_name].format == true)
|
||||
end
|
||||
|
||||
return config
|
6
lua/cosmic/config/mappings.lua
Normal file
6
lua/cosmic/config/mappings.lua
Normal file
|
@ -0,0 +1,6 @@
|
|||
-- Additional remaps
|
||||
--[[
|
||||
local map = require('cosmic.utils').map
|
||||
|
||||
map('i', 'jj', '<esc>', { noremap = true, silent = true })
|
||||
]]
|
|
@ -7,6 +7,9 @@ local utils = require('cosmic.utils')
|
|||
local colors = require('cosmic.core.theme.colors')
|
||||
local highlight = utils.highlight
|
||||
local icons = require('cosmic.core.theme.icons')
|
||||
local config = require('cosmic.config')
|
||||
|
||||
local main_icon = config.statusline.main_icon
|
||||
|
||||
local get_mode = function()
|
||||
local mode_colors = {
|
||||
|
@ -93,7 +96,7 @@ gls.left = {
|
|||
},
|
||||
{
|
||||
Ghost = {
|
||||
provider = BracketProvider(icons.ghost, true),
|
||||
provider = BracketProvider(main_icon, true),
|
||||
highlight = 'GalaxyViModeInv',
|
||||
},
|
||||
},
|
||||
|
@ -380,7 +383,7 @@ gls.short_line_left = {
|
|||
},
|
||||
{
|
||||
GhostShort = {
|
||||
provider = BracketProvider(icons.ghost, true),
|
||||
provider = BracketProvider(main_icon, true),
|
||||
highlight = { colors.bg, colors.white },
|
||||
},
|
||||
},
|
||||
|
|
|
@ -3,3 +3,17 @@ require('cosmic.pluginsInit')
|
|||
require('cosmic.compiled')
|
||||
require('cosmic.mappings')
|
||||
require('cosmic.editor')
|
||||
|
||||
do
|
||||
local ok, err = pcall(require, 'cosmic.config.editor')
|
||||
if not ok then
|
||||
error(string.format('Error loading custom editor settings...\n\n%s', err))
|
||||
end
|
||||
end
|
||||
|
||||
do
|
||||
local ok, err = pcall(require, 'cosmic.config.mappings')
|
||||
if not ok then
|
||||
error(string.format('Error loading custom mapping settings...\n\n%s', err))
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,3 +5,4 @@ vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with(vim.lsp.handlers.s
|
|||
vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(vim.lsp.handlers.hover, {
|
||||
border = 'single',
|
||||
})
|
||||
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
local config = require('cosmic.config')
|
||||
local M = {}
|
||||
|
||||
local auto_format_lock = false;
|
||||
|
||||
function M.on_attach(client, bufnr)
|
||||
local function buf_set_option(...)
|
||||
vim.api.nvim_buf_set_option(bufnr, ...)
|
||||
|
@ -8,10 +11,22 @@ function M.on_attach(client, bufnr)
|
|||
-- Enable completion triggered by <c-x><c-o>
|
||||
buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
|
||||
|
||||
local formatting_servers = { 'efm', 'eslint' }
|
||||
if vim.tbl_contains(formatting_servers, client.name) then
|
||||
if config.lsp.can_client_format(client.name) then
|
||||
client.resolved_capabilities.document_formatting = true
|
||||
client.resolved_capabilities.document_range_formatting = true
|
||||
-- check user config to see if we can format on save
|
||||
if config.lsp.format_on_save and not auto_format_lock then
|
||||
auto_format_lock = true -- just run autocommand once
|
||||
local format_filetypes = ''
|
||||
if (vim.tbl_islist(config.lsp.format_on_save)) then
|
||||
for _, ft in pairs(config.lsp.format_on_save) do
|
||||
format_filetypes = format_filetypes .. '*' .. ft
|
||||
end
|
||||
else
|
||||
format_filetypes = '*'
|
||||
end
|
||||
vim.cmd(string.format('autocomd BufWritePre %s lua vim.lsp.buf.formatting()', format_filetypes))
|
||||
end
|
||||
else
|
||||
client.resolved_capabilities.document_formatting = false
|
||||
client.resolved_capabilities.document_range_formatting = false
|
||||
|
@ -45,4 +60,6 @@ M.root_dir = function(fname)
|
|||
or util.root_pattern('tsconfig.json')(fname)
|
||||
end
|
||||
|
||||
M.autostart = true
|
||||
|
||||
return M
|
||||
|
|
|
@ -1,30 +1,75 @@
|
|||
local util = require('lspconfig').util
|
||||
local config = require('cosmic.config')
|
||||
local formatters = {}
|
||||
|
||||
local stylua = {
|
||||
formatters.stylua = {
|
||||
formatCommand = 'stylua -s --quote-style AutoPreferSingle --indent-type Spaces --indent-width 2 -',
|
||||
formatStdin = true,
|
||||
}
|
||||
|
||||
local prettier = {
|
||||
formatters.eslint = {
|
||||
lintCommand = 'eslint_d -f unix --stdin --stdin-filename ${INPUT}',
|
||||
lintStdin = true,
|
||||
lintFormats = { '%f:%l:%c: %m' },
|
||||
lintIgnoreExitCode = true,
|
||||
formatCommand = 'eslint_d --stdin --fix-to-stdout --stdin-filename=${INPUT}',
|
||||
formatStdin = true,
|
||||
}
|
||||
|
||||
formatters.prettier = {
|
||||
-- formatCommand = 'prettier --stdin-filepath ${INPUT}',
|
||||
formatCommand = 'prettierd "${INPUT}"',
|
||||
formatStdin = true,
|
||||
}
|
||||
|
||||
local filetypes = {
|
||||
css = { prettier },
|
||||
html = { prettier },
|
||||
lua = { stylua },
|
||||
javascript = { prettier },
|
||||
javascriptreact = { prettier },
|
||||
json = { prettier },
|
||||
markdown = { prettier },
|
||||
scss = { prettier },
|
||||
typescript = { prettier },
|
||||
typescriptreact = { prettier },
|
||||
yaml = { prettier },
|
||||
local filetype_defaults = {
|
||||
'css',
|
||||
'html',
|
||||
'lua',
|
||||
'javascript',
|
||||
'javascriptreact',
|
||||
'json',
|
||||
'markdown',
|
||||
'scss',
|
||||
'typescript',
|
||||
'typescriptreact',
|
||||
'yaml',
|
||||
}
|
||||
|
||||
formatters.defaults = {
|
||||
eslint = {
|
||||
'javascript',
|
||||
'javascriptreact',
|
||||
'json',
|
||||
'typescriptreact',
|
||||
'typescript',
|
||||
},
|
||||
prettier = {
|
||||
'css',
|
||||
'html',
|
||||
'javascript',
|
||||
'javascriptreact',
|
||||
'json',
|
||||
'typescriptreact',
|
||||
'typescript',
|
||||
'markdown',
|
||||
'scss',
|
||||
'yaml',
|
||||
},
|
||||
stylua = { 'lua' },
|
||||
}
|
||||
|
||||
local languages = {}
|
||||
for formatter, filetypes in pairs(formatters.defaults) do
|
||||
-- disable specific formatters
|
||||
if not vim.tbl_contains(config.lsp.servers.efm.disable_formatters, formatter) then
|
||||
for _, filetype in pairs(filetypes) do
|
||||
languages[filetype] = languages[filetype] or {}
|
||||
table.insert(languages[filetype], formatters[formatter])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return {
|
||||
init_options = { documentFormatting = true, codeAction = true },
|
||||
root_dir = function(fname)
|
||||
|
@ -34,6 +79,6 @@ return {
|
|||
or util.root_pattern('.eslintrc.js')(fname)
|
||||
or util.root_pattern('tsconfig.json')(fname)
|
||||
end,
|
||||
filetypes = vim.tbl_keys(filetypes),
|
||||
settings = { languages = filetypes },
|
||||
filetypes = filetype_defaults,
|
||||
settings = { languages = languages },
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
local default_config = require('cosmic.lsp.providers.defaults')
|
||||
local config = require('cosmic.config')
|
||||
local lsp_installer = require('nvim-lsp-installer')
|
||||
|
||||
lsp_installer.settings({
|
||||
|
@ -16,24 +17,61 @@ lsp_installer.settings({
|
|||
},
|
||||
})
|
||||
|
||||
-- initial default serverse
|
||||
local requested_servers = {
|
||||
'eslint',
|
||||
'efm',
|
||||
'tsserver',
|
||||
'sumneko_lua',
|
||||
'jsonls',
|
||||
'cssls',
|
||||
'html',
|
||||
}
|
||||
|
||||
-- get disabled servers from config
|
||||
local disabled_servers = {}
|
||||
for config_server, config_opt in pairs(config.lsp.servers) do
|
||||
if config_opt == false then
|
||||
table.insert(disabled_servers, config_server)
|
||||
elseif not vim.tbl_contains(requested_servers, config_server) then
|
||||
-- add additonally defined servers to be installed
|
||||
-- todo: how to handle non-default server opts?
|
||||
table.insert(requested_servers, config_server)
|
||||
end
|
||||
end
|
||||
|
||||
-- go through requested_servers and ensure installation
|
||||
local lsp_installer_servers = require('nvim-lsp-installer.servers')
|
||||
for _, requested_server in pairs(requested_servers) do
|
||||
local ok, server = lsp_installer_servers.get_server(requested_server)
|
||||
if ok then
|
||||
if not server:is_installed() then
|
||||
server:install()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- print(vim.inspect(requested_servers))
|
||||
-- print(vim.inspect(disabled_servers))
|
||||
|
||||
lsp_installer.on_server_ready(function(server)
|
||||
local opts = default_config
|
||||
|
||||
opts.autostart = true
|
||||
if vim.tbl_contains(disabled_servers, server.name) then
|
||||
opts.autostart = false
|
||||
end
|
||||
|
||||
if server.name == 'sumneko_lua' then
|
||||
local config = require('cosmic.lsp.providers.lua')
|
||||
opts = vim.tbl_deep_extend('force', opts, config)
|
||||
opts = vim.tbl_deep_extend('force', opts, require('cosmic.lsp.providers.lua'))
|
||||
elseif server.name == 'tsserver' then
|
||||
local config = require('cosmic.lsp.providers.tsserver')
|
||||
opts = vim.tbl_deep_extend('force', opts, config)
|
||||
opts = vim.tbl_deep_extend('force', opts, require('cosmic.lsp.providers.tsserver'))
|
||||
elseif server.name == 'efm' then
|
||||
local config = require('cosmic.lsp.providers.efm')
|
||||
opts = vim.tbl_deep_extend('force', opts, config)
|
||||
opts = vim.tbl_deep_extend('force', opts, require('cosmic.lsp.providers.efm'))
|
||||
elseif server.name == 'jsonls' then
|
||||
local config = require('cosmic.lsp.providers.jsonls')
|
||||
opts = vim.tbl_deep_extend('force', opts, config)
|
||||
opts = vim.tbl_deep_extend('force', opts, require('cosmic.lsp.providers.jsonls'))
|
||||
elseif server.name == 'eslint' then
|
||||
local config = require('cosmic.lsp.providers.eslint')
|
||||
opts = vim.tbl_deep_extend('force', opts, config)
|
||||
opts = vim.tbl_deep_extend('force', opts, require('cosmic.lsp.providers.eslint'))
|
||||
end
|
||||
|
||||
-- This setup() function is exactly the same as lspconfig's setup function (:help lspconfig-quickstart)
|
||||
|
|
|
@ -24,6 +24,8 @@ if not present then
|
|||
|
||||
if present then
|
||||
print('Packer cloned successfully.')
|
||||
packer.sync()
|
||||
packer.compile()
|
||||
else
|
||||
error("Couldn't clone packer !\nPacker path: " .. packer_path .. '\n' .. packer)
|
||||
end
|
||||
|
|
20
readme.md
20
readme.md
|
@ -30,7 +30,7 @@ Full featured native LSP functionality!
|
|||
- Explore files with [nvim-tree](https://github.com/kyazdani42/nvim-tree.lua)
|
||||
- Fuzzy finder and some LSP actions with [Telescope](https://github.com/nvim-telescope/telescope.nvim)
|
||||
- Floating terminal with [vim-floaterm](https://github.com/voldikss/vim-floaterm)
|
||||
- Easy LSP installation with [nvim-lsp-installer](https://github.com/williamboman/nvim-lsp-installer)
|
||||
- Auto LSP installation with [nvim-lsp-installer](https://github.com/williamboman/nvim-lsp-installer)
|
||||
- Autocompletion provided by [nvim-cmp](https://github.com/hrsh7th/nvim-cmp)
|
||||
- Snippet support via [LuaSnip](https://github.com/L3MON4D3/LuaSnip)
|
||||
- Session management with [auto-session](https://github.com/rmagatti/auto-session)
|
||||
|
@ -52,20 +52,22 @@ _While CosmicNvim is geared specifically toward TypeScript/JavaScript developmen
|
|||
```
|
||||
$ cd ~/.config
|
||||
$ git clone git@github.com:mattleong/CosmicNvim.git nvim
|
||||
$ nvim .
|
||||
```
|
||||
|
||||
You will need to set up Packers compiled file via the steps below:
|
||||
|
||||
1. Start NVIM
|
||||
2. Run `PackerUpdate` & `PackerCompile`
|
||||
3. Restart NVIM
|
||||
4. Install LSP servers, `:LspInstallInfo` (hit enter to install)
|
||||
|
||||
Additional Cosmic installation [details](https://github.com/mattleong/CosmicNvim/wiki/Installation).
|
||||
|
||||
Additional LSP server installation [details](https://github.com/mattleong/CosmicNvim/wiki/Installing-LSP-servers).
|
||||
|
||||
## Mappings
|
||||
## Configuration
|
||||
|
||||
[Cosmic configurations](./lua/cosmic/config/config.lua)
|
||||
|
||||
[Add additional mappings](./lua/cosmic/config/mappings.lua)
|
||||
|
||||
[Add addtional vim options](./lua/cosmic/config/editor.lua)
|
||||
|
||||
## Default Mappings
|
||||
|
||||
[File Navigation](./lua/cosmic/core/navigation/mappings.lua)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue