Skip to content

Commit

Permalink
feat: mark schemas as experimental (#1089)
Browse files Browse the repository at this point in the history
Closes #1078

### Summary of Changes

Schemas are now marked as experimental.
  • Loading branch information
lars-reimann authored Apr 23, 2024
1 parent 368b6af commit 09faaf0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { AstUtils, ValidationAcceptor } from 'langium';
import { isSdsUnionType, type SdsConstraintList, type SdsLiteralType, type SdsUnionType } from '../generated/ast.js';
import {
isSdsUnionType,
type SdsConstraintList,
type SdsLiteralType,
SdsSchema,
type SdsUnionType,
} from '../generated/ast.js';
import { SafeDsServices } from '../safe-ds-module.js';

export const CODE_EXPERIMENTAL_LANGUAGE_FEATURE = 'experimental/language-feature';
Expand Down Expand Up @@ -38,6 +44,23 @@ export const literalTypesShouldBeUsedWithCaution = (services: SafeDsServices) =>
};
};

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

return (node: SdsSchema, accept: ValidationAcceptor) => {
if (!settingsProvider.shouldValidateExperimentalLanguageFeatures()) {
/* c8 ignore next 2 */
return;
}

accept('warning', 'Schemas are experimental and may change without prior notice.', {
node,
property: 'name',
code: CODE_EXPERIMENTAL_LANGUAGE_FEATURE,
});
};
};

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { annotationCallMustHaveCorrectTarget, targetsShouldNotHaveDuplicateEntri
import {
constraintListsShouldBeUsedWithCaution,
literalTypesShouldBeUsedWithCaution,
schemasShouldBeUsedWithCaution,
unionTypesShouldBeUsedWithCaution,
} from './experimentalLanguageFeatures.js';
import {
Expand Down Expand Up @@ -354,7 +355,7 @@ export const registerValidationChecks = function (services: SafeDsServices) {
referenceTargetShouldNotExperimental(services),
],
SdsResult: [resultMustHaveTypeHint],
SdsSchema: [schemaMustContainUniqueNames],
SdsSchema: [schemaMustContainUniqueNames, schemasShouldBeUsedWithCaution(services)],
SdsSegment: [
segmentMustContainUniqueNames,
segmentParameterShouldBeUsed(services),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package tests.validation.experimentalLanguageFeature.schemas

// $TEST$ warning "Schemas are experimental and may change without prior notice."
schema »MySchema« {}

0 comments on commit 09faaf0

Please sign in to comment.