Guest User

Untitled

a guest
Jan 10th, 2025
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.67 KB | Software | 0 0
  1. require("config.lazy")
  2. require("config.vim-tree")
  3.  
  4. local lspconfig = require('lspconfig')
  5. local lsp_capabilities = require('cmp_nvim_lsp').default_capabilities()
  6.  
  7. lspconfig.lua_ls.setup{
  8.   settings = {
  9.        Lua = {
  10.         runtime = {
  11.             version = 'LuaJIT',
  12.         },
  13.         workspace = { checkThirdParty = true },
  14.         telemetry = { enable = false },
  15.         library = {
  16.               "${3rd}/love2d/library",
  17.         },
  18.         diagnostics = {
  19.             globals = { 'vim', 'table', 'love' },
  20.             disable = { "lowercase-global" }
  21.         },
  22.         capabilities = lsp_capabilities
  23.       }
  24. }}
  25.  
  26. vim.api.nvim_create_autocmd('LspAttach', {
  27.   desc = 'LSP Actions',
  28.   callback = function()
  29.     local bufmap = function(mode, lhs, rhs)
  30.       local opts = {buffer = true}
  31.       vim.keymap.set(mode, lhs, rhs, opts)
  32.     end
  33.  
  34.     -- Show documentation about hover keyword
  35.     bufmap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<cr>')
  36.  
  37.     -- Go to definition
  38.     bufmap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<cr>')
  39.  
  40.     -- Go to declaration
  41.     bufmap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<cr>')
  42.  
  43.     -- Show implementations
  44.     bufmap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<cr>')
  45.  
  46.     -- Go to type definition
  47.     bufmap('n', 'go', '<cmd>lua vim.lsp.buf.type_definition()<cr>')
  48.  
  49.     -- List references
  50.     bufmap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<cr>')
  51.  
  52.     -- Show function arguments
  53.     bufmap('n', 'gs', '<cmd>lua vim.lsp.buf.signature_help()<cr>')
  54.  
  55.     -- Rename symbol
  56.     bufmap('n', '<F2>', '<cmd>lua vim.lsp.buf.rename()<cr>')
  57.  
  58.     -- List "code actions" at the position
  59.     bufmap('n', '<F4>', '<cmd>lua vim.lsp.buf.code_action()<cr>')
  60.  
  61.     -- Show line diagnostics
  62.     bufmap('n', 'gl', '<cmd>lua vim.diagnostic.open_float()<cr>')
  63.  
  64.     -- Go to previous diagnostic
  65.     bufmap('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<cr>')
  66.  
  67.     -- Go to next diagnostic
  68.     bufmap('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<cr>')
  69.   end
  70. })
  71.  
  72.  
  73. -- Mic options
  74. vim.opt.completeopt = {'menu', 'menuone', 'noselect'}
  75. vim.opt.number = true
  76. vim.g.mapleader = ","
  77. -----tab width
  78. vim.opt.tabstop = 4
  79. vim.opt.shiftwidth = 4
  80. vim.opt.expandtab = true
  81.  
  82. -- CMP configuración
  83. local cmp = require('cmp')
  84. local luasnip = require('luasnip')
  85. local select_opts = {behavior = cmp.SelectBehavior.Select}
  86. cmp.setup({
  87.   snippet = {
  88.     expand = function(args)
  89.       luasnip.lsp_expand(args.body)
  90.     end
  91.   },
  92.   sources = {
  93.     {name = 'path'},
  94.     {name = 'nvim_lsp', keyword_length = 1},
  95.     {name = 'buffer', keyword_length = 3},
  96.     {name = 'luasnip', keyword_length = 2},
  97.   },
  98.   window = {
  99.     documentation = cmp.config.window.bordered()
  100.   },
  101. mapping = {
  102.    ['<Tab>'] = cmp.mapping.confirm({ select = true }),  -- Confirmar con <CR>
  103.   },
  104. })
  105.  
  106.  
  107. -- For LOVE2D
  108. local function run_love_in_new_terminal()
  109.     local current_dir = vim.fn.getcwd()
  110.     local command = "taskkill /f /im love.exe & start cmd.exe /c love " .. vim.fn.shellescape(current_dir) .. " --console"
  111.     print(command)
  112.     vim.fn.system(command)
  113. end
  114. vim.api.nvim_create_user_command(
  115.     "OpenLove",
  116.     run_love_in_new_terminal,
  117.     {}
  118. )
  119. -- Save and Run Love Project in the current dir
  120. vim.api.nvim_set_keymap('n', '<leader>l', ':w<CR>:OpenLove<CR>', { noremap = true, silent = true })
  121.  
  122. -- Open Tree
  123. vim.api.nvim_set_keymap('n', '<C-t>', ':NvimTreeToggle<CR>', { noremap = true, silent = true })
  124.  
  125. -- For reload config file (init.lua)
  126. vim.api.nvim_set_keymap('n', '<C-r>', ':so $MYVIMRC<CR>', { noremap = true, silent = true })
  127.  
  128. -- Colors scheme
  129. vim.opt.termguicolors = true
  130. vim.cmd.colorscheme('tokyonight')
  131.  
Tags: lua neovim love2d
Add Comment
Please, Sign In to add comment