languages.lua (3196B)
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('dart') == 1 then 74 lspconfig.dartls.setup({}) 75 end 76 if vim.fn.executable('lua-language-server') == 1 then 77 lspconfig.lua_ls.setup({}) 78 end 79 if vim.fn.executable('rust-analyzer') == 1 then 80 lspconfig.rust_analyzer.setup({}) 81 end 82 if vim.fn.executable('sourcekit-lsp') == 1 then 83 local cfg = create_sourcekit_cfg(sdk_map.iOS) 84 lspconfig.sourcekit.setup(cfg) 85 end 86 87 vim.api.nvim_create_autocmd("LspAttach", { 88 group = vim.api.nvim_create_augroup("UserLspConfig", {}), 89 callback = function(ev) 90 local opts = { buffer = ev.buf, silent = true } 91 opts.desc = "See available code actions" 92 vim.keymap.set({"n", "v"}, "<leader>ca", vim.lsp.buf.code_action, opts) 93 opts.desc = "Smart rename" 94 vim.keymap.set("n", "<leader>cr", vim.lsp.buf.rename, opts) 95 opts.desc = "Show documentation for what is under cursor" 96 vim.keymap.set("n", "K", vim.lsp.buf.hover, opts) 97 end, 98 }) 99 end, 100 }, 101 { "rhysd/vim-clang-format" }, 102 { "rust-lang/rust.vim" }, 103 }