Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions src/PrettierEditService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,20 +472,27 @@ export default class PrettierEditService implements Disposable {
}

let parser: PrettierBuiltInParserName | string | undefined;
if (fileInfo && fileInfo.inferredParser) {
parser = fileInfo.inferredParser;
} else if (languageId !== "plaintext") {
if (languageId !== "plaintext") {
// Don't attempt VS Code language for plaintext because we never have
// a formatter for plaintext and most likely the reason for this is
// somebody has registered a custom file extension without properly
// configuring the parser in their prettier config.
this.loggingService.logWarning(
`Parser not inferred, trying VS Code language.`
);
const { languages } = await prettierInstance.getSupportInfo({
plugins: [],
Copy link

Copilot AI Nov 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The getSupportInfo call uses an empty plugins array, but resolvedConfig?.plugins is available at this point and could contain custom plugins that add support for additional languages. This means custom plugins won't be considered when resolving the parser from languageId, potentially causing parser resolution to fail unnecessarily. Consider passing resolvedConfig?.plugins?.filter((item): item is string => typeof item === "string") || [] instead of an empty array, similar to how plugins are passed to getFileInfo at line 459.

Suggested change
plugins: [],
plugins:
resolvedConfig?.plugins?.filter(
(item): item is string => typeof item === "string"
) || [],

Copilot uses AI. Check for mistakes.
});
parser = getParserFromLanguageId(languages, uri, languageId);

if (!parser && fileInfo?.inferredParser) {
this.loggingService.logWarning(
`No parser found for languageId=${languageId}, using inferredParser=${fileInfo.inferredParser}.`
);
parser = fileInfo.inferredParser;
}
} else if (fileInfo && fileInfo.inferredParser) {
this.loggingService.logWarning(
`VS Code language not selected, trying inferredParser.`
Copy link

Copilot AI Nov 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The warning message "VS Code language not selected" is misleading. At this point, we know languageId === "plaintext", which means VS Code has selected a language (plaintext), not that no language was selected. Consider updating the message to something like "languageId is plaintext, using inferredParser" to better reflect the actual condition.

Suggested change
`VS Code language not selected, trying inferredParser.`
`languageId is plaintext, using inferredParser=${fileInfo.inferredParser}.`

Copilot uses AI. Check for mistakes.
);
parser = fileInfo.inferredParser;
}
Comment on lines +475 to 496
Copy link

Copilot AI Nov 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change introduces a significant behavioral modification to parser selection logic, prioritizing languageId over inferredParser. Consider adding test coverage for scenarios such as:

  1. User manually selects a language that differs from the file extension
  2. languageId is plaintext and falls back to inferredParser
  3. languageId is set but no parser is found, then falls back to inferredParser

This would help prevent regressions and document the expected behavior.

Copilot uses AI. Check for mistakes.

if (!parser) {
Expand Down