Skip to content

Commit

Permalink
Fill new .vscode/launch.json using vim.snippet
Browse files Browse the repository at this point in the history
  • Loading branch information
mfussenegger committed Dec 5, 2024
1 parent d1d55d8 commit 242598c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 14 deletions.
36 changes: 36 additions & 0 deletions lua/dap/_cmds.lua
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,40 @@ function M.bufread_eval()
end


---@param args vim.api.keyset.create_autocmd.callback_args
function M.newlaunchjson(args)
if vim.snippet then
local text = [[{
"\$schema": "https://raw.githubusercontent.com/mfussenegger/dapconfig-schema/master/dapconfig-schema.json",
"version": "0.2.0",
"configurations": [
{
"type": "${1:adaptername}",
"request": "${2|launch,request|}",
"name": "${3:run}"${0}
}
]
}]]
api.nvim_buf_call(args.buf, function()
vim.snippet.expand(text)
end)
else
local lines = {
'{',
' "$schema": "https://raw.githubusercontent.com/mfussenegger/dapconfig-schema/master/dapconfig-schema.json",',
' "version": "0.2.0",',
' "configurations": [',
' {',
' "type": "<adapter-name>",',
' "request": "launch",',
' "name": "Launch"',
' }',
' ]',
'}'
}
api.nvim_buf_set_lines(args.buf, 0, -1, true, lines)
end
end


return M
15 changes: 1 addition & 14 deletions plugin/dap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,7 @@ if api.nvim_create_autocmd then
group = launchjson_group,
pattern = pattern,
callback = function(args)
local lines = {
'{',
' "$schema": "https://raw.githubusercontent.com/mfussenegger/dapconfig-schema/master/dapconfig-schema.json",',
' "version": "0.2.0",',
' "configurations": [',
' {',
' "type": "<adapter-name>",',
' "request": "launch",',
' "name": "Launch"',
' }',
' ]',
'}'
}
api.nvim_buf_set_lines(args.buf, 0, -1, true, lines)
require("dap._cmds").newlaunchjson(args)
end
})

Expand Down

0 comments on commit 242598c

Please sign in to comment.