LSP: Don't respond to non-GDScript files
- Fixes GDQuest/zed-gdscript#6 but may also apply to other LSP clients.
Background
When an LSP client saves, Godot's LSP server receives a textDocument/didSave notification. Depending on how the LSP client is implemented, it may send this notification for any file, not necessarily only GDScript files. Godot's LSP server wouldn't do any checking on the file type received from this notification, so it would send back syntax errors for whatever file was saved.
According to the LSP spec, unless the server has previously sent TextDocumentSaveRegistrationOptions, the LSP client should send the textDocument/didSave notification for all files saved. See: the LSP spec and zed-industries/zed/pull/19183. (Can someone more familiar with LSP spec confirm this?)
Godot's LSP mostly uses static registrations during initialization for its LSP server capabilities, but TextDocumentSaveRegistrationOptions is only available as a dynamic registration. This makes implementing the fix that way a bit uglier than just checking file types when receiving notifications.
Fix
We will now check for a file being a valid GDScript file, via the language ID or file extension, before processing it any further. While this fix was specifically for the textDocument/didSave notification, I added checks for other related notifications as well.