mchakravarty / CodeEditorView

SwiftUI code editor view for iOS, visionOS, and macOS
Apache License 2.0
680 stars 57 forks source link

In some cases, `messages.removeAll()` won't clear all shown messages. #110

Open Cubik65536 opened 4 weeks ago

Cubik65536 commented 4 weeks ago

In my app, I use messages to show compilation error. The code parser would throw an Error containing a list of Error instances, each of those contains information necessary to add error messages to the CodeEditor.

When there's an error thrown, messages.insert is used to add all error messages to the messages: Set<TextLocated<Message>> state variable to show the error at the corresponding place on the editor view.

However, sometimes, messages.removeAll() couldn't remove all error shown, even when the messages set is already empty, some previously shown messages would stay.

I couldn't reproduce this in the demo app, I will try to make it happen and update this issue accordingly.


Related: https://github.com/iXORTech/Typstify/issues/5

mchakravarty commented 3 weeks ago

That's weird. Maybe some views stay around while the underlying messages are already gone. It would definitely be helpful if you could find an example that reproduces the problem.

Generally, speaking have you had a look at the LanguageService API (it's a protocol) that is part of the LanguageSupport target. It uses Compose to asynchronously push error messages to the editor from underlying compiler tooling. (It also provides other facilities, such as autocompletion etc.) This is what I'm using in my own app to push diagnostics to the editor view and it seems to work fine.

Cubik65536 commented 3 weeks ago

That's weird. Maybe some views stay around while the underlying messages are already gone. It would definitely be helpful if you could find an example that reproduces the problem.

I'll continue to dig into this.

Generally, speaking have you had a look at the LanguageService API (it's a protocol) that is part of the LanguageSupport target. It uses Compose to asynchronously push error messages to the editor from underlying compiler tooling. (It also provides other facilities, such as autocompletion etc.) This is what I'm using in my own app to push diagnostics to the editor view and it seems to work fine.

I haven't and I will take a look at it then.