Skip to content

Commit

Permalink
fix(nvim_snippets): cannot expand snippet on indented line (#240)
Browse files Browse the repository at this point in the history
  • Loading branch information
przepompownia authored Jan 14, 2025
1 parent eec6019 commit 487bc70
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lua/null-ls/builtins/completion/nvim_snippets.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ local methods = require("null-ls.methods")
local COMPLETION = methods.internal.COMPLETION

-- based on pattern from cmp-luasnip
local pattern = "\\%([^[:alnum:][:blank:]]\\+\\|\\w\\+\\)"
local regex = vim.regex([[\%(]] .. pattern .. [[\)\m$]])
local regex = vim.regex([===[\%(\%([^[:alnum:][:blank:]]\+\|\w\+\)\)\m$]===])

local function nvim_snippet_exists()
local status, _ = pcall(require, "snippets")
Expand Down Expand Up @@ -43,10 +42,12 @@ return h.make_builtin({
return
end

local prefix = vim.trim(line_to_cursor:sub(start_col))
local items = {}
local snippets = get_loaded_snippets(params.filetype)

for _, item in pairs(snippets) do
if vim.startswith(item.prefix, line_to_cursor:sub(start_col)) then
if vim.startswith(item.prefix, prefix) then
local insertText = (type(item.body) == "table") and table.concat(item.body, "\n") or item.body
local textEdit = {
range = {
Expand Down

0 comments on commit 487bc70

Please sign in to comment.