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: Add linking tests #9

Draft
wants to merge 3 commits into
base: feature/langium-project
Choose a base branch
from
Draft
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
13 changes: 13 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
}
}
41 changes: 41 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Build

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
name: CI (${{ matrix.os }})
strategy:
fail-fast: false
matrix:
os: [windows-latest, ubuntu-latest]
runs-on: ${{ matrix.os }}
timeout-minutes: 20
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 9
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'pnpm'
- name: Build monorepo
shell: bash
run: |
pnpm install
pnpm build
- name: Test monorepo
if: success() || failure()
shell: bash
run: |
pnpm test
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.vscode/*
!.vscode/extensions.json
!.vscode/launch.json
!.vscode/tasks.json
node_modules/
dist/
out/
**/src/generated
**/syntaxes/pli.merged.json
*.tsbuildinfo
*.vsix
3 changes: 3 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
auto-install-peers = true
lockfile = true
link-workspace-packages = true
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v20.18.1
6 changes: 6 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"recommendations": [
"langium.langium-vscode",
"vitest.explorer"
]
}
88 changes: 88 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// A launch configuration that launches the extension inside a new window
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
{
"version": "0.2.0",
"configurations": [
{
"name": "Run Extension",
"type": "extensionHost",
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}/packages/vscode-extension",
"${workspaceFolder}/code_samples"
],
"sourceMaps": true,
"outFiles": [
"${workspaceFolder}/packages/language/out/**/*.js",
"${workspaceFolder}/packages/vscode-extension/out/**/*.js"
]
},
{
"name": "Run Web Extension",
"type": "extensionHost",
"debugWebWorkerHost": true,
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}/packages/vscode-extension",
"--extensionDevelopmentKind=web",
"${workspaceFolder}/code_samples"
],
"sourceMaps": true,
"outFiles": [
"${workspaceFolder}/packages/language/out/**/*.js",
"${workspaceFolder}/packages/vscode-extension/out/**/*.js"
]
},
{
"name": "Attach to Language Server",
"type": "node",
"port": 6009,
"request": "attach",
"skipFiles": [
"<node_internals>/**"
],
"sourceMaps": true,
"outFiles": [
"${workspaceFolder}/packages/language/out/**/*.js",
"${workspaceFolder}/packages/vscode-extension/out/**/*.js",
"${workspaceFolder}/node_modules/langium"
]
},
{
"name": "Vitest: Run All",
"type": "node",
"request": "launch",
"skipFiles": [
"<node_internals>/**",
],
"cwd": "${workspaceFolder}",
"runtimeExecutable": "pnpm",
"args": [
"vitest",
"run",
"--no-watch"
],
"smartStep": true,
"console": "integratedTerminal"
},
{
"name": "Vitest: Run Selected File",
"type": "node",
"request": "launch",
"autoAttachChildProcesses": true,
"skipFiles": [
"<node_internals>/**"
],
"runtimeExecutable": "pnpm",
"args": [
"vitest",
"run",
"${relativeFile}"
],
"smartStep": true,
"console": "integratedTerminal"
}
]
}
2 changes: 1 addition & 1 deletion code_samples/CHART.pli
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*PROCESS X(S),A(S),LINECOUNT(60);
/*PROCESS X(S),A(S),LINECOUNT(60); */
/* %M% %I% %D% %T%
PUNCH ' IDENTIFY **%M%1(''%M%/%I% %D% %T%'')'
PUNCH ' ENTRY PLISTART '
Expand Down
2 changes: 1 addition & 1 deletion code_samples/MACROS.pli
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*PROCESS MI(':'),NEST,X,AG,A,MAR(2,72,1),GN,NUM,STG;
/*PROCESS MI(':'),NEST,X,AG,A,MAR(2,72,1),GN,NUM,STG; */

/*** (CHECK): ***/

Expand Down
2 changes: 1 addition & 1 deletion code_samples/PLI0002.pli
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

/* DECLARE HOST-VARIABLE */
DCL TIMESTAMP CHAR(26);
DCL BUF1_CLOB SQL TYPE IS CLOB_FILE;
DCL BUF1_CLOB; // SQL TYPE IS CLOB_FILE;
EXEC SQL DECLARE :BUF1_CLOB VARIABLE CCSID EBCDIC;

