Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 4, 2025

Description

Untitled documents (unsaved files) couldn't be formatted when prettier.requireConfig was enabled, even when the workspace contained a valid .prettierrc file.

Root cause: Untitled documents have a display name like "Untitled-1" rather than a real file path. Config resolution searched from this fake path, found nothing, and disabled formatting when requireConfig: true.

Solution: Detect untitled documents via uri.scheme !== "file" and use the workspace folder path as the config search base instead.

Changes

  • ModuleResolverNode.ts

    • Added isUntitledDocument() and getConfigSearchPath() helpers
    • Modified getResolvedConfig() to use workspace folder for untitled documents
  • Test coverage

    • Added test-fixtures/require-config/ with requireConfig enabled
    • Added integration tests for untitled document formatting

Behavior

// Before: Returns "disabled" for untitled docs even with workspace config
await getResolvedConfig(untitledDoc, { requireConfig: true })

// After: Finds workspace .prettierrc and returns config
await getResolvedConfig(untitledDoc, { requireConfig: true })

Related Issue

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Refactoring (no functional changes)
  • CI/Build changes

Checklist

  • I have read the CONTRIBUTING guidelines
  • My code follows the code style of this project (npm run lint passes)
  • I have run npm run prettier to format my code
  • I have added/updated tests that prove my fix or feature works
  • All new and existing tests pass (npm test)
  • I have updated the CHANGELOG.md with a summary of my changes

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • update.code.visualstudio.com
    • Triggering command: /usr/local/bin/node node /home/REDACTED/work/prettier-vscode/prettier-vscode/node_modules/.bin/vscode-test (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Unsaved files can't format with require config</issue_title>
<issue_description>When attempting to format a new document that is not saved or part of the workspace if require config is enabled the file cannot be formatted.

"INFO" - 4:01:59 PM] Formatting untitled:Untitled-1
["DEBUG" - 4:01:59 PM] Using bundled version of prettier.
["INFO" - 4:01:59 PM] EditorConfig support is enabled, checking for .editorconfig files
["INFO" - 4:01:59 PM] No local configuration (i.e. .prettierrc or .editorconfig) detected, will fall back to VS Code configuration
["INFO" - 4:01:59 PM] Require config set to true but no config file found, disabling formatting.
["INFO" - 4:02:17 PM] Using config file at /Users/ntotten/zuplo/docs/.prettierrc
["INFO" - 4:02:17 PM] EditorConfig support is enabled, checking for .editorconfig files
["INFO" - 4:02:17 PM] Resolved config:
{
  "useTabs": false,
  "tabWidth": 2,
  "endOfLine": "lf"
}
```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits December 4, 2025 21:13
- Modified getResolvedConfig to use workspace folder path for config search when document is untitled
- Added test fixture for requireConfig scenario
- Added integration tests for untitled document formatting

Co-authored-by: ntotten <282782+ntotten@users.noreply.github.com>
- Added isUntitledDocument() helper method for better readability
- Added getConfigSearchPath() helper method to encapsulate logic
- Improved testability and maintainability

Co-authored-by: ntotten <282782+ntotten@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix untitled files formatting with require config Fix: Untitled documents can't format with requireConfig enabled Dec 4, 2025
Copilot AI requested a review from ntotten December 4, 2025 21:24
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.

Unsaved files can't format with require config

2 participants