Skip to content

feat: improve notification when no configuration file is found#135

Open
AMDphreak wants to merge 6 commits into
dprint:mainfrom
dev-centr:fix/missing-config-notification
Open

feat: improve notification when no configuration file is found#135
AMDphreak wants to merge 6 commits into
dprint:mainfrom
dev-centr:fix/missing-config-notification

Conversation

@AMDphreak

Copy link
Copy Markdown

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

Ryan Johnson added 6 commits February 9, 2026 16:41
- 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.
@dsherret

dsherret commented Feb 10, 2026

Copy link
Copy Markdown
Member

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?

@jimmy-zhening-luo

Copy link
Copy Markdown

[...] 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 notification changes.

@jimmy-zhening-luo

Copy link
Copy Markdown

I'm not sure i like the idea of notifying the user (won't this cause issues if multiple formatters are configured?

@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 editor.formatOnSave is enabled, this error toast will trigger on every single file save.) The only way to suppress error toasts is to select a default formatter for the language, which the toast elicits the user to do, generating this User setting (using markdown as the example):

{
  "[markdown]": {
    "editor.defaultFormatter": "dprint.dprint",
  },

By the way, multiple dprint instances #132 causes VSCode to throw an error on every invocation of dprint even when dprint is the configured default or only available formatter! It's only happened to me twice in two months of heavy usage, but in comparison ESLint (inb4 linter not a formatter) or even the deplorable Prettier have never had this issue.

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 dprint's output stream to manually examine it only to find a very unhelpful informational log (Dprint could not find a config file or whatever).

A notification toast would be a far better experience IMO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants