summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob McDonnell <jacob@simplelittledream.com>2022-11-24 11:31:53 -0500
committerJacob McDonnell <jacob@simplelittledream.com>2022-11-24 11:31:53 -0500
commit7ed38f42d4b41a6621a052b3f3ab6bdf26a1f09d (patch)
tree181b929b8c0407168b2c1b6e8599558919a05328
parentced8c4826a71ccd929266f3e3a8de3ca6c6f953d (diff)
Gofmt on save in nvim
-rw-r--r--.config/coc/extensions/package.json3
-rw-r--r--.config/coc/memos.json77
-rw-r--r--.config/nvim/init.vim12
-rw-r--r--.config/nvim/lua/lsp_config.lua100
4 files changed, 167 insertions, 25 deletions
diff --git a/.config/coc/extensions/package.json b/.config/coc/extensions/package.json
index 2eb42bd..7450a76 100644
--- a/.config/coc/extensions/package.json
+++ b/.config/coc/extensions/package.json
@@ -7,7 +7,8 @@
"coc-java": ">=1.5.5",
"coc-pairs": ">=1.3.2",
"coc-python": ">=1.2.13",
- "coc-tsserver": ">=1.10.5"
+ "coc-tsserver": ">=1.10.5",
+ "coc-flutter": ">=1.9.9"
},
"disabled": [],
"locked": []
diff --git a/.config/coc/memos.json b/.config/coc/memos.json
index 23657ba..51d5f29 100644
--- a/.config/coc/memos.json
+++ b/.config/coc/memos.json
@@ -26,7 +26,7 @@
"sysPrefix": "/opt/homebrew/opt/python@3.10/Frameworks/Python.framework/Versions/3.10",
"fileHash": "1910ec10c8373e45fce0a181a4651a5bb8a8f48f728505ba1e441738ff84b968807c6e14b1ea05c1eea8e5c16c62b0b1db885de7a7bbdca1916f0ebb790e9ce7"
},
- "expiry": 1668278228004
+ "expiry": 1668882677806
},
"/opt/homebrew/bin/python3.v3": {
"data": {
@@ -51,7 +51,7 @@
"sysPrefix": "/opt/homebrew/opt/python@3.10/Frameworks/Python.framework/Versions/3.10",
"fileHash": "0e69ba9c7283252581c51a1b17ac991b8c7c2f3218bed7e7267a66ea8db287d301355e226a8de1f0e1555b54ff263a1a8fc3a31d781814633e44eaad4a94dee0"
},
- "expiry": 1668278228006
+ "expiry": 1668882677815
},
"/opt/homebrew/bin/python3.8.v3": {
"data": {
@@ -76,7 +76,7 @@
"sysPrefix": "/opt/homebrew/Cellar/python@3.8/3.8.15/Frameworks/Python.framework/Versions/3.8",
"fileHash": "cf6bca9eef82597c4d88213768bdfb8811199093c6ccdd85f3c598cd33fa6cbf143b1b07f04edbf3c8b62f914f4cdc520034cc8b4bf723a60cd72e30574eebff"
},
- "expiry": 1668278228001
+ "expiry": 1668882677818
},
"/opt/homebrew/bin/python3.9.v3": {
"data": {
@@ -101,7 +101,7 @@
"sysPrefix": "/opt/homebrew/opt/python@3.9/Frameworks/Python.framework/Versions/3.9",
"fileHash": "b6d571c5b48c97e6988822ba142f973b5408a90a77a0ab98a680a44fd017417d1060ac62c75b2b1360c1fa7026f6de47a9c63aea20d7c348629d69e9ba8bb45d"
},
- "expiry": 1668278228022
+ "expiry": 1668882677830
},
"/opt/homebrew/opt/python@3.10/bin/python3.10.v3": {
"data": {
@@ -126,7 +126,7 @@
"sysPrefix": "/opt/homebrew/opt/python@3.10/Frameworks/Python.framework/Versions/3.10",
"fileHash": "36f5313ec0417c1c53a1ae2f73454216f7ae3f5e89517fcfabd3424122d0523c5ba275f5fcff93e126a8f68e5a03b275bcbe5cb412d43e0215b888b5aa0b74d2"
},
- "expiry": 1668278228094
+ "expiry": 1668882677850
},
"INTERPRETERS_CACHE_v3_CurrentPathService": [
{
@@ -174,7 +174,8 @@
},
"sysPrefix": "/opt/homebrew/opt/python@3.10/Frameworks/Python.framework/Versions/3.10",
"fileHash": "36f5313ec0417c1c53a1ae2f73454216f7ae3f5e89517fcfabd3424122d0523c5ba275f5fcff93e126a8f68e5a03b275bcbe5cb412d43e0215b888b5aa0b74d2",
- "type": "Unknown"
+ "type": "Unknown",
+ "cachedEntry": true
},
"preferredGlobalPyInterpreter": {
"architecture": 3,
@@ -224,17 +225,19 @@
"sysPrefix": "/opt/homebrew/opt/python@3.10/Frameworks/Python.framework/Versions/3.10",
"fileHash": "36f5313ec0417c1c53a1ae2f73454216f7ae3f5e89517fcfabd3424122d0523c5ba275f5fcff93e126a8f68e5a03b275bcbe5cb412d43e0215b888b5aa0b74d2",
"type": "Unknown",
- "displayName": "Python 3.10.8 64-bit"
+ "cachedEntry": true,
+ "displayName": "Python 3.10.8 64-bit",
+ "__store": true
}
},
- "expiry": 1668278228165
+ "expiry": 1668882677811
},
"/opt/homebrew/opt/python@3.10/bin/python3.10.interpreter.displayName.v7": {
"data": {
"displayName": "Python 3.10.8 64-bit",
"hash": "36f5313ec0417c1c53a1ae2f73454216f7ae3f5e89517fcfabd3424122d0523c5ba275f5fcff93e126a8f68e5a03b275bcbe5cb412d43e0215b888b5aa0b74d2-e6cd247a972cad6127b7bcb1809370f1"
},
- "expiry": 1668278228115
+ "expiry": 1668882677839
},
"/usr/local/bin/python3.v3": {
"data": {
@@ -259,7 +262,7 @@
"sysPrefix": "/usr/local/opt/python@3.9/Frameworks/Python.framework/Versions/3.9",
"fileHash": "47e5e29f33ea67428f0eee0bc1f045f7ff86ab0878f21fc61e6d476c60cebf36ef81e63f7b97b134d74f4b7ba4ef0607cda3c00b11ac2a6f541e3743fe2c6c21"
},
- "expiry": 1668278228774
+ "expiry": 1668882677945
},
"/usr/local/bin/python3.9.v3": {
"data": {
@@ -284,7 +287,7 @@
"sysPrefix": "/usr/local/opt/python@3.9/Frameworks/Python.framework/Versions/3.9",
"fileHash": "2eedc3183557a39ccf5e512205a78594fcc02e817273434752d8c1527276b75d42c3111c300b1465adc2d3b2c61c240b6655ea79ca6fa3d459822d66897b9f86"
},
- "expiry": 1668278228776
+ "expiry": 1668882677946
},
"/usr/bin/python3.v3": {
"data": {
@@ -309,7 +312,7 @@
"sysPrefix": "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9",
"fileHash": "1eccbdcbe105feb81fc58cf4015784105c9ee5a828ceaae3cedd7ce9fe0a03d3e1055e17202fb253568442f0f861b0d125affe08747ea342cee2435802a03736"
},
- "expiry": 1668278228207
+ "expiry": 1668882677983
},
"INTERPRETERS_CACHE_v3_KnownPathsService": [
{
@@ -641,35 +644,35 @@
"displayName": "Python 3.10.8 64-bit",
"hash": "0e69ba9c7283252581c51a1b17ac991b8c7c2f3218bed7e7267a66ea8db287d301355e226a8de1f0e1555b54ff263a1a8fc3a31d781814633e44eaad4a94dee0-89cfdd86c805836c556b88248b3b0809"
},
- "expiry": 1668279447882
+ "expiry": 1668711303540
},
"/opt/homebrew/bin/python3.8.interpreter.displayName.v7": {
"data": {
"displayName": "Python 3.8.15 64-bit",
"hash": "cf6bca9eef82597c4d88213768bdfb8811199093c6ccdd85f3c598cd33fa6cbf143b1b07f04edbf3c8b62f914f4cdc520034cc8b4bf723a60cd72e30574eebff-51f59145312ea2eb2d6d6c3f521e5575"
},
- "expiry": 1668279447881
+ "expiry": 1668711303541
},
"/opt/homebrew/bin/python3.9.interpreter.displayName.v7": {
"data": {
"displayName": "Python 3.9.15 64-bit",
"hash": "b6d571c5b48c97e6988822ba142f973b5408a90a77a0ab98a680a44fd017417d1060ac62c75b2b1360c1fa7026f6de47a9c63aea20d7c348629d69e9ba8bb45d-02e162736e7c9edd0bf4e7ae808fd501"
},
- "expiry": 1668279447877
+ "expiry": 1668711303542
},
"/usr/local/bin/python3.interpreter.displayName.v7": {
"data": {
"displayName": "Python 3.9.5 64-bit",
"hash": "47e5e29f33ea67428f0eee0bc1f045f7ff86ab0878f21fc61e6d476c60cebf36ef81e63f7b97b134d74f4b7ba4ef0607cda3c00b11ac2a6f541e3743fe2c6c21-345e37cd55eb9b73c22a13e7fc48b206"
},
- "expiry": 1668279447878
+ "expiry": 1668711303543
},
"/usr/bin/python3.interpreter.displayName.v7": {
"data": {
"displayName": "Python 3.9.6 64-bit",
"hash": "1eccbdcbe105feb81fc58cf4015784105c9ee5a828ceaae3cedd7ce9fe0a03d3e1055e17202fb253568442f0f861b0d125affe08747ea342cee2435802a03736-8f5d17f24a9d0c768b9211375618ba81"
},
- "expiry": 1668279447880
+ "expiry": 1668711303545
},
"InterpreterAutoSeletionRule-system": {
"architecture": 3,
@@ -693,6 +696,7 @@
"sysPrefix": "/opt/homebrew/opt/python@3.10/Frameworks/Python.framework/Versions/3.10",
"fileHash": "36f5313ec0417c1c53a1ae2f73454216f7ae3f5e89517fcfabd3424122d0523c5ba275f5fcff93e126a8f68e5a03b275bcbe5cb412d43e0215b888b5aa0b74d2",
"type": "Unknown",
+ "cachedEntry": true,
"displayName": "Python 3.10.8 64-bit"
},
"/opt/homebrew/bin/python3.interpreter.Details.v7": {
@@ -723,7 +727,7 @@
"displayName": "Python 3.10.8 64-bit"
}
},
- "expiry": 1668279447896
+ "expiry": 1668711303551
},
"/opt/homebrew/bin/python3.8.interpreter.Details.v7": {
"data": {
@@ -753,7 +757,7 @@
"displayName": "Python 3.8.15 64-bit"
}
},
- "expiry": 1668279447894
+ "expiry": 1668711303553
},
"/opt/homebrew/bin/python3.9.interpreter.Details.v7": {
"data": {
@@ -783,7 +787,7 @@
"displayName": "Python 3.9.15 64-bit"
}
},
- "expiry": 1668279447889
+ "expiry": 1668711303555
},
"/usr/local/bin/python3.interpreter.Details.v7": {
"data": {
@@ -813,7 +817,7 @@
"displayName": "Python 3.9.5 64-bit"
}
},
- "expiry": 1668279447890
+ "expiry": 1668711303557
},
"/usr/bin/python3.interpreter.Details.v7": {
"data": {
@@ -843,7 +847,7 @@
"displayName": "Python 3.9.6 64-bit"
}
},
- "expiry": 1668279447893
+ "expiry": 1668711303559
},
"InterpreterAutoSeletionRule-cachedInterpreters": {
"architecture": 3,
@@ -1107,5 +1111,34 @@
},
"INTERPRETERS_CACHE_v3_PipEnvService": [],
"INTERPRETERS_CACHE_v3_WorkspaceVirtualEnvService": []
+ },
+ "coc-python|/Users/jmm/Documents/Projects/Experiments/imapTest": {
+ "INTERPRETERS_CACHE_v3_PipEnvService:28ebab2045718d741db6fcd905616ce1": [],
+ "INTERPRETERS_CACHE_v3_WorkspaceVirtualEnvService:28ebab2045718d741db6fcd905616ce1": [],
+ "autoSelectedWorkspacePythonInterpreter-/Users/jmm/Documents/Projects/Experiments/imapTest": {
+ "architecture": 3,
+ "path": "/opt/homebrew/opt/python@3.10/bin/python3.10",
+ "version": {
+ "options": {
+ "loose": false,
+ "includePrerelease": false
+ },
+ "loose": false,
+ "raw": "3.10.8-final",
+ "major": 3,
+ "minor": 10,
+ "patch": 8,
+ "prerelease": [
+ "final"
+ ],
+ "build": [],
+ "version": "3.10.8-final"
+ },
+ "sysPrefix": "/opt/homebrew/opt/python@3.10/Frameworks/Python.framework/Versions/3.10",
+ "fileHash": "36f5313ec0417c1c53a1ae2f73454216f7ae3f5e89517fcfabd3424122d0523c5ba275f5fcff93e126a8f68e5a03b275bcbe5cb412d43e0215b888b5aa0b74d2",
+ "type": "Unknown"
+ },
+ "INTERPRETERS_CACHE_v3_PipEnvService": [],
+ "INTERPRETERS_CACHE_v3_WorkspaceVirtualEnvService": []
}
} \ No newline at end of file
diff --git a/.config/nvim/init.vim b/.config/nvim/init.vim
index 6ed4ff1..3c6dad3 100644
--- a/.config/nvim/init.vim
+++ b/.config/nvim/init.vim
@@ -62,10 +62,11 @@ Plug 'NLKNguyen/papercolor-theme'
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-telescope/telescope.nvim', { 'tag': '0.1.0' }
Plug 'ThePrimeagen/harpoon'
+Plug 'neovim/nvim-lspconfig'
call plug#end()
" Goyo plugin makes text more readable when writing prose:
-map <leader>f :Goyo \| set bg=dark \| set linebreak<CR>
+map <leader>f :Goyo \| set linebreak<CR>
" Commentary plugin
map <leader>c :Commentary \| set linebreak<CR>
@@ -78,12 +79,19 @@ let g:coc_global_extensions = [
\ 'coc-clangd',
\ 'coc-go',
\ 'coc-pairs',
- \ 'coc-python'
+ \ 'coc-python',
+ \ 'coc-flutter'
\ ]
" runs gofmt when closing a go file.
autocmd VimLeave *.go !gofmt -w %
+" This handles gofmt on save
+" https://www.getman.io/posts/programming-go-in-neovim/
+lua require("lsp_config")
+autocmd BufWritePre *.go lua vim.lsp.buf.formatting()
+autocmd BufWritePre *.go lua goimports(1000)
+
set t_Co=256
" ChangeBackground changes the background mode based on macOS's `Appearance`
diff --git a/.config/nvim/lua/lsp_config.lua b/.config/nvim/lua/lsp_config.lua
new file mode 100644
index 0000000..be7e018
--- /dev/null
+++ b/.config/nvim/lua/lsp_config.lua
@@ -0,0 +1,100 @@
+local nvim_lsp = require('lspconfig')
+
+local capabilities = vim.lsp.protocol.make_client_capabilities()
+capabilities.textDocument.completion.completionItem.snippetSupport = true
+
+local on_attach = function(client, bufnr)
+ local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
+ local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
+
+ buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
+
+ -- Mappings.
+ local opts = { noremap=true, silent=true }
+ buf_set_keymap('n', 'gD', '<Cmd>lua vim.lsp.buf.declaration()<CR>', opts)
+ buf_set_keymap('n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts)
+ buf_set_keymap('n', 'ga', '<Cmd>lua vim.lsp.buf.code_action()<CR>', opts)
+ buf_set_keymap('n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts)
+ buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
+ buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
+ buf_set_keymap('n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
+ buf_set_keymap('n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
+ buf_set_keymap('n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
+ buf_set_keymap('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
+ buf_set_keymap('n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
+ buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
+ buf_set_keymap('n', '<space>e', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
+ buf_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
+ buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
+ buf_set_keymap('n', '<space>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts)
+
+ -- Set some keybinds conditional on server capabilities
+ if client.resolved_capabilities.document_formatting then
+ buf_set_keymap("n", "ff", "<cmd>lua vim.lsp.buf.formatting()<CR>", opts)
+ elseif client.resolved_capabilities.document_range_formatting then
+ buf_set_keymap("n", "ff", "<cmd>lua vim.lsp.buf.range_formatting()<CR>", opts)
+ end
+
+ -- Set autocommands conditional on server_capabilities
+ if client.resolved_capabilities.document_highlight then
+ vim.api.nvim_exec([[
+ hi LspReferenceRead cterm=bold ctermbg=DarkMagenta guibg=LightYellow
+ hi LspReferenceText cterm=bold ctermbg=DarkMagenta guibg=LightYellow
+ hi LspReferenceWrite cterm=bold ctermbg=DarkMagenta guibg=LightYellow
+ augroup lsp_document_highlight
+ autocmd! * <buffer>
+ autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()
+ autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()
+ augroup END
+ ]], false)
+ end
+end
+
+nvim_lsp.gopls.setup{
+ cmd = {'gopls'},
+ -- for postfix snippets and analyzers
+ capabilities = capabilities,
+ settings = {
+ gopls = {
+ experimentalPostfixCompletions = true,
+ analyses = {
+ unusedparams = true,
+ shadow = true,
+ },
+ staticcheck = true,
+ },
+ },
+ on_attach = on_attach,
+}
+
+ function goimports(timeoutms)
+ local context = { source = { organizeImports = true } }
+ vim.validate { context = { context, "t", true } }
+
+ local params = vim.lsp.util.make_range_params()
+ params.context = context
+
+ -- See the implementation of the textDocument/codeAction callback
+ -- (lua/vim/lsp/handler.lua) for how to do this properly.
+ local result = vim.lsp.buf_request_sync(0, "textDocument/codeAction", params, timeout_ms)
+ if not result or next(result) == nil then return end
+ local actions = result[1].result
+ if not actions then return end
+ local action = actions[1]
+
+ -- textDocument/codeAction can return either Command[] or CodeAction[]. If it
+ -- is a CodeAction, it can have either an edit, a command or both. Edits
+ -- should be executed first.
+ if action.edit or type(action.command) == "table" then
+ if action.edit then
+ vim.lsp.util.apply_workspace_edit(action.edit)
+ end
+ if type(action.command) == "table" then
+ vim.lsp.buf.execute_command(action.command)
+ end
+ else
+ vim.lsp.buf.execute_command(action)
+ end
+ end
+
+--vim.lsp.set_log_level("debug") \ No newline at end of file