Skip to content

Commit

Permalink
feat: settings to hide selected warnings/infos (#795)
Browse files Browse the repository at this point in the history
Closes #35

### Summary of Changes

Add settings to hide
* code style infos,
* experimental language feature warnings,
* experimental library element warnings,
* name convention warnings.
  • Loading branch information
lars-reimann committed Nov 22, 2023
1 parent 47f85d0 commit ff7c23a
Show file tree
Hide file tree
Showing 10 changed files with 623 additions and 309 deletions.
3 changes: 3 additions & 0 deletions packages/safe-ds-lang/src/language/safe-ds-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { SafeDsDocumentBuilder } from './workspace/safe-ds-document-builder.js';
import { SafeDsPackageManager } from './workspace/safe-ds-package-manager.js';
import { SafeDsWorkspaceManager } from './workspace/safe-ds-workspace-manager.js';
import { SafeDsPurityComputer } from './purity/safe-ds-purity-computer.js';
import { SafeDsSettingsProvider } from './workspace/safe-ds-settings-provider.js';

/**
* Declaration of custom services - add your own service classes here.
Expand Down Expand Up @@ -79,6 +80,7 @@ export type SafeDsAddedServices = {
};
workspace: {
PackageManager: SafeDsPackageManager;
SettingsProvider: SafeDsSettingsProvider;
};
};

Expand Down Expand Up @@ -144,6 +146,7 @@ export const SafeDsModule: Module<SafeDsServices, PartialLangiumServices & SafeD
},
workspace: {
PackageManager: (services) => new SafeDsPackageManager(services),
SettingsProvider: (services) => new SafeDsSettingsProvider(services),
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ import { Parameter } from '../../helpers/nodeProperties.js';
import { SafeDsServices } from '../../safe-ds-module.js';
import { parameterCanBeAnnotated } from '../other/declarations/annotationCalls.js';

export const CODE_DEPRECATED_ASSIGNED_RESULT = 'deprecated/assigned-result';
export const CODE_DEPRECATED_CALLED_ANNOTATION = 'deprecated/called-annotation';
export const CODE_DEPRECATED_CORRESPONDING_PARAMETER = 'deprecated/corresponding-parameter';
export const CODE_DEPRECATED_REFERENCED_DECLARATION = 'deprecated/referenced-declaration';
export const CODE_DEPRECATED_LIBRARY_ELEMENT = 'deprecated/library-element';
export const CODE_DEPRECATED_REQUIRED_PARAMETER = 'deprecated/required-parameter';

export const assigneeAssignedResultShouldNotBeDeprecated =
Expand All @@ -35,7 +32,7 @@ export const assigneeAssignedResultShouldNotBeDeprecated =
if (services.builtins.Annotations.callsDeprecated(assignedObject)) {
accept('warning', `The assigned result '${assignedObject.name}' is deprecated.`, {
node,
code: CODE_DEPRECATED_ASSIGNED_RESULT,
code: CODE_DEPRECATED_LIBRARY_ELEMENT,
tags: [DiagnosticTag.Deprecated],
});
}
Expand All @@ -52,7 +49,7 @@ export const annotationCallAnnotationShouldNotBeDeprecated =
accept('warning', `The called annotation '${annotation.name}' is deprecated.`, {
node,
property: 'annotation',
code: CODE_DEPRECATED_CALLED_ANNOTATION,
code: CODE_DEPRECATED_LIBRARY_ELEMENT,
tags: [DiagnosticTag.Deprecated],
});
}
Expand All @@ -68,7 +65,7 @@ export const argumentCorrespondingParameterShouldNotBeDeprecated =
if (services.builtins.Annotations.callsDeprecated(parameter)) {
accept('warning', `The corresponding parameter '${parameter.name}' is deprecated.`, {
node,
code: CODE_DEPRECATED_CORRESPONDING_PARAMETER,
code: CODE_DEPRECATED_LIBRARY_ELEMENT,
tags: [DiagnosticTag.Deprecated],
});
}
Expand All @@ -84,7 +81,7 @@ export const namedTypeDeclarationShouldNotBeDeprecated =
if (services.builtins.Annotations.callsDeprecated(declaration)) {
accept('warning', `The referenced declaration '${declaration.name}' is deprecated.`, {
node,
code: CODE_DEPRECATED_REFERENCED_DECLARATION,
code: CODE_DEPRECATED_LIBRARY_ELEMENT,
tags: [DiagnosticTag.Deprecated],
});
}
Expand All @@ -100,7 +97,7 @@ export const referenceTargetShouldNotBeDeprecated =
if (services.builtins.Annotations.callsDeprecated(target)) {
accept('warning', `The referenced declaration '${target.name}' is deprecated.`, {
node,
code: CODE_DEPRECATED_REFERENCED_DECLARATION,
code: CODE_DEPRECATED_LIBRARY_ELEMENT,
tags: [DiagnosticTag.Deprecated],
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ import {
} from '../../generated/ast.js';
import { SafeDsServices } from '../../safe-ds-module.js';

export const CODE_EXPERIMENTAL_ASSIGNED_RESULT = 'experimental/assigned-result';
export const CODE_EXPERIMENTAL_CALLED_ANNOTATION = 'experimental/called-annotation';
export const CODE_EXPERIMENTAL_CORRESPONDING_PARAMETER = 'experimental/corresponding-parameter';
export const CODE_EXPERIMENTAL_REFERENCED_DECLARATION = 'experimental/referenced-declaration';
export const CODE_EXPERIMENTAL_LIBRARY_ELEMENT = 'experimental/library-element';

export const assigneeAssignedResultShouldNotBeExperimental = (services: SafeDsServices) => {
const settingsProvider = services.workspace.SettingsProvider;

return async (node: SdsAssignee, accept: ValidationAcceptor) => {
if (!(await settingsProvider.shouldValidateExperimentalLibraryElement())) {
/* c8 ignore next 2 */
return;
}

