-
Notifications
You must be signed in to change notification settings - Fork 4
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
directed_changes #18
base: master
Are you sure you want to change the base?
directed_changes #18
Conversation
Codecov Report
@@ Coverage Diff @@
## master #18 +/- ##
==========================================
- Coverage 31.70% 30.32% -1.38%
==========================================
Files 20 20
Lines 1782 1863 +81
==========================================
Hits 565 565
- Misses 1217 1298 +81
Continue to review full report at Codecov.
|
What exactly are the |
Co-authored-by: Matthias Seiffert <matthias-seiffert@hotmail.de>
I added some comments to clarify the function a little bit. I'm still not content with the naming, but "hints" or "identifier" should be a name for a source location. The best and most intuitive naming I could find for a source location is the identifier of the first variable the value is bound to. If the value is never bound to a name this might be empty. |
struct SuggestedSourceChange {
std::string hint;
std::shared_ptr<SourceChange> source_change;
}
Do we really need to insert the Also something to think about: There might be groups of source changes that should be applied together. E.g. x = 1
y = 2
z = x + y -- want to change z to 5 In this case we could do one of the following changes:
But of course this could be divided by arbitrarily tiny differences (e.g. |
The problem is that source changes are currently a tree of SourceAssignments with SourceChangeAnd and SourceChangeOr as inner nodes. Changing this to a list of alternatives would probably be possible but definitely a major change and in the worst case lead to exponentially? (in the number of literals in the program) increased size in memory. I agree that a proper type for the hint is needed (maybe the source has no textual representation etc) and a kind of iterator over the source change tree. It should support different heuristics to prioritize the alternatives (currently, it does a depth first search and chooses the first result). I like the concept of inserting $ operators into the program as this way, the choice of alternatives has no internal state. All state is explicit in the program (which is also one premise of the direct manipulation that is directly reflected in the code). The problem is, that $ completely removes the possibility from the source change tree so the previous alternative is not available anymore. I plan to change that in the future (maybe) using an alternative semantics to $ that does not delete the source location information but instead just marks the alternative as impossible to apply to the program. |
It already does only the first and second alternative, roughly like this:
which defaults to the first alternative SourceAssignment(1->3). Inserting $ before 1 results then results in:
defaulting to the second alternative SourceAssignment(2->4) |
What do you mean by internal state? You have source code and a source change and get new source code back. I don't see any internal state there. Or do you mean when you want to change the value multiple times (e.g. by dragging a line)? Then the GUI could simply save the location of the literal that should change and use that to select correct SourceChange the next time it wants to apply it. I'm not sure if this is currently possible. |
I want to choose the literal that is changed before the marker is moved. One way I could think of is using the cursor position in the editor as a way to specify which location should be changed if possible (here the cursor position is the state). Another way that is a context menu to choose the alternative. In this case I can either internally save which entry is currently chosen or I make this state explicit by inserting $.
Yes, I could save it in the GUI. But I don't like that I cannot save or see that. Another technical reason is that reexecuting the program invalidates most internal data structures so that I would have to match the chosen location to the new source locations somehow (I already have this problem using hints and the solutions are not very elegant). Perhaps tree-sitter solves this problem in the future. |
I feel like this is getting off-topic but for an easy to use GUI I would imagine something like:
Here the GUI needs to
|
Helper functions to choose an alternative between different possible SourceChanges. Used in development version of the interactive_script plugin.