dotfiles

Personal dotfiles
git clone https://git.bracken.jp/dotfiles.git
Log | Files | Refs | LICENSE

languages.lua (3793B)


      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 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   vim.lsp.config.sourcekit = 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     event = { "BufReadPre", "BufNewFile" },
     67     config = function()
     68       if vim.fn.executable('clangd') == 1 then
     69         vim.lsp.config.clangd = {}
     70       end
     71       if vim.fn.executable('lua-language-server') == 1 then
     72         vim.lsp.config.lua_ls = {}
     73       end
     74       if vim.fn.executable('rust-analyzer') == 1 then
     75         vim.lsp.config.rust_analyzer = {}
     76       end
     77       if vim.fn.executable('beancount-lsp') == 1 then
     78         vim.lsp.config.beancount = {
     79           init_options = {
     80             journal_file = (function()
     81               return vim.fn.findfile('main.beancount', '.')
     82             end)(),
     83           },
     84         }
     85       end
     86       if vim.fn.executable('sourcekit-lsp') == 1 then
     87         local cfg = create_sourcekit_cfg(sdk_map.iOS)
     88         vim.lsp.config.sourcekit = cfg
     89       end
     90       if vim.fn.executable('basedpyright-langserver') == 1 then
     91         vim.lsp.config.basedpyright = {
     92           settings = {
     93             basedpyright = {
     94               analysis = {
     95                 autoImportCompletions = true,
     96                 typeCheckingMode = "basic",
     97                 diagnosticMode = "openFilesOnly",
     98               },
     99             },
    100           },
    101         }
    102       end
    103 
    104       vim.api.nvim_create_autocmd("LspAttach", {
    105         group = vim.api.nvim_create_augroup("UserLspConfig", {}),
    106         callback = function(ev)
    107           local opts = { buffer = ev.buf, silent = true }
    108           opts.desc = "See available code actions"
    109           vim.keymap.set({"n", "v"}, "<leader>ca", vim.lsp.buf.code_action, opts)
    110           opts.desc = "Smart rename"
    111           vim.keymap.set("n", "<leader>cr", vim.lsp.buf.rename, opts)
    112           opts.desc = "Show documentation for what is under cursor"
    113           vim.keymap.set("n", "K", vim.lsp.buf.hover, opts)
    114           opts.desc = "Format buffer"
    115           vim.keymap.set("n", "<leader>F", vim.lsp.buf.format, opts)
    116         end,
    117       })
    118     end,
    119   },
    120   { "rhysd/vim-clang-format" },
    121   { "rust-lang/rust.vim" },
    122 }