The problem of multiple extension implementations

Hello,When I use two extensions at the same time, one for keyword highlighting and the other for bracket segmentation and highlighting, there seems to be a conflict. When I delete the brackets after using them, an error message will appear. What should I do? I also tried to merge it into a ViewPlugin, but how to merge DecorationSet has become my problem, and it seems that it cannot achieve a separate effect. Here is my code:




Extensions should compose without issues, especially if they only add decoration. If you can reduce this to a minimal script that runs on codemirror.net/try, I’ll see if I can find the problem.

As long as parentheses are used and then removed until there are no parentheses, an error will occur. This is my minimum code running address, but there seems to be a problem running it online. I am not very familiar with this, but the code is all here. Thank you.

https://codemirror.net/try/#c=aW1wb3J0IHsgRGVjb3JhdGlvbiwgRGVjb3JhdGlvblNldCwgRWRpdG9yVmlldywgTWF0Y2hEZWNvcmF0b3IsIFZpZXdQbHVnaW4sIFZpZXdVcGRhdGUgfSBmcm9tICdAY29kZW1pcnJvci92aWV3JzsKaW1wb3J0IHsgYXV0b2NvbXBsZXRpb24sIENvbXBsZXRpb24sIENvbXBsZXRpb25Db250ZXh0LCBDb21wbGV0aW9uUmVzdWx0IH0gZnJvbSAnQGNvZGVtaXJyb3IvYXV0b2NvbXBsZXRlJzsKaW1wb3J0IHsgRGlhZ25vc3RpYywgbGludGVyLCBsaW50R3V0dGVyIH0gZnJvbSAnQGNvZGVtaXJyb3IvbGludCc7CgoKY29uc3QgYnJhY2tldFBsdWdpbiA9IChjb2xvcjogc3RyaW5nLCBjbGFzc05hbWU6IHN0cmluZykgPT4gewogICAgY29uc3QgbWF0Y2hlciA9IG5ldyBNYXRjaERlY29yYXRvcih7CiAgICAgICAgcmVnZXhwOiAvWygpXS9nLAogICAgICAgIGRlY29yYXRpb246IChtYXRjaCwgdmlldywgcG9zKSA9PiB7CiAgICAgICAgICAgIGNvbnN0IHN0eWxlOiBzdHJpbmcgPSBgY29sb3I6ICR7Y29sb3J9O2A7CiAgICAgICAgICAgIGNvbnN0IGNoYXIgPSBtYXRjaFswXTsKICAgICAgICAgICAgaWYgKGNoYXIgPT09ICcoJykgewogICAgICAgICAgICAgICAgcmV0dXJuIERlY29yYXRpb24ubWFyayh7IGNsYXNzOiAnbGVmdC1icmFja2V0JywgYXR0cmlidXRlczogeyBzdHlsZTogc3R5bGUgfSB9KTsKICAgICAgICAgICAgfSBlbHNlIGlmIChjaGFyID09PSAnKScpIHsKICAgICAgICAgICAgICAgIHJldHVybiBEZWNvcmF0aW9uLm1hcmsoeyBjbGFzczogJ3JpZ2h0LWJyYWNrZXQnLCBhdHRyaWJ1dGVzOiB7IHN0eWxlOiBzdHlsZSB9IH0pOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHJldHVybiBEZWNvcmF0aW9uLm1hcmsoe30pOwogICAgICAgIH0sCiAgICB9KTsKCiAgICByZXR1cm4gVmlld1BsdWdpbi5mcm9tQ2xhc3MoCiAgICAgICAgY2xhc3MgewogICAgICAgICAgICBkZWNvcmF0aW9uczogRGVjb3JhdGlvblNldDsKICAgICAgICAgICAgY29uc3RydWN0b3IodmlldzogRWRpdG9yVmlldykgewogICAgICAgICAgICAgICAgdGhpcy5kZWNvcmF0aW9ucyA9IG1hdGNoZXIuY3JlYXRlRGVjbyh2aWV3KTsKICAgICAgICAgICAgfQogICAgICAgICAgICB1cGRhdGUodXBkYXRlOiBWaWV3VXBkYXRlKSB7CiAgICAgICAgICAgICAgICBpZiAodXBkYXRlLmRvY0NoYW5nZWQgfHwgdXBkYXRlLnZpZXdwb3J0Q2hhbmdlZCkgewogICAgICAgICAgICAgICAgICAgIHRoaXMuZGVjb3JhdGlvbnMgPSBtYXRjaGVyLnVwZGF0ZURlY28odXBkYXRlLCB0aGlzLmRlY29yYXRpb25zKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH0sCiAgICAgICAgewogICAgICAgICAgICBkZWNvcmF0aW9uczogKGluc3RhbmNlOiBhbnkpID0+IGluc3RhbmNlLmRlY29yYXRpb25zLAogICAgICAgIH0KICAgICk7Cn07Cgpjb25zdCBrZXl3b3Jkc1BsdWdpbiA9IChrZXl3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GF0ZURlY28odXBkYXRlLCB0aGlzLmRlY29yYXRpb25zKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH0sCiAgICAgICAgewogICAgICAgICAgICBkZWNvcmF0aW9uczogKGluc3RhbmNlKSA9PiBpbnN0YW5jZS5kZWNvcmF0aW9ucywKICAgICAgICB9CiAgICApOwp9CgoKbmV3IEVkaXRvclZpZXcoewogICAgZG9jOiAiU1VNKCkiLAogICAgZXh0ZW5zaW9uczogWwogICAgICAgIGtleXdvcmRzUGx1Z2luKFsiU1VNIiwgIk1BWCIsICJNSU4iXSwgJyMwMGZmMDAnLCAnYzInKSwKICAgICAgICBicmFja2V0UGx1Z2luKCcjZTFlMTM3JywgJ2MzJyksCiAgICBdLAogICAgcGFyZW50OiBkb2N1bWVudC5ib2R5Cn0p