export const assigneeAssignedResultShouldNotBeExperimental =
(services: SafeDsServices) => (node: SdsAssignee, accept: ValidationAcceptor) => {
if (isSdsWildcard(node)) {
return;
}
Expand All @@ -30,13 +34,21 @@ export const assigneeAssignedResultShouldNotBeExperimental =
if (services.builtins.Annotations.callsExperimental(assignedObject)) {
accept('warning', `The assigned result '${assignedObject.name}' is experimental.`, {
node,
code: CODE_EXPERIMENTAL_ASSIGNED_RESULT,
code: CODE_EXPERIMENTAL_LIBRARY_ELEMENT,
});
}
};
};

export const annotationCallAnnotationShouldNotBeExperimental = (services: SafeDsServices) => {
const settingsProvider = services.workspace.SettingsProvider;

return async (node: SdsAnnotationCall, accept: ValidationAcceptor) => {
if (!(await settingsProvider.shouldValidateExperimentalLibraryElement())) {
/* c8 ignore next 2 */
return;
}

export const annotationCallAnnotationShouldNotBeExperimental =
(services: SafeDsServices) => (node: SdsAnnotationCall, accept: ValidationAcceptor) => {
const annotation = node.annotation?.ref;
if (!annotation) {
return;
Expand All @@ -46,13 +58,21 @@ export const annotationCallAnnotationShouldNotBeExperimental =
accept('warning', `The called annotation '${annotation.name}' is experimental.`, {
node,
property: 'annotation',
code: CODE_EXPERIMENTAL_CALLED_ANNOTATION,
code: CODE_EXPERIMENTAL_LIBRARY_ELEMENT,
});
}
};
};

export const argumentCorrespondingParameterShouldNotBeExperimental = (services: SafeDsServices) => {
const settingsProvider = services.workspace.SettingsProvider;

return async (node: SdsArgument, accept: ValidationAcceptor) => {
if (!(await settingsProvider.shouldValidateExperimentalLibraryElement())) {
/* c8 ignore next 2 */
return;
}

export const argumentCorrespondingParameterShouldNotBeExperimental =
(services: SafeDsServices) => (node: SdsArgument, accept: ValidationAcceptor) => {
const parameter = services.helpers.NodeMapper.argumentToParameter(node);
if (!parameter) {
return;
Expand All @@ -61,13 +81,21 @@ export const argumentCorrespondingParameterShouldNotBeExperimental =
if (services.builtins.Annotations.callsExperimental(parameter)) {
accept('warning', `The corresponding parameter '${parameter.name}' is experimental.`, {
node,
code: CODE_EXPERIMENTAL_CORRESPONDING_PARAMETER,
code: CODE_EXPERIMENTAL_LIBRARY_ELEMENT,
});
}
};
};

export const namedTypeDeclarationShouldNotBeExperimental = (services: SafeDsServices) => {
const settingsProvider = services.workspace.SettingsProvider;

return async (node: SdsNamedType, accept: ValidationAcceptor) => {
if (!(await settingsProvider.shouldValidateExperimentalLibraryElement())) {
/* c8 ignore next 2 */
return;
}

export const namedTypeDeclarationShouldNotBeExperimental =
(services: SafeDsServices) => (node: SdsNamedType, accept: ValidationAcceptor) => {
const declaration = node.declaration?.ref;
if (!declaration) {
return;
Expand All @@ -76,13 +104,21 @@ export const namedTypeDeclarationShouldNotBeExperimental =
if (services.builtins.Annotations.callsExperimental(declaration)) {
accept('warning', `The referenced declaration '${declaration.name}' is experimental.`, {
node,
code: CODE_EXPERIMENTAL_REFERENCED_DECLARATION,
code: CODE_EXPERIMENTAL_LIBRARY_ELEMENT,
});
}
};
};

export const referenceTargetShouldNotExperimental = (services: SafeDsServices) => {
const settingsProvider = services.workspace.SettingsProvider;

return async (node: SdsReference, accept: ValidationAcceptor) => {
if (!(await settingsProvider.shouldValidateExperimentalLibraryElement())) {
/* c8 ignore next 2 */
return;
}

export const referenceTargetShouldNotExperimental =
(services: SafeDsServices) => (node: SdsReference, accept: ValidationAcceptor) => {
const target = node.target.ref;
if (!target || isSdsParameter(target)) {
return;
Expand All @@ -91,7 +127,8 @@ export const referenceTargetShouldNotExperimental =
if (services.builtins.Annotations.callsExperimental(target)) {
accept('warning', `The referenced declaration '${target.name}' is experimental.`, {
node,
code: CODE_EXPERIMENTAL_REFERENCED_DECLARATION,
code: CODE_EXPERIMENTAL_LIBRARY_ELEMENT,
});
}
};
};
Loading

0 comments on commit ff7c23a

Please sign in to comment.