Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(fix) skip parser error when there's likely another preprocessor involved #1569

Merged
merged 2 commits into from
Jul 27, 2022
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
11 changes: 11 additions & 0 deletions packages/language-server/src/lib/documents/Document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@ export class Document extends WritableDocument {
return lang.replace(/^text\//, '');
}

/**
* Returns true if there's `lang="X"` on script or style or template.
*/
hasLanguageAttribute(): boolean {
return (
!!this.getLanguageAttribute('script') ||
!!this.getLanguageAttribute('style') ||
!!this.getLanguageAttribute('template')
);
}

private addDefaultLanguage(
config: SvelteConfig | undefined,
tagInfo: TagInformation | null,
Expand Down
4 changes: 3 additions & 1 deletion packages/language-server/src/lib/documents/configLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface SvelteConfig {
compilerOptions?: CompileOptions;
preprocess?: InternalPreprocessorGroup | InternalPreprocessorGroup[];
loadConfigError?: any;
isFallbackConfig?: boolean;
}

const DEFAULT_OPTIONS: CompileOptions = {
Expand Down Expand Up @@ -257,7 +258,8 @@ export class ConfigLoader {
transpileOnly: true,
compilerOptions: { sourceMap: true, inlineSourceMap: false }
}
})
}),
isFallbackConfig: true
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ async function createParserErrorDiagnostic(error: any, document: Document) {
document.scriptInfo || document.moduleScriptInfo
);

if (
(!document.config?.preprocess || document.config.isFallbackConfig) &&
document.hasLanguageAttribute()
) {
Logger.error(
`Parsing ${document.getFilePath()} failed. No preprocess config found but lang tag exists. Skip showing error because they likely use other preprocessors.`
);
return [];
}

if (isInStyle || isInScript) {
diagnostic.message +=
'\n\nIf you expect this syntax to work, here are some suggestions: ';
Expand Down