feat: improve notification when no configuration file is found#135
feat: improve notification when no configuration file is found#135AMDphreak wants to merge 6 commits into
Conversation
- Properly dispose of old formatting provider before registering a new one in legacy backend. - Ensure LanguageClient is properly stopped and disposed in LSP backend. - Updated ExtensionBackend interface to include explicit dispose method. Follows #1
- Implement async disposal for EditorService and FolderService. - Serialize re-initialization calls in the main extension. - Add debouncing to configuration change events. - Ensures old processes are fully shut down before new ones start. Follows dprint#132
Moved re-initialization logic and variable declarations before their first usage in the `activate` function to prevent `ReferenceError`.
The startReadingStdout() loop was restarting the dprint process during shutdown because _disposed was only set in the finally block, after the graceful close attempt. By setting it immediately, the loop exits cleanly when it detects the process death. Also improved re-initialization debouncing to use a pendingReInit flag instead of recursively queuing debounced calls, which could cause chains of unnecessary reinitializations.
The dprint CLI modifies config files (e.g., dprint.jsonc) during startup, which triggered the file watcher and caused an infinite re-initialization loop with 'failed to fill whole buffer' errors. Instead of auto-restarting, show a toast notification asking the user to confirm: 'Dprint configuration changed. Refresh plugin to apply?' This eliminates the race condition entirely. Also: - Set _disposed flag before graceful shutdown in EditorService5 - Made disposal async throughout the service chain - Added serialization guard for concurrent re-initializations Fixes dprint#132
…print#134) Registers a fallback formatting provider when no configuration file is found to provide a more intelligent error message instead of letting VS Code show its generic and misleading "cannot format" toast.
|
I'm not sure i like the idea of notifying the user (won't this cause issues if multiple formatters are configured? I forget how it works), but also this seems to have a lot of unrelated changes. Would you be able to split them out into targeted prs? |
Yes, this PR seems includes the five commits from #133. At a glance (haven't done a full diff), the two changes look unrelated. Would suggest closing this and opening a new PR with only the |
@dsherret Regarding multiple formatters being configured: VSCode requires at most one formatter per language. VSCode throws an error notification toast on each format invocation, if multiple formatters are even available for a given language. (If {
"[markdown]": {
"editor.defaultFormatter": "dprint.dprint",
},By the way, So, only one formatter is allowed. If dprint is running, dprint is the formatter. The only time the user would see a toast informing them that dprint could not find a config file would be when dprint is the only formatter. The current state (silent failure) is arguably a far worse user experience, since developers should not be expected to manually open the Output console and select A notification toast would be a far better experience IMO. |
This PR improves the user experience when dprint is configured as the default formatter but no configuration file exists in the workspace. Instead of seeing a generic and misleading VS Code error message, the user will now see a helpful toast from dprint explaining that no configuration file was found.\n\nFixes #134