languages.lua (4551B)
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 vim.lsp.config.sourcekit = cfg 47 vim.lsp.enable('sourcekit') 48 end, {}) 49 50 -- UseMacosSdk: configures sourcekit for macOS development. 51 vim.api.nvim_create_user_command('UseMacosSdk', function() 52 local cfg = create_sourcekit_cfg(sdk_map.macOS) 53 vim.lsp.config.sourcekit = cfg 54 vim.lsp.enable('sourcekit') 55 end, {}) 56 57 return { 58 { 59 "https://gn.googlesource.com/gn", 60 opts = {}, 61 config = function(plugin) 62 vim.opt.rtp:append(plugin.dir .. "/misc/vim") 63 end 64 }, 65 { 66 "neovim/nvim-lspconfig", 67 event = { "BufReadPre", "BufNewFile" }, 68 config = function() 69 if vim.fn.executable('clangd') == 1 then 70 vim.lsp.config.clangd = {} 71 vim.lsp.enable('clangd') 72 end 73 if vim.fn.executable('lua-language-server') == 1 then 74 vim.lsp.config.lua_ls = {} 75 vim.lsp.enable('lua_ls') 76 end 77 if vim.fn.executable('zls') == 1 then 78 vim.lsp.config.zls = {} 79 vim.lsp.enable('zls') 80 end 81 if vim.fn.executable('rust-analyzer') == 1 then 82 vim.lsp.config.rust_analyzer = {} 83 vim.lsp.enable('rust_analyzer') 84 end 85 if vim.fn.executable('beancount-language-server') == 1 then 86 vim.lsp.config.beancount = { 87 cmd = { "beancount-language-server", "--stdio" }, 88 init_options = { 89 journal_file = (function() 90 -- Search upwards for main.beancount starting from the current working directory 91 local file = vim.fn.findfile('main.beancount', '.;') 92 if file ~= '' then 93 -- Expand the relative result into a full absolute path 94 return vim.fn.fnamemodify(file, ':p') 95 end 96 return "" 97 end)(), 98 }, 99 } 100 vim.lsp.enable('beancount') 101 end 102 if vim.fn.executable('sourcekit-lsp') == 1 then 103 local cfg = create_sourcekit_cfg(sdk_map.iOS) 104 vim.lsp.config.sourcekit = cfg 105 vim.lsp.enable('sourcekit') 106 end 107 if vim.fn.executable('basedpyright-langserver') == 1 then 108 vim.lsp.config.basedpyright = { 109 settings = { 110 basedpyright = { 111 analysis = { 112 autoImportCompletions = true, 113 typeCheckingMode = "basic", 114 diagnosticMode = "openFilesOnly", 115 }, 116 }, 117 }, 118 } 119 vim.lsp.enable('basedpyright') 120 end 121 122 vim.api.nvim_create_autocmd("LspAttach", { 123 group = vim.api.nvim_create_augroup("UserLspConfig", {}), 124 callback = function(ev) 125 local opts = { buffer = ev.buf, silent = true } 126 opts.desc = "See available code actions" 127 vim.keymap.set({"n", "v"}, "<leader>ca", vim.lsp.buf.code_action, opts) 128 opts.desc = "Smart rename" 129 vim.keymap.set("n", "<leader>cr", vim.lsp.buf.rename, opts) 130 opts.desc = "Show documentation for what is under cursor" 131 vim.keymap.set("n", "K", vim.lsp.buf.hover, opts) 132 opts.desc = "Format buffer" 133 vim.keymap.set("n", "<leader>F", vim.lsp.buf.format, opts) 134 end, 135 }) 136 end, 137 }, 138 { "rhysd/vim-clang-format" }, 139 { "rust-lang/rust.vim" }, 140 { "ziglang/zig.vim" }, 141 }