unisonweb / unison

A friendly programming language from the future
https://unison-lang.org
Other
5.75k stars 269 forks source link

feature: current branch shorthand in transcripts #5189

Open aryairani opened 3 months ago

aryairani commented 3 months ago

Is your feature request related to a problem? Please describe.

When I'm writing transcripts, typing .> at the start of each line was NBD, but typing scratch/main> at the start of each line is tedious and error-prone.

Describe the solution you'd like

  1. > defaults to the "current branch", which is scratch/main initially, but can be altered by other commands. the actual branch is shown in the output.md
  2. /branch or proj/branch> implicitly creates-empty and switches to /branch or proj/branch respectively; (this rule can be kept or we can get rid of it)
  3. > or /branch or project/branch> alone on a line is valid; the current branch or specified branch is shown in the output.md as well; (this is also optional, we could require explicit use of switch, but not clear why we would want to)

e.g.


Input:

```ucm
> ls
> branch.create foo
>
/bar>
other/other>

Output:
scratch/main> ls

  nothing to show

scratch/main> branch.create foo

  Done. I've created the foo branch based off of main.

  Tip: To merge your work back into the main branch, first `switch /main` then `merge /foo`.

scratch/foo>
scratch/bar>
other/other>


4. Currently we suppress the normal implicit branch creation output, but we could decide to include it in the output

**Describe alternatives you've considered**
I considered typing it once and copy/pasting, but it's still annoying and also not really practical to dedicate the system clipboard to this purpose while editing transcripts.

**Additional context**
aryairani commented 3 months ago

I can try and see if Copilot is good enough. Result: it does sort of work, but is also annoying.

ceedubs commented 2 months ago

There is some discussion (which I think probably should be linked to in Additional context) in #5173 in which @mitchellwrosen and I speculate that this short-hand wouldn't hold its weight.

aryairani commented 2 months ago

@ceedubs I don't understand if you have an opposition to the feature request? However, I apologize for cluttering/distracting the other ticket with it.

ceedubs commented 2 months ago

@aryairani right I am slightly opposed. In addition to the reasons listed in the other ticket, I fear it could mask issues. Like imagine that there was a regression and branch.create stopped automatically switching you to the new branch. I think that it would be better for our transcripts to explicitly specify that a certain branch is expected than to use the current branch which might not be the one that we intend.

Maybe it would be fine and I could just avoid using the shorthand if I don't trust myself to use it responsibly. But to me the additional complexity and potential for mistakes doesn't seem worth the benefit.

aryairani commented 2 months ago

Ah okay. Just to clarify, the there's never been a way to test that branch.create automatically switches you to the new branch, just like there has never been a way to test that cd would actually switch you to the specified namespace, because the next "prompt" in the input transcript overrides the current branch/namespace.

By leaving the prompt unspecified in the input, this proposed shorthand feature would give us the ability to test that for the first time.

ceedubs commented 2 months ago

@aryairani right I should clarify that I'm not comparing to the current state but to the proposal in #5173.

aryairani commented 2 months ago

I see, I had missed that.