[WIP] Support for graphviz dot
Hey @AndrewRadev
This is my initial version for graphviz dot support. While it works as intended for nodes that are variables (in most cases this holds), it lacks robustness against string node names which contain special characters. For instance, I started with split(line, ';') instead of using proper regular expressions. Thus a node identifier like"this, makes;-> problems" is not covered yet. However, what you typically do in dot is declaring nodes as variables where you can add any label once, instead of using it as the node identifier directly (which you would always have to repeat in edge definitions) e.g.:
X [label="some super complex label, and stuff; -> something"]
X -> A, B;
Splitjoin objects
- Multiple statements (
A -> B; X -> Y) - Multi-edges (
A -> B,C) - Chained (transitive) edges (
A -> B;\n B->C)
On splitting callbacks are issued top-down. On joining, bottom-up. ~~A possible improvement for the second and third case would be to also consider joining two statements on a single line (for now it only works if there is 1 statement per line in two consecutive lines).~~ Now, I included the case of joining two statements on a single line. Still, the behavior could be even more sensitive to cursor position (e.g. join statement 2 and 3 on one line if the cursor is in statement 2).
Two examples:
// Example 1
// Cursor on 'A'
A, B -> C -> D -> E; X -> Y;
// gS
A, B -> C -> D -> E;
X -> Y;
// gS
A, B -> C;
C -> D;
D -> E;
X -> Y;
// gS
A -> C;
B -> C;
C -> D;
D -> E;
X -> Y;
// gJ
A, B -> C;
C -> D;
D -> E;
X -> Y;
// gJ
A, B -> C -> D;
D -> E;
X -> Y;
// gJ
A, B -> C -> D -> E;
X -> Y;
// gJ
A, B -> C -> D -> E; X -> Y;
// Example 2
// Cursor on 'A'
A, B -> C, D;
// gS
A -> C;
A -> D;
B -> C;
B -> D;
// gJ
A -> C, D;
B -> C;
B -> D;
// jgJ
A -> C, D;
B -> C, D;
// kgJ
A, B -> C, D;
https://github.com/AndrewRadev/splitjoin.vim/issues/105
Why do checks fail after just dropping a single echo statement, whereas previous commits succeeded? Strange.
The tests seem to pass after rerunning the build. I saw something about some rust tests in the failure, so maybe there was an issue with TravisCI (I disabled the rust tests on travis, long story).
Anyway, the existing are fine, but I guess that's to be expected, it's support for a brand new thing. I'm going to write some tests for the new code soon, and I'll push them to this PR (since recently, github allows me to do that :)).
I've left some comments. In general, it looks great, and I really appreciate your work. You've definitely thought of a lot of cases :). It'll be easy to build a good test suite for the code.
We might have to restructure it, though. I pointed it out in one comment, that taking the line and working with just the string is usually not enough. More often than not, parsing the contents of the line requires working with the text in the buffer as much as possible, since the buffer text contains syntax information. I definitely think it's doable, though.
I'll see what I can do about the tests, I'm a bit busy these days, but I'll get more free time in a couple of weeks. If you run into issues, and/or are not sure how exactly to implement something, feel absolutely free to write a comment in the PR, ask me for advice, I might even implement it myself, if I can allocate the time.
Thanks. Where exactly can I find the comments you left in the code?
You can see them in this pull request. If you click on "files changed", you'll end up on this page: https://github.com/AndrewRadev/splitjoin.vim/pull/109/files. Scroll, and you'll see my comments inline in the diff.
Hmm, I still cannot access the review comments :cry:
Ugh, I guess it was my fault, sorry. Turns out, the comments were somehow batched, and I needed to "Submit review" to make them visible. I really didn't expect this. Might be some recent change in how github comments work.
Anyway, sorry about this, but they should be visible now.
I've added some test to the dot support, in order to exercise it. I've found one issue that I fixed, but I'm not sure about the other one. Basically, joining this doesn't seem to work correctly:
A, B -> C -> D;
D -> E;
The result seems to be:
A, B -> C -> D; D -> E;
The tests are in this commit, because I couldn't push them to the PR: https://github.com/AndrewRadev/splitjoin.vim/commit/8f61383a20e491b496aadfd52921e6f8139e4e29
Thanks. I merged the commit with the test cases and will continue working on the PR. :+1: