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

[Feature] add input dialog to dapui.eval() #139

Closed
VisionaryAppDev opened this issue Sep 18, 2022 · 14 comments
Closed

[Feature] add input dialog to dapui.eval() #139

VisionaryAppDev opened this issue Sep 18, 2022 · 14 comments

Comments

@VisionaryAppDev
Copy link

Hello @rcarriga,

When calling lua require("dapui").eval(), could we have the statement at cursor or highlighted expression shown above the result windows as an input text? So, we could further testing and evaluating the expression just like in the Intellij?

For example, I have highlighted list variable and then executing lua require("dapui").eval() to see and understand the data. After that, I wanted to filter the item that is greater than 3 and count back the result. So, if there is an input above the result window, I could just append the expression as list.filter(data -> data > 3).toList().size() without the need to write it into my project file and then calling dapui.eval() again. Doing so save a lot of time and hassle when we need to evaluate multiple expression while testing logic and debugging.

intellij-eval-expression-sample.mp4
@rcarriga
Copy link
Owner

I'd say this more of role for the REPL or watch expressions. nvim-dap-ui doesn't aim to cover as many use cases as Intellij does, instead allowing for easy extensibility.

If you do want to use the hover, you could write a wrapper using vim.ui.input

function()
  vim.ui.input({ prompt = "> " }, function(expr)
    dapui.eval(expr)
  end)
end,

Of course you can extra features like remembering the last expression, defaulting to the current word on no input.
You can use the same method that dapui uses to do this (the util function is technically not public but it hasn't changed since written and won't be anytime soon)

  if not expr then
    if vim.fn.mode() == "v" then
      local start = vim.fn.getpos("v")
      local finish = vim.fn.getpos(".")
      local lines = require("dapui.util").get_selection(start, finish)
      expr = table.concat(lines, "\n")
    else
      expr = expr or vim.fn.expand("<cexpr>")
    end
  end

@VisionaryAppDev
Copy link
Author

I find adding input box above require("dapui").eval() is quite challenging and haven't found any related document and solution yet. So, could you share some idea and how did you get your UI done in the first place? So I could try creating my own as well.

@rcarriga
Copy link
Owner

On thinking about this more, the hover edit mapping makes more sense to edit the expression text rather than setting the value of the expression. I've updated the hover element so now you can use the edit mapping to edit the expression and it will update the displayed value

rcarriga added a commit that referenced this issue Sep 22, 2022
BREAKING CHANGE: Previously the edit mapping would edit the value of the
expression being evaluated. In the context of a hover this makes less
sense and is far less likely to be the use case than changing what is
being evaluated.

See #139
@VisionaryAppDev
Copy link
Author

Hello @rcarriga,

use the edit mapping to edit the expression

Could you explain this a bit more? Couldn't figure out what you mean.

@rcarriga
Copy link
Owner

The edit mapping e by default will allow you to edit the expression. So when you enter the hover window, press e and type whatever new expression you want

@VisionaryAppDev
Copy link
Author

I have tried it and now I could edit the expression. But, there are some enhancement needed.

  • When press e to edit the expression, the original expression should be shown up instead of the result. Like in the video, instead of showing ArrayList@27 size=5, list should be shown instead because we want to further evaluate the expression not the result.
  • When I tried to evaluate other expression using e, they doesn't seem to work at all. As message shown at the bottom Debug server doesn't support setting list.
  • Input box should always be there by default instead of the need to press e because when debugging the code, we want to evaluate and evaluate lot of expression in other to learn and understand what is going on. If we always need to press e after submit the expression, it may be too much overwhelming.
tesing-video.mp4

@rcarriga
Copy link
Owner

You haven't updated your nvim-dap-ui, that's the old version

Input box should always be there by default instead of the need to press e because when debugging the code, we want to evaluate and evaluate lot of expression in other to learn and understand what is going on. If we always need to press e after submit the expression, it may be too much overwhelming.

You'd have to press i to enter insert mode anyway so I don't see the problem here

@VisionaryAppDev
Copy link
Author

You haven't updated your nvim-dap-ui, that's the old version

Sorry, my bad.

Btw, I have updated to the latest version now and tried again and found there is some question, and issue:

  • e works only if my cursor is at the top. Otherwise, result will be placed inside the input text instead of the expression. (Please see in the video)
  • Is there a shortcut/binding to get my cursor focus on the hover result other than using mouse click?
  • Could we have the auto completion inside the input text as well?
test-video.mp4

@VisionaryAppDev
Copy link
Author

Could we have the auto completion inside the input text as well?

Seem like this one can be added by adding dapui_hover buffer type into cmp-dap configuration. I have create a merge request that will add this option to the readme. So, please check it out.

@rcarriga
Copy link
Owner

e works only if my cursor is at the top. Otherwise, result will be placed inside the input text instead of the expression. (Please see in the video)

That's just how the window works. It allows you to edit the value of properties of the value. You can just press gg to jump to the top of the window. You could map this to do it one key by using an autocmd au FileType dapui_hover nmap <buffer> E gge

Is there a shortcut/binding to get my cursor focus on the hover result other than using mouse click?

Calling eval again with the same expression or passing enter = true to the eval function (see :h dapui.eval())

@VisionaryAppDev
Copy link
Author

It allows you to edit the value of properties of the value.

For example, If I have a list of number that contains value [1, 10, 3, 4, 5]. Then when I press e on the second item which is 10 in this case. Then I edit value to 2 and press Enter. So, does it mean that the value will become 2, Is that correct?

@rcarriga
Copy link
Owner

Yes correct though the adapter must support it

@VisionaryAppDev
Copy link
Author

Thanks @rcarriga for your time and response. I've bought you a cup of coffee so hopefully you will enjoy it.

@rcarriga
Copy link
Owner

Much appreciated, thank you 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants