-
-
Notifications
You must be signed in to change notification settings - Fork 217
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
notebook markdown comments #1828
base: dev
Are you sure you want to change the base?
Conversation
So this is my experiment to get markdown comments working. Turns out parsing Clojure can still be pretty difficult in certain edge cases. |
Can you summarize the need for parsing a bit? Where in the process does it happen, how often, etcetera. I'm thinking we are already doing parsing of the document and want to reason around wether that parsing can be used as is, or be augmented. |
What we currently need is not super difficult, I think I'm just being stubborn and wanting to do it the functional, Clojure way, which is more difficult in JS. (def hover-map
{:stuff "in-here"
:ohter "yeah"
;; Yada yada
:deeper {:a 1, "foo" :bar, [1 2 3] (vec (range 2000))}})
;; Line comment, line 1
;;
;; Line comment, line 2
(defn foo []
(println "bar")) I would want something like this as output: [{
value: "(def hover-map\n {:stuff \"in-here\"\n :ohter \"yeah\"\n ;; Yada yada\n :deeper {:a 1, \"foo\" :bar, [1 2 3] (vec (range 2000))}})",
kind: vscode.NotebookCellKind.Code,
languageId: 'clojure',
metadata: { endingWhitespace: '\n\n' },
},
{
value: "Line comment, line 1\n \n Line comment, line 2 ",
kind: vscode.NotebookCellKind.Markup,
languageId: 'markdown',
metadata: { asMarkdown: true, endingWhitespace: '\n'},
},
{
value: "(defn foo []\n (println \"bar\"))",
kind: vscode.NotebookCellKind.Code,
languageId: 'clojure',
metadata: { endingWhitespace: '\n'},
}] I can mostly get there already as you can see with this PR, but there are a lot of edge cases and then I will probably have to do some look-ahead or backtracking to move newlines/whitespace to the correct cell. |
Sorry for late reply, I somehow missed that there was new info here! Thanks for elaborating. Together with the code, I am starting to understand the nature of the problem now. (I think.)
I'm not totally against using cljs. Though, it would mean that this category of code would be solved in two different ways, with possibly different nuances in how they deal with details/edge cases. I think we're risking causing confusion for ourselves and for the users. Also, the problem seems like a quite perfect fit for the Token Cursor. Assuming we use the Token Cursor and build on the approach you have started with (top level clojure ranges interpolated with non-clojure), maybe the convention could be that all consecutive blocks of lines starting with
When converting notebook blocks to text:
I.e. very much like what is done already, just the extra blocks created by the partitioning and the removal/adding of Does this make sense? |
Yeah after playing with rich comments a bit I think the cursor should be enough, just feels strange to do "state" things 😅 |
94eca88
to
7fcc022
Compare
I've changed this to use the cursor directly. I still need to keep track of lines without the |
Are we, though? Sure, the Token Cursor is a very stateful creature, but in this case we are more inspecting state than doing anything ”state”, aren't we? I see it as we are reading a representation of the state of the file contents.
I'll have a look. I did think the previous approach seemed sufficient, but maybe it was a bit opaque... Will be back when I've checked it out. |
Now checked. I can't figure out where the change ”to use the cursor directly” is. I see mostly changes to do with RFCs. Anyway, it looks right to me, what is there now. I'll try to find some time to try it out as well. |
ah sorry, I forgot to remove the old calls 😅 it's now easier to see that I'm using the cursor directly instead of getting the top-level forms. |
8979ea5
to
eef3bcf
Compare
What has changed?
;;
at the startFixes #
My Calva PR Checklist
If this PR involves only documentation changes, I have:
published
branch.If this PR involves code changes, 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.ci/circleci: build
test.npm run prettier-format
)npm run eslint
before creating your PR, or runnpm run eslint-watch
to eslint as you go).Ping @PEZ, @bpringe, @corasaurus-hex, @Cyrik