Port the bracketmatching plugin #20
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Logic can stay largely the same. Will need access to token info, so this should probably wait for the highlighter integration to stabilize a bit.
Mostly done in
cac0a01b56I implemented the token type matching in
0450d9d945in a hacky way. Do you want a direct way to access token info from the highlighter? Do you want to somehow make the highlighter accessible from the state?I think what we talked about last time was to make it possible to get token types from the state, and have the view component of the highlighter use that mechanism when highlighting. We want to somehow cache those results, so that things like bracket matching don't recompute stuff that the highlighter just computed, but that cache can be relatively small and simple.
I remember that discussion. Do you think we need another cache in addition to
legacy-modes'StateCache? Getting token types from the state could useStateCacheinternally and extract the token type from theRangeDecoration.Yes, I think it makes sense to separate caching the states from caching the tokens. I wouldn't store tokens in the format of decorations—those are just the materialization of the tokens given to the editor, and an awkward format for something like the bracket matcher to access. Maybe keep lines of tokens as arrays or something? We might have to revisit this if we ever get a new mode system off the ground and want to provide compatible interfaces, but for now it's okay to keep it simple.
By »keep lines of tokens as array« do you mean for actual lines of the document?
I'll try to outline my understanding of your suggestion. There is a
StateCachethat stores mode states (S), keeps track of the frontier and provides:That's used by
TokenTypeCachethat maybe providesAnd decorating is just calling
iterTokensfor a range and mapping{from, to, string}intoRangeDecorations with a one-entry cache (lastDecorations.TokenTypeCacheis easily accessible through the state.Yes, that sounds reasonable (though, since we're not depending on ES6, I don't think we should make
Iteratorpart of our interface—that'll require polyfillingSymboland generating big ugly code forfor/of). Since the highlighter will be running the mode a line at a time, maybe just getting a full line as an array is workable.You'll have to see what works as you implement it—I can't really tell yet, at this point.
I didn't mean ES iterators, yes. I think we can work with lines as units for now, since our old modes work that way. What should the interface in
EditorStatelook like? I suppose the token type provider has to register itself somehow?I started work on separating the caches in 8e98a4e3e0b9d0bc6fe3a891f11fc73515e2c31b.
TokenTypeCachedoesn't actually cache yet, and I don't know what a good cache strategy would be here. I also didn't exposeTokenTypeCacheyet onEditorState.Adapted to the new line interface in c605247991c442745ce6086bf18ace7c72fc981a.
Nice! (Though I think you meant
a7b35f6539)Nice, but I actually meant the tokenTypes branch :)
The implementation in
https://github.com/codemirror/codemirror.next/blob/master/matchbrackets/src/matchbrackets.ts
appears to be pretty complete. Any remaining work required for this issue?
Really excited to see this project happening, thank you for all your work!
It's quite complete, but the way decorations are referenced is awkward. I started work to make decorations accessible on the editor state in https://github.com/codemirror/codemirror.next/tree/tokenTypes.
This issue feels closeable, as the bracket matching plugin seems pretty stable.
There's one open item — using tokenizer information when matching brackets, to avoid, for example, matching a bracket in a string or comment with one in the actual source language.
I'm noticing that the
.codemirror-nonmatching-bracketclass is not appearing on any bracket elements, even after this commit where the class was addedgithub.com/codemirror/codemirror.next@b21b89713bHere's a reproduction example, where you can see that the
.codemirror-matching-bracketis activated, but not.codemirror-nonmatching-bracket. Expected behavior: all non-matching brackets get the class.codemirror-nonmatching-bracket.That's not how this plugin works—it only highlights the bracket at the cursor position.
Ah I see. It was my misunderstanding as to what should be expected.
In this case, it's not clear when
.codemirror-nonmatching-bracketwould be activated, if at all.In
([), if you're over one of the parentheses.Aha! I get it now. Thank you @adrianheine
Closing this now that the lezer branch has landed. It's not unlikely that there are some problems in the new code still, but we'll open specific separate issues as we run into them.