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

Pre-populate variable name prompt with word under cursor if no variable can be found through treesitter #59

Closed
nobleach opened this issue Nov 2, 2023 · 8 comments · Fixed by #61
Labels
enhancement New feature or request

Comments

@nobleach
Copy link

nobleach commented Nov 2, 2023

Often I want to log something I am certain is a variable. For example, in Typescript:

export async function loader({ context, request }: LoaderArgs) {
  //-------------------------------^  This is a variable
  const config = ConfigProvider.getInstance('development').getConfig();
}

If I try to log either of those variables, I'm asked to enter a variable name. That's frustrating as I have to type it out. It defeats the purpose of having a quick keyboard shortcut.

If I select the word in visual mode, I can log it. But still, that's annoying.

Is there a way to say, "trust me, I KNOW this word is a variable, treat it as such"?

@andrewferrier
Copy link
Owner

andrewferrier commented Nov 2, 2023

@nobleach absolutely! In that particular case, one way that should work right now would be to use visual mode. Sitting on context, type viw to select the word, then g?v to print it.

Alternatively, you could use operator-pending mode: g?oiw.

However, I think your case is good, because Typescript is a commonly-used language, and we probably should pick up that word as a variable anyway. Let me keep this issue open and adopt it for that case.

@andrewferrier
Copy link
Owner

There's also another interesting idea here, which is that it would be good if the prompt for variable name was pre-populated with whatever's under the cursor (when debugprint cannot automatically detect it as a variable from Treesitter, which is what's happening today). So in fact I'll use this issue for that idea, and open another one for the Typescript-specific issue...

@andrewferrier andrewferrier changed the title Fallback to word under cursor even if TreeSitter doesn't think it's a variable Pre-populate variable name prompt with word under cursor if no variable can be found through treesitter Nov 2, 2023
@andrewferrier andrewferrier added the enhancement New feature or request label Nov 2, 2023
@nobleach
Copy link
Author

nobleach commented Nov 2, 2023

I think both are great ideas! A couple of years ago, I had written my own "smart console.log" in Lua just to take whatever was under the cursor and print this: console.log('<symbol>', <symbol>); on the following line. It was dumb but it was super useful in JavaScript. I found that I wanted it in other languages too. That's how I arrived at your fantastic plugin. The important thing though is the immediacy of doing something like <leader>c. If I have to type too many things, I lose the flow (yep - first world problems, right?). So even though I am doing viw g?v right now, it feels less than ideal.

@andrewferrier
Copy link
Owner

@nobleach yep, all fair points :) So I'll try and address both of these ideas and that should fix the problem for Typescript out-of-the-box, and give a better fallback for languages where Treesitter support doesn't exist yet.

@nobleach
Copy link
Author

nobleach commented Nov 2, 2023

Hey that's really cool. I know open source can seem thankless at times, so thank you for the work you're doing on this project!

@andrewferrier
Copy link
Owner

No problem! So this one - #59 - I've already pushed a fix for, so if you update to the top of the main branch you should find that now works, please let me know what you think.

#60 will take a bit longer, but feel free to track that issue for progress... :)

@nobleach
Copy link
Author

nobleach commented Nov 2, 2023

That's honestly the quickest turnaround I've ever seen. Thank you so very much for looking at it. I works great.

@andrewferrier
Copy link
Owner

No worries, you're welcome :)

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

Successfully merging a pull request may close this issue.

2 participants