Skip to content

Commit

Permalink
Merge branch 'main' into feat/add-debug-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
jorg-vr committed Dec 8, 2023
2 parents 9632591 + 7beaf84 commit aa3d72b
Show file tree
Hide file tree
Showing 33 changed files with 2,358 additions and 2,357 deletions.
11 changes: 11 additions & 0 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ updates:
open-pull-requests-limit: 99
labels:
- "dependencies"
groups:
eslint:
patterns:
- "eslint*"
codemirror:
patterns:
- "*codemirror*"
- "@lezer*"
types:
patterns:
- "@types*"
- package-ecosystem: github-actions
directory: "/"
schedule:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/deploy-pages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ jobs:
with:
python-version: '3.9'
- name: Checkout branch
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Clone main
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: dodona-edu/papyros
path: papyros
Expand All @@ -40,7 +40,7 @@ jobs:
mv papyros/dist dist
mv devdist dist/dev
- name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action@v4.4.1
uses: JamesIves/github-pages-deploy-action@v4.5.0
with:
branch: gh-pages # The branch the action should deploy to.
folder: dist # The folder the action should deploy.
6 changes: 3 additions & 3 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ jobs:
name: JavaScript
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 14.x
node-version: 16.x
cache: yarn
- name: Install dependencies
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install and Build 🔧
run: |
yarn install
yarn build:library
- name: Publish @dodona/papyros to NPM
uses: JS-DevTools/npm-publish@v1
uses: JS-DevTools/npm-publish@v3
with:
token: ${{ secrets.NPM_AUTH_TOKEN }}
check-version: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-drafter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ jobs:
runs-on: ubuntu-latest
steps:
# Drafts next release notes as Pull Requests are merged into "develop"
- uses: toolmantim/release-drafter@v5.21.1
- uses: toolmantim/release-drafter@v5.25.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6 changes: 3 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ jobs:
name: JavaScript
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 14.x
node-version: 16.x
cache: yarn
- name: Install dependencies
run: |
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/validate-translations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set up Node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 14.x
node-version: 16.x
cache: yarn
- name: Install dependencies
run: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ yarn-error.log*
translationIssues.txt
# Ignore output of local pip install when building the tar
src/workers/python/python_package/
src/workers/python/python_package.tar.gz.load_by_url
20 changes: 18 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,23 @@ module.exports = {
preset: 'ts-jest',
testEnvironment: 'jsdom',
setupFiles: ["./test/SetupJest.ts"],
moduleNameMapper: {
"\\.(load_by_url)$": "<rootDir>/test/__mocks__/MockTar.ts"
// fix import.meta error https://github.com/kulshekhar/ts-jest/issues/3888#issuecomment-1722524078
transform: {
'^.+\\.tsx?$': [
'ts-jest',
{
diagnostics: {
ignoreCodes: [1343]
},
astTransformers: {
before: [
{
path: 'ts-jest-mock-import-meta',
options: { metaObjectReplacement: { url: 'https://www.url.com' } }
}
]
}
}
]
}
};
87 changes: 45 additions & 42 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,61 +1,64 @@
{
"name": "@dodona/papyros",
"version": "1.0.0",
"version": "2.0.0",
"private": false,
"homepage": ".",
"devDependencies": {
"@types/escape-html": "^1.0.1",
"@types/i18n-js": "^3.8.2",
"@types/jest": "27.4.1",
"@types/serviceworker": "^0.0.56",
"@typescript-eslint/eslint-plugin": "^5.29.0",
"@typescript-eslint/parser": "^5.29.0",
"autoprefixer": "^10.4.0",
"css-loader": "^6.5.1",
"eslint": "^8.18.0",
"@types/escape-html": "^1.0.3",
"@types/i18n-js": "^3.8.7",
"@types/jest": "^29.5.10",
"@types/serviceworker": "^0.0.79",
"@typescript-eslint/eslint-plugin": "^6.9.0",
"@typescript-eslint/parser": "^6.9.0",
"autoprefixer": "^10.4.16",
"css-loader": "^6.8.1",
"eslint": "^8.52.0",
"eslint-config-google": "^0.14.0",
"eslint-plugin-jest": "^27.1.1",
"eslint-plugin-jest": "^27.6.0",
"file-loader": "^6.2.0",
"i18n-extract": "^0.6.7",
"jest": "27.0.0",
"postcss": "^8.3.11",
"postcss-import": "^15.0.0",
"postcss-loader": "^7.0.0",
"style-loader": "^3.3.1",
"tailwindcss": "^3.1.4",
"terser-webpack-plugin": "^5.3.1",
"ts-jest": "^27.1.4",
"ts-loader": "^9.2.6",
"typescript": "^4.7.4",
"url-loader": "^4.1.1",
"webpack": "^5.70.0",
"webpack-cli": "^4.10.0",
"webpack-dev-server": "^4.9.2",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"postcss": "^8.4.31",
"postcss-import": "^15.1.0",
"postcss-loader": "^7.3.3",
"style-loader": "^3.3.3",
"tailwindcss": "^3.3.5",
"terser-webpack-plugin": "^5.3.9",
"ts-jest": "^29.1.1",
"ts-jest-mock-import-meta": "^1.1.0",
"ts-loader": "^9.5.0",
"typescript": "^5.2.2",
"webpack": "^5.89.0",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^4.15.1",
"worker-loader": "^3.0.8"
},
"dependencies": {
"@codemirror/autocomplete": "^6.0.2",
"@codemirror/commands": "^6.0.0",
"@codemirror/lang-javascript": "^6.0.0",
"@codemirror/lang-python": "^6.0.0",
"@codemirror/language": "^6.1.0",
"@codemirror/lint": "^6.0.0",
"@codemirror/search": "^6.0.0",
"@codemirror/state": "^6.0.1",
"@codemirror/theme-one-dark": "^6.0.0",
"@codemirror/view": "^6.0.2",
"@lezer/common": "^1.0.0",
"comlink": "^4.3.1",
"comsync": "^0.0.8",
"@codemirror/autocomplete": "^6.11.1",
"@codemirror/commands": "^6.3.1",
"@codemirror/lang-javascript": "^6.2.1",
"@codemirror/lang-python": "^6.1.3",
"@codemirror/language": "^6.9.3",
"@codemirror/lint": "^6.4.2",
"@codemirror/search": "^6.5.4",
"@codemirror/state": "^6.3.2",
"@codemirror/theme-one-dark": "^6.1.2",
"@codemirror/view": "^6.22.1",
"@lezer/common": "^1.1.0",
"comlink": "^4.4.1",
"comsync": "^0.0.9",
"escape-html": "^1.0.3",
"i18n-js": "^3.8.0",
"pyodide-worker-runner": "^0.0.10",
"sync-message": "^0.0.10"
"pyodide": "^0.22.0",
"pyodide-worker-runner": "1.3.2",
"sync-message": "^0.0.12"
},
"scripts": {
"start": "webpack serve --mode development",
"setup": "bash scripts/setup.sh",
"build:app": "bash scripts/build_package.sh development",
"build:library": "bash scripts/build_package.sh production",
"build:app": "bash scripts/build.sh development",
"build:library": "bash scripts/build_library.sh",
"test": "jest",
"lint": "eslint --ext '.js' --ext '.ts' src",
"validate:translations": "node scripts/ValidateTranslations.js"
Expand Down
File renamed without changes.
8 changes: 8 additions & 0 deletions scripts/build_library.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
rm -rf dist
cd src/workers/python
python3 build_package.py
cd -
tsc
mv src/workers/python/python_package.tar.gz.load_by_url dist/workers/python
npx tailwindcss -i ./src/Papyros.css -o ./dist/Papyros.css
1 change: 1 addition & 0 deletions src/App.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import "./Papyros.css";
import {
addPapyrosPrefix,
DEFAULT_LOCALE, DEFAULT_PROGRAMMING_LANGUAGE,
Expand Down
67 changes: 0 additions & 67 deletions src/Backend.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,7 @@
import { CompletionContext, CompletionResult } from "@codemirror/autocomplete";
import { BackendEvent, BackendEventType } from "./BackendEvent";
import { syncExpose, SyncExtras } from "comsync";
import { BackendEventQueue } from "./BackendEventQueue";

/**
* Interface to represent the CodeMirror CompletionContext in a worker
*/
export interface WorkerAutocompleteContext {
/**
* Whether the autocompletion was explicitly requested (using keybindings)
*/
explicit: boolean;
/**
* The absolute position in the CodeMirror document
*/
pos: number;
/**
* The line number of the cursor while completing (1-based)
*/
line: number;
/**
* The column number of the cursor while completing (1-based)
*/
column: number;
/**
* The full text to autocomplete for
*/
text: string;
/**
* The match before the cursor (determined by a regex)
*/
before: {
from: number; // Absolute position of the start of the match
to: number; // Absolute position of the end of the match
text: string; // The matched text
} | null;
}

export interface WorkerDiagnostic {
/**
* 1-based index of the starting line containing the issue
Expand Down Expand Up @@ -146,38 +111,6 @@ export abstract class Backend<Extras extends SyncExtras = SyncExtras> {
*/
public abstract runCode(extras: Extras, code: string, mode?: string): Promise<void>;

/**
* Converts the context to a cloneable object containing useful properties
* to generate autocompletion suggestions with
* Class instances are not passable to workers, so we extract the useful information
* @param {CompletionContext} context Current context to autocomplete for
* @param {RegExp} expr Expression to match the previous token with
* @return {WorkerAutocompleteContext} Completion context that can be passed as a message
*/
public static convertCompletionContext(context: CompletionContext, expr = /\w*(\.)?/):
WorkerAutocompleteContext {
const [lineNr, column] = context.state.selection.ranges.map(range => {
const line = context.state.doc.lineAt(range.head);
return [line.number, (range.head - line.from)];
})[0];
const beforeMatch = context.matchBefore(expr);
return {
explicit: context.explicit,
before: beforeMatch,
pos: context.pos,
column: column,
line: lineNr,
text: context.state.doc.toString()
};
}

/**
* Generate autocompletion suggestions for the given context
* @param {WorkerAutocompleteContext} context Context to autcomplete in
*/
public abstract autocomplete(context: WorkerAutocompleteContext):
Promise<CompletionResult | null>;

/**
* Generate linting suggestions for the given code
* @param {string} code The code to lint
Expand Down
6 changes: 2 additions & 4 deletions src/BackendManager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { Backend } from "./Backend";
import { ProgrammingLanguage } from "./ProgrammingLanguage";
import PythonWorker from "./workers/python/PythonWorker.worker";
import JavaScriptWorker from "./workers/javascript/JavaScriptWorker.worker";
import { BackendEvent, BackendEventType } from "./BackendEvent";
import { LogType, papyrosLog } from "./util/Logging";
import { Channel, makeChannel } from "sync-message";
Expand Down Expand Up @@ -122,13 +120,13 @@ export abstract class BackendManager {
BackendManager.subscriberMap = new Map();
BackendManager.registerBackend(ProgrammingLanguage.Python,
() => new PyodideClient<Backend>(
() => new PythonWorker(),
() => new Worker(new URL("./workers/python/worker", import.meta.url)),
BackendManager.channel
)
);
BackendManager.registerBackend(ProgrammingLanguage.JavaScript,
() => new SyncClient<Backend>(
() => new JavaScriptWorker(),
() => new Worker(new URL("./workers/javascript/worker", import.meta.url)),
BackendManager.channel
)
);
Expand Down
4 changes: 0 additions & 4 deletions src/CodeRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,6 @@ export class CodeRunner extends Renderable<CodeRunnerRenderOptions> {
this.outputManager.onOverflow(null);
})
);
this.editor.setCompletionSource(async context => {
const completionContext = Backend.convertCompletionContext(context);
return await workerProxy.autocomplete(completionContext);
});
this.editor.setLintingSource(
async view => {
const workerDiagnostics = await workerProxy.lintCode(this.editor.getText());
Expand Down
Loading

0 comments on commit aa3d72b

Please sign in to comment.