Skip to content
Merged
Show file tree
Hide file tree
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
14 changes: 12 additions & 2 deletions packages/language-server/src/plugins/svelte/SveltePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ export class SveltePlugin
CodeActionsProvider {
private docManager = new Map<Document, SvelteDocument>();

constructor(private configManager: LSConfigManager, private prettierConfig: any) {}
constructor(
private configManager: LSConfigManager,
private prettierConfig: any,
private editorConfig?: any,
) {}

async getDiagnostics(document: Document): Promise<Diagnostic[]> {
if (!this.featureEnabled('diagnostics')) {
Expand Down Expand Up @@ -67,7 +71,13 @@ export class SveltePlugin
const prettier = importPrettier(filePath);
// Try resolving the config through prettier and fall back to possible editor config
const config =
(await prettier.resolveConfig(filePath, { editorconfig: true })) || this.prettierConfig;
(await prettier.resolveConfig(filePath, { editorconfig: true })) ||
this.prettierConfig ||
// Be defensive here because IDEs other than VSCode might not have these settings
(this.editorConfig && this.editorConfig.tabSize && {
tabWidth: this.editorConfig.tabSize,
useTabs: !this.editorConfig.insertSpaces,
});
// Take .prettierignore into account
const fileInfo = await prettier.getFileInfo(filePath, {
ignorePath: this.prettierConfig?.ignorePath ?? '.prettierignore',
Expand Down
1 change: 1 addition & 0 deletions packages/language-server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export function startServer(options?: LSOptions) {
(sveltePlugin = new SveltePlugin(
configManager,
evt.initializationOptions?.prettierConfig || {},
evt.initializationOptions?.editorConfig, // deliberatly don't fall back to empty object
)),
);
pluginHost.register(new HTMLPlugin(docManager, configManager));
Expand Down
1 change: 1 addition & 0 deletions packages/svelte-vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export function activate(context: ExtensionContext) {
initializationOptions: {
config: workspace.getConfiguration('svelte.plugin'),
prettierConfig: workspace.getConfiguration('prettier'),
editorConfig: workspace.getConfiguration('editor', { languageId: 'svelte' }),
dontFilterIncompleteCompletions: true, // VSCode filters client side and is smarter at it than us
},
};
Expand Down