DCL I FIXED BIN(31);
Expand Down
3 changes: 3 additions & 0 deletions code_samples/messages/IBM1295IE.pli
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
TEST: PROCEDURE OPTIONS(MAIN) REORDER;
dcl x(-2) fixed bin; //error: IBM1295IE Sole bound specified is less than 1. An upper bound of 1 is assumed.
END TEST;
2 changes: 2 additions & 0 deletions code_samples/messages/IBM1324IE.pli
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
0PACK: PACKAGE EXPORTS(TEST, TEST, TEST); //error: TEST has 3 occurences, needed 1
0END;
3 changes: 3 additions & 0 deletions code_samples/messages/IBM1388IE.pli
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
0a: proc( x ) options(nodescriptor); //error: The NODESCRIPTOR attribute is invalid when any parameters have the NONCONNECTED attribute.
dcl x(20) fixed bin nonconnected;
0end a;
27 changes: 27 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "pli-workspace",
"description": "Base workspace package",
"version": "0.0.1",
"type": "module",
"private": true,
"scripts": {
"watch": "tsc -b tsconfig.build.json --watch",
"build": "pnpm langium:generate && tsc -b tsconfig.build.json && pnpm --dir packages/vscode-extension build && node ./scripts/merge-tmlanguage.mjs",
"build:clean": "pnpm clean && pnpm build",
"lint": "eslint src --ext ts",
"langium:generate": "pnpm --dir packages/language langium:generate",
"langium:watch": "pnpm --dir packages/language langium:watch",
"test": "vitest"
},
"devDependencies": {
"@types/node": "^18.19.70",
"@typescript-eslint/eslint-plugin": "~7.13.1",
"@typescript-eslint/parser": "~7.13.1",
"deepmerge": "^1.5.2",
"eslint": "~8.57.1",
"langium": "~3.2.1",
"shx": "~0.3.4",
"typescript": "~5.4.5",
"vitest": "^1.6.0"
}
}
1 change: 1 addition & 0 deletions packages/language/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# PL1 Language Package
10 changes: 10 additions & 0 deletions packages/language/langium-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"projectName": "Pl1",
"languages": [{
"id": "pli",
"grammar": "src/pli.langium",
"fileExtensions": [".pli"],
"caseInsensitive": true
}],
"out": "src/generated"
}
44 changes: 44 additions & 0 deletions packages/language/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "pli-language",
"description": "The language specific package",
"version": "0.0.1",
"type": "module",
"engines": {
"node": ">=18.0.0"
},
"files": [
"out",
"src"
],
"main": "./out/index.js",
"module": "./out/index.js",
"exports": {
".": {
"types": "./out/index.d.ts",
"default": "./out/index.js"
}
},
"typesVersions": {
"*": {
".": [
"out/index"
]
}
},
"scripts": {
"clean": "shx rm -fr *.tsbuildinfo out",
"build": "echo 'No build step'",
"build:clean": "npm run clean && npm run build",
"langium:generate": "langium generate",
"langium:watch": "langium generate --watch"
},
"dependencies": {
"chevrotain": "^11.0.3",
"langium": "~3.2.0",
"vscode-languageserver": "~9.0.1",
"vscode-languageserver-types": "^3.17.5"
},
"devDependencies": {
"langium-cli": "~3.2.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*
*/

import { AstNode, JSDocDocumentationProvider } from 'langium';
import { isDeclaredVariable, isDoType3Variable, isLabelPrefix, isProcedureStatement, ProcedureStatement } from '../generated/ast';

export class PliDocumentationProvider extends JSDocDocumentationProvider {

override getDocumentation(node: AstNode): string | undefined {
if (isDeclaredVariable(node)) {
const declaredItem = node.$container;
let text = '```\n' + `DECLARE ${node.name} `;
for (const attribute of declaredItem.attributes) {
text += `${attribute.$cstNode?.text} `;
}
text += '\n```';
return text;
} else if (isLabelPrefix(node) && isProcedureStatement(node.$container)) {
return this.getProcedureHoverContent(node.$container);
} else if (isProcedureStatement(node)) {
return this.getProcedureHoverContent(node);
} else if (isDoType3Variable(node)) {
return '```\nDECLARE' + node.name + '\n```';
}
return '';
}

private getProcedureHoverContent(node: ProcedureStatement): string | undefined {
let text = '```\n';
for (const label of node.labels) {
text += `${label.name} `;
}
text += 'PROCEDURE ';
if (node.parameters.length > 0) {
text += '(' + node.parameters.map(e => e.id).join(', ') + ') ';
}
if (node.recursive.length > 0) {
text += 'RECURSIVE ';
}
if (node.order.includes('ORDER')) {
text += 'ORDER ';
} else if (node.order.includes('REORDER')) {
text += 'REORDER ';
}
if (node.options.length > 0) {
text += node.options.map(e => e.$cstNode?.text).join(' ');
}
if (node.returns.length > 0) {
text += node.returns.map(e => e.$cstNode?.text).join(' ');
}
text += '\n```';
return text;
}

}
17 changes: 17 additions & 0 deletions packages/language/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*
*/

export * from './pli-module.js';
export * from './validation/pli-validator.js';
export * from './generated/ast.js';
export * from './generated/grammar.js';
export * from './generated/module.js';
export * from './workspace/pli-builtin-functions.js';
Loading