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

Add support for loading launch.json files #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,16 @@ require'telescope'.extensions.dap.list_breakpoints{}
require'telescope'.extensions.dap.variables{}
require'telescope'.extensions.dap.frames{}
```

## Launch.json support

`Telescope dap configurations` supports `launch.json` (as in VSCode). Any
configurations loaded from a `launch.json` file will be appended to the list
obtained from `dap.configurations`. See [VSCode
docs](https://code.visualstudio.com/docs/editor/debugging#_launch-configurations)
for `launch.json` format.

```viml
:Telescope dap configuration load_from_file=true " load configs from .vscode/launch.json
:Telescope dap configuration load_from_file=path/to/launch.json " load configs from path/to/launch.json
```
14 changes: 14 additions & 0 deletions lua/telescope/_extensions/dap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,20 @@ local configurations = function(opts)
end
end

if opts.load_from_file then
local path = type(opts.load_from_file) == 'string' and
opts.load_from_file or
'.vscode/launch.json'
if vim.fn.filereadable(path) == 1 then
local file = vim.fn.readfile(path)
local json = vim.fn.json_decode(file)
assert(json.configurations, "launch.json must have a 'configurations' key")
for _, config in ipairs(json.configurations) do
table.insert(results, config)
end
end
end

if vim.tbl_isempty(results) then
return
end
Expand Down