Bold is a fast text editor. A public beta is coming soon.
Half of this month was spent on threads. I mentioned in the past that files aren’t fully non-blocking. The beginning of the month was spent on writing code for the IO thread. The threading code only ran in test, so the second week was getting it into the IDE. Lessons learned from the event system allowed me to implement this in a way that isn’t annoying. This might sound complicated, but the most complicated code is opening a file, and it’s actually pretty simple despite sounding difficult. The code is in 4 functions in about 30 lines of code, next to each other. It works like this
- Main thread wants to open a file (after checking it’s not already opened), sends a message to the background thread
- Background threa…
Bold is a fast text editor. A public beta is coming soon.
Half of this month was spent on threads. I mentioned in the past that files aren’t fully non-blocking. The beginning of the month was spent on writing code for the IO thread. The threading code only ran in test, so the second week was getting it into the IDE. Lessons learned from the event system allowed me to implement this in a way that isn’t annoying. This might sound complicated, but the most complicated code is opening a file, and it’s actually pretty simple despite sounding difficult. The code is in 4 functions in about 30 lines of code, next to each other. It works like this
- Main thread wants to open a file (after checking it’s not already opened), sends a message to the background thread
- Background thread asks the IO thread to open it up
- IO thread opens it, then sends the file to the background thread
- Background thread checks the file extension, and checks if it should start an LSP, then sends the file to a worker thread, or messages the main thread on failure
- Worker thread scans the file (newlines, code folding, etc), then sends it to the main thread
- Main thread considers the file ready and drawn in the next frame
Step two might be unnecessary, but at the moment, the main thread is simple. The main thread doesn’t directly interact with the IO thread or workers; it sends it to the BG thread because the background thread handles a lot of bookkeeping. Another thing in the second week was improving the code folding logic
Since async was working well, in week 3 I wrote code that checks if the system theme changed and dynamically changes the theme. I didn’t want LSPs to be hardcoded, so I wrote some code that let a user set LSPs, DAPs, and other language specifics through a config file. At the end of the week, I deleted a few dozen lines of old code and updated my linter rules. This got the ball rolling for week 4.
Week 4, I added more linter/static analysis rules and ended up refactoring nearly 1K lines of code. There were a few functions that I felt were bug-prone, so I rewrote those. I didn’t run the thread-sanitizer when I wrote all that async code, so week 4 I ran it and made sure no race conditions snuck in. The hardest part of the week was rewriting a few utility classes without breaking all the code that depended on them. The reason they would break was that a lot of functions required more parameters, and the replacement code didn’t try to do the same thing. Having tests let me replace the old class with the new pretty quickly.