languages.lua (3483B)
1 -- Sourcekit SDK map. 2 local sdk_map = { 3 iOS = { 4 platform = '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform', 5 path = '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk', 6 target = 'arm64-apple-ios13.0' 7 }, 8 macOS = { 9 platform = '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform', 10 path = '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk', 11 target = 'arm64-apple-macosx10.15' 12 } 13 } 14 -- Returns the sourcekit config for the specified SDK. 15 local function create_sourcekit_cfg(sdk) 16 local sourcekit_lsp_config = { 17 cmd = { 18 'sourcekit-lsp', 19 '-Xswiftc', 20 '-sdk', 21 '-Xswiftc', 22 sdk.path, 23 '-Xswiftc', 24 '-target', 25 '-Xswiftc', 26 sdk.target, 27 '-Xswiftc', 28 '-I' .. sdk.platform .. '/Developer/usr/lib', 29 '-Xswiftc', 30 '-F' .. sdk.platform .. '/Developer/Library/Frameworks', 31 }, 32 capabilities = { 33 workspace = { 34 didChangeWatchedFiles = { 35 dynamicRegistration = true, 36 }, 37 }, 38 }, 39 } 40 return sourcekit_lsp_config 41 end 42 43 -- UseIosSdk: configures sourcekit for iOS development. 44 vim.api.nvim_create_user_command('UseIosSdk', function() 45 local cfg = create_sourcekit_cfg(sdk_map.iOS) 46 require'lspconfig'.sourcekit.setup(cfg) 47 end, {}) 48 49 -- UseMacosSdk: configures sourcekit for macOS development. 50 vim.api.nvim_create_user_command('UseMacosSdk', function() 51 local cfg = create_sourcekit_cfg(sdk_map.macOS) 52 require'lspconfig'.sourcekit.setup(cfg) 53 end, {}) 54 55 return { 56 { 57 "https://gn.googlesource.com/gn", 58 opts = {}, 59 config = function(plugin) 60 vim.opt.rtp:append(plugin.dir .. "/misc/vim") 61 end 62 }, 63 { "nathangrigg/vim-beancount" }, 64 { 65 "neovim/nvim-lspconfig", 66 opts = {}, 67 event = { "BufReadPre", "BufNewFile" }, 68 config = function() 69 local lspconfig = require('lspconfig') 70 if vim.fn.executable('clangd') == 1 then 71 lspconfig.clangd.setup({}) 72 end 73 if vim.fn.executable('lua-language-server') == 1 then 74 lspconfig.lua_ls.setup({}) 75 end 76 if vim.fn.executable('rust-analyzer') == 1 then 77 lspconfig.rust_analyzer.setup({}) 78 end 79 if vim.fn.executable('beancount-lsp') == 1 then 80 lspconfig.beancount.setup({ 81 init_options = { 82 journal_file = (function() 83 return vim.fn.findfile('main.beancount', '.') 84 end)(), 85 }, 86 }) 87 end 88 if vim.fn.executable('sourcekit-lsp') == 1 then 89 local cfg = create_sourcekit_cfg(sdk_map.iOS) 90 lspconfig.sourcekit.setup(cfg) 91 end 92 93 vim.api.nvim_create_autocmd("LspAttach", { 94 group = vim.api.nvim_create_augroup("UserLspConfig", {}), 95 callback = function(ev) 96 local opts = { buffer = ev.buf, silent = true } 97 opts.desc = "See available code actions" 98 vim.keymap.set({"n", "v"}, "<leader>ca", vim.lsp.buf.code_action, opts) 99 opts.desc = "Smart rename" 100 vim.keymap.set("n", "<leader>cr", vim.lsp.buf.rename, opts) 101 opts.desc = "Show documentation for what is under cursor" 102 vim.keymap.set("n", "K", vim.lsp.buf.hover, opts) 103 opts.desc = "Format buffer" 104 vim.keymap.set("n", "<leader>F", vim.lsp.buf.format, opts) 105 end, 106 }) 107 end, 108 }, 109 { "rhysd/vim-clang-format" }, 110 { "rust-lang/rust.vim" }, 111 }