dotfiles

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

languages.lua (4410B)


      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('rust-analyzer') == 1 then
     78         vim.lsp.config.rust_analyzer = {}
     79         vim.lsp.enable('rust_analyzer')
     80       end
     81       if vim.fn.executable('beancount-language-server') == 1 then
     82         vim.lsp.config.beancount = {
     83           cmd = { "beancount-language-server", "--stdio" },
     84           init_options = {
     85             journal_file = (function()
     86               -- Search upwards for main.beancount starting from the current working directory
     87               local file = vim.fn.findfile('main.beancount', '.;')
     88               if file ~= '' then
     89                 -- Expand the relative result into a full absolute path
     90                 return vim.fn.fnamemodify(file, ':p')
     91               end
     92               return ""
     93             end)(),
     94           },
     95         }
     96         vim.lsp.enable('beancount')
     97       end
     98       if vim.fn.executable('sourcekit-lsp') == 1 then
     99         local cfg = create_sourcekit_cfg(sdk_map.iOS)
    100         vim.lsp.config.sourcekit = cfg
    101         vim.lsp.enable('sourcekit')
    102       end
    103       if vim.fn.executable('basedpyright-langserver') == 1 then
    104         vim.lsp.config.basedpyright = {
    105           settings = {
    106             basedpyright = {
    107               analysis = {
    108                 autoImportCompletions = true,
    109                 typeCheckingMode = "basic",
    110                 diagnosticMode = "openFilesOnly",
    111               },
    112             },
    113           },
    114         }
    115         vim.lsp.enable('basedpyright')
    116       end
    117 
    118       vim.api.nvim_create_autocmd("LspAttach", {
    119         group = vim.api.nvim_create_augroup("UserLspConfig", {}),
    120         callback = function(ev)
    121           local opts = { buffer = ev.buf, silent = true }
    122           opts.desc = "See available code actions"
    123           vim.keymap.set({"n", "v"}, "<leader>ca", vim.lsp.buf.code_action, opts)
    124           opts.desc = "Smart rename"
    125           vim.keymap.set("n", "<leader>cr", vim.lsp.buf.rename, opts)
    126           opts.desc = "Show documentation for what is under cursor"
    127           vim.keymap.set("n", "K", vim.lsp.buf.hover, opts)
    128           opts.desc = "Format buffer"
    129           vim.keymap.set("n", "<leader>F", vim.lsp.buf.format, opts)
    130         end,
    131       })
    132     end,
    133   },
    134   { "rhysd/vim-clang-format" },
    135   { "rust-lang/rust.vim" },
    136 }