cursorless icon indicating copy to clipboard operation
cursorless copied to clipboard

Add language overrides for delimiter maps

Open fidgetingbits opened this issue 2 years ago • 8 comments

This is me breaking out some functionality that was part of PR #1911 since that PR has lots of work to be done and it may still benefit other languages that get in sooner. I've applied the suggested changes from pokey in that PR's code review.

I've also added a placeholder map for lua which uses [[ ]] for multiline support as noted in PR #1962, however I realized as I went to add it that it's not as simple as the way I did it for nix because I can't just reuse the existing singleQuote entry since lua actually uses single quotes. So this may actually be a bit harder, and reminds me of this discussion. So before I go randomly hacking stuff I'm curious what you think the best approach here is.

These are the comments I had left in the Nix PR about these changes:

  • I called returning delimiterToText as getSimpleDelimiterMap to kind of mirror complexDelimiterMap.

  • I'm not sure is if you still want a delimiterMap.ts standalone file, and then a getSimpleDelimiterMap.ts only for that function. Now delimiterToText isn't referenced anywhere else, so seemed maybe okay to keep them together.

  • I also thought about adding getComplexDelimiterMap(), but atm because complexDelimiterMap only ever uses the keys from the delimiterToText it won't change even if the language has different values, so seemed unnecessary. These are all things I could guess at your preferences, but may as well ask instead.

  • I also noticed leftToRightMap in that file isn't actually used anywhere so can be deleted I think, but also not sure about doing that as part of a totally unrelated code change, to keep commits clean.

Checklist

  • [_] I have added tests
  • [_] I have updated the docs and cheatsheet
  • [x] I have not broken the cheatsheet

fidgetingbits avatar Nov 09 '23 02:11 fidgetingbits

I would be tempted to introduce a new delimiter type for [[, and then make complex delimiter list customisable so you can include it

WDYT @AndreasArvidsson

pokey avatar Nov 09 '23 08:11 pokey

See https://github.com/cursorless-dev/cursorless/pull/1911#discussion_r1386549043 for a comment about some code from this PR.

fidgetingbits avatar Nov 13 '23 01:11 fidgetingbits

I would be tempted to introduce a new delimiter type for [[, and then make complex delimiter list customisable so you can include it

WDYT @AndreasArvidsson

I think I need a bit more info on your suggestion

AndreasArvidsson avatar Nov 13 '23 13:11 AndreasArvidsson

I would be tempted to introduce a new delimiter type for [[, and then make complex delimiter list customisable so you can include it WDYT @AndreasArvidsson

I think I need a bit more info on your suggestion

the problem is that in lua, [[ and ]] can be used as delimiters for a quote. So I'm proposing to add those as a new delimiter type doubleSquareBrackets. Then we'd need "string" to include those. "string" is defined as a complex delimiter string: ["singleQuotes", "doubleQuotes", "backtickQuotes"],, so we'd add doubleSquareBrackets to that list, but only for Lua.

One thing we'd need to think about is that that would cause [[foo]] to be viewed as a pair for our text-based matchers, and it wouldn't be considered a "square", which is probably not great. So we'd prob need a way for that pair not to be active outside of Lua

pokey avatar Nov 13 '23 13:11 pokey

I would be tempted to introduce a new delimiter type for [[, and then make complex delimiter list customisable so you can include it WDYT @AndreasArvidsson

I think I need a bit more info on your suggestion

the problem is that in lua, [[ and ]] can be used as delimiters for a quote. So I'm proposing to add those as a new delimiter type doubleSquareBrackets. Then we'd need "string" to include those. "string" is defined as a complex delimiter string: ["singleQuotes", "doubleQuotes", "backtickQuotes"],, so we'd add doubleSquareBrackets to that list, but only for Lua.

One thing we'd need to think about is that that would cause [[foo]] to be viewed as a pair for our text-based matchers, and it wouldn't be considered a "square", which is probably not great. So we'd prob need a way for that pair not to be active outside of Lua

I agree, but we still need to make square actually work of course.

AndreasArvidsson avatar Nov 14 '23 07:11 AndreasArvidsson

Ok @fidgetingbits I think we're in agreement. Lmk if you need help figuring out how to put the above to practice

pokey avatar Nov 14 '23 10:11 pokey

Ok @fidgetingbits I think we're in agreement. Lmk if you need help figuring out how to put the above to practice

Ya some guidance would be good, as much as I'd love to try to figure it out on my own. My typescript experience consists of what's in this PR. I suspect it would take me quite a long time to work out what to do.

fidgetingbits avatar Dec 15 '23 06:12 fidgetingbits

Ok I'll take this over when I get a minute

pokey avatar Dec 15 '23 14:12 pokey