before change to base lazy
This commit is contained in:
parent
c51b67a644
commit
3022b2eb12
6 changed files with 185 additions and 131 deletions
32
lua/custom/snips.lua
Normal file
32
lua/custom/snips.lua
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
local ls = require 'luasnip'
|
||||
local s = ls.snippet
|
||||
local t = ls.text_node
|
||||
local f = ls.function_node
|
||||
|
||||
-- Function to generate the namespace based on the file path
|
||||
local function generate_namespace()
|
||||
local file_path = vim.fn.expand '%:p:h' -- Get the file path of the current buffer
|
||||
-- Adjust 'src' or 'project_root' based on your directory structure
|
||||
local namespace = file_path:gsub('.*src[\\/]', ''):gsub('[\\/]', '.') -- Replace slashes with dots
|
||||
return 'namespace ' .. namespace
|
||||
end
|
||||
|
||||
-- Function to get the file name (without extension) as the class name
|
||||
local function get_class_name()
|
||||
return vim.fn.expand '%:t:r' -- Get the file name without the extension
|
||||
end
|
||||
|
||||
-- Snippet for C# class generation
|
||||
ls.add_snippets('cs', {
|
||||
s('myclass', { -- Updated the trigger from 'class' to 'myclass'
|
||||
-- Insert the namespace based on the file path
|
||||
f(generate_namespace, {}),
|
||||
t { '', '' }, -- Line break after namespace
|
||||
-- Generate class name based on file name
|
||||
t 'public class ',
|
||||
f(get_class_name, {}),
|
||||
t { '', '{', '\t' },
|
||||
ls.insert_node(0), -- Cursor here
|
||||
t { '', '}' }, -- End of class
|
||||
}),
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue