Skip to content

Commit

Permalink
prettier resolution options parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
ntotten committed Dec 19, 2019
1 parent c02c9bf commit a1ec4d3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
10 changes: 7 additions & 3 deletions src/ModuleResolver.ts
Expand Up @@ -24,6 +24,10 @@ interface ModuleResult<T> {
modulePath: string | undefined;
}

interface PrettierResolutionOptions {
showWarnings: boolean;
}

const globalPaths: {
[key: string]: { cache: string | undefined; get(): string | undefined };
} = {
Expand Down Expand Up @@ -80,7 +84,7 @@ export class ModuleResolver implements Disposable {
*/
public getPrettierInstance(
fileName?: string,
isUserInteractive: boolean = false
options?: PrettierResolutionOptions
): PrettierModule {
if (!fileName) {
return prettier;
Expand Down Expand Up @@ -109,7 +113,7 @@ export class ModuleResolver implements Disposable {
}
}

if (!moduleInstance && isUserInteractive) {
if (!moduleInstance && options?.showWarnings) {
this.loggingService.logInfo("Using bundled version of prettier.");
}

Expand All @@ -122,7 +126,7 @@ export class ModuleResolver implements Disposable {
semver.gte(moduleInstance.version, minPrettierVersion);

if (!isValidVersion) {
if (isUserInteractive) {
if (options?.showWarnings) {
// We only prompt when formatting a file. If we did it on load there
// could be lots of these notifications which would be annoying.
this.notificationService.warnOutdatedPrettierVersion(modulePath);
Expand Down
7 changes: 3 additions & 4 deletions src/PrettierEditService.ts
Expand Up @@ -215,10 +215,9 @@ export default class PrettierEditService implements Disposable {
// LEGACY: Remove in version 4.x
this.notificationService.warnIfLegacyConfiguration(uri);

const prettierInstance = this.moduleResolver.getPrettierInstance(
fileName,
true /* Show outdated or fallback warnings */
);
const prettierInstance = this.moduleResolver.getPrettierInstance(fileName, {
showWarnings: true
});

const vscodeConfig = getConfig(uri);

Expand Down

0 comments on commit a1ec4d3

Please sign in to comment.