-
-
Notifications
You must be signed in to change notification settings - Fork 223
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
Wip/add comment string when clauses #1030
Wip/add comment string when clauses #1030
Conversation
Thanks for taking the time on this! I just requested a few small changes, but I also think this code should probably be moved out of |
Thanks - I'll make those changes here (sorry for the clumsy leavings!), but presumably forestall refreshing the PR 'till we hear back from Pez on the structure issue. |
Oops. Pushed to my fork on autopilot. Anyway, those minor changes done. |
Please keep pushing to your fork. We'll treat this as WIP until it's done and it is much easier if we all can look at and test the same thing. |
Yep it's all up to date with @bpringe's requested change |
Looks good to me. The only thing that had me thinking was the
This second thing then touches the name of the context. I see two ways to deal with it:
Option 2 would allow to create keybindings that use structural behaviour in one direction and plain text behaviour in the other direction. Option 1 leaves option 2 open so I would pull this PR regardless which option you choose. I think a good place to put this code is in a file at the root named Once we have this in its own module we can get a bit fancier in future PRs. 😄 I've previously been a bit frustrated that I can't read the contexts from the code. So been thinking that maybe some Virtual DOM inspired approach would make sense. But that's for later! Haha. |
A few thoughts about the above @PEZ
As I say, quite happy to revise any of that if you disagree, but I've pushed as-is so you can have a look. |
Sorry for late reply. This PR is going to make Calva a lot better, I think. About the |a|(= (deref an-atom)
@an-atom|b|)|c|
|d|;; It's a common mistake to forget to|e| deref|f|
[g|(|h|first an-atom)|i|
(first @an-atom) I just made up a syntax where there are cursor positions,
I don't have the time to test this build right now, but I think that it won't allow us to create this behaviour. I do think I know a much less messy way (than my last idea) to achieve it. I could be wrong, but my hunch says that if we have the contexts FYI, there is a property on the cursor named |
This should be covered with some unit tests, I think. To make that possible we need for the functions under test do not require vscode knowledge, and even live in a module that does not import vscode. Without browsing the code base I am not sure what it entails. But if the non-vscode parts of this lives in the cursor-doc folder. I think the context-figuring functions should work an something implementing |
@PEZ - thanks for spending the time to think that through. I think your I find it hard to think comprehensively about this kind of thing in the abstract so I'll implement your approach here & try using it in working on some clojure stuff later today. On unit tests - I haven't had a look through your existing test suite yet. Will do soon & then I'll take note of your comments here. |
(That commit's not quite working as expected yet - still a wip) |
src/cursor-doc/token-cursor.ts
Outdated
@@ -676,7 +676,7 @@ export class LispTokenCursor extends TokenCursor { | |||
withinComment() { | |||
const cursor = this.clone(); | |||
const token_type = cursor.getToken().type; | |||
return token_type === 'comment' || (token_type === 'eol' && cursor.getPrevToken().type === 'comment'); | |||
return token_type === 'comment'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it that either the token or the previous token is comment maybe? So both |a|
and |b|
here would be inComment:
|a|;; foo|b|<nl>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My mistake - misinterpretation of what we had decided.
Excuse my absence here - I haven't forgotten about this. I'll be back to it sometime this week. |
Sorry it took a while to get back to this. It's still a wip. 2 remaining issues in addition to anything you spot:
|
- some keybinds might require conditions like (calva:cursorInString && !calva:CursorAtEndOfLine), but VSCode API currently doesn't allow parentheses in where clauses (microsoft/vscode#91473) - so add preconfigured compounds where convenient
I've added a POC of this - it adds 2 'compound' where clauses, {
"key": "ctrl+left",
"command": "paredit.backwardSexp",
"when": "calva:keybindingsEnabled && editorTextFocus && editorLangId == 'clojure' && paredit:keyMap =~ /original|strict/ && !calva:cursorInCommentExcludingSOL"
},
{
"key": "ctrl+left",
"command": "-paredit.backwardSexp",
"when": "calva:keybindingsEnabled && editorTextFocus && editorLangId == 'clojure' && paredit:keyMap =~ /original|strict/"
},
{
"key": "ctrl+right",
"command": "paredit.forwardSexp",
"when": "calva:keybindingsEnabled && editorTextFocus && editorLangId == 'clojure' && paredit:keyMap =~ /original|strict/ && !calva:cursorInCommentExcludingEOL"
},
{
"key": "ctrl+right",
"command": "-paredit.forwardSexp",
"when": "calva:keybindingsEnabled && editorTextFocus && editorLangId == 'clojure' && paredit:keyMap =~ /original|strict/"
}, I haven't been doing much clojure lately so this is imperfectly tested as yet. |
Looks great. I will be testing it today. I'm starting to think the default key bindings should be like the examples you have there. |
Whoo, feels great! There are two quirky things I notice
I'll be testing this further today, as I am writing my dram thing mostly in comments I happen to be the perfect tester. 😄 |
Thanks for checking that out @PEZ . I had the same reaction re your 2nd point. It's all a bit semantically weird really -in effect kind of jumping between different languages. I haven't played around with the results much yet, but there's scope for using the new contexts with other keybindings (deletes etc). Anyway let me know what else you come up with. I should be able to have a crack at some fixes/changes Mon and/or Tue. |
Yeah, totally interesting problem with the two languages. I like that with your work here we stop just ignoring that there are languages within the language, even if we'll have some boundary cases left (like my first observation above). Also agree that the contexts will be of broader use. I've already added that for deletion on my branch. Btw, if I push that branch, will you be able to use that then? I've resolved the merge conflicts too. Might just try it and see what happens. Apologies in advance if it messes things up for you. |
Seems it just became a regular branch. You can pull it in, if you like: https://github.com/BetterThanTomorrow/calva/tree/crispinb-wip/add-comment-string-when-clauses |
I just came across this (again?) recently. Glad we have this work being done by @crispinb! |
I can pick this up from here if you have run out of time to spend on it, @crispinb . It seems close to finished and it is good stuff! |
Hey @PEZ - I did drop the ball a bit there (apologies - I don't want to be the annoying disappearing contributor). I won't get back to it for at least a week so please feel free if you have the time & inclination. If you do I'll see if there's something else I can pick up. Either way works for me. |
Haha, don't worry. You are not an annoying contributor just because you have a life. 😄 We'll see what the week brings. Today I realised I need your changes for fixing an issue, so if I find myself fixing that issue I will first finish this work. You'll see when you come back if the work is still waiting for you. |
What has Changed?
extensions.ts
, called from onDidChangeTextEditorSelection & onDidChangeActiveTextEditor subscriptionsFixes ##1023
My Calva PR Checklist
I have:
dev
branch. (Or have specific reasons to target some other branch.)published
. (Sorry for the nagging.)[Unreleased]
entry inCHANGELOG.md
, linking the issue(s) that the PR is addressing.The Calva Team PR Checklist:
Before merging we (at least one of us) have:
dev
branch (unless reasons).Ping @PEZ, @kstehn, @cfehse, @bpringe