Please use this. The previous one was based on typescript, and I found that it cannot be run directly. I have made adjustments again. Thank you again。
https://codemirror.net/try/#c=aW1wb3J0IHsgRGVjb3JhdGlvbiwgRWRpdG9yVmlldywgTWF0Y2hEZWNvcmF0b3IsIFZpZXdQbHVnaW4sIFZpZXdVcGRhdGUgfSBmcm9tICdAY29kZW1pcnJvci92aWV3JwoKCmZ1bmN0aW9uIGJyYWNrZXRQbHVnaW4gKGNvbG9yLCBjbGFzc05hbWUpIHsKICAgIGNvbnN0IG1hdGNoZXIgPSBuZXcgTWF0Y2hEZWNvcmF0b3IoewogICAgICAgIHJlZ2V4cDogL1soKV0vZywKICAgICAgICBkZWNvcmF0aW9uOiAobWF0Y2gsIHZpZXcsIHBvcykgPT4gewogICAgICAgICAgICBjb25zdCBzdHlsZSA9IGBjb2xvcjogJHtjb2xvcn07YDsKICAgICAgICAgICAgY29uc3QgY2hhciA9IG1hdGNoWzBdOwogICAgICAgICAgICBpZiAoY2hhciA9PT0gJygnKSB7CiAgICAgICAgICAgICAgICByZXR1cm4gRGVjb3JhdGlvbi5tYXJrKHsgY2xhc3M6ICdsZWZ0LWJyYWNrZXQnLCBhdHRyaWJ1dGVzOiB7IHN0eWxlOiBzdHlsZSB9IH0pOwogICAgICAgICAgICB9IGVsc2UgaWYgKGNoYXIgPT09ICcpJykgewogICAgICAgICAgICAgICAgcmV0dXJuIERlY29yYXRpb24ubWFyayh7IGNsYXNzOiAncmlnaHQtYnJhY2tldCcsIGF0dHJpYnV0ZXM6IHsgc3R5bGU6IHN0eWxlIH0gfSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcmV0dXJuIERlY29yYXRpb24ubWFyayh7fSk7CiAgICAgICAgfSwKICAgIH0pOwoKICAgIHJldHVybiBWaWV3UGx1Z2luLmZyb21DbGFzcygKICAgICAgICBjbGFzcyB7CiAgICAgICAgICAgIGRlY29yYXRpb25zOwogICAgICAgICAgICBjb25zdHJ1Y3Rvcih2aWV3KSB7CiAgICAgICAgICAgICAgICB0aGlzLmRlY29yYXRpb25zID0gbWF0Y2hlci5jcmVhdGVEZWNvKHZpZXcpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHVwZGF0ZSh1cGRhdGUpIHsKICAgICAgICAgICAgICAgIGlmICh1cGRhdGUuZG9jQ2hhbmdlZCB8fCB1cGRhdGUudmlld3BvcnRDaGFuZ2VkKSB7CiAgICAgICAgICAgICAgICAgICAgdGhpcy5kZWNvcmF0aW9ucyA9IG1hdGNoZXIudXBkYXRlRGVjbyh1cGRhdGUsIHRoaXMuZGVjb3JhdGlvbnMpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgfSwKICAgICAgICB7CiAgICAgICAgICAgIGRlY29yYXRpb25zOiAoaW5zdGFuY2UpID0+IGluc3RhbmNlLmRlY29yYXRpb25zLAogICAgICAgIH0KICAgICk7Cn07CgpmdW5jdGlvbiBrZXl3b3Jkc1BsdWdpbiAgKGtleXdvcmRzLCBjb2xvciwgY2xhc3NOYW1lKSB7CiAgICBjb25zdCByZWdleHAgPSBuZXcgUmVnRXhwKGtleXdvcmRzLmpvaW4oJ3wnKSwgJ2cnKTsKICAgIGNvbnN0IGtleXdvcmRNYXRjaGVyID0gbmV3IE1hdGNoRGVjb3JhdG9yKHsKICAgICAgICByZWdleHA6IHJlZ2V4cCwKICAgICAgICBkZWNvcmF0aW9uOiAobWF0Y2gsIHZpZXcsIHBvcykgPT4gewoKICAgICAgICAgICAgY29uc3Qgc3R5bGUgPSBgY29sb3I6ICR7Y29sb3J9O2A7CiAgICAgICAgICAgIHJldHVybiBEZWNvcmF0aW9uLm1hcmsoewogICAgICAgICAgICAgICAgYXR0cmlidXRlczogewogICAgICAgICAgICAgICAgICAgIHN0eWxlLAogICAgICAgICAgICAgICAgfSwKICAgICAgICAgICAgICAgIGNsYXNzOiBjbGFzc05hbWUsCiAgICAgICAgICAgIH0pOwogICAgICAgIH0sCiAgICB9KTsKICAgIHJldHVybiBWaWV3UGx1Z2luLmZyb21DbGFzcygKICAgICAgICBjbGFzcyB7CiAgICAgICAgICAgIGRlY29yYXRpb25zOwogICAgICAgICAgICBjb25zdHJ1Y3Rvcih2aWV3KSB7CiAgICAgICAgICAgICAgICB0aGlzLmRlY29yYXRpb25zID0ga2V5d29yZE1hdGNoZXIuY3JlYXRlRGVjbyh2aWV3KTsKICAgICAgICAgICAgfQogICAgICAgICAgICB1cGRhdGUodXBkYXRlKSB7CiAgICAgICAgICAgICAgICBpZiAodXBkYXRlLmRvY0NoYW5nZWQgfHwgdXBkYXRlLnZpZXdwb3J0Q2hhbmdlZCkgewogICAgICAgICAgICAgICAgICAgIHRoaXMuZGVjb3JhdGlvbnMgPSBrZXl3b3JkTWF0Y2hlci51cGRhdGVEZWNvKHVwZGF0ZSwgdGhpcy5kZWNvcmF0aW9ucyk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICB9LAogICAgICAgIHsKICAgICAgICAgICAgZGVjb3JhdGlvbnM6IChpbnN0YW5jZSkgPT4gaW5zdGFuY2UuZGVjb3JhdGlvbnMsCiAgICAgICAgfQogICAgKTsKfQoKCm5ldyBFZGl0b3JWaWV3KHsKICAgIGRvYzogIlNVTSgpIiwKICAgIGV4dGVuc2lvbnM6IFsKICAgICAgICBrZXl3b3Jkc1BsdWdpbihbIlNVTSIsICJNQVgiLCAiTUlOIl0sICcjMDBmZjAwJywgJ2MyJyksCiAgICAgICAgYnJhY2tldFBsdWdpbignI2UxZTEzNycsICdjMycpLAogICAgXSwKICAgIHBhcmVudDogZG9jdW1lbnQuYm9keQp9KQ==

This happens as well with just one MatchDecorator extension. It was a regression in @codemirror/view 6.36.0 caused by a fix that made the code take a path it accidentally never took before, and that path having another bug. This patch (in 6.36.1) should fix it.

2 Likes

I have updated the latest dependency and it is fine now. Thank you very much