I've been working with the C_API using clangd as an LSP and I was hoping y'all might make some small quality of life improvements. The change is effectively a no-op but makes the individual headers more ergonomic to view.
When I open a pd_api_*.h header file in my IDE (e.g. GoTo definition for a type in pd_api_gfx.h), it is outside my project folder. As a result my clangd handles analysis as a single file project, so instead of evaluating the import chain through the pd_api.h entrypoint it just looks at the file itself. It then gets confused because there's a bunch of missing #includes because it does not evaluate pd_api.h first and pickup all the #include <stdbool.h>, #include <stdint.h> from there.
Without this, the clangd LSP reports spurious diagnostic errors to your workspace whenever a playdate header is open which looks like this:
I know this isn't strictly a bug. But it's generally good hygiene to explicitly include any required #includes in a header rather than the implicit assumption that another external header will have already been loaded. When compiling they will be no-ops, but it makes navigating the headers more user-friendly.
Steps to reproduce/test with Zed:
cd ~/Developer/PlaydateSDK/C_API
echo 'CompileFlags:
Add: ["-xc", "-DTARGET_EXTENSION=1"]' > .clangd
zed . pd_api/pd_api_gfx.h
# notice the errors
wget https://gist.githubusercontent.com/notpeter/252c4ea0f9b8c44d3a42745dd5ac542d/raw/e8b8477bdab06b83281724b728d5a1e7756062cf/0001-Imports-and-such.patch
patch < 0001-Imports-and-such.patch
# notice the errors have gone away
You can also reproduce with VSCode, with llvm-vs-code-extensions.vscode-clangd extension. Substitute code . for zed . above.
Here's a patch: 0001-imports-and-such-patch
P.S. Any chance you could also remove the trailing whitespace from these files while you're at it too? That is even less "important" but I'm working on generating annotated header files to support inline documentation (like playdate-luacats with lua-language-server, but for C with clangd) and it's a pain to deal with pure-whitespace diffs. Here's a patch for that too: 0002-trailing-whitespace-patch.
