languages.lua (5897B)
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.enable('clangd') 71 end 72 if vim.fn.executable('lua-language-server') == 1 then 73 vim.lsp.enable('lua_ls') 74 end 75 if vim.fn.executable('zls') == 1 then 76 vim.lsp.enable('zls') 77 end 78 if vim.fn.executable('rust-analyzer') == 1 then 79 vim.lsp.enable('rust_analyzer') 80 end 81 if vim.fn.executable('beancount-language-server') == 1 then 82 vim.lsp.enable('beancount') 83 end 84 if vim.fn.executable('sourcekit-lsp') == 1 then 85 local cfg = create_sourcekit_cfg(sdk_map.iOS) 86 vim.lsp.config.sourcekit = cfg 87 vim.lsp.enable('sourcekit') 88 end 89 if vim.fn.executable('basedpyright-langserver') == 1 then 90 vim.lsp.enable('basedpyright') 91 end 92 if vim.fn.executable('markdown-oxide') == 1 then 93 vim.lsp.config('markdown_oxide', { 94 capabilities = vim.lsp.protocol.make_client_capabilities() 95 }) 96 vim.lsp.enable('markdown_oxide') 97 end 98 99 vim.api.nvim_create_autocmd("LspAttach", { 100 group = vim.api.nvim_create_augroup("UserLspConfig", {}), 101 callback = function(ev) 102 local opts = { buffer = ev.buf, silent = true } 103 104 -- Enable auto-completion if supported/enabled by the client. 105 local client = vim.lsp.get_client_by_id(ev.data.client_id) 106 if client and client:supports_method("textDocument/completion") then 107 vim.lsp.completion.enable(true, ev.data.client_id, ev.buf, { 108 autotrigger = false, 109 }) 110 end 111 112 opts.desc = "See available code actions" 113 vim.keymap.set({"n", "v"}, "<leader>ca", vim.lsp.buf.code_action, opts) 114 opts.desc = "Smart rename" 115 vim.keymap.set("n", "<leader>cr", vim.lsp.buf.rename, opts) 116 opts.desc = "Show documentation for what is under cursor" 117 vim.keymap.set("n", "K", vim.lsp.buf.hover, opts) 118 opts.desc = "Format buffer" 119 vim.keymap.set("n", "<leader>F", vim.lsp.buf.format, opts) 120 121 -- Setup markdown-oxide daily note command if attached. 122 if client and client.name == "markdown_oxide" then 123 vim.api.nvim_buf_create_user_command(ev.buf, "Daily", function(args) 124 local input = args.args 125 local arguments = {} 126 if input ~= "" then 127 arguments = { input } 128 end 129 client:exec_cmd({ command = "jump", arguments = arguments }, { bufnr = ev.buf }) 130 end, { desc = "Open daily note", nargs = "*" }) 131 end 132 end, 133 }) 134 end, 135 }, 136 { 137 "nvim-treesitter/nvim-treesitter", 138 build = ":TSUpdate", 139 init = function() 140 vim.api.nvim_create_autocmd("FileType", { 141 desc = "Automatically start Tree-sitter highlighting if a parser is available", 142 callback = function(args) 143 local lang = vim.treesitter.language.get_lang(args.match) 144 if not lang then return end 145 146 local ok, parser = pcall(vim.treesitter.get_parser, args.buf, lang) 147 if not ok or not parser then return end 148 149 vim.treesitter.start(args.buf, lang) 150 end, 151 }) 152 end, 153 config = function() 154 require("nvim-treesitter").install({ 155 -- Bash, C, C++, Markdown, Lua, Markdown, Python supported by default. 156 "rust", 157 "swift", 158 "zig", 159 }) 160 end, 161 }, 162 { 163 'MeanderingProgrammer/render-markdown.nvim', 164 -- dependencies = { 'nvim-treesitter/nvim-treesitter', 'nvim-mini/mini.nvim' }, -- if you use the mini.nvim suite 165 -- dependencies = { 'nvim-treesitter/nvim-treesitter', 'nvim-mini/mini.icons' }, -- if you use standalone mini plugins 166 -- dependencies = { 'nvim-treesitter/nvim-treesitter', 'nvim-tree/nvim-web-devicons' }, -- if you prefer nvim-web-devicons 167 ---@module 'render-markdown' 168 ---@type render.md.UserConfig 169 opts = {}, 170 } 171 } 172