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

feat: stop validation after lexing/parsing errors #662

Merged
merged 3 commits into from
Oct 22, 2023
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
18 changes: 9 additions & 9 deletions src/language/helpers/safe-ds-node-mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ import {
SdsYield,
} from '../generated/ast.js';
import { CallableType, StaticType } from '../typing/model.js';
import { findLocalReferences, getContainerOfType, Stream, stream } from 'langium';
import { EMPTY_STREAM, findLocalReferences, getContainerOfType, Stream } from 'langium';
import {
getAbstractResults,
getArguments,
isNamedArgument,
isNamedTypeArgument,
getParameters,
getTypeArguments,
getTypeParameters,
isNamedArgument,
isNamedTypeArgument,
} from './nodeProperties.js';

export class SafeDsNodeMapper {
Expand Down Expand Up @@ -155,13 +155,13 @@ export class SafeDsNodeMapper {
*/
parameterToReferences(node: SdsParameter | undefined): Stream<SdsReference> {
if (!node) {
return stream();
return EMPTY_STREAM;
}

const containingCallable = getContainerOfType(node, isSdsCallable);
/* c8 ignore start */
if (!containingCallable) {
return stream();
return EMPTY_STREAM;
}
/* c8 ignore stop */

Expand All @@ -175,13 +175,13 @@ export class SafeDsNodeMapper {
*/
placeholderToReferences(node: SdsPlaceholder | undefined): Stream<SdsReference> {
if (!node) {
return stream();
return EMPTY_STREAM;
}

const containingBlock = getContainerOfType(node, isSdsBlock);
/* c8 ignore start */
if (!containingBlock) {
return stream();
return EMPTY_STREAM;
}
/* c8 ignore stop */

Expand All @@ -195,12 +195,12 @@ export class SafeDsNodeMapper {
*/
resultToYields(node: SdsResult | undefined): Stream<SdsYield> {
if (!node) {
return stream();
return EMPTY_STREAM;
}

const containingSegment = getContainerOfType(node, isSdsSegment);
if (!containingSegment) {
return stream();
return EMPTY_STREAM;
}

return findLocalReferences(node, containingSegment)
Expand Down
2 changes: 2 additions & 0 deletions src/language/safe-ds-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { SafeDsTypeChecker } from './typing/safe-ds-type-checker.js';
import { SafeDsCoreTypes } from './typing/safe-ds-core-types.js';
import { SafeDsNodeKindProvider } from './lsp/safe-ds-node-kind-provider.js';
import { SafeDsDocumentSymbolProvider } from './lsp/safe-ds-document-symbol-provider.js';
import { SafeDsDocumentBuilder } from './workspace/safe-ds-document-builder.js';

/**
* Declaration of custom services - add your own service classes here.
Expand Down Expand Up @@ -106,6 +107,7 @@ export const SafeDsSharedModule: Module<SafeDsSharedServices, DeepPartial<SafeDs
NodeKindProvider: () => new SafeDsNodeKindProvider(),
},
workspace: {
DocumentBuilder: (services) => new SafeDsDocumentBuilder(services),
WorkspaceManager: (services) => new SafeDsWorkspaceManager(services),
},
};
Expand Down
4 changes: 2 additions & 2 deletions src/language/typing/safe-ds-class-hierarchy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SafeDsServices } from '../safe-ds-module.js';
import { SafeDsClasses } from '../builtins/safe-ds-classes.js';
import { SdsClass } from '../generated/ast.js';
import { stream, Stream } from 'langium';
import { EMPTY_STREAM, stream, Stream } from 'langium';
import { getParentTypes } from '../helpers/nodeProperties.js';
import { SafeDsTypeComputer } from './safe-ds-type-computer.js';
import { ClassType } from './model.js';
Expand Down Expand Up @@ -39,7 +39,7 @@ export class SafeDsClassHierarchy {
*/
streamSuperclasses(node: SdsClass | undefined): Stream<SdsClass> {
if (!node) {
return stream();
return EMPTY_STREAM;
}

return stream(this.superclassesGenerator(node));
Expand Down
11 changes: 11 additions & 0 deletions src/language/workspace/safe-ds-document-builder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { BuildOptions, DefaultDocumentBuilder } from 'langium';

export class SafeDsDocumentBuilder extends DefaultDocumentBuilder {
override updateBuildOptions: BuildOptions = {
validation: {
categories: ['built-in', 'fast'],
stopAfterLexingErrors: true,
stopAfterParsingErrors: true,
},
};
}
8 changes: 4 additions & 4 deletions tests/language/builtins/builtinFilesCorrectness.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ import { URI } from 'langium';
import { locationToString } from '../../helpers/location.js';
import { AssertionError } from 'assert';
import { isEmpty } from '../../../src/helpers/collectionUtils.js';
import { loadDocuments } from '../../helpers/testResources.js';

const workspace = createSafeDsServices(NodeFileSystem).SafeDs.shared.workspace;
const services = createSafeDsServices(NodeFileSystem).SafeDs;
const builtinFiles = listBuiltinFiles();

describe('builtin files', () => {
beforeAll(async () => {
const documents = builtinFiles.map((uri) => workspace.LangiumDocuments.getOrCreateDocument(uri));
await workspace.DocumentBuilder.build(documents, { validation: true });
await loadDocuments(services, builtinFiles, { validation: true });
});

const testCases = builtinFiles.map((uri) => ({
uri,
shortenedResourceName: uriToShortenedResourceName(uri, 'builtins'),
}));
it.each(testCases)('[$shortenedResourceName] should have no errors or warnings', async ({ uri }) => {
const document = workspace.LangiumDocuments.getOrCreateDocument(uri);
const document = services.shared.workspace.LangiumDocuments.getOrCreateDocument(uri);

const errorsOrWarnings =
document.diagnostics?.filter(
Expand Down