Skip to content
Open
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
8 changes: 4 additions & 4 deletions apps/docs-generator/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
}
},
"start": {
"executor": "@nx/js:node",
"dependsOn": ["generate-language-server"],
"executor": "nx:run-commands",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add a comment here and say that this did not work with @nx/js:node and link the PR?

"dependsOn": ["generate-language-server", "build"],
"options": {
"watch": false,
"buildTarget": "docs-generator:build"
"commands": ["node dist/apps/docs-generator/main.js"],
"parallel": false
}
},
"generate-language-server": {
Expand Down
4 changes: 3 additions & 1 deletion apps/docs-generator/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,6 @@ ${exampleModel.toString()}

main()
.then(() => console.log('Finished generating docs!'))
.catch((e) => console.error(e));
.catch((e) => {
throw e;
});
25 changes: 5 additions & 20 deletions apps/docs-generator/src/user-doc-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,15 @@ that fullfil [_constraints_](./primitive-value-types#constraints).`.trim(),
valueTypes
.filter((valueType) => valueType.isReferenceableByUser())
.forEach((valueType) => {
const description = valueType.getUserDocDescription();
assert(
valueType.getUserDoc() !== undefined,
description !== undefined,
`Documentation is missing for user extendable value type: ${valueType.getName()}`,
);
builder
.heading(valueType.getName(), 2)
.description(valueType.getUserDoc() ?? '', 3)
.examples(
[
{
code: `
block ExampleTableInterpreter oftype TableInterpreter {
header: true;
columns: [
"columnName" oftype ${valueType.getName()}
];
}`.trim(),
description: `A block of type \`TableInterpreter\` that
interprets data in the column \`columnName\` as \`${valueType.getName()}\`.
`.trim(),
},
],
3,
);
.description(description, 3)
.examples(valueType.getUserDocExamples(), 3);
});

return builder.build();
Expand Down Expand Up @@ -109,7 +94,7 @@ block ExampleTableInterpreter oftype TableInterpreter {
return builder.build();
}

private extractDocsFromComment(comment?: string | undefined):
private extractDocsFromComment(comment?: string):
| {
description: string | undefined;
examples: ExampleDoc[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class BooleanValuetype extends PrimitiveValueType<boolean> {
return true;
}

override getUserDoc(): string {
override getUserDocDescription(): string {
return `
A boolean value.
Examples: true, false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class DecimalValuetype extends PrimitiveValueType<number> {
return true;
}

override getUserDoc(): string {
override getUserDocDescription(): string {
return `
A decimal value.
Example: 3.14
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class IntegerValuetype extends PrimitiveValueType<number> {
return true;
}

override getUserDoc(): string {
override getUserDocDescription(): string {
return `
An integer value.
Example: 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from '../../../expressions/internal-value-representation';
import { AbstractValueType } from '../abstract-value-type';
import { type ValueType } from '../value-type';
import { type ExampleDoc } from '../../typed-object/typed-object-wrapper';

export abstract class PrimitiveValueType<
I extends InternalValidValueRepresentation = InternalValidValueRepresentation,
Expand All @@ -33,10 +34,39 @@ export abstract class PrimitiveValueType<
* Text only, no comment characters.
* Should be given for all user-referenceable value types {@link isReferenceableByUser}
*/
getUserDoc(): string | undefined {
getUserDocDescription(): string | undefined {
return undefined;
}

getUserDocExamples(): ExampleDoc[] {
const name = this.getName();
const capitalizedName = name.charAt(0).toUpperCase() + name.slice(1);
return [
{
code: `
valuetype TableSchema {
tableColumn: ${name};
}
transfrom tableRowParser {
from r oftype SheetRow;
to tableRow oftye TableSchema;

tableRow: {
tableColumn: as${capitalizedName} (r . "tableColumn");
};
}
block ExampleTableInterpreter oftype TableInterpreter {
header: true;
columns: TableSchema;
parseWith: tableRowParser;
}`.trim(),
description:
`A block of type \`TableInterpreter\` that interprets data in the column "columnName" as \`${name}\`.
`.trim(),
},
Comment on lines +47 to +66
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be cool to have a real example / close to a real use-case and not a dummy one

];
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
fromString(_s: string): I | InvalidValue {
return new InvalidValue(`Cannot parse ${this.getName()}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import { PrimitiveValueType } from './primitive-value-type';
import { type ValueTypeVisitor } from '../value-type';
import { type InternalValidValueRepresentation } from '../../../expressions';
import { type ExampleDoc } from '../../typed-object/typed-object-wrapper';

export class SheetRowValueType extends PrimitiveValueType<string[]> {
acceptVisitor<R>(visitor: ValueTypeVisitor<R>): R {
Expand All @@ -19,6 +20,41 @@ export class SheetRowValueType extends PrimitiveValueType<string[]> {
return 'SheetRow';
}

override getUserDocDescription(): string {
return `
The values of a row inside a sheet. Only usable inside a transform that parses SheetRows into a value type.
Accessible via the dot operator (see example).
`.trim();
}

override getUserDocExamples(): ExampleDoc[] {
return [
{
code: `
valuetype Coordinate {
x: decimal;
y: decimal;
}
transfrom coordinateParser {
from r oftype SheetRow;
to coord oftye Coordinate;

coord: {
x: asDecimal (r . "x");
y: asDecimal (r . 1);
};
}
block ExampleTableInterpreter oftype TableInterpreter {
header: true;
columns: Coordinate;
parseWith: CoordinateParser;
}`.trim(),
description:
'A transform, used in a block of type `TableInterpreter`, that interprets a `SheetRow` into a table row with columns `x` and `y`.',
},
];
}

override isInternalValidValueRepresentation(
operandValue: InternalValidValueRepresentation,
): operandValue is string[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ export class TextValuetype extends PrimitiveValueType<string> {
return true;
}

override getUserDoc(): string {
override getUserDocDescription(): string {
return `
A text value.
A text value.
Example: "Hello World"
`.trim();
}
Expand Down
2 changes: 1 addition & 1 deletion libs/language-server/src/lib/workspace/stdlib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function getStdLib() {
function parseBuiltinValuetypeToJayvee(valueType: PrimitiveValueType): string {
const lines: string[] = [];

const userDoc = valueType.getUserDoc();
const userDoc = valueType.getUserDocDescription();
if (userDoc !== undefined) {
lines.push(parseAsComment(userDoc));
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"example:gtfs": "nx run interpreter:run -d example/gtfs-static.jv -dg peek",
"example:gtfs-rt": "nx run interpreter:run -d example/gtfs-rt.jv -dg peek",
"example:workbooks": "nx run interpreter:run -d example/workbooks-xlsx.jv -dg peek",
"example:vehicles": "nx run interpreter:run -d -e DB_HOST=localhost -e DB_PORT=5432 -e DB_USERNAME=postgres -e DB_PASSWORD=postgres -e DB_DATABASE=postgres example/electric-vehicles.jv -dg peek"
"example:vehicles": "nx run interpreter:run -d -e DB_HOST=localhost -e DB_PORT=5432 -e DB_USERNAME=postgres -e DB_PASSWORD=postgres -e DB_DATABASE=postgres example/electric-vehicles.jv -dg peek",
"clean": "nx reset && rm -r dist/ tmp/ apps/vs-code-extension/assets/jayvee.tmLanguage.json apps/docs/docs/user/block-types/**/*.md apps/docs/docs/user/value-types/built-in-value-types.md apps/docs/docs/user/examples/*.md apps/docs/src/theme/prism-jayvee.js libs/language-server/src/lib/*/generated libs/monaco-editor/src/lib/{language-configuration,jayvee.tmLanguage}.json"
},
"private": true,
"dependencies": {
Expand Down