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

Get span of each item #19

Open
HKalbasi opened this issue May 22, 2024 · 4 comments
Open

Get span of each item #19

HKalbasi opened this issue May 22, 2024 · 4 comments

Comments

@HKalbasi
Copy link

I need this to detect which item the cursor is in it. Would you accept a PR for this functionality?

@comex
Copy link
Owner

comex commented Dec 25, 2024

Sorry for my inattention to this repo. I happened to notice this when visiting the issue tracker due to another issue that was just opened. If you’re still interested, I’m willing to review PRs. Maybe this can be combined with the other two parsing feature requests (#9 and #13) into a more featureful lower-level API?

(@fenhl, I’ll make sure not to do anything without your input, unless you’re not available. Of course, this can wait until after the holidays. I’m just responding today because that’s when I noticed this.)

@fenhl
Copy link
Collaborator

fenhl commented Dec 25, 2024

That sounds like a good idea.

@HKalbasi
Copy link
Author

I honestly don't remember exactly why I needed this. It was probably for my crate clap-repl to detect the cursor position for auto complete, but it seems now auto complete is working even when cursor is in the middle of the line, so maybe this was a XY problem and I didn't really need this.

@HKalbasi
Copy link
Author

I looked at my code and found that I worked around the problem by trimming the input to the cursor position. That is, to detect the word position of the cursor in this example:

some             command --foo x                --bar --baz
                                         ^

We can parse the trimmed version using shlex:

some             command --f
                                         ^

and the number of tokens (in this case, 3) is the answer.

Although my original problem is solved, I still think there is some utility in returning the spans in a more featureful parsing api, and most of the other parsing libraries have such a api.

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

3 participants