Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql snippets not working #490

Open
mairs8 opened this issue Sep 16, 2024 · 2 comments
Open

sql snippets not working #490

mairs8 opened this issue Sep 16, 2024 · 2 comments
Labels
information and testing needs more information and testing

Comments

@mairs8
Copy link

mairs8 commented Sep 16, 2024

the wiki states that it includes sql snippets. However when i go into a .sql file and start typing, no snippets come up. In fact there is no completion box showing or anything. what could i be doing wrong? below is a snippet (pun intended) of my neovim config if it helps.

local cmp = require("cmp")
require("luasnip.loaders.from_vscode").lazy_load()
--require("luasnip").config.setup {} -- from https://youtu.be/Co7gcSvq6jA?list=PLko9chwSoP-2RxNuglpJriLO5HHXIcP6x&t=550

local luasnip = require 'luasnip'
luasnip.config.setup {}

cmp.setup({
  snippet = {
    expand = function(args)
      require("luasnip").lsp_expand(args.body)
    end,
  },
  window = {
    completion = cmp.config.window.bordered(),
    documentation = cmp.config.window.bordered(),
  },

  
  -- https://github.com/nvim-lua/kickstart.nvim/blob/master/init.lua
        -- For an understanding of why these mappings were
        -- chosen, you will need to read `:help ins-completion`
        --
        -- No, but seriously. Please read `:help ins-completion`, it is really good!
  mapping = cmp.mapping.preset.insert({
    --['<C-n>'] = cmp.mapping.select_next_item(), -- this is used to move down the menu when the window pops up.
    --['<C-p>'] = cmp.mapping.select_prev_item(),
    --["<C-b>"] = cmp.mapping.scroll_docs(-4), -- sometimes the snippet will be longer than window. This is used to scroll further down.
    --["<C-f>"] = cmp.mapping.scroll_docs(4),
    --["<C-Space>"] = cmp.mapping.complete(),
    --["<C-e>"] = cmp.mapping.abort(),
    --["<CR>"] = cmp.mapping.confirm({ select = true }),

          -- Select the [n]ext item
          ['<C-n>'] = cmp.mapping.select_next_item(),
          -- Select the [p]revious item
          ['<C-p>'] = cmp.mapping.select_prev_item(),

          -- Scroll the documentation window [b]ack / [f]orward
          ['<C-b>'] = cmp.mapping.scroll_docs(-4),
          ['<C-f>'] = cmp.mapping.scroll_docs(4),

          -- Accept ([y]es) the completion.
          --  This will auto-import if your LSP supports it.
          --  This will expand snippets if the LSP sent a snippet.
          ['<C-y>'] = cmp.mapping.confirm { select = true },

          -- If you prefer more traditional completion keymaps,
          -- you can uncomment the following lines
          --['<CR>'] = cmp.mapping.confirm { select = true },
          --['<Tab>'] = cmp.mapping.select_next_item(),
          --['<S-Tab>'] = cmp.mapping.select_prev_item(),

          -- Manually trigger a completion from nvim-cmp.
          --  Generally you don't need this, because nvim-cmp will display
          --  completions whenever it has completion options available.
          ['<C-Space>'] = cmp.mapping.complete {},

          -- Think of <c-l> as moving to the right of your snippet expansion.
          --  So if you have a snippet that's like:
          --  function $name($args)
          --    $body
          --  end
          --
          -- <c-l> will move you to the right of each of the expansion locations.
          -- <c-h> is similar, except moving you backwards.
          ['<C-l>'] = cmp.mapping(function()
            if luasnip.expand_or_locally_jumpable() then
              luasnip.expand_or_jump()
            end
          end, { 'i', 's' }),
          ['<C-h>'] = cmp.mapping(function()
            if luasnip.locally_jumpable(-1) then
              luasnip.jump(-1)
            end
          end, { 'i', 's' }),
  }),

  -- https://youtu.be/_DnmphIwnjo?t=537
  sources = cmp.config.sources(
    { 
      { name = "luasnip" }, 
      { name = "nvim_lsp" }, 
      { name = "path" } 
    },
    { 
      { name = "buffer" } 
    } --TODO can i move into above block
  ),
})

    -- https://github.com/hrsh7th/cmp-cmdline?tab=readme-ov-file#setup
    -- https://youtu.be/upM6FOtdLeU?t=239
    -- `/` cmdline setup.
    cmp.setup.cmdline('/', {
      mapping = cmp.mapping.preset.cmdline(),
      sources = {
        { name = 'buffer' }
      }
    })
        -- `:` cmdline setup.
        cmp.setup.cmdline(':', {
          mapping = cmp.mapping.preset.cmdline(),
          sources = cmp.config.sources({
            { name = 'path' }
          }, {
            {
              name = 'cmdline',
              option = {
                ignore_cmds = { 'Man', '!' }
              }
            }
          })
        })
require("luasnip.loaders.from_vscode").lazy_load()

-- https://www.youtube.com/watch?v=FmHhonPjvvA
local ls = require "luasnip"
local s = ls.snippet
local t = ls.text_node
local i = ls.insert_node

ls.add_snippets("lua", {
    s("hello", {
        t('print("hello world")'),
    })
})

ls.add_snippets("all", {
    s("lf", 
    { t('local $1 = function ($2)\n $0\nend'), }
    )
})


ls.snippets = {
    all = {
    -- Available in any filetype
    ls.parser.parse_snippet("expand", "-- this is what was expanded!"),
    },
}
@OkelleyDevelopment
Copy link
Collaborator

From the snippet it's not really possible to test the issue. In your config, do you source this repo like:

require("lazy").setup({
    { "nvim-lua/plenary.nvim", dev = false },
    -- snip
    {
        "L3MON4D3/LuaSnip",
        dependencies = { "rafamadriz/friendly-snippets" },
    },
    -- /snip
})

Based on the fact nothing shows, it seems like you might have not done this step. If you have let us know and someone is bound to be able to offer further assistance.

@OkelleyDevelopment
Copy link
Collaborator

@mairs8 any update?

@OkelleyDevelopment OkelleyDevelopment added the information and testing needs more information and testing label Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
information and testing needs more information and testing
Projects
None yet
Development

No branches or pull requests

2 participants