Skip to content
Merged
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
13 changes: 12 additions & 1 deletion packages/language-server/src/plugins/svelte/SveltePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class SveltePlugin
(await prettier.resolveConfig(filePath, { editorconfig: true })) || this.prettierConfig;
const formattedCode = prettier.format(document.getText(), {
...config,
plugins: [require.resolve('prettier-plugin-svelte')],
plugins: getSveltePlugin(),
parser: 'svelte' as any,
});

Expand All @@ -79,6 +79,17 @@ export class SveltePlugin
formattedCode,
),
];

function getSveltePlugin() {
// Only provide our version of the svelte plugin if the user doesn't have one in
// the workspace already. If we did it, Prettier would - for some reason - use
// the workspace version for parsing and the extension version for printing,
// which could crash if the contract of the parser output changed.
const hasPluginLoadedAlready = prettier
.getSupportInfo()
.languages.some((l) => l.name === 'svelte');
return hasPluginLoadedAlready ? [] : [require.resolve('prettier-plugin-svelte')];
}
}

async getCompletions(document: Document, position: Position): Promise<CompletionList | null> {
Expand Down