Skip to content

Commit

Permalink
Simplify checking for incorrect extractor and loader blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
georg-schwarz committed Jan 16, 2024
1 parent 00867cd commit 8e68450
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 27 deletions.
31 changes: 10 additions & 21 deletions libs/language-server/src/lib/validation/checks/block-definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,6 @@ function checkPipesOfBlock(
const blockType = new BlockTypeWrapper(block?.type);
const pipes = collectPipes(block, whatToCheck);

const isStartOrEnd =
(whatToCheck === 'input' && !blockType.hasInput()) ||
(whatToCheck === 'output' && !blockType.hasOutput());
if (isStartOrEnd) {
if (pipes.length > 0) {
for (const pipe of pipes) {
context.accept(
'error',
`Blocks of type ${blockType.type} do not have an ${whatToCheck}`,
whatToCheck === 'input'
? pipe.getToDiagnostic()
: pipe.getFromDiagnostic(),
);
}
}
return;
}

const hasMultipleInputPorts = pipes.length > 1 && whatToCheck === 'input';
if (hasMultipleInputPorts) {
for (const pipe of pipes) {
Expand All @@ -70,8 +52,6 @@ function checkPipesOfBlock(
return;
}

// above: there should be pipes (defined by blocktype)
// but there aren't any
if (pipes.length === 0) {
const isLastBlockOfCompositeBlocktype =
isCompositeBlocktypeDefinition(block.$container) &&
Expand All @@ -81,9 +61,18 @@ function checkPipesOfBlock(
isCompositeBlocktypeDefinition(block.$container) &&
block.$container.blocks.at(0)?.name === block.name;

const isExtractorBlock = !blockType.hasInput();
const isLoaderBlock = !blockType.hasOutput();

// exception: the first block in a composite block is connected to the input, not another block
// exception: The last block in a composite block is connected to the output, not another block
if (!isLastBlockOfCompositeBlocktype && !isFirstBlockOfCompositeBlocktype) {
// exception: the extractor / loader block in a pipeline
if (
!isLastBlockOfCompositeBlocktype &&
!isFirstBlockOfCompositeBlocktype &&
!isExtractorBlock &&
!isLoaderBlock
) {
context.accept(
'warning',
`A pipe should be connected to the ${whatToCheck} of this block`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,10 @@ function checkBlockCompatibility(
const fromBlockType = new BlockTypeWrapper(fromBlockTypeDefinition);
const toBlockType = new BlockTypeWrapper(toBlockTypeDefinition);

if (fromBlockType.hasOutput() && toBlockType.hasInput()) {
if (!fromBlockType.canBeConnectedTo(toBlockType)) {
const errorMessage = `The output type "${fromBlockType.outputType}" of ${fromBlockType.type} is incompatible with the input type "${toBlockType.inputType}" of ${toBlockType.type}`;
context.accept('error', errorMessage, pipeWrapper.getFromDiagnostic());
context.accept('error', errorMessage, pipeWrapper.getToDiagnostic());
}
if (!fromBlockType.canBeConnectedTo(toBlockType)) {
const errorMessage = `The output type "${fromBlockType.outputType}" of ${fromBlockType.type} is incompatible with the input type "${toBlockType.inputType}" of ${toBlockType.type}`;
context.accept('error', errorMessage, pipeWrapper.getFromDiagnostic());
context.accept('error', errorMessage, pipeWrapper.getToDiagnostic());
}
}
}

0 comments on commit 8e68450

Please sign in to comment.