├── .dockerignore ├── .editorconfig ├── .github ├── CODEOWNERS ├── gitpod.yml ├── stale.yml └── workflows │ ├── debugger-py.yml │ ├── ghp.yml │ ├── ls-clangd.yml │ ├── ls-eclipsejdt.yml │ ├── ls-groovy.yml │ ├── main.yml │ ├── peer.yml │ └── verify.yml ├── .gitignore ├── .gitpod.yml ├── .vscode ├── extensions.json ├── launch.json └── settings.json ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── docs ├── images │ ├── no-overrides.png │ └── with-overrides.png └── versions-and-history.md ├── eslint.config.mjs ├── index.html ├── package-lock.json ├── package.json ├── packages ├── client │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── package.json │ ├── src │ │ ├── client.ts │ │ ├── commonTypes.ts │ │ ├── fs │ │ │ ├── definitions.ts │ │ │ ├── endpoints │ │ │ │ └── defaultEndpoint.ts │ │ │ └── index.ts │ │ ├── index.ts │ │ ├── tools │ │ │ ├── index.ts │ │ │ ├── logging.ts │ │ │ └── utils.ts │ │ ├── vscode │ │ │ ├── fakeWorker.ts │ │ │ ├── index.ts │ │ │ └── services.ts │ │ └── workerFactory.ts │ ├── test │ │ ├── fs │ │ │ └── endpoints │ │ │ │ └── emptyEndpoint.test.ts │ │ ├── tools │ │ │ ├── index.test.ts │ │ │ └── utils.test.ts │ │ ├── vscode │ │ │ └── services.test.ts │ │ └── workerFactory.test.ts │ ├── tsconfig.json │ ├── tsconfig.src.json │ └── tsconfig.test.json ├── examples │ ├── .gitignore │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── appPlayground.html │ ├── bare.html │ ├── browser.html │ ├── clangd.html │ ├── eclipse.jdt.ls.html │ ├── ghp_appPlayground.html │ ├── ghp_browser.html │ ├── ghp_clangd.html │ ├── ghp_langium_classic.html │ ├── ghp_langium_extended.html │ ├── ghp_react_appPlayground.html │ ├── ghp_react_statemachine.html │ ├── ghp_statemachine.html │ ├── ghp_tsExtHost.html │ ├── groovy.html │ ├── index.html │ ├── json.html │ ├── langium_classic.html │ ├── langium_extended.html │ ├── package.json │ ├── python.html │ ├── react_appPlayground.html │ ├── react_python.html │ ├── react_statemachine.html │ ├── resources │ │ ├── appPlayground │ │ │ ├── hello.ts │ │ │ ├── tester.ts │ │ │ └── views.html │ │ ├── clangd │ │ │ ├── build-docker.sh │ │ │ ├── build.Dockerfile │ │ │ ├── build.docker-compose.yml │ │ │ ├── clangd-include.files.md │ │ │ ├── configure-docker.sh │ │ │ ├── configure.Dockerfile │ │ │ ├── configure.docker-compose.yml │ │ │ ├── scripts │ │ │ │ └── extractDockerFiles.ts │ │ │ ├── wait_stdin.patch │ │ │ └── workspace │ │ │ │ ├── .clangd │ │ │ │ ├── main.cpp │ │ │ │ └── tester.h │ │ ├── debugger │ │ │ ├── Dockerfile │ │ │ ├── docker-compose.yml │ │ │ └── package.json │ │ ├── eclipse.jdt.ls │ │ │ ├── Dockerfile │ │ │ ├── docker-compose.yml │ │ │ └── workspace │ │ │ │ └── hello.java │ │ ├── groovy │ │ │ ├── Dockerfile │ │ │ └── docker-compose.yml │ │ ├── langium │ │ │ ├── langium-dsl │ │ │ │ └── example.langium │ │ │ └── statemachine │ │ │ │ ├── example-mod.statemachine │ │ │ │ └── example.statemachine │ │ ├── python │ │ │ ├── bad.py │ │ │ ├── hello.py │ │ │ └── hello2.py │ │ ├── scripts │ │ │ └── downloadResources.ts │ │ └── styles │ │ │ └── views.css │ ├── src │ │ ├── appPlayground │ │ │ ├── common.ts │ │ │ ├── config.ts │ │ │ ├── launcher.ts │ │ │ ├── main.ts │ │ │ ├── reactLauncher.ts │ │ │ └── reactMain.tsx │ │ ├── bare │ │ │ └── client.ts │ │ ├── browser │ │ │ └── main.ts │ │ ├── clangd │ │ │ ├── README.md │ │ │ ├── client │ │ │ │ ├── config.ts │ │ │ │ ├── main.ts │ │ │ │ ├── mainRemoteMessageChannelFs.ts │ │ │ │ └── workerHandler.ts │ │ │ ├── definitions.ts │ │ │ └── worker │ │ │ │ ├── clangd-server.ts │ │ │ │ ├── json_stream.ts │ │ │ │ ├── memfs-tools.ts │ │ │ │ └── workerRemoteMessageChannelFs.ts │ │ ├── common │ │ │ ├── client │ │ │ │ └── utils.ts │ │ │ └── node │ │ │ │ ├── language-server-runner.ts │ │ │ │ └── server-commons.ts │ │ ├── debugger │ │ │ ├── client │ │ │ │ └── debugger.ts │ │ │ ├── common │ │ │ │ └── definitions.ts │ │ │ └── server │ │ │ │ ├── DAPSocket.ts │ │ │ │ └── debugServer.ts │ │ ├── eclipse.jdt.ls │ │ │ ├── client │ │ │ │ └── main.ts │ │ │ ├── config.ts │ │ │ └── server │ │ │ │ ├── direct.ts │ │ │ │ └── main.ts │ │ ├── groovy │ │ │ ├── client │ │ │ │ └── main.ts │ │ │ ├── config.ts │ │ │ └── server │ │ │ │ ├── direct.ts │ │ │ │ └── main.ts │ │ ├── index.ts │ │ ├── json │ │ │ ├── client │ │ │ │ └── wrapperWs.ts │ │ │ └── server │ │ │ │ ├── direct.ts │ │ │ │ ├── json-server.ts │ │ │ │ └── main.ts │ │ ├── langium │ │ │ ├── langium-dsl │ │ │ │ ├── config │ │ │ │ │ ├── classicConfig.ts │ │ │ │ │ ├── extendedConfig.ts │ │ │ │ │ ├── langium.configuration.json │ │ │ │ │ ├── langium.monarch.ts │ │ │ │ │ └── langium.tmLanguage.json │ │ │ │ ├── worker │ │ │ │ │ └── langium-server.ts │ │ │ │ └── wrapperLangium.ts │ │ │ └── statemachine │ │ │ │ ├── config │ │ │ │ ├── langium-config.json │ │ │ │ ├── language-configuration.json │ │ │ │ └── wrapperStatemachineConfig.ts │ │ │ │ ├── launcher.ts │ │ │ │ ├── ls │ │ │ │ ├── generated │ │ │ │ │ ├── ast.ts │ │ │ │ │ ├── grammar.ts │ │ │ │ │ └── module.ts │ │ │ │ ├── statemachine-module.ts │ │ │ │ ├── statemachine-validator.ts │ │ │ │ └── statemachine.langium │ │ │ │ ├── main-react.tsx │ │ │ │ ├── main.ts │ │ │ │ ├── syntaxes │ │ │ │ └── statemachine.tmLanguage.json │ │ │ │ └── worker │ │ │ │ ├── statemachine-server-port.ts │ │ │ │ ├── statemachine-server-start.ts │ │ │ │ └── statemachine-server.ts │ │ ├── multi │ │ │ ├── config.ts │ │ │ └── twoLanguageClients.ts │ │ ├── node.ts │ │ ├── python │ │ │ ├── client │ │ │ │ ├── config.ts │ │ │ │ ├── main.ts │ │ │ │ └── reactPython.tsx │ │ │ └── server │ │ │ │ ├── direct.ts │ │ │ │ └── main.ts │ │ ├── ts │ │ │ └── wrapperTs.ts │ │ └── vite-env.d.ts │ ├── statemachine.html │ ├── style.css │ ├── tsExtHost.html │ ├── tsconfig.json │ ├── tsconfig.src.json │ ├── two_langauge_clients.html │ ├── vite.config.deploy.ts │ ├── vite.config.preview.ts │ └── vite.production.base.ts ├── vscode-ws-jsonrpc │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── package.json │ ├── src │ │ ├── connection.ts │ │ ├── disposable.ts │ │ ├── index.ts │ │ ├── logger.ts │ │ ├── server │ │ │ ├── connection.ts │ │ │ ├── index.ts │ │ │ └── launch.ts │ │ └── socket │ │ │ ├── connection.ts │ │ │ ├── index.ts │ │ │ ├── reader.ts │ │ │ ├── socket.ts │ │ │ └── writer.ts │ ├── tsconfig.json │ └── tsconfig.src.json ├── wrapper-react │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── package.json │ ├── src │ │ └── index.tsx │ ├── test │ │ ├── helper.ts │ │ └── index.test.tsx │ ├── tsconfig.json │ ├── tsconfig.src.json │ └── tsconfig.test.json └── wrapper │ ├── .gitignore │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── package.json │ ├── src │ ├── editorApp.ts │ ├── index.ts │ ├── languageClientWrapper.ts │ ├── vscode │ │ ├── index.ts │ │ ├── localeLoader.ts │ │ ├── services.ts │ │ └── viewsService.ts │ ├── workers │ │ └── workerLoaders.ts │ └── wrapper.ts │ ├── test │ ├── editorApp-classic.test.ts │ ├── editorApp.test.ts │ ├── languageClientWrapper.test.ts │ ├── support │ │ ├── helper-classic.ts │ │ └── helper.ts │ ├── utils.test.ts │ ├── vscode │ │ └── services.test.ts │ ├── workers │ │ └── workerLoaders.test.ts │ ├── wrapper-classic.test.ts │ └── wrapper.test.ts │ ├── tsconfig.json │ ├── tsconfig.src.json │ └── tsconfig.test.json ├── scripts ├── auth.sh ├── clean.ts └── helper.ts ├── tsconfig.build.json ├── tsconfig.json ├── verify ├── README.md ├── angular │ ├── .gitignore │ ├── README.md │ ├── angular.json │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── app │ │ │ ├── app.component.html │ │ │ ├── app.component.scss │ │ │ └── app.component.ts │ │ ├── index.html │ │ ├── main.ts │ │ ├── monaco-angular-wrapper │ │ │ ├── monaco-angular-wrapper.component.html │ │ │ ├── monaco-angular-wrapper.component.scss │ │ │ └── monaco-angular-wrapper.component.ts │ │ └── save-code.service.ts │ └── tsconfig.json ├── buildAll.ps1 ├── buildAll.sh ├── buildPeers.ps1 ├── buildPeers.sh ├── next │ ├── .gitignore │ ├── app │ │ ├── layout.tsx │ │ └── page.tsx │ ├── next-env.d.ts │ ├── next.config.mjs │ ├── package-lock.json │ ├── package.json │ └── tsconfig.json ├── peerNpm │ ├── package-lock.json │ ├── package.json │ ├── src │ │ └── testerNpm.ts │ └── tsconfig.json ├── peerPnpm │ ├── package.json │ ├── pnpm-lock.yaml │ ├── src │ │ └── testerPnpm.ts │ └── tsconfig.json ├── peerYarn │ ├── .gitignore │ ├── package.json │ ├── src │ │ └── testerYarn.ts │ ├── tsconfig.json │ └── yarn.lock ├── vite │ ├── .gitignore │ ├── index.html │ ├── package-lock.json │ ├── package.json │ ├── src │ │ └── client │ │ │ └── main.ts │ └── vite.config.ts └── webpack │ ├── .gitignore │ ├── index.html │ ├── package-lock.json │ ├── package.json │ ├── src │ └── client │ │ └── main.ts │ ├── tsconfig.json │ └── webpack.config.js ├── vite.config.ts ├── vitest.config.ts └── vitest.shims.d.ts /.dockerignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 4 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [*.json] 12 | indent_size = 2 13 | 14 | [*.md] 15 | indent_size = 2 16 | 17 | [*.yml] 18 | indent_size = 2 19 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @CGNonofr @kaisalmen 2 | -------------------------------------------------------------------------------- /.github/gitpod.yml: -------------------------------------------------------------------------------- 1 | pulls: 2 | # Enable for pull requests 3 | perform: true 4 | # Customize a comment to post on a pull request. Comment out to use the default 5 | # comment: 6 | 7 | issues: 8 | # enable for issues 9 | perform: true 10 | # issues with these labels will be considered. Set to `[]` to disable for issues 11 | labels: 12 | - help wanted 13 | - good first issue 14 | # Customize a comment to post on an issue. Comment out to use the default 15 | # comment: 16 | -------------------------------------------------------------------------------- /.github/stale.yml: -------------------------------------------------------------------------------- 1 | # Number of days of inactivity before an issue becomes stale 2 | daysUntilStale: 60 3 | # Number of days of inactivity before a stale issue is closed 4 | daysUntilClose: 7 5 | # Issues with these labels will never be considered stale 6 | exemptLabels: 7 | - pinned 8 | - security 9 | # Label to use when marking an issue as stale 10 | staleLabel: stale 11 | # Comment to post when marking an issue as stale. Set to `false` to disable 12 | markComment: > 13 | This issue has been automatically marked as stale because it has not had 14 | recent activity. It will be closed if no further activity occurs. Thank you 15 | for your contributions. 16 | # Comment to post when removing the stale label. Set to `false` to disable 17 | unmarkComment: false 18 | # Comment to post when closing a stale Issue or Pull Request. Set to `false` to disable 19 | closeComment: false -------------------------------------------------------------------------------- /.github/workflows/debugger-py.yml: -------------------------------------------------------------------------------- 1 | name: Python Debugger Image 2 | 3 | on: 4 | workflow_dispatch: 5 | push: 6 | branches: 7 | - issue-690-debugger 8 | 9 | env: 10 | REGISTRY: ghcr.io 11 | REPO_NAME: ${{ github.repository }} 12 | PATH_CONTEXT: ./packages/examples/resources/debugger 13 | CONTAINER_NAME: debugger-py 14 | 15 | jobs: 16 | image-debugger-py: 17 | name: Build & Deploy Python Debugger 18 | runs-on: ubuntu-latest 19 | 20 | permissions: 21 | contents: read 22 | packages: write 23 | attestations: write 24 | id-token: write 25 | 26 | timeout-minutes: 15 27 | steps: 28 | - name: Checkout 29 | uses: actions/checkout@v4 30 | 31 | - name: Login to GitHub Container Registry 32 | uses: docker/login-action@v3 33 | with: 34 | registry: ${{ env.REGISTRY }} 35 | username: ${{ github.actor }} 36 | password: ${{ secrets.GITHUB_TOKEN }} 37 | 38 | - name: Extract metadata 39 | id: meta 40 | uses: docker/metadata-action@v5 41 | with: 42 | images: | 43 | ${{ env.REGISTRY }}/${{ env.REPO_NAME }}/${{ env.CONTAINER_NAME }} 44 | # enforce latest tag for now 45 | tags: | 46 | type=raw,value=latest 47 | 48 | - name: Build & Push 49 | id: push 50 | uses: docker/build-push-action@v6 51 | with: 52 | context: . 53 | file: ${{ env.PATH_CONTEXT }}/Dockerfile 54 | push: true 55 | tags: ${{ steps.meta.outputs.tags }} 56 | labels: ${{ steps.meta.outputs.labels }} 57 | 58 | - name: Attest 59 | uses: actions/attest-build-provenance@v1 60 | with: 61 | subject-name: ${{ env.REGISTRY }}/${{ env.REPO_NAME }}/${{ env.CONTAINER_NAME }} 62 | subject-digest: ${{ steps.push.outputs.digest }} 63 | push-to-registry: true 64 | -------------------------------------------------------------------------------- /.github/workflows/ghp.yml: -------------------------------------------------------------------------------- 1 | name: Build Production for GitHub Pages 2 | 3 | on: 4 | push: 5 | branches: 6 | - "ghp" 7 | 8 | # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages 9 | permissions: 10 | contents: read 11 | pages: write 12 | id-token: write 13 | 14 | jobs: 15 | ghp-build: 16 | runs-on: ubuntu-latest 17 | timeout-minutes: 15 18 | 19 | steps: 20 | - name: Checkout 21 | uses: actions/checkout@v4 22 | 23 | - name: Volta 24 | uses: volta-cli/action@v4 25 | 26 | - name: Use pnpm 27 | uses: pnpm/action-setup@v3 28 | with: 29 | version: 9 30 | 31 | - name: Install 32 | shell: bash 33 | run: | 34 | npm ci 35 | 36 | - name: Versions Report 37 | shell: bash 38 | run: | 39 | npm run report:versions 40 | 41 | - name: Build 42 | run: | 43 | npm run build 44 | 45 | - name: Build Production 46 | run: | 47 | npm run production:build 48 | 49 | - name: Setup Pages 50 | id: pages 51 | uses: actions/configure-pages@v5 52 | 53 | - name: Upload artifact 54 | uses: actions/upload-pages-artifact@v3 55 | with: 56 | path: ./packages/examples/production/ 57 | 58 | ghp-deploy: 59 | needs: ghp-build 60 | environment: 61 | name: github-pages 62 | url: ${{ steps.deployment.outputs.page_url }} 63 | runs-on: ubuntu-latest 64 | 65 | steps: 66 | - name: Deploy to GitHub Pages 67 | id: deployment 68 | uses: actions/deploy-pages@v4 69 | -------------------------------------------------------------------------------- /.github/workflows/ls-eclipsejdt.yml: -------------------------------------------------------------------------------- 1 | name: Eclipse JDT LS Image 2 | 3 | on: 4 | workflow_dispatch: 5 | 6 | env: 7 | REGISTRY: ghcr.io 8 | REPO_NAME: ${{ github.repository }} 9 | PATH_CONTEXT: ./packages/examples/resources/eclipse.jdt.ls 10 | CONTAINER_NAME: eclipse.jdt.ls 11 | 12 | jobs: 13 | image-eclipsejdtls: 14 | name: Build & Deploy Eclipse JDT LS 15 | runs-on: ubuntu-latest 16 | 17 | permissions: 18 | contents: read 19 | packages: write 20 | attestations: write 21 | id-token: write 22 | 23 | timeout-minutes: 15 24 | steps: 25 | - name: Checkout 26 | uses: actions/checkout@v4 27 | 28 | - name: Login to GitHub Container Registry 29 | uses: docker/login-action@v3 30 | with: 31 | registry: ${{ env.REGISTRY }} 32 | username: ${{ github.actor }} 33 | password: ${{ secrets.GITHUB_TOKEN }} 34 | 35 | - name: Extract metadata 36 | id: meta 37 | uses: docker/metadata-action@v5 38 | with: 39 | images: | 40 | ${{ env.REGISTRY }}/${{ env.REPO_NAME }}/${{ env.CONTAINER_NAME }} 41 | # enforce latest tag for now 42 | tags: | 43 | type=raw,value=latest 44 | 45 | - name: Build & Push 46 | id: push 47 | uses: docker/build-push-action@v6 48 | with: 49 | context: . 50 | file: ${{ env.PATH_CONTEXT }}/Dockerfile 51 | push: true 52 | tags: ${{ steps.meta.outputs.tags }} 53 | labels: ${{ steps.meta.outputs.labels }} 54 | 55 | - name: Attest 56 | uses: actions/attest-build-provenance@v1 57 | with: 58 | subject-name: ${{ env.REGISTRY }}/${{ env.REPO_NAME }}/${{ env.CONTAINER_NAME }} 59 | subject-digest: ${{ steps.push.outputs.digest }} 60 | push-to-registry: true 61 | -------------------------------------------------------------------------------- /.github/workflows/ls-groovy.yml: -------------------------------------------------------------------------------- 1 | name: Groovy LS Image 2 | 3 | on: 4 | workflow_dispatch: 5 | 6 | env: 7 | REGISTRY: ghcr.io 8 | REPO_NAME: ${{ github.repository }} 9 | PATH_CONTEXT: ./packages/examples/resources/groovy 10 | CONTAINER_NAME: groovy.ls 11 | 12 | jobs: 13 | image-groovyls: 14 | name: Build & Deploy Groovy LS 15 | runs-on: ubuntu-latest 16 | 17 | permissions: 18 | contents: read 19 | packages: write 20 | attestations: write 21 | id-token: write 22 | 23 | timeout-minutes: 15 24 | steps: 25 | - name: Checkout 26 | uses: actions/checkout@v4 27 | 28 | - name: Login to GitHub Container Registry 29 | uses: docker/login-action@v3 30 | with: 31 | registry: ${{ env.REGISTRY }} 32 | username: ${{ github.actor }} 33 | password: ${{ secrets.GITHUB_TOKEN }} 34 | 35 | - name: Extract metadata 36 | id: meta 37 | uses: docker/metadata-action@v5 38 | with: 39 | images: | 40 | ${{ env.REGISTRY }}/${{ env.REPO_NAME }}/${{ env.CONTAINER_NAME }} 41 | # enforce latest tag for now 42 | tags: | 43 | type=raw,value=latest 44 | 45 | - name: Build & Push 46 | id: push 47 | uses: docker/build-push-action@v6 48 | with: 49 | context: . 50 | file: ${{ env.PATH_CONTEXT }}/Dockerfile 51 | push: true 52 | tags: ${{ steps.meta.outputs.tags }} 53 | labels: ${{ steps.meta.outputs.labels }} 54 | 55 | - name: Attest 56 | uses: actions/attest-build-provenance@v1 57 | with: 58 | subject-name: ${{ env.REGISTRY }}/${{ env.REPO_NAME }}/${{ env.CONTAINER_NAME }} 59 | subject-digest: ${{ steps.push.outputs.digest }} 60 | push-to-registry: true 61 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: Build, Lint and Test 2 | 3 | on: 4 | push: 5 | branches: 6 | - 'main' 7 | tags-ignore: 8 | - '**' 9 | pull_request: 10 | branches: 11 | - main 12 | - dev 13 | workflow_dispatch: 14 | 15 | jobs: 16 | build: 17 | runs-on: ubuntu-latest 18 | timeout-minutes: 10 19 | 20 | steps: 21 | - name: Checkout 22 | uses: actions/checkout@v4 23 | 24 | - name: Volta 25 | uses: volta-cli/action@v4 26 | with: 27 | node-version: 20 28 | 29 | - name: Use pnpm 30 | uses: pnpm/action-setup@v3 31 | with: 32 | version: 9 33 | 34 | - name: Install 35 | shell: bash 36 | run: | 37 | npm ci 38 | 39 | - name: Versions Report 40 | shell: bash 41 | run: | 42 | npm run report:versions 43 | 44 | - name: Build 45 | shell: bash 46 | run: | 47 | npm run build 48 | 49 | - name: Lint 50 | shell: bash 51 | run: | 52 | npm run lint 53 | 54 | - name: Test 55 | shell: bash 56 | run: | 57 | npm run test:install 58 | npm run test:run 59 | -------------------------------------------------------------------------------- /.github/workflows/peer.yml: -------------------------------------------------------------------------------- 1 | name: Verification Peer Builds 2 | 3 | on: 4 | push: 5 | branches: 6 | - 'peer' 7 | workflow_dispatch: 8 | 9 | jobs: 10 | peerVerify: 11 | runs-on: ubuntu-latest 12 | timeout-minutes: 10 13 | 14 | steps: 15 | - name: Checkout 16 | uses: actions/checkout@v4 17 | 18 | - name: Volta 19 | uses: volta-cli/action@v4 20 | 21 | - name: Use pnpm 22 | uses: pnpm/action-setup@v3 23 | with: 24 | version: 9 25 | 26 | - name: Install 27 | shell: bash 28 | run: | 29 | npm ci 30 | 31 | - name: Versions Report 32 | shell: bash 33 | run: | 34 | npm run report:versions 35 | 36 | - name: Execute peer verification 37 | shell: bash 38 | run: | 39 | bash ./verify/buildPeers.sh 40 | -------------------------------------------------------------------------------- /.github/workflows/verify.yml: -------------------------------------------------------------------------------- 1 | name: Verification Builds 2 | 3 | on: 4 | push: 5 | branches: 6 | - 'verify' 7 | workflow_dispatch: 8 | 9 | jobs: 10 | verify: 11 | runs-on: ubuntu-latest 12 | timeout-minutes: 10 13 | 14 | steps: 15 | - name: Checkout 16 | uses: actions/checkout@v4 17 | 18 | - name: Volta 19 | uses: volta-cli/action@v4 20 | 21 | - name: Use pnpm 22 | uses: pnpm/action-setup@v3 23 | with: 24 | version: 9 25 | 26 | - name: Install 27 | shell: bash 28 | run: | 29 | npm ci 30 | 31 | - name: Versions Report 32 | shell: bash 33 | run: | 34 | npm run report:versions 35 | 36 | - name: Execute verification 37 | shell: bash 38 | run: | 39 | bash ./verify/buildPeers.sh 40 | bash ./verify/buildAll.sh 41 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | bundle 2 | dist 3 | lib 4 | node_modules 5 | *.tsbuildinfo 6 | .angular 7 | __screenshots__ 8 | .chrome 9 | -------------------------------------------------------------------------------- /.gitpod.yml: -------------------------------------------------------------------------------- 1 | ports: 2 | - port: 30000 3 | - port: 30001 4 | - port: 8080 5 | tasks: 6 | - before: bash scripts/auth.sh 7 | init: npm i 8 | command: npm run build 9 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "dbaeumer.vscode-eslint", 4 | "editorconfig.editorconfig", 5 | "davidanson.vscode-markdownlint", 6 | "vitest.explorer" 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible Node.js debug attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch JSON LS", 9 | "type": "node", 10 | "request": "launch", 11 | "args": ["${workspaceRoot}/packages/examples/src/json/server/direct.ts"], 12 | "runtimeArgs": ["--nolazy", "--loader", "ts-node/esm"], 13 | "cwd": "${workspaceRoot}/packages/examples", 14 | "internalConsoleOptions": "openOnSessionStart" 15 | }, 16 | { 17 | "name": "Launch Python LS", 18 | "type": "node", 19 | "request": "launch", 20 | "args": ["${workspaceRoot}/packages/examples/src/python/server/direct.ts"], 21 | "runtimeArgs": ["--nolazy", "--loader", "ts-node/esm"], 22 | "cwd": "${workspaceRoot}/packages/examples", 23 | "internalConsoleOptions": "openOnSessionStart" 24 | }, 25 | { 26 | "name": "Chrome", 27 | "type": "chrome", 28 | "request": "launch", 29 | "url": "http://localhost:20001", 30 | "webRoot": "${workspaceFolder}", 31 | "userDataDir": "${workspaceFolder}/.chrome/profile" 32 | }, 33 | { 34 | "name": "Chrome Preview", 35 | "type": "chrome", 36 | "request": "launch", 37 | "url": "http://localhost:20002", 38 | "webRoot": "${workspaceFolder}/packages/examples/production", 39 | "userDataDir": "${workspaceFolder}/.chrome/profile" 40 | }, 41 | { 42 | "type": "node", 43 | "request": "launch", 44 | "name": "Run Vitest Browser Debug", 45 | "program": "${workspaceRoot}/node_modules/vitest/vitest.mjs", 46 | "args": ["--config", "vitest.config.ts", "--inspect-brk=20222", "--browser", "--no-file-parallelism"], 47 | "console": "integratedTerminal" 48 | }, 49 | { 50 | "type": "chrome", 51 | "request": "attach", 52 | "name": "Attach to Playwright Chromium", 53 | "port": 20222 54 | } 55 | ], 56 | "compounds": [ 57 | { 58 | "name": "Debug Vitest Browser", 59 | "configurations": ["Attach to Playwright Chromium", "Run Vitest Browser Debug"], 60 | "stopAll": true 61 | } 62 | ] 63 | } 64 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "typescript.tsdk": "node_modules/typescript/lib", 3 | "editor.guides.bracketPairs": true, 4 | "editor.formatOnSave": false, 5 | "workbench.editor.revealIfOpen": true, 6 | "[javascript]": { 7 | "editor.formatOnSave": true, 8 | }, 9 | "[typescript]": { 10 | "editor.formatOnSave": true, 11 | }, 12 | "eslint.codeAction.showDocumentation": { 13 | "enable": true 14 | }, 15 | "eslint.format.enable": false, 16 | "eslint.validate": [ 17 | "javascript", 18 | "typescript" 19 | ], 20 | "[json]": { 21 | "editor.defaultFormatter": "vscode.json-language-features" 22 | }, 23 | "terminal.integrated.scrollback": 10000 24 | } 25 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes for `monaco-languageclient` are found here: 4 | 5 | [monaco-languageclient CHANGELOG](./packages/client/CHANGELOG.md) 6 | 7 | All notable changes for `vscode-ws-jsonrpc` are found here: 8 | 9 | [vscode-ws-jsonrpc CHANGELOG](./packages/vscode-ws-jsonrpc/CHANGELOG.md) 10 | 11 | All notable changes for `monaco-editor-wrapper` are found here: 12 | 13 | [monaco-editor-wrapper CHANGELOG](./packages/wrapper/CHANGELOG.md) 14 | 15 | All notable changes for `@typefox/monaco-editor-react` are found here: 16 | 17 | [@typefox/monaco-editor-react CHANGELOG](./packages/wrapper-react/CHANGELOG.md) 18 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | - Contributions to catch up with latest versions of LSP and Monaco are always welcomed! 4 | - Contributions to propose a new example should be only accepted if an author is ready to become a maintainer and help with upgrading and testing it with latest versions of LSP and Monaco. 5 | 6 | ## Pull Request 7 | Please do not `git merge` main branch into a feature branch. Always `git rebase` a feature or bugfix branch to the latest main if you require changes from main. 8 | 9 | ## Maintaining 10 | 11 | The project is maintained by individuals using for its own purposes and being ready to help as it suites them. 12 | There is no guarantee on time of response to issues and pull requests. 13 | 14 | ### Current Maintainers 15 | 16 | - @CGNonofr - Loïc Mangeonjean 17 | - @kaisalmen - Kai Salmen 18 | 19 | ### Past Maintainers 20 | 21 | - @AlexTugarev - Alex Tugarev 22 | - @akosyakov - Anton Kosyakov 23 | - @zewa666 - Vildan Softic 24 | - @gatesn - Nicholas Gates 25 | - @mofux - Thomas Zilz 26 | - @BroKun - Yukun Wang 27 | - @rcjsuen - Remy Suen 28 | - @asual - Rostislav Hristov 29 | - @johnwiseheart - John Wiseheart 30 | - @RomanNikitenko - Roman Nikitenko 31 | - @azatsarynnyy - Artem Zatsarynnyi 32 | 33 | ### How to become a maintainer? 34 | 35 | Please contact one of the current maintainers. Other maintainers can add you as a collaborator with `Admin` access. A new maintainer should be listed as [a current maintainer](#current-maintainers) above and as [a code owner](.github/CODEOWNERS). 36 | 37 | ### Releases 38 | 39 | Releases are currently manually created by @kaisalmen or @CGNonofr. We have been thinking about [semantic release](https://github.com/TypeFox/monaco-languageclient/issues/365), but this is not yet decided or implementated. 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright 2018 - present TypeFox GmbH 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /docs/images/no-overrides.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TypeFox/monaco-languageclient/129a4f43d76d3687ca96785c2cc65e2f4bd481cd/docs/images/no-overrides.png -------------------------------------------------------------------------------- /docs/images/with-overrides.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TypeFox/monaco-languageclient/129a4f43d76d3687ca96785c2cc65e2f4bd481cd/docs/images/with-overrides.png -------------------------------------------------------------------------------- /packages/client/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright 2018 - present TypeFox GmbH 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /packages/client/src/client.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | import { BaseLanguageClient, MessageTransports, type LanguageClientOptions } from 'vscode-languageclient/browser.js'; 7 | 8 | export type MonacoLanguageClientOptions = { 9 | name: string; 10 | id?: string; 11 | clientOptions: LanguageClientOptions; 12 | messageTransports: MessageTransports; 13 | } 14 | 15 | export class MonacoLanguageClient extends BaseLanguageClient { 16 | protected readonly messageTransports: MessageTransports; 17 | 18 | constructor({ id, name, clientOptions, messageTransports }: MonacoLanguageClientOptions) { 19 | super(id ?? name.toLowerCase(), name, clientOptions); 20 | this.messageTransports = messageTransports; 21 | } 22 | 23 | protected override createMessageTransports(_encoding: string): Promise { 24 | return Promise.resolve(this.messageTransports); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /packages/client/src/commonTypes.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | import type { MonacoLanguageClient } from './client.js'; 7 | 8 | export type ConnectionConfigOptions = WebSocketConfigOptionsDirect | WebSocketConfigOptionsParams | WebSocketConfigOptionsUrl | WorkerConfigOptionsParams | WorkerConfigOptionsDirect; 9 | 10 | export interface WebSocketCallOptions { 11 | /** Adds handle on languageClient */ 12 | onCall: (languageClient?: MonacoLanguageClient) => void; 13 | /** Reports Status Of Language Client */ 14 | reportStatus?: boolean; 15 | } 16 | 17 | export interface WebSocketConfigOptionsDirect { 18 | $type: 'WebSocketDirect' 19 | webSocket: WebSocket 20 | startOptions?: WebSocketCallOptions; 21 | stopOptions?: WebSocketCallOptions; 22 | } 23 | 24 | export interface WebSocketUrlParams { 25 | secured: boolean; 26 | host: string; 27 | port?: number; 28 | path?: string; 29 | extraParams?: Record>; 30 | } 31 | 32 | export interface WebSocketConfigOptionsParams extends WebSocketUrlParams { 33 | $type: 'WebSocketParams' 34 | startOptions?: WebSocketCallOptions; 35 | stopOptions?: WebSocketCallOptions; 36 | } 37 | 38 | export interface WebSocketUrlString { 39 | url: string; 40 | } 41 | 42 | export interface WebSocketConfigOptionsUrl extends WebSocketUrlString { 43 | $type: 'WebSocketUrl' 44 | startOptions?: WebSocketCallOptions; 45 | stopOptions?: WebSocketCallOptions; 46 | } 47 | 48 | export interface WorkerConfigOptionsParams { 49 | $type: 'WorkerConfig' 50 | url: URL; 51 | type: 'classic' | 'module'; 52 | messagePort?: MessagePort; 53 | workerName?: string; 54 | } 55 | 56 | export interface WorkerConfigOptionsDirect { 57 | $type: 'WorkerDirect'; 58 | worker: Worker; 59 | messagePort?: MessagePort; 60 | } 61 | -------------------------------------------------------------------------------- /packages/client/src/fs/endpoints/defaultEndpoint.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | import type { Logger } from 'monaco-languageclient/tools'; 7 | import type { DirectoryListingRequest, DirectoryListingRequestResult, FileReadRequest, FileReadRequestResult, FileSystemEndpoint, FileUpdate, FileUpdateResult, StatsRequest, StatsRequestResult } from '../definitions.js'; 8 | import { EndpointType } from '../definitions.js'; 9 | 10 | export class EmptyFileSystemEndpoint implements FileSystemEndpoint { 11 | 12 | private endpointType: EndpointType; 13 | private logger?: Logger; 14 | 15 | constructor(endpointType: EndpointType) { 16 | this.endpointType = endpointType; 17 | } 18 | 19 | init(): void { } 20 | 21 | getFileSystemInfo(): string { 22 | return 'This file system performs no operations.'; 23 | } 24 | 25 | setLogger(logger: Logger): void { 26 | this.logger = logger; 27 | } 28 | 29 | getEndpointType(): EndpointType { 30 | return this.endpointType; 31 | } 32 | 33 | readFile(params: FileReadRequest): Promise { 34 | this.logger?.info(`Reading file: ${params.resourceUri}`); 35 | return Promise.resolve({ 36 | status: 'denied', 37 | content: '' 38 | }); 39 | } 40 | 41 | writeFile(params: FileUpdate): Promise { 42 | this.logger?.info(`Writing file: ${params.resourceUri}`); 43 | return Promise.resolve({ status: 'denied' }); 44 | } 45 | 46 | syncFile(params: FileUpdate): Promise { 47 | this.logger?.info(`Syncing file: ${params.resourceUri}`); 48 | return Promise.resolve({ status: 'denied' }); 49 | } 50 | 51 | getFileStats(params: StatsRequest): Promise { 52 | this.logger?.info(`Getting file stats for: "${params.resourceUri}" (${params.type})`); 53 | return Promise.reject('No stats available.'); 54 | } 55 | 56 | listFiles(params: DirectoryListingRequest): Promise { 57 | this.logger?.info(`Listing files for directory: "${params.directoryUri}"`); 58 | return Promise.reject('No file listing possible.'); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /packages/client/src/fs/index.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | export * from './definitions.js'; 7 | export * from './endpoints/defaultEndpoint.js'; 8 | -------------------------------------------------------------------------------- /packages/client/src/index.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | export * from './client.js'; 7 | export * from './commonTypes.js'; 8 | -------------------------------------------------------------------------------- /packages/client/src/tools/index.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | export * from './logging.js'; 7 | export * from './utils.js'; 8 | -------------------------------------------------------------------------------- /packages/client/src/tools/logging.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | import { ConsoleLogger as VSCodeConsoleLogger, type ILogger } from '@codingame/monaco-vscode-log-service-override'; 7 | import { LogLevel } from '@codingame/monaco-vscode-api'; 8 | 9 | export interface Logger extends ILogger { 10 | createErrorAndLog(message: string, ...params: unknown[]): Error; 11 | } 12 | 13 | export class ConsoleLogger extends VSCodeConsoleLogger { 14 | 15 | constructor(logLevel?: LogLevel, useColors?: boolean) { 16 | super(logLevel ?? LogLevel.Off, useColors); 17 | } 18 | 19 | createErrorAndLog(message: string, ...params: unknown[]) { 20 | if (this.getLevel() >= LogLevel.Error) { 21 | this.error(message, ...params); 22 | } 23 | return new Error(message); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /packages/client/src/tools/utils.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | import type { WebSocketUrlParams, WebSocketUrlString } from 'monaco-languageclient'; 7 | 8 | export const createUrl = (config: WebSocketUrlParams | WebSocketUrlString) => { 9 | let buildUrl = ''; 10 | if ((config as WebSocketUrlString).url) { 11 | const options = config as WebSocketUrlString; 12 | if (!options.url.startsWith('ws://') && !options.url.startsWith('wss://')) { 13 | throw new Error(`This is not a proper websocket url: ${options.url}`); 14 | } 15 | buildUrl = options.url; 16 | } else { 17 | const options = config as WebSocketUrlParams; 18 | const protocol = options.secured ? 'wss' : 'ws'; 19 | buildUrl = `${protocol}://${options.host}`; 20 | if (options.port !== undefined) { 21 | if (options.port !== 80) { 22 | buildUrl += `:${options.port}`; 23 | } 24 | } 25 | if (options.path !== undefined) { 26 | buildUrl += `/${options.path}`; 27 | } 28 | if (options.extraParams) { 29 | const url = new URL(buildUrl); 30 | 31 | for (const [key, value] of Object.entries(options.extraParams)) { 32 | url.searchParams.set(key, value instanceof Array ? value.join(',') : value.toString()); 33 | } 34 | 35 | buildUrl = url.toString(); 36 | } 37 | } 38 | return buildUrl; 39 | }; 40 | -------------------------------------------------------------------------------- /packages/client/src/vscode/fakeWorker.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | export class FakeWorker { 7 | url: string | URL; 8 | options?: WorkerOptions; 9 | 10 | constructor(url: string | URL, options?: WorkerOptions) { 11 | this.url = url; 12 | this.options = options; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /packages/client/src/vscode/index.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | export * from './fakeWorker.js'; 7 | export * from './services.js'; 8 | -------------------------------------------------------------------------------- /packages/client/src/workerFactory.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | import { getEnhancedMonacoEnvironment } from 'monaco-languageclient/vscode/services'; 7 | import type { Logger } from 'monaco-languageclient/tools'; 8 | 9 | export type WorkerLoader = (() => Worker) | undefined; 10 | 11 | export interface WorkerFactoryConfig { 12 | workerLoaders?: Record; 13 | logger?: Logger; 14 | getWorkerOverride?: (moduleId: string, label: string) => Worker; 15 | } 16 | 17 | export const useWorkerFactory = (config: WorkerFactoryConfig) => { 18 | const envEnhanced = getEnhancedMonacoEnvironment(); 19 | 20 | const getWorker = (moduleId: string, label: string) => { 21 | config.logger?.info(`getWorker: moduleId: ${moduleId} label: ${label}`); 22 | 23 | const workerFunc = config.workerLoaders?.[label] ?? undefined; 24 | if (workerFunc === undefined) { 25 | throw new Error(`Unimplemented worker ${label} (${moduleId})`); 26 | } 27 | return workerFunc(); 28 | }; 29 | envEnhanced.getWorker = config.getWorkerOverride ?? getWorker; 30 | }; 31 | -------------------------------------------------------------------------------- /packages/client/test/fs/endpoints/emptyEndpoint.test.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | import { describe, expect, test } from 'vitest'; 7 | import { EmptyFileSystemEndpoint, EndpointType } from 'monaco-languageclient/fs'; 8 | 9 | describe('EmptyFileSystemEndpoint Tests', () => { 10 | 11 | const endpoint = new EmptyFileSystemEndpoint(EndpointType.EMPTY); 12 | 13 | test('readFile', async () => { 14 | const result = await endpoint.readFile({ resourceUri: '/tmp/test.js' }); 15 | expect(result).toEqual({ 16 | status: 'denied', 17 | content: '' 18 | }); 19 | }); 20 | 21 | test('writeFile', async () => { 22 | const result = await endpoint.writeFile({ 23 | resourceUri: '/tmp/test.js', 24 | content: 'const text = "Hello World!";' 25 | }); 26 | expect(result).toEqual({ 27 | status: 'denied' 28 | }); 29 | }); 30 | 31 | test('syncFile', async () => { 32 | const result = await endpoint.syncFile({ 33 | resourceUri: '/tmp/test.js', 34 | content: 'const text = "Hello World!";' 35 | }); 36 | expect(result).toEqual({ 37 | status: 'denied' 38 | }); 39 | }); 40 | 41 | test('getFileStats', async () => { 42 | await expect(async () => { 43 | await endpoint.getFileStats({ 44 | type: 'file', 45 | resourceUri: '/tmp/test.js' 46 | }); 47 | }).rejects.toThrowError('No stats available.'); 48 | }); 49 | 50 | test('listFiles', async () => { 51 | await expect(async () => { 52 | await endpoint.listFiles({ 53 | directoryUri: '/tmp' 54 | }); 55 | }).rejects.toThrowError('No file listing possible.'); 56 | }); 57 | 58 | }); 59 | -------------------------------------------------------------------------------- /packages/client/test/tools/index.test.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | import { describe, expect, test } from 'vitest'; 7 | import { ConsoleLogger } from 'monaco-languageclient/tools'; 8 | import { LogLevel } from '@codingame/monaco-vscode-api'; 9 | 10 | describe('Logger', () => { 11 | 12 | test('Config: None', () => { 13 | const logger = new ConsoleLogger(); 14 | 15 | expect(logger.getLevel()).toBe(LogLevel.Off); 16 | }); 17 | 18 | test('Config: Off', () => { 19 | const logger = new ConsoleLogger(LogLevel.Off); 20 | 21 | expect(logger.getLevel()).toBe(LogLevel.Off); 22 | }); 23 | 24 | test('Config: Info', () => { 25 | const logger = new ConsoleLogger(LogLevel.Info); 26 | 27 | expect(logger.getLevel()).toBe(LogLevel.Info); 28 | }); 29 | 30 | test('Config: Debug', () => { 31 | const logger = new ConsoleLogger(LogLevel.Debug); 32 | 33 | expect(logger.getLevel()).toBe(LogLevel.Debug); 34 | }); 35 | 36 | test('Config: checkLogLevel debug', () => { 37 | const logger = new ConsoleLogger(LogLevel.Debug); 38 | 39 | expect(logger.getLevel()).toBe(LogLevel.Debug); 40 | }); 41 | 42 | }); 43 | -------------------------------------------------------------------------------- /packages/client/test/vscode/services.test.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | import { describe, expect, test } from 'vitest'; 7 | import { initServices, type MonacoEnvironmentEnhanced } from 'monaco-languageclient/vscode/services'; 8 | 9 | describe('VSCode services Tests', () => { 10 | 11 | test('initServices', async () => { 12 | const vscodeApiConfig = { 13 | userConfiguration: { 14 | json: JSON.stringify({ 15 | 'workbench.colorTheme': 'Default Dark Modern' 16 | }) 17 | } 18 | }; 19 | 20 | let envEnhanced = (self as Window).MonacoEnvironment as MonacoEnvironmentEnhanced; 21 | expect(envEnhanced).toBeUndefined(); 22 | 23 | // call initServices with userConfiguration 24 | const promise = initServices(vscodeApiConfig); 25 | envEnhanced = (self as Window).MonacoEnvironment as MonacoEnvironmentEnhanced; 26 | expect(envEnhanced.vscodeInitialising).toBeTruthy(); 27 | expect(envEnhanced.vscodeApiInitialised).toBeFalsy(); 28 | 29 | // try a second time and expect that the api init is ongoing but not completed 30 | const secondCallResult = await initServices(vscodeApiConfig); 31 | 32 | expect(secondCallResult).toBeFalsy(); 33 | envEnhanced = (self as Window).MonacoEnvironment as MonacoEnvironmentEnhanced; 34 | expect(envEnhanced.vscodeInitialising).toBeTruthy(); 35 | expect(envEnhanced.vscodeApiInitialised).toBeFalsy(); 36 | 37 | // wait for the initial promise to complete and expect that api init was completed and is no longer ongoing 38 | const initialCallResult = await promise; 39 | expect(initialCallResult).toBeTruthy(); 40 | envEnhanced = (self as Window).MonacoEnvironment as MonacoEnvironmentEnhanced; 41 | expect(envEnhanced.vscodeInitialising).toBeFalsy(); 42 | expect(envEnhanced.vscodeApiInitialised).toBeTruthy(); 43 | }); 44 | 45 | }); 46 | -------------------------------------------------------------------------------- /packages/client/test/workerFactory.test.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | import { describe, expect, test } from 'vitest'; 7 | import { LogLevel } from '@codingame/monaco-vscode-api'; 8 | import { ConsoleLogger } from 'monaco-languageclient/tools'; 9 | import { useWorkerFactory } from 'monaco-languageclient/workerFactory'; 10 | 11 | describe('WorkerFactory Tests', () => { 12 | 13 | test('useWorkerFactory: Nothing', () => { 14 | 15 | useWorkerFactory({}); 16 | 17 | const monWin = (self as Window); 18 | const getWorker = () => monWin.MonacoEnvironment?.getWorker?.('test', 'TextEditorWorker'); 19 | expect(getWorker).toThrowError('Unimplemented worker TextEditorWorker (test)'); 20 | }); 21 | 22 | test('useWorkerFactory: TextEditorWorker', async () => { 23 | const logger = new ConsoleLogger(LogLevel.Info); 24 | 25 | useWorkerFactory({ 26 | workerLoaders: { 27 | TextEditorWorker: () => new Worker( 28 | new URL('@codingame/monaco-vscode-editor-api/esm/vs/editor/editor.worker.js', import.meta.url), 29 | { type: 'module' } 30 | ) 31 | }, 32 | logger 33 | }); 34 | 35 | const monWin = (self as Window); 36 | const getWorker = () => monWin.MonacoEnvironment?.getWorker?.('test', 'TextEditorWorker'); 37 | const workerFunc = getWorker(); 38 | expect(workerFunc).toBeDefined(); 39 | expect(workerFunc).toBeInstanceOf(Worker); 40 | }); 41 | 42 | }); 43 | -------------------------------------------------------------------------------- /packages/client/tsconfig.json: -------------------------------------------------------------------------------- 1 | // this file is required for VSCode to work properly 2 | { 3 | "extends": "./tsconfig.src.json", 4 | "compilerOptions": { 5 | "noEmit": true, 6 | "rootDir": "." 7 | }, 8 | "include": [ 9 | "src/**/*", 10 | "test/**/*" 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /packages/client/tsconfig.src.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig", 3 | "compilerOptions": { 4 | "rootDir": "src", 5 | "outDir": "lib", 6 | "declarationDir": "lib", 7 | // because vscode-jsonrpc requires DedicatedWorkerGlobalScope 8 | // we are required to include both DOM and WebWorker libs 9 | // the only way out currently is to disable lib checking 10 | "skipLibCheck": true 11 | }, 12 | "include": [ 13 | "src/**/*.ts", 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /packages/client/tsconfig.test.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.src.json", 3 | "compilerOptions": { 4 | "noEmit": true, 5 | "rootDir": "test" 6 | }, 7 | "references": [{ 8 | "path": "./tsconfig.src.json" 9 | }], 10 | "include": [ 11 | "test/**/*.ts", 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /packages/examples/.gitignore: -------------------------------------------------------------------------------- 1 | resources/clangd/wasm 2 | resources/groovy/external 3 | resources/eclipse.jdt.ls/ls 4 | resources/eclipse.jdt.ls/*.tar.gz 5 | resources/vsix 6 | production 7 | -------------------------------------------------------------------------------- /packages/examples/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright 2023 - present TypeFox GmbH 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /packages/examples/README.md: -------------------------------------------------------------------------------- 1 | # Monaco Language Client Examples 2 | 3 | [![Gitpod - Code Now](https://img.shields.io/badge/Gitpod-code%20now-blue.svg?longCache=true)](https://gitpod.io#https://github.com/TypeFox/monaco-languageclient) 4 | [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?longCache=true)](https://github.com/TypeFox/monaco-languageclient/labels/help%20wanted) 5 | [![monaco-languageclient](https://github.com/TypeFox/monaco-languageclient/actions/workflows/actions.yml/badge.svg)](https://github.com/TypeFox/monaco-languageclient/actions/workflows/actions.yml) 6 | [![NPM Version](https://img.shields.io/npm/v/monaco-languageclient-examples.svg)](https://www.npmjs.com/package/monaco-languageclient-examples) 7 | [![NPM Download](https://img.shields.io/npm/dt/monaco-languageclient-examples.svg)](https://www.npmjs.com/package/monaco-languageclient-examples) 8 | 9 | This package contains [all examples from the monaco-languageclient repository](https://github.com/TypeFox/monaco-languageclient/blob/main/README.md#examples). 10 | 11 | ## CHANGELOG 12 | 13 | All changes are noted in the [CHANGELOG](https://github.com/TypeFox/monaco-languageclient/blob/main/packages/examples/CHANGELOG.md). 14 | 15 | ## Getting Started 16 | 17 | This is npm package is part of the mono repo. Please follow the main repositories [instructions]]() to get started with local development. 18 | 19 | ## Usage 20 | 21 | Needs to be added. 22 | 23 | ## License 24 | 25 | [MIT](https://github.com/TypeFox/monaco-languageclient/blob/main/packages/examples/LICENSE) 26 | -------------------------------------------------------------------------------- /packages/examples/appPlayground.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Application Playground 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | Application Playground - [Back to Index] Heads up: This is a prototype and still evolving. 15 |
16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /packages/examples/bare.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSON Language Client & Language Server (Web Socket) 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | JSON Language Client & Language Server (Web Socket) - [Back to Index] 15 |
16 |
17 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /packages/examples/browser.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Language Client Pure Browser Example 6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | Language Client Pure Browser Example - [Back to Index] 14 |
15 |
16 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /packages/examples/clangd.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Cpp Language Client & Clangd Language Server (Worker/Wasm) 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | Cpp Language Client & Clangd Language Server (Worker/Wasm) - [Back to Index] 15 |
16 | 17 | 18 | The clangd language server worker has been derived from: clangd-in-browser 19 |
20 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /packages/examples/eclipse.jdt.ls.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Java Language Client & Language Server (Web Socket) 6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | Java Language Client & Language Server (Web Socket) - [Back to Index] 14 |
15 | 16 | 17 | Launch backend with: docker compose -f ./packages/examples/resources/eclipse.jdt.ls/docker-compose.yml up -d
18 |
19 |
20 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /packages/examples/ghp_appPlayground.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Application Playground 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | Application Playground - [Back to Index] Heads up: This is a prototype and still evolving. 16 |
17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /packages/examples/ghp_browser.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Language Client Pure Browser Example 6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | Language Client Pure Browser Example - [Back to Index] 14 |
15 |
16 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /packages/examples/ghp_clangd.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Cpp Language Client & Clangd Language Server (Worker/Wasm) 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | Cpp Language Client & Clangd Language Server (Worker/Wasm) - [Back to Index] 16 |
17 | 18 | 19 | The clangd language server worker has been derived from: clangd-in-browser 20 |
21 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /packages/examples/ghp_langium_classic.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Langium Grammar DSL (Classic Mode) 6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | Langium Grammar DSL (Classic Mode) - [Back to Index] 14 |
15 | 16 | 17 |
18 |
19 | ; 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /packages/examples/ghp_langium_extended.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Langium Grammar DSL (Extended Mode) 6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | Langium Grammar DSL (Extended Mode) - [Back to Index] 14 |
15 | 16 | 17 |
18 |
19 | ; 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /packages/examples/ghp_react_appPlayground.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Application Playground 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | Application Playground - [Back to Index] Heads up: This is a prototype and still evolving. 17 |
18 |
19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /packages/examples/ghp_react_statemachine.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | React: Langium Statemachine Language Client & Language Server (Worker) 8 | 9 | 10 | 11 | 12 |
13 | React: Langium Statemachine Language Client & Language Server (Worker) - [Back to Index] 14 |
15 | 16 | 17 | 18 |
19 |
20 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /packages/examples/ghp_statemachine.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Langium Statemachine Client & Language Server (Worker) 8 | 9 | 10 | 11 | 12 |
13 | Langium Statemachine Client & Language Server (Worker) - [Back to Index] 14 |
15 | 16 | 17 |
18 |
19 |
20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /packages/examples/ghp_tsExtHost.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | TypeScript Extension Host Worker 8 | 9 | 10 | 11 | 12 |
13 | TypeScript Extension Host Worker - [Back to Index] 14 |
15 | 16 | 17 | 18 | 19 |
20 | 21 |
22 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /packages/examples/groovy.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Groovy Language Client & Language Server (Web Socket) 6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | Groovy Language Client & Language Server (Web Socket) - [Back to Index] 14 |
15 | 16 | 17 | Launch backend with: docker compose -f ./packages/examples/resources/groovy/docker-compose.yml up -d
18 |
19 |
20 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /packages/examples/json.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | JSON Language Client & Language Server (Web Socket) 6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | JSON Language Client & Language Server (Web Socket) - [Back to Index] 14 |
15 | 16 | 17 |
18 |
19 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /packages/examples/langium_classic.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Langium Grammar DSL (Classic Mode) 6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | Langium Grammar DSL (Classic Mode) - [Back to Index] 14 |
15 | 16 | 17 |
18 |
19 | ; 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /packages/examples/langium_extended.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Langium Grammar DSL (Extended Mode) 6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | Langium Grammar DSL (Extended Mode) - [Back to Index] 14 |
15 | 16 | 17 |
18 |
19 | ; 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /packages/examples/python.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Python Language Client & Pyright Language Server (Web Socket) 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | Python Language Client & Pyright Language Server (Web Socket) - [Back to Index] 15 |
16 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /packages/examples/react_appPlayground.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Application Playground 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | Application Playground - [Back to Index] Heads up: This is a prototype and still evolving. 16 |
17 |
18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /packages/examples/react_python.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | React: Python Language Client & Language Server (Web Socket) 8 | 9 | 10 | 11 | 12 | 13 |
14 | React: Python Language Client & Language Server (Web Socket) - [Back to Index] 15 |
16 |
17 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /packages/examples/react_statemachine.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | React: Langium Statemachine Language Client & Language Server (Worker) 8 | 9 | 10 | 11 | 12 |
13 | React: Langium Statemachine Language Client & Language Server (Worker) - [Back to Index] 14 |
15 | 16 | 17 | 18 |
19 |
20 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /packages/examples/resources/appPlayground/hello.ts: -------------------------------------------------------------------------------- 1 | function sayHello(): string { 2 | // intentionally erroneous to test import resolution 3 | console.log(sayFoo()); 4 | return 'Hello'; 5 | }; 6 | 7 | sayHello(); 8 | -------------------------------------------------------------------------------- /packages/examples/resources/appPlayground/tester.ts: -------------------------------------------------------------------------------- 1 | export const sayFoo = () => { 2 | return 'Foo'; 3 | }; 4 | -------------------------------------------------------------------------------- /packages/examples/resources/appPlayground/views.html: -------------------------------------------------------------------------------- 1 | 4 |
5 |
6 | 7 |
8 |
9 |
10 | 11 |
12 |
13 |
14 |
15 |
16 |
17 | 18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 | -------------------------------------------------------------------------------- /packages/examples/resources/clangd/build.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ghcr.io/typefox/monaco-languageclient/clangd-wasm-configure:latest 2 | 3 | COPY build-docker.sh /builder/build-docker.sh 4 | COPY wait_stdin.patch /builder/wait_stdin.patch 5 | 6 | RUN (cd /builder; bash ./build-docker.sh) 7 | -------------------------------------------------------------------------------- /packages/examples/resources/clangd/build.docker-compose.yml: -------------------------------------------------------------------------------- 1 | services: 2 | clangd-wasm-build: 3 | image: ghcr.io/typefox/monaco-languageclient/clangd-wasm-build:latest 4 | build: 5 | dockerfile: ./build.Dockerfile 6 | context: . 7 | # only linux/amd64 for now 8 | platforms: 9 | - "linux/amd64" 10 | platform: linux/amd64 11 | container_name: clangd-wasm-build 12 | -------------------------------------------------------------------------------- /packages/examples/resources/clangd/configure-docker.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # It's not recommend for you to run this script directly, 3 | # (because I'm not good at writing this sorry) 4 | # but you can use it as a reference for building. 5 | 6 | # 0. Configs 7 | 8 | # sudo apt install vim git build-essential cmake ninja-build python3 9 | 10 | ## Note: Better to make sure WASI SDK version matches the LLVM version 11 | EMSDK_VER=3.1.52 12 | WASI_SDK_VER=22.0 13 | WASI_SDK_VER_MAJOR=22 14 | LLVM_VER=18.1.2 15 | LLVM_VER_MAJOR=18 16 | 17 | # 1. Get Emscripten 18 | 19 | git clone --branch $EMSDK_VER --depth 1 https://github.com/emscripten-core/emsdk 20 | pushd emsdk 21 | ./emsdk install $EMSDK_VER 22 | ./emsdk activate $EMSDK_VER 23 | source ./emsdk_env.sh 24 | popd 25 | 26 | # 2. Prepare WASI sysroot 27 | 28 | wget -O- https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-$WASI_SDK_VER_MAJOR/wasi-sysroot-$WASI_SDK_VER.tar.gz | tar -xz 29 | 30 | # 3a. Build LLVM 31 | 32 | git clone --branch llvmorg-$LLVM_VER --depth 1 https://github.com/llvm/llvm-project 33 | -------------------------------------------------------------------------------- /packages/examples/resources/clangd/configure.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu 2 | 3 | RUN apt update \ 4 | && apt upgrade -y \ 5 | && apt install -y curl git wget build-essential cmake ninja-build python3 6 | 7 | RUN curl https://get.volta.sh | bash 8 | ENV VOLTA_FEATURE_PNPM=1 9 | ENV VOLTA_HOME "/root/.volta" 10 | ENV PATH "$VOLTA_HOME/bin:$PATH" 11 | 12 | RUN volta install node \ 13 | && volta install pnpm 14 | 15 | RUN mkdir /builder 16 | 17 | COPY configure-docker.sh /builder/configure-docker.sh 18 | RUN (cd /builder; bash ./configure-docker.sh) 19 | -------------------------------------------------------------------------------- /packages/examples/resources/clangd/configure.docker-compose.yml: -------------------------------------------------------------------------------- 1 | services: 2 | clangd-wasm-configure: 3 | image: ghcr.io/typefox/monaco-languageclient/clangd-wasm-configure:latest 4 | build: 5 | dockerfile: ./configure.Dockerfile 6 | context: . 7 | # only linux/amd64 for now 8 | platforms: 9 | - "linux/amd64" 10 | platform: linux/amd64 11 | container_name: clangd-wasm-configure 12 | -------------------------------------------------------------------------------- /packages/examples/resources/clangd/scripts/extractDockerFiles.ts: -------------------------------------------------------------------------------- 1 | import * as fs from "node:fs"; 2 | import child_process from "node:child_process"; 3 | 4 | const outputDir = './resources/clangd/wasm'; 5 | 6 | try { 7 | child_process.execFileSync('docker', ['create', '--name', 'extract-clangd', 'ghcr.io/typefox/monaco-languageclient/clangd-wasm-build:latest']); 8 | 9 | // clean but only if container start was successful 10 | fs.rmSync(outputDir, { 11 | force: true, 12 | recursive: true 13 | }); 14 | fs.mkdirSync(outputDir); 15 | 16 | child_process.execFileSync('docker', ['cp', 'extract-clangd:/builder/llvm-project/build/bin/clangd.js', outputDir]); 17 | child_process.execFileSync('docker', ['cp', 'extract-clangd:/builder/llvm-project/build/bin/clangd.wasm', outputDir]); 18 | child_process.execFileSync('docker', ['cp', 'extract-clangd:/builder/llvm-project/build/bin/clangd.worker.js', outputDir]); 19 | child_process.execFileSync('docker', ['cp', 'extract-clangd:/builder/llvm-project/build/bin/clangd.worker.mjs', outputDir]); 20 | child_process.execFileSync('docker', ['rm', 'extract-clangd']); 21 | } catch (e) { 22 | console.warn('Clangd wasm data was not extracted from container image!'); 23 | } 24 | -------------------------------------------------------------------------------- /packages/examples/resources/clangd/wait_stdin.patch: -------------------------------------------------------------------------------- 1 | diff --git a/clang-tools-extra/clangd/JSONTransport.cpp b/clang-tools-extra/clangd/JSONTransport.cpp 2 | index 9dc0df807..b1a4e9bd1 100644 3 | --- a/clang-tools-extra/clangd/JSONTransport.cpp 4 | +++ b/clang-tools-extra/clangd/JSONTransport.cpp 5 | @@ -1,3 +1,26 @@ 6 | +#ifdef __EMSCRIPTEN__ 7 | + 8 | +#include 9 | + 10 | +#include "support/Shutdown.h" 11 | +#include 12 | + 13 | +EM_ASYNC_JS(void, waitForStdin, (), { 14 | + await Module.stdinReady(); 15 | +}) 16 | + 17 | +template ()())> 18 | +Ret doUntilStdinAvailable( 19 | + const std::enable_if_t& fail, 20 | + const Fun& f) { 21 | + waitForStdin(); 22 | + return clang::clangd::retryAfterSignalUnlessShutdown(fail, f); 23 | +} 24 | + 25 | +#define retryAfterSignalUnlessShutdown doUntilStdinAvailable 26 | + 27 | +#endif 28 | + 29 | //===--- JSONTransport.cpp - sending and receiving LSP messages over JSON -===// 30 | // 31 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 32 | -------------------------------------------------------------------------------- /packages/examples/resources/clangd/workspace/.clangd: -------------------------------------------------------------------------------- 1 | { 2 | CompileFlags: 3 | { 4 | Add: [ 5 | '-xc++', 6 | '-std=c++2b', 7 | '-pedantic-errors', 8 | '-Wall', 9 | '--target=wasm32-wasi', 10 | '-isystem/usr/include/c++/v1', 11 | '-isystem/usr/include/wasm32-wasi/c++/v1', 12 | '-isystem/usr/include', 13 | '-isystem/usr/include/wasm32-wasi' 14 | ] 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /packages/examples/resources/clangd/workspace/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "tester.h" 3 | 4 | int main(int argc, char **argv) { 5 | printf("Hello World\n"); 6 | } 7 | -------------------------------------------------------------------------------- /packages/examples/resources/clangd/workspace/tester.h: -------------------------------------------------------------------------------- 1 | namespace Tester { 2 | class MyClass { 3 | public: 4 | void printHelloWorld(); 5 | }; 6 | } 7 | -------------------------------------------------------------------------------- /packages/examples/resources/debugger/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ghcr.io/graalvm/graalpy-community:24 2 | 3 | RUN curl https://get.volta.sh | bash 4 | ENV VOLTA_FEATURE_PNPM=1 5 | ENV VOLTA_HOME "/root/.volta" 6 | ENV PATH "$VOLTA_HOME/bin:$PATH" 7 | 8 | RUN volta install node@22 9 | 10 | RUN mkdir -p /home/mlc/workspace 11 | RUN mkdir -p /home/mlc/server/src 12 | 13 | COPY ./packages/examples/resources/debugger/package.json /home/mlc/server 14 | COPY ./packages/examples/src/debugger/server/debugServer.ts /home/mlc/server/src 15 | COPY ./packages/examples/src/debugger/server/DAPSocket.ts /home/mlc/server/src 16 | 17 | WORKDIR /home/mlc/server 18 | -------------------------------------------------------------------------------- /packages/examples/resources/debugger/docker-compose.yml: -------------------------------------------------------------------------------- 1 | services: 2 | debugger: 3 | container_name: debugger-py 4 | image: ghcr.io/typefox/monaco-languageclient/debugger-py:latest 5 | build: 6 | dockerfile: ./packages/examples/resources/debugger/Dockerfile 7 | context: ../../../.. 8 | # only linux/amd64 for now 9 | platforms: 10 | - "linux/amd64" 11 | platform: linux/amd64 12 | ports: 13 | - 55555:5555 14 | tty: true 15 | # just for completness. Is already set in the Dockerfile 16 | working_dir: /home/mlc/server 17 | command: [ 18 | "bash", "-c", "npm run start" 19 | ] 20 | -------------------------------------------------------------------------------- /packages/examples/resources/debugger/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "graalpy-debugger", 3 | "version": "2025.2.1", 4 | "description": "Monaco Language client Graalpy Debugger", 5 | "author": { 6 | "name": "TypeFox GmbH", 7 | "url": "http://www.typefox.io" 8 | }, 9 | "license": "MIT", 10 | "type": "module", 11 | "main": "./dist/debugServer.js", 12 | "module": "./dist/debugServer.js", 13 | "exports": { 14 | ".": { 15 | "types": "./dist/debugServer.d.ts", 16 | "default": "./dist/debugServer.js" 17 | } 18 | }, 19 | "typesVersions": { 20 | "*": { 21 | ".": [ 22 | "dist/debugServer" 23 | ] 24 | } 25 | }, 26 | "engines": { 27 | "node": ">=20.10.0", 28 | "npm": ">=10.2.3" 29 | }, 30 | "volta": { 31 | "node": "22.16.0", 32 | "npm": "10.9.2" 33 | }, 34 | "dependencies": { 35 | "express": "~4.21.2", 36 | "ws": "~8.18.0" 37 | }, 38 | "devDependencies": { 39 | "tsx": "~4.19.2" 40 | }, 41 | "scripts": { 42 | "start": "npm i && tsx src/debugServer.ts" 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /packages/examples/resources/eclipse.jdt.ls/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM eclipse-temurin:17-jdk 2 | 3 | ARG PATH_MLC=/home/mlc 4 | ARG PATH_ECLIPSE_JDT=${PATH_MLC}/packages/examples/resources/eclipse.jdt.ls/ls 5 | ARG JDT_TAR_URL=https://download.eclipse.org/jdtls/milestones/1.37.0/jdt-language-server-1.37.0-202406271335.tar.gz 6 | ARG JDT_TAR_LOCAL=eclipse.jdt.ls.tar.gz 7 | 8 | RUN apt update \ 9 | && apt upgrade -y 10 | RUN apt install -y wget 11 | 12 | RUN curl https://get.volta.sh | bash 13 | ENV VOLTA_FEATURE_PNPM=1 14 | ENV VOLTA_HOME="/root/.volta" 15 | ENV PATH="$VOLTA_HOME/bin:$PATH" 16 | RUN volta install node@20 17 | 18 | # prepare 19 | RUN mkdir -p ${PATH_MLC} 20 | 21 | # copy repo content 22 | COPY ./ ${PATH_MLC} 23 | 24 | RUN cd ${PATH_MLC} \ 25 | && npm i \ 26 | && npm run build 27 | 28 | # download and extract Eclipse JDT LS in target folder 29 | RUN mkdir -p ${PATH_ECLIPSE_JDT} \ 30 | && cd ${PATH_ECLIPSE_JDT} \ 31 | && wget -O ${JDT_TAR_LOCAL} ${JDT_TAR_URL} \ 32 | && tar -xzf ${JDT_TAR_LOCAL} 33 | 34 | WORKDIR ${PATH_MLC} 35 | 36 | CMD ["/bin/bash", "npm run start:example:server:jdtls"] 37 | -------------------------------------------------------------------------------- /packages/examples/resources/eclipse.jdt.ls/docker-compose.yml: -------------------------------------------------------------------------------- 1 | services: 2 | eclipsejdtls: 3 | image: ghcr.io/typefox/monaco-languageclient/eclipse.jdt.ls:latest 4 | build: 5 | dockerfile: ./packages/examples/resources/eclipse.jdt.ls/Dockerfile 6 | context: ../../../.. 7 | # only linux/amd64 for now 8 | platforms: 9 | - "linux/amd64" 10 | platform: linux/amd64 11 | command: [ 12 | "bash", "-c", "npm run start:example:server:jdtls" 13 | ] 14 | ports: 15 | - 30003:30003 16 | working_dir: /home/mlc 17 | container_name: eclipsejdtls 18 | -------------------------------------------------------------------------------- /packages/examples/resources/eclipse.jdt.ls/workspace/hello.java: -------------------------------------------------------------------------------- 1 | public static void main (String[] args) { 2 | System.out.println("Hello World!"); 3 | } 4 | -------------------------------------------------------------------------------- /packages/examples/resources/groovy/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM gradle:7-jdk17-focal 2 | 3 | ARG HOME_DIR=/home/gradle 4 | ARG PATH_MLC=${HOME_DIR}/mlc 5 | ARG PATH_GLS=${HOME_DIR}/groovy-language-server 6 | ARG PATH_GROOVY_JAR=${PATH_MLC}/packages/examples/resources/groovy/lib 7 | 8 | RUN apt update \ 9 | && apt upgrade -y 10 | RUN apt install -y curl 11 | 12 | RUN curl https://get.volta.sh | bash 13 | ENV VOLTA_FEATURE_PNPM=1 14 | ENV VOLTA_HOME="/root/.volta" 15 | ENV PATH="$VOLTA_HOME/bin:$PATH" 16 | RUN volta install node@20 17 | 18 | # prepare 19 | RUN cd ${HOME_DIR} \ 20 | && mkdir -p ${PATH_MLC} 21 | 22 | # build groovy language server 23 | RUN cd ${HOME_DIR} \ 24 | && git clone https://github.com/GroovyLanguageServer/groovy-language-server \ 25 | && cd ${PATH_GLS} \ 26 | && ./gradlew build \ 27 | && cd ${HOME_DIR} 28 | 29 | # copy repo content 30 | COPY ./ ${PATH_MLC} 31 | 32 | RUN cd ${PATH_MLC} \ 33 | && npm i \ 34 | && npm run build 35 | 36 | # copy language server to target 37 | RUN mkdir -p ${PATH_GROOVY_JAR} \ 38 | && cp ${PATH_GLS}/build/libs/groovy-language-server-all.jar ${PATH_GROOVY_JAR} 39 | 40 | WORKDIR ${PATH_MLC} 41 | 42 | CMD ["/bin/bash", "npm run start:example:server:groovy"] 43 | -------------------------------------------------------------------------------- /packages/examples/resources/groovy/docker-compose.yml: -------------------------------------------------------------------------------- 1 | services: 2 | groovyls: 3 | image: ghcr.io/typefox/monaco-languageclient/groovy.ls:latest 4 | build: 5 | dockerfile: ./packages/examples/resources/groovy/Dockerfile 6 | context: ../../../.. 7 | # only linux/amd64 for now 8 | platforms: 9 | - "linux/amd64" 10 | platform: linux/amd64 11 | command: [ 12 | "bash", "-c", "npm run start:example:server:groovy" 13 | ] 14 | ports: 15 | - 30002:30002 16 | working_dir: /home/gradle/mlc 17 | container_name: groovyls 18 | -------------------------------------------------------------------------------- /packages/examples/resources/langium/statemachine/example-mod.statemachine: -------------------------------------------------------------------------------- 1 | statemachine TrafficLight 2 | 3 | events 4 | switchCapacity 5 | next 6 | 7 | initialState PowerOff 8 | 9 | state PowerOff 10 | switchCapacity => RedLight 11 | end 12 | 13 | state RedLight 14 | switchCapacity => PowerOff 15 | next => GreenLight 16 | end 17 | 18 | state OrangeLight 19 | switchCapacity => PowerOff 20 | next => RedLight 21 | end 22 | 23 | state YellowLight 24 | switchCapacity => PowerOff 25 | next => OrangeLight 26 | end 27 | 28 | state GreenLight 29 | switchCapacity => PowerOff 30 | next => YellowLight 31 | end 32 | -------------------------------------------------------------------------------- /packages/examples/resources/langium/statemachine/example.statemachine: -------------------------------------------------------------------------------- 1 | statemachine TrafficLight 2 | 3 | events 4 | switchCapacity 5 | next 6 | 7 | initialState PowerOff 8 | 9 | state PowerOff 10 | switchCapacity => RedLight 11 | end 12 | 13 | state RedLight 14 | switchCapacity => PowerOff 15 | next => GreenLight 16 | end 17 | 18 | state YellowLight 19 | switchCapacity => PowerOff 20 | next => RedLight 21 | end 22 | 23 | state GreenLight 24 | switchCapacity => PowerOff 25 | next => YellowLight 26 | end 27 | -------------------------------------------------------------------------------- /packages/examples/resources/python/bad.py: -------------------------------------------------------------------------------- 1 | # code is intentionally incorrect - language server will pick this up on connection and highlight the error 2 | def main(): 3 | return pass 4 | -------------------------------------------------------------------------------- /packages/examples/resources/python/hello.py: -------------------------------------------------------------------------------- 1 | # if hello2 is not resolved the file is not availale on the language server 2 | from hello2 import print_hello 3 | 4 | print_hello() 5 | print("Hello Moon!") 6 | -------------------------------------------------------------------------------- /packages/examples/resources/python/hello2.py: -------------------------------------------------------------------------------- 1 | def print_hello(): 2 | 3 | x=5 4 | print("Hello World!") 5 | 6 | print_hello() -------------------------------------------------------------------------------- /packages/examples/resources/scripts/downloadResources.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | import { existsSync, mkdirSync, writeFileSync } from 'node:fs'; 7 | import { dirname, resolve } from 'node:path'; 8 | import { fileURLToPath } from 'node:url'; 9 | 10 | export const getLocalDirectory = () => { 11 | const __filename = fileURLToPath(import.meta.url); 12 | return dirname(__filename); 13 | }; 14 | 15 | const downloadResource = async (url: string, targetDir: string, filename: string) => { 16 | const target = resolve(targetDir, filename); 17 | if (existsSync(target)) { 18 | console.log(`Skipping download because ${target} already exists.`); 19 | } else { 20 | const result = mkdirSync(targetDir, { recursive: true }); 21 | if (result) { 22 | console.log(`Created target directory: ${targetDir}`); 23 | } 24 | console.log(`Downloading ${url} to ${target}`); 25 | const resp = await fetch(url); 26 | const buffer = await resp.arrayBuffer(); 27 | writeFileSync(target, Buffer.from(buffer)); 28 | } 29 | }; 30 | 31 | // Source: https://gist.github.com/wanglf/7acc591890dc0d8ceff1e7ec9af32a55?permalink_comment_id=4151555#gistcomment-4151555 32 | // https://marketplace.visualstudio.com/_apis/public/gallery/publishers/${publisher}/vsextensions/${extension}/${version}/vspackage 33 | 34 | await downloadResource('https://marketplace.visualstudio.com/_apis/public/gallery/publishers/GitHub/vsextensions/github-vscode-theme/6.3.5/vspackage', 35 | resolve(getLocalDirectory(), '../vsix/'), 'github-vscode-theme.vsix'); 36 | 37 | // not yet used 38 | await downloadResource('https://marketplace.visualstudio.com/_apis/public/gallery/publishers/TypeFox/vsextensions/open-collaboration-tools/0.2.4/vspackage', 39 | resolve(getLocalDirectory(), '../vsix/'), 'open-collaboration-tools.vsix'); 40 | -------------------------------------------------------------------------------- /packages/examples/resources/styles/views.css: -------------------------------------------------------------------------------- 1 | :root { 2 | font-family: Inter, Avenir, Helvetica, Arial, sans-serif; 3 | font-size: 16px; 4 | line-height: 24px; 5 | font-weight: 400; 6 | 7 | font-synthesis: none; 8 | text-rendering: optimizeLegibility; 9 | -webkit-font-smoothing: antialiased; 10 | -moz-osx-font-smoothing: grayscale; 11 | -webkit-text-size-adjust: 100%; 12 | } 13 | 14 | body { 15 | background-color: var(--vscode-editorWidget-background); 16 | color: var(--vscode-editorWidget-foreground); 17 | margin: 0; 18 | } 19 | 20 | #sidebarDiv, 21 | #sidebarRightDiv { 22 | display: flex; 23 | flex: none; 24 | border: 1px solid var(--vscode-editorWidget-border); 25 | } 26 | 27 | #sidebar { 28 | width: 300px; 29 | } 30 | 31 | #editorsDiv { 32 | flex: 1; 33 | min-width: 0; 34 | } 35 | 36 | #editors { 37 | position: relative; 38 | min-width: 0; 39 | height: 99%; 40 | border: 1px solid var(--vscode-editorWidget-border); 41 | } 42 | 43 | #sidebar-right { 44 | max-width: 500px; 45 | } 46 | 47 | #auxiliaryBar-left, 48 | #auxiliaryBar { 49 | max-width: 300px; 50 | } 51 | 52 | #panel { 53 | display: none; 54 | flex: 1; 55 | border: 1px solid var(--vscode-editorWidget-border); 56 | min-height: 0; 57 | } 58 | 59 | #titleBar { 60 | position: relative; 61 | flex: none; 62 | } 63 | 64 | #banner { 65 | flex: none; 66 | } 67 | 68 | #workbench-container { 69 | height: 95vh; 70 | display: flex; 71 | flex-direction: column 72 | } 73 | 74 | #workbench-top { 75 | display: flex; 76 | gap: 20px; 77 | flex: 2; 78 | min-height: 0 79 | } 80 | -------------------------------------------------------------------------------- /packages/examples/src/appPlayground/common.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | import * as vscode from 'vscode'; 7 | import type { RegisterLocalProcessExtensionResult } from '@codingame/monaco-vscode-api/extensions'; 8 | import { MonacoEditorLanguageClientWrapper } from 'monaco-editor-wrapper'; 9 | import type { ConfigResult } from './config.js'; 10 | 11 | export const configurePostStart = async (wrapper: MonacoEditorLanguageClientWrapper, configResult: ConfigResult) => { 12 | const result = wrapper.getExtensionRegisterResult('mlc-app-playground') as RegisterLocalProcessExtensionResult; 13 | result.setAsDefaultApi(); 14 | 15 | // WA: Force show explorer and not search 16 | await vscode.commands.executeCommand('workbench.view.explorer'); 17 | 18 | await Promise.all([ 19 | await vscode.workspace.openTextDocument(configResult.helloTsUri), 20 | await vscode.workspace.openTextDocument(configResult.testerTsUri) 21 | ]); 22 | 23 | await Promise.all([ 24 | await vscode.window.showTextDocument(configResult.helloTsUri) 25 | ]); 26 | 27 | console.log('Application Playground started'); 28 | }; 29 | -------------------------------------------------------------------------------- /packages/examples/src/appPlayground/launcher.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | import { initLocaleLoader } from 'monaco-editor-wrapper/vscode/locale'; 7 | await initLocaleLoader(); 8 | 9 | const { runApplicationPlayground } = await import('./main.js'); 10 | runApplicationPlayground(); 11 | -------------------------------------------------------------------------------- /packages/examples/src/appPlayground/main.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | import { MonacoEditorLanguageClientWrapper } from 'monaco-editor-wrapper'; 7 | import { configure } from './config.js'; 8 | import { configurePostStart } from './common.js'; 9 | import { disableElement } from '../common/client/utils.js'; 10 | 11 | const wrapper = new MonacoEditorLanguageClientWrapper(); 12 | 13 | export const runApplicationPlayground = async () => { 14 | disableElement('button-start', true); 15 | const configResult = configure(document.body); 16 | await wrapper.init(configResult.wrapperConfig); 17 | await configurePostStart(wrapper, configResult); 18 | }; 19 | -------------------------------------------------------------------------------- /packages/examples/src/appPlayground/reactLauncher.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | import { initLocaleLoader } from 'monaco-editor-wrapper/vscode/locale'; 7 | await initLocaleLoader(); 8 | 9 | const { runApplicationPlaygroundReact } = await import('./reactMain.js'); 10 | runApplicationPlaygroundReact(); 11 | -------------------------------------------------------------------------------- /packages/examples/src/appPlayground/reactMain.tsx: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | import React from 'react'; 7 | import ReactDOM from 'react-dom/client'; 8 | import { MonacoEditorLanguageClientWrapper } from 'monaco-editor-wrapper'; 9 | import { MonacoEditorReactComp } from '@typefox/monaco-editor-react'; 10 | import { configure } from './config.js'; 11 | import { configurePostStart } from './common.js'; 12 | 13 | export const runApplicationPlaygroundReact = async () => { 14 | 15 | const configResult = configure(); 16 | const root = ReactDOM.createRoot(document.getElementById('react-root')!); 17 | const App = () => { 18 | return ( 19 |
20 | { 23 | await configurePostStart(wrapper, configResult); 24 | }} 25 | onError={(e) => { 26 | console.error(e); 27 | }} /> 28 |
29 | ); 30 | }; 31 | root.render(); 32 | }; 33 | -------------------------------------------------------------------------------- /packages/examples/src/clangd/README.md: -------------------------------------------------------------------------------- 1 | # Cpp Language Client & Clangd Language Server (Worker/Wasm) 2 | 3 | This example is based on the wonderful [work](https://github.com/guyutongxue/clangd-in-browser) from [Guyutongxue](https://github.com/guyutongxue). 4 | 5 | This example has less features and therefore less code and will be used to test and integrate new features under development. 6 | -------------------------------------------------------------------------------- /packages/examples/src/clangd/definitions.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | export const HOME_DIR = '/home/web_user'; 7 | export const WORKSPACE_PATH = `${HOME_DIR}/workspace`; 8 | -------------------------------------------------------------------------------- /packages/examples/src/clangd/worker/json_stream.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | const QUOT = 34; 7 | const LBRACE = 123; 8 | const RBRACE = 125; 9 | const BACKSLASH = 92; 10 | 11 | export class JsonStream { 12 | #inJson = false; 13 | #rawText: number[] = []; 14 | #unbalancedBraces = 0; 15 | #inString = false; 16 | #inEscape = 0; 17 | readonly #textDecoder = new TextDecoder(); 18 | 19 | constructor() { } 20 | 21 | /** 22 | * Insert a char into current partial JSON 23 | * @param charCode 24 | * @returns Complete JSON string if the inserted char makes the JSON complete, otherwise null 25 | */ 26 | insert(charCode: number): string | null { 27 | if (!this.#inJson && charCode === LBRACE) { 28 | this.#inJson = true; 29 | this.#rawText = []; 30 | } 31 | if (!this.#inJson) { 32 | return null; 33 | } 34 | this.#rawText.push(charCode); 35 | if (this.#inString) { 36 | if (this.#inEscape) { 37 | if (charCode === 75) { 38 | // \uxxxx 39 | this.#inEscape += 4; 40 | } 41 | this.#inEscape--; 42 | } else { 43 | if (charCode === BACKSLASH) { 44 | this.#inEscape = 1; 45 | } else if (charCode === QUOT) { 46 | this.#inString = false; 47 | } 48 | } 49 | } else { 50 | if (charCode === LBRACE) { 51 | this.#unbalancedBraces++; 52 | } else if (charCode === RBRACE) { 53 | this.#unbalancedBraces--; 54 | if (this.#unbalancedBraces === 0) { 55 | this.#inJson = false; 56 | return this.#textDecoder.decode(new Uint8Array(this.#rawText)); 57 | } 58 | } else if (charCode === QUOT) { 59 | this.#inString = true; 60 | } 61 | } 62 | return null; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /packages/examples/src/clangd/worker/memfs-tools.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | export const fsReadAllFiles = (emscriptenFs: typeof FS, baseFolder: string) => { 7 | const files: string[] = []; 8 | const directories: string[] = []; 9 | 10 | const crawlFolder = (folder: string) => { 11 | const folderListing = emscriptenFs.readdir(folder); 12 | for (const name of folderListing) { 13 | // do not process the current and parent directory 14 | if (name === '.' || name === '..') { 15 | continue; 16 | } 17 | 18 | const path = `${folder}/${name}`.replaceAll('//', '/'); 19 | try { 20 | const { mode } = emscriptenFs.lookupPath(path, { parent: false }).node; 21 | if (emscriptenFs.isFile(mode)) { 22 | files.push(path); 23 | } else if (emscriptenFs.isDir(mode)) { 24 | directories.push(path); 25 | crawlFolder(path); 26 | } else { 27 | console.log(`Ignored: ${path}`); 28 | } 29 | } catch (error) { 30 | console.error(`${path} provoked an error: ${error}`); 31 | } 32 | } 33 | }; 34 | 35 | crawlFolder(baseFolder); 36 | 37 | // files.forEach((file) => { console.log(file); }); 38 | console.log(`Found ${files.length} files.`); 39 | return { 40 | files, 41 | directories 42 | }; 43 | }; 44 | -------------------------------------------------------------------------------- /packages/examples/src/common/client/utils.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | import { RegisteredMemoryFile } from '@codingame/monaco-vscode-files-service-override'; 7 | import type { IStoredWorkspace } from '@codingame/monaco-vscode-configuration-service-override'; 8 | import type { Uri } from 'vscode'; 9 | 10 | export const disableElement = (id: string, disabled: boolean) => { 11 | const button = document.getElementById(id) as HTMLButtonElement | HTMLInputElement | null; 12 | if (button !== null) { 13 | button.disabled = disabled; 14 | } 15 | }; 16 | 17 | export const createDefaultWorkspaceFile = (workspaceFile: Uri, workspacePath: string) => { 18 | return new RegisteredMemoryFile( 19 | workspaceFile, 20 | JSON.stringify( 21 | { 22 | folders: [ 23 | { 24 | path: workspacePath 25 | } 26 | ] 27 | }, 28 | null, 29 | 2 30 | ) 31 | ); 32 | }; 33 | 34 | export const delayExecution = (ms: number) => { 35 | return new Promise((resolve) => setTimeout(resolve, ms)); 36 | }; 37 | -------------------------------------------------------------------------------- /packages/examples/src/common/node/language-server-runner.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | import { WebSocketServer } from 'ws'; 7 | import { Server } from 'node:http'; 8 | import express from 'express'; 9 | import { getLocalDirectory, type LanguageServerRunConfig, upgradeWsServer } from './server-commons.js'; 10 | 11 | /** LSP server runner */ 12 | export const runLanguageServer = ( 13 | languageServerRunConfig: LanguageServerRunConfig 14 | ) => { 15 | process.on('uncaughtException', err => { 16 | console.error('Uncaught Exception: ', err.toString()); 17 | if (err.stack !== undefined) { 18 | console.error(err.stack); 19 | } 20 | }); 21 | 22 | // create the express application 23 | const app = express(); 24 | // server the static content, i.e. index.html 25 | const dir = getLocalDirectory(import.meta.url); 26 | app.use(express.static(dir)); 27 | // start the http server 28 | const httpServer: Server = app.listen(languageServerRunConfig.serverPort); 29 | const wss = new WebSocketServer(languageServerRunConfig.wsServerOptions); 30 | // create the web socket 31 | upgradeWsServer(languageServerRunConfig, { 32 | server: httpServer, 33 | wss 34 | }); 35 | }; 36 | -------------------------------------------------------------------------------- /packages/examples/src/debugger/common/definitions.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | import { RegisteredMemoryFile } from '@codingame/monaco-vscode-files-service-override'; 7 | import { Uri } from 'vscode'; 8 | 9 | export type FileDefinition = { 10 | path: string; 11 | code: string; 12 | uri: Uri; 13 | } 14 | 15 | export type InitMessage = { 16 | id: 'init', 17 | files: Record 18 | defaultFile: string; 19 | debuggerExecCall: string; 20 | }; 21 | 22 | export type ConfigParams = { 23 | extensionName: string; 24 | languageId: string; 25 | documentSelector: string[]; 26 | homeDir: string; 27 | workspaceRoot: string; 28 | workspaceFile: Uri; 29 | htmlContainer?: HTMLElement; 30 | protocol: 'ws' | 'wss'; 31 | hostname: string; 32 | port: number; 33 | files: Map; 34 | defaultFile: string; 35 | helpContainerCmd: string; 36 | debuggerExecCall: string; 37 | } 38 | 39 | export const createDebugLaunchConfigFile = (workspacePath: string, type: string) => { 40 | return new RegisteredMemoryFile( 41 | Uri.file(`${workspacePath}/.vscode/launch.json`), 42 | JSON.stringify( 43 | { 44 | version: '0.2.0', 45 | configurations: [ 46 | { 47 | name: 'Debugger: Lauch', 48 | type, 49 | request: 'attach', 50 | } 51 | ] 52 | }, 53 | null, 54 | 2 55 | ) 56 | ); 57 | }; 58 | 59 | -------------------------------------------------------------------------------- /packages/examples/src/eclipse.jdt.ls/config.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | export const eclipseJdtLsConfig = { 6 | port: 30003, 7 | path: '/jdtls', 8 | basePath: '/home/mlc/packages/examples/resources/eclipse.jdt.ls' 9 | }; 10 | -------------------------------------------------------------------------------- /packages/examples/src/eclipse.jdt.ls/server/direct.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | import { runEclipseJdtLs } from './main.js'; 7 | 8 | runEclipseJdtLs(); 9 | -------------------------------------------------------------------------------- /packages/examples/src/eclipse.jdt.ls/server/main.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | import { runLanguageServer } from '../../common/node/language-server-runner.js'; 7 | import { LanguageName } from '../../common/node/server-commons.js'; 8 | import { eclipseJdtLsConfig } from '../config.js'; 9 | 10 | export const runEclipseJdtLs = () => { 11 | runLanguageServer({ 12 | serverName: 'Eclipse JDT LS', 13 | pathName: eclipseJdtLsConfig.path, 14 | serverPort: eclipseJdtLsConfig.port, 15 | runCommand: LanguageName.java, 16 | runCommandArgs: [ 17 | '-Declipse.application=org.eclipse.jdt.ls.core.id1', 18 | '-Dosgi.bundles.defaultStartLevel=4', 19 | '-Declipse.product=org.eclipse.jdt.ls.core.product', 20 | '-Dlog.level=ALL', 21 | '-Xmx1G', 22 | '--add-modules=ALL-SYSTEM', 23 | '--add-opens', 24 | 'java.base/java.util=ALL-UNNAMED', 25 | '--add-opens', 26 | 'java.base/java.lang=ALL-UNNAMED', 27 | '-jar', 28 | `${eclipseJdtLsConfig.basePath}/ls/plugins/org.eclipse.equinox.launcher_1.6.900.v20240613-2009.jar`, 29 | '-configuration', 30 | `${eclipseJdtLsConfig.basePath}/ls/config_linux`, 31 | '-data', 32 | `${eclipseJdtLsConfig.basePath}/workspace` 33 | ], 34 | wsServerOptions: { 35 | noServer: true, 36 | perMessageDeflate: false 37 | } 38 | }); 39 | }; 40 | -------------------------------------------------------------------------------- /packages/examples/src/groovy/config.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | export const groovyConfig = { 6 | port: 30002, 7 | path: '/groovy', 8 | basePath: '/home/gradle/mlc/packages/examples/resources/groovy' 9 | }; 10 | -------------------------------------------------------------------------------- /packages/examples/src/groovy/server/direct.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | import { runGroovyLanguageServer } from './main.js'; 7 | 8 | runGroovyLanguageServer(); 9 | -------------------------------------------------------------------------------- /packages/examples/src/groovy/server/main.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | import { runLanguageServer } from '../../common/node/language-server-runner.js'; 7 | import { LanguageName } from '../../common/node/server-commons.js'; 8 | import { groovyConfig } from '../config.js'; 9 | 10 | export const runGroovyLanguageServer = () => { 11 | runLanguageServer({ 12 | serverName: 'GROOVY', 13 | pathName: groovyConfig.path, 14 | serverPort: groovyConfig.port, 15 | runCommand: LanguageName.java, 16 | runCommandArgs: [ 17 | '-jar', 18 | `${groovyConfig.basePath}/lib/groovy-language-server-all.jar` 19 | ], 20 | wsServerOptions: { 21 | noServer: true, 22 | perMessageDeflate: false 23 | } 24 | }); 25 | }; 26 | -------------------------------------------------------------------------------- /packages/examples/src/index.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | export * from './common/client/utils.js'; 7 | -------------------------------------------------------------------------------- /packages/examples/src/json/server/direct.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | import { resolve } from 'node:path'; 6 | import { runJsonServer } from './main.js'; 7 | import { getLocalDirectory } from '../../common/node/server-commons.js'; 8 | 9 | const baseDir = resolve(getLocalDirectory(import.meta.url)); 10 | const relativeDir = '../../../dist/json/server/json-server.js'; 11 | runJsonServer(baseDir, relativeDir); 12 | -------------------------------------------------------------------------------- /packages/examples/src/json/server/main.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | import { resolve } from 'node:path'; 7 | import cors from 'cors'; 8 | 9 | import { runLanguageServer } from '../../common/node/language-server-runner.js'; 10 | import { LanguageName } from '../../common/node/server-commons.js'; 11 | import express from 'express'; 12 | export const runJsonServer = (baseDir: string, relativeDir: string) => { 13 | const processRunPath = resolve(baseDir, relativeDir); 14 | runLanguageServer({ 15 | serverName: 'JSON', 16 | pathName: '/sampleServer', 17 | serverPort: 30000, 18 | runCommand: LanguageName.node, 19 | runCommandArgs: [ 20 | processRunPath, 21 | '--stdio' 22 | ], 23 | wsServerOptions: { 24 | noServer: true, 25 | perMessageDeflate: false 26 | } 27 | }); 28 | 29 | startMockHttpServerForSavingCodeFromEditor(); 30 | }; 31 | 32 | export const startMockHttpServerForSavingCodeFromEditor = () => { 33 | const app = express(); 34 | app.use(cors()); 35 | app.use(express.json()); 36 | app.post('/save-code', (req, res) => { 37 | const { code } = req.body; 38 | console.log('Received code:', code); 39 | res.json({ success: true, message: code}); 40 | }); 41 | 42 | const PORT = 3003; 43 | app.listen(PORT, () => { 44 | console.log(`JSON server running on port ${PORT}`); 45 | }); 46 | }; 47 | -------------------------------------------------------------------------------- /packages/examples/src/langium/langium-dsl/worker/langium-server.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2018-2022 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | /// 6 | 7 | import { EmptyFileSystem } from 'langium'; 8 | import { type DefaultSharedModuleContext, startLanguageServer } from 'langium/lsp'; 9 | import { createLangiumGrammarServices } from 'langium/grammar'; 10 | import { BrowserMessageReader, BrowserMessageWriter, createConnection } from 'vscode-languageserver/browser.js'; 11 | 12 | /* browser specific setup code */ 13 | const messageReader = new BrowserMessageReader(self as DedicatedWorkerGlobalScope); 14 | const messageWriter = new BrowserMessageWriter(self as DedicatedWorkerGlobalScope); 15 | 16 | messageReader.listen((message) => { 17 | console.log('Received message from main thread:', message); 18 | }); 19 | 20 | // Inject the shared services and language-specific services 21 | const context = { 22 | connection: createConnection(messageReader, messageWriter), 23 | ...EmptyFileSystem 24 | } as unknown as DefaultSharedModuleContext; 25 | const { shared } = createLangiumGrammarServices(context); 26 | 27 | console.log('Starting langium-dsl server...'); 28 | 29 | // Start the language server with the shared services 30 | startLanguageServer(shared); 31 | -------------------------------------------------------------------------------- /packages/examples/src/langium/statemachine/config/langium-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "projectName": "Statemachine", 3 | "out": "../ls/generated", 4 | "languages": [ 5 | { 6 | "id": "statemachine", 7 | "grammar": "../ls/statemachine.langium", 8 | "fileExtensions": [ 9 | ".statemachine" 10 | ], 11 | "textMate": { 12 | "out": "../syntaxes/statemachine.tmLanguage.json" 13 | } 14 | } 15 | ] 16 | } -------------------------------------------------------------------------------- /packages/examples/src/langium/statemachine/config/language-configuration.json: -------------------------------------------------------------------------------- 1 | { 2 | "comments": { 3 | // symbol used for single line comment. Remove this entry if your language does not support line comments 4 | "lineComment": "//", 5 | // symbols used for start and end a block comment. Remove this entry if your language does not support block comments 6 | "blockComment": [ "/*", "*/" ] 7 | }, 8 | // symbols used as brackets 9 | "brackets": [ 10 | ["{", "}"], 11 | ["[", "]"], 12 | ["(", ")"] 13 | ], 14 | // symbols that are auto closed when typing 15 | "autoClosingPairs": [ 16 | ["{", "}"], 17 | ["[", "]"], 18 | ["(", ")"], 19 | ["\"", "\""], 20 | ["'", "'"] 21 | ], 22 | // symbols that can be used to surround a selection 23 | "surroundingPairs": [ 24 | ["{", "}"], 25 | ["[", "]"], 26 | ["(", ")"], 27 | ["\"", "\""], 28 | ["'", "'"] 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /packages/examples/src/langium/statemachine/launcher.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | import { initLocaleLoader } from 'monaco-editor-wrapper/vscode/locale'; 7 | await initLocaleLoader(); 8 | 9 | const { runStatemachineWrapper } = await import('./main.js'); 10 | runStatemachineWrapper(); 11 | -------------------------------------------------------------------------------- /packages/examples/src/langium/statemachine/ls/generated/module.ts: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * This file was generated by langium-cli 3.3.0. 3 | * DO NOT EDIT MANUALLY! 4 | ******************************************************************************/ 5 | 6 | import type { LangiumSharedCoreServices, LangiumCoreServices, LangiumGeneratedCoreServices, LangiumGeneratedSharedCoreServices, LanguageMetaData, Module } from 'langium'; 7 | import { StatemachineAstReflection } from './ast.js'; 8 | import { StatemachineGrammar } from './grammar.js'; 9 | 10 | export const StatemachineLanguageMetaData = { 11 | languageId: 'statemachine', 12 | fileExtensions: ['.statemachine'], 13 | caseInsensitive: false, 14 | mode: 'development' 15 | } as const satisfies LanguageMetaData; 16 | 17 | export const StatemachineGeneratedSharedModule: Module = { 18 | AstReflection: () => new StatemachineAstReflection() 19 | }; 20 | 21 | export const StatemachineGeneratedModule: Module = { 22 | Grammar: () => StatemachineGrammar(), 23 | LanguageMetaData: () => StatemachineLanguageMetaData, 24 | parser: {} 25 | }; 26 | -------------------------------------------------------------------------------- /packages/examples/src/langium/statemachine/ls/statemachine.langium: -------------------------------------------------------------------------------- 1 | grammar Statemachine 2 | 3 | entry Statemachine: 4 | 'statemachine' name=ID 5 | ('events' events+=Event+)? 6 | ('commands' commands+=Command+)? 7 | 'initialState' init=[State] 8 | states+=State*; 9 | 10 | Event: 11 | name=ID; 12 | 13 | Command: 14 | name=ID; 15 | 16 | State: 17 | 'state' name=ID 18 | ('actions' '{' actions+=[Command]+ '}')? 19 | transitions+=Transition* 20 | 'end'; 21 | 22 | Transition: 23 | event=[Event] '=>' state=[State]; 24 | 25 | hidden terminal WS: /\s+/; 26 | terminal ID: /[_a-zA-Z][\w_]*/; 27 | 28 | hidden terminal ML_COMMENT: /\/\*[\s\S]*?\*\//; 29 | hidden terminal SL_COMMENT: /\/\/[^\n\r]*/; 30 | -------------------------------------------------------------------------------- /packages/examples/src/langium/statemachine/syntaxes/statemachine.tmLanguage.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "statemachine", 3 | "scopeName": "source.statemachine", 4 | "fileTypes": [ 5 | ".statemachine" 6 | ], 7 | "patterns": [ 8 | { 9 | "include": "#comments" 10 | }, 11 | { 12 | "name": "keyword.control.statemachine", 13 | "match": "\\b(actions|commands|end|events|initialState|state|statemachine)\\b" 14 | } 15 | ], 16 | "repository": { 17 | "comments": { 18 | "patterns": [ 19 | { 20 | "name": "comment.block.statemachine", 21 | "begin": "/\\*", 22 | "beginCaptures": { 23 | "0": { 24 | "name": "punctuation.definition.comment.statemachine" 25 | } 26 | }, 27 | "end": "\\*/", 28 | "endCaptures": { 29 | "0": { 30 | "name": "punctuation.definition.comment.statemachine" 31 | } 32 | } 33 | }, 34 | { 35 | "begin": "//", 36 | "beginCaptures": { 37 | "1": { 38 | "name": "punctuation.whitespace.comment.leading.statemachine" 39 | } 40 | }, 41 | "end": "(?=$)", 42 | "name": "comment.line.statemachine" 43 | } 44 | ] 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /packages/examples/src/langium/statemachine/worker/statemachine-server-port.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | /// 7 | 8 | import { start } from './statemachine-server-start.js'; 9 | 10 | declare const self: DedicatedWorkerGlobalScope; 11 | 12 | self.onmessage = async (event: MessageEvent) => { 13 | const data = event.data; 14 | console.log(event.data); 15 | if (data.port !== undefined) { 16 | start(data.port, 'statemachine-server-port'); 17 | 18 | setTimeout(() => { 19 | // test independent communication 20 | self.postMessage('started'); 21 | }, 1000); 22 | } 23 | }; 24 | -------------------------------------------------------------------------------- /packages/examples/src/langium/statemachine/worker/statemachine-server-start.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | /// 7 | 8 | import { EmptyFileSystem } from 'langium'; 9 | import { startLanguageServer } from 'langium/lsp'; 10 | import { BrowserMessageReader, BrowserMessageWriter, createConnection } from 'vscode-languageserver/browser.js'; 11 | import { createStatemachineServices } from '../ls/statemachine-module.js'; 12 | 13 | export let messageReader: BrowserMessageReader | undefined; 14 | export let messageWriter: BrowserMessageWriter | undefined; 15 | 16 | export const start = (port: MessagePort | DedicatedWorkerGlobalScope, name: string) => { 17 | console.log(`Starting ${name}...`); 18 | /* browser specific setup code */ 19 | messageReader = new BrowserMessageReader(port); 20 | messageWriter = new BrowserMessageWriter(port); 21 | 22 | messageReader.listen((message) => { 23 | console.log('Received message from main thread:', message); 24 | }); 25 | 26 | const connection = createConnection(messageReader, messageWriter); 27 | 28 | // Inject the shared services and language-specific services 29 | const { shared } = createStatemachineServices({ connection, ...EmptyFileSystem }); 30 | 31 | // Start the language server with the shared services 32 | startLanguageServer(shared); 33 | }; 34 | -------------------------------------------------------------------------------- /packages/examples/src/langium/statemachine/worker/statemachine-server.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | /// 7 | 8 | import { start } from './statemachine-server-start.js'; 9 | 10 | declare const self: DedicatedWorkerGlobalScope; 11 | 12 | start(self, 'statemachine-server'); 13 | -------------------------------------------------------------------------------- /packages/examples/src/multi/config.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | import * as vscode from 'vscode'; 7 | import { MonacoLanguageClient } from 'monaco-languageclient'; 8 | import type { LanguageClientConfig } from 'monaco-editor-wrapper'; 9 | 10 | export const createJsonLanguageClientConfig: () => LanguageClientConfig = () => { 11 | return { 12 | name: 'JSON Client', 13 | clientOptions: { 14 | documentSelector: ['json'] 15 | }, 16 | connection: { 17 | options: { 18 | $type: 'WebSocketParams', 19 | host: 'localhost', 20 | port: 30000, 21 | path: 'sampleServer', 22 | secured: false 23 | } 24 | } 25 | }; 26 | }; 27 | 28 | export const createPythonLanguageClientConfig: () => LanguageClientConfig = () => { 29 | return { 30 | connection: { 31 | options: { 32 | $type: 'WebSocketParams', 33 | host: 'localhost', 34 | port: 30001, 35 | path: 'pyright', 36 | secured: false, 37 | extraParams: { 38 | authorization: 'UserAuth' 39 | }, 40 | startOptions: { 41 | onCall: (languageClient?: MonacoLanguageClient) => { 42 | setTimeout(() => { 43 | ['pyright.restartserver', 'pyright.organizeimports'].forEach((cmdName) => { 44 | vscode.commands.registerCommand(cmdName, (...args: unknown[]) => { 45 | languageClient?.sendRequest('workspace/executeCommand', { command: cmdName, arguments: args }); 46 | }); 47 | }); 48 | }, 250); 49 | }, 50 | reportStatus: true, 51 | } 52 | } 53 | }, 54 | clientOptions: { 55 | documentSelector: ['python', 'py'], 56 | workspaceFolder: { 57 | index: 0, 58 | name: 'workspace', 59 | uri: vscode.Uri.parse('/workspace') 60 | } 61 | } 62 | }; 63 | }; 64 | -------------------------------------------------------------------------------- /packages/examples/src/node.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | /* server side export only */ 7 | export * from './common/node/server-commons.js'; 8 | export * from './common/node/language-server-runner.js'; 9 | export * from './json/server/json-server.js'; 10 | export * from './json/server/main.js'; 11 | export * from './python/server/main.js'; 12 | -------------------------------------------------------------------------------- /packages/examples/src/python/client/main.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | import * as vscode from 'vscode'; 7 | import { type RegisterLocalProcessExtensionResult } from '@codingame/monaco-vscode-api/extensions'; 8 | import { MonacoEditorLanguageClientWrapper } from 'monaco-editor-wrapper'; 9 | import { createWrapperConfig } from './config.js'; 10 | import { configureDebugging } from '../../debugger/client/debugger.js'; 11 | 12 | export const runPythonWrapper = async () => { 13 | const appConfig = createWrapperConfig(); 14 | const wrapper = new MonacoEditorLanguageClientWrapper(); 15 | 16 | if (wrapper.isStarted()) { 17 | console.warn('Editor was already started!'); 18 | } else { 19 | await wrapper.init(appConfig.wrapperConfig); 20 | 21 | const result = wrapper.getExtensionRegisterResult('mlc-python-example') as RegisterLocalProcessExtensionResult; 22 | result.setAsDefaultApi(); 23 | 24 | const initResult = wrapper.getExtensionRegisterResult('debugger-py-client') as RegisterLocalProcessExtensionResult | undefined; 25 | if (initResult !== undefined) { 26 | configureDebugging(await initResult.getApi(), appConfig.configParams); 27 | } 28 | 29 | await vscode.commands.executeCommand('workbench.view.explorer'); 30 | await vscode.window.showTextDocument(appConfig.configParams.files.get('hello2.py')!.uri); 31 | 32 | await wrapper.start(); 33 | } 34 | }; 35 | -------------------------------------------------------------------------------- /packages/examples/src/python/client/reactPython.tsx: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | import * as vscode from 'vscode'; 7 | import { type RegisterLocalProcessExtensionResult } from '@codingame/monaco-vscode-api/extensions'; 8 | import React from 'react'; 9 | import ReactDOM from 'react-dom/client'; 10 | import { MonacoEditorReactComp } from '@typefox/monaco-editor-react'; 11 | import { MonacoEditorLanguageClientWrapper } from 'monaco-editor-wrapper'; 12 | import { createWrapperConfig } from './config.js'; 13 | import { configureDebugging } from '../../debugger/client/debugger.js'; 14 | 15 | export const runPythonReact = async () => { 16 | const appConfig = createWrapperConfig(); 17 | 18 | const onLoad = async (wrapper: MonacoEditorLanguageClientWrapper) => { 19 | const result = wrapper.getExtensionRegisterResult('mlc-python-example') as RegisterLocalProcessExtensionResult; 20 | result.setAsDefaultApi(); 21 | 22 | const initResult = wrapper.getExtensionRegisterResult('debugger-py-client') as RegisterLocalProcessExtensionResult | undefined; 23 | if (initResult !== undefined) { 24 | configureDebugging(await initResult.getApi(), appConfig.configParams); 25 | } 26 | 27 | await vscode.commands.executeCommand('workbench.view.explorer'); 28 | await vscode.window.showTextDocument(appConfig.configParams.files.get('hello2.py')!.uri); 29 | }; 30 | 31 | const root = ReactDOM.createRoot(document.getElementById('react-root')!); 32 | 33 | const App = () => { 34 | return ( 35 |
36 | { 41 | console.error(e); 42 | }} /> 43 |
44 | ); 45 | }; 46 | root.render(); 47 | }; 48 | -------------------------------------------------------------------------------- /packages/examples/src/python/server/direct.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | import { resolve } from 'node:path'; 7 | import { runPythonServer } from './main.js'; 8 | import { getLocalDirectory } from '../../common/node/server-commons.js'; 9 | 10 | const baseDir = resolve(getLocalDirectory(import.meta.url)); 11 | const relativeDir = '../../../../../node_modules/pyright/dist/pyright-langserver.js'; 12 | runPythonServer(baseDir, relativeDir); 13 | -------------------------------------------------------------------------------- /packages/examples/src/python/server/main.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | import { resolve } from 'node:path'; 7 | import { IncomingMessage } from 'node:http'; 8 | import { runLanguageServer } from '../../common/node/language-server-runner.js'; 9 | import { LanguageName } from '../../common/node/server-commons.js'; 10 | 11 | export const runPythonServer = (baseDir: string, relativeDir: string) => { 12 | const processRunPath = resolve(baseDir, relativeDir); 13 | runLanguageServer({ 14 | serverName: 'PYRIGHT', 15 | pathName: '/pyright', 16 | serverPort: 30001, 17 | runCommand: LanguageName.node, 18 | runCommandArgs: [ 19 | processRunPath, 20 | '--stdio' 21 | ], 22 | wsServerOptions: { 23 | noServer: true, 24 | perMessageDeflate: false, 25 | clientTracking: true, 26 | verifyClient: ( 27 | clientInfo: { origin: string; secure: boolean; req: IncomingMessage }, 28 | callback 29 | ) => { 30 | const parsedURL = new URL(`${clientInfo.origin}${clientInfo.req.url ?? ''}`); 31 | const authToken = parsedURL.searchParams.get('authorization'); 32 | if (authToken === 'UserAuth') { 33 | callback(true); 34 | } else { 35 | callback(false); 36 | } 37 | } 38 | }, 39 | logMessages: true 40 | }); 41 | }; 42 | -------------------------------------------------------------------------------- /packages/examples/src/vite-env.d.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | /// 7 | 8 | declare module '*?raw' { 9 | const content: string; 10 | export default content; 11 | } 12 | 13 | declare module '*?worker&url' { 14 | const content: string; 15 | export default content; 16 | } 17 | -------------------------------------------------------------------------------- /packages/examples/statemachine.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Langium Statemachine Client & Language Server (Worker) 8 | 9 | 10 | 11 | 12 |
13 | Langium Statemachine Client & Language Server (Worker) - [Back to Index] 14 |
15 | 16 | 17 |
18 |
19 |
20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /packages/examples/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: Helvetica, Arial, Sans-Serif; 3 | } 4 | 5 | .exampleHeadelineDiv { 6 | padding: 5px 0px 5px 0px; 7 | } 8 | 9 | .exampleHeadeline { 10 | font-weight: bold; 11 | font-size: 20px; 12 | } 13 | -------------------------------------------------------------------------------- /packages/examples/tsExtHost.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | TypeScript Extension Host Worker 8 | 9 | 10 | 11 | 12 |
13 | TypeScript Extension Host Worker - [Back to Index] 14 |
15 | 16 | 17 | 18 | 19 |
20 | 21 |
22 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /packages/examples/tsconfig.json: -------------------------------------------------------------------------------- 1 | // this file is required for VSCode to work properly 2 | { 3 | "extends": "./tsconfig.src.json", 4 | "compilerOptions": { 5 | "noEmit": true, 6 | "rootDir": "." 7 | }, 8 | "include": [ 9 | "src/**/*", 10 | "test/**/*" 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /packages/examples/tsconfig.src.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "rootDir": "src", 5 | "outDir": "dist", 6 | "declarationDir": "dist", 7 | // because vscode-jsonrpc requires DedicatedWorkerGlobalScope 8 | // we are required to include both DOM and WebWorker libs 9 | // the only way out currently is to disable lib checking 10 | "skipLibCheck": true 11 | }, 12 | "references": [{ 13 | "path": "../client/tsconfig.src.json", 14 | }, 15 | { 16 | "path": "../vscode-ws-jsonrpc/tsconfig.src.json" 17 | }, 18 | { 19 | "path": "../wrapper/tsconfig.src.json" 20 | }, 21 | { 22 | "path": "../wrapper-react/tsconfig.src.json" 23 | }], 24 | "include": [ 25 | "src/**/*.ts", 26 | "src/**/*.d.ts", 27 | "src/**/*.tsx", 28 | "src/**/*.json", 29 | "src/**/*.langium" 30 | ] 31 | } 32 | -------------------------------------------------------------------------------- /packages/examples/two_langauge_clients.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Json & Python Languageclients & Language Server (Web Socket) 6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | Json & Python Languageclients & Language Server (Web Socket) - [Back to Index] 14 |
15 | 16 | 17 | 18 | 19 |
20 |
21 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /packages/examples/vite.config.deploy.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite'; 2 | import { buildBaseProductionConfig } from './vite.production.base.js'; 3 | 4 | export default defineConfig(({ command }) => { 5 | console.log(`Running: ${command}`); 6 | const productionConfig = buildBaseProductionConfig(); 7 | productionConfig.base = 'https://typefox.github.io/monaco-languageclient/'; 8 | return productionConfig; 9 | }); 10 | 11 | -------------------------------------------------------------------------------- /packages/examples/vite.config.preview.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite'; 2 | import { buildBaseProductionConfig } from './vite.production.base.js'; 3 | 4 | export default defineConfig(({ command }) => { 5 | console.log(`Running: ${command}`); 6 | const productionConfig = buildBaseProductionConfig(); 7 | productionConfig.base = 'http://localhost:20002/'; 8 | productionConfig.preview = { 9 | port: 20002, 10 | cors: { 11 | origin: '*' 12 | }, 13 | headers: { 14 | 'Cross-Origin-Opener-Policy': 'same-origin', 15 | 'Cross-Origin-Embedder-Policy': 'require-corp' 16 | } 17 | }; 18 | return productionConfig; 19 | }); 20 | 21 | -------------------------------------------------------------------------------- /packages/examples/vite.production.base.ts: -------------------------------------------------------------------------------- 1 | import { UserConfig } from 'vite'; 2 | import vsixPlugin from '@codingame/monaco-vscode-rollup-vsix-plugin'; 3 | import { viteStaticCopy } from 'vite-plugin-static-copy'; 4 | import path from 'path'; 5 | 6 | export const buildBaseProductionConfig: () => UserConfig = () => { 7 | return { 8 | build: { 9 | target: 'ES2022', 10 | rollupOptions: { 11 | input: { 12 | index: path.resolve(__dirname, 'index.html'), 13 | langiumClassic: path.resolve(__dirname, 'ghp_langium_classic.html'), 14 | langiumExtended: path.resolve(__dirname, 'ghp_langium_extended.html'), 15 | statemachine: path.resolve(__dirname, 'ghp_statemachine.html'), 16 | clangd: path.resolve(__dirname, 'ghp_clangd.html'), 17 | appPlayground: path.resolve(__dirname, 'ghp_appPlayground.html'), 18 | browser: path.resolve(__dirname, 'ghp_browser.html'), 19 | tsExtHost: path.resolve(__dirname, 'ghp_tsExtHost.html'), 20 | reactAppPlayground: path.resolve(__dirname, 'ghp_react_appPlayground.html'), 21 | reactStatemachine: path.resolve(__dirname, 'ghp_react_statemachine.html') 22 | } 23 | }, 24 | emptyOutDir: false, 25 | assetsInlineLimit: 0, 26 | outDir: path.resolve(__dirname, 'production') 27 | }, 28 | plugins: [ 29 | vsixPlugin(), 30 | viteStaticCopy({ 31 | targets: [ 32 | { 33 | src: 'resources/clangd/wasm/clangd.js', 34 | dest: 'assets' 35 | }, 36 | { 37 | src: 'resources/clangd/wasm/clangd.worker.mjs', 38 | dest: 'assets' 39 | } 40 | ] 41 | }) 42 | ], 43 | worker: { 44 | format: 'es' 45 | }, 46 | esbuild: { 47 | minifySyntax: false 48 | } 49 | }; 50 | } 51 | -------------------------------------------------------------------------------- /packages/vscode-ws-jsonrpc/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright 2018 - present TypeFox GmbH 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /packages/vscode-ws-jsonrpc/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vscode-ws-jsonrpc", 3 | "version": "3.4.0", 4 | "description": "VSCode JSON RPC over WebSocket", 5 | "author": { 6 | "name": "TypeFox GmbH", 7 | "url": "http://www.typefox.io" 8 | }, 9 | "homepage": "https://github.com/TypeFox/monaco-languageclient/blob/main/packages/vscode-ws-jsonrpc/README.md", 10 | "license": "MIT", 11 | "repository": { 12 | "type": "git", 13 | "url": "git+https://github.com/TypeFox/monaco-languageclient.git", 14 | "directory": "packages/vscode-ws-jsonrpc" 15 | }, 16 | "bugs": { 17 | "url": "https://github.com/TypeFox/monaco-languageclient/issues" 18 | }, 19 | "type": "module", 20 | "main": "./lib/index.js", 21 | "module": "./lib/index.js", 22 | "exports": { 23 | ".": { 24 | "types": "./lib/index.d.ts", 25 | "default": "./lib/index.js" 26 | }, 27 | "./server": { 28 | "types": "./lib/server/index.d.ts", 29 | "default": "./lib/server/index.js" 30 | }, 31 | "./socket": { 32 | "types": "./lib/socket/index.d.ts", 33 | "default": "./lib/socket/index.js" 34 | } 35 | }, 36 | "typesVersions": { 37 | "*": { 38 | ".": [ 39 | "lib/index" 40 | ], 41 | "server": [ 42 | "lib/server" 43 | ], 44 | "socket": [ 45 | "lib/socket" 46 | ] 47 | } 48 | }, 49 | "engines": { 50 | "node": ">=20.10.0", 51 | "npm": ">=10.2.3" 52 | }, 53 | "volta": { 54 | "node": "22.16.0", 55 | "npm": "10.9.2" 56 | }, 57 | "files": [ 58 | "lib", 59 | "src", 60 | "README.md", 61 | "CHANGELOG.md", 62 | "LICENSE" 63 | ], 64 | "dependencies": { 65 | "vscode-jsonrpc": "~8.2.1" 66 | }, 67 | "scripts": { 68 | "clean": "shx rm -fr ./lib *.tsbuildinfo", 69 | "compile": "tsc --build tsconfig.src.json", 70 | "build:msg": "echo Building vscode-ws-jsonrpc:", 71 | "build": "npm run build:msg && npm run clean && npm run compile" 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /packages/vscode-ws-jsonrpc/src/connection.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | import type { MessageConnection, Logger } from 'vscode-jsonrpc'; 7 | import { createWebSocketConnection } from './socket/connection.js'; 8 | import type { IWebSocket } from './socket/socket.js'; 9 | import { ConsoleLogger } from './logger.js'; 10 | 11 | export function listen(options: { 12 | webSocket: WebSocket; 13 | logger?: Logger; 14 | onConnection: (connection: MessageConnection) => void; 15 | }) { 16 | const { webSocket, onConnection } = options; 17 | const logger = options.logger || new ConsoleLogger(); 18 | webSocket.onopen = () => { 19 | const socket = toSocket(webSocket); 20 | const connection = createWebSocketConnection(socket, logger); 21 | onConnection(connection); 22 | }; 23 | } 24 | 25 | export function toSocket(webSocket: WebSocket): IWebSocket { 26 | return { 27 | send: content => webSocket.send(content), 28 | onMessage: cb => { 29 | webSocket.onmessage = event => cb(event.data); 30 | }, 31 | onError: cb => { 32 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 33 | webSocket.onerror = (event: any) => { 34 | if (Object.hasOwn(event, 'message')) { 35 | cb(event.message); 36 | } 37 | }; 38 | }, 39 | onClose: cb => { 40 | webSocket.onclose = event => cb(event.code, event.reason); 41 | }, 42 | dispose: () => webSocket.close() 43 | }; 44 | } 45 | -------------------------------------------------------------------------------- /packages/vscode-ws-jsonrpc/src/disposable.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | import { Disposable } from 'vscode-jsonrpc'; 7 | 8 | export class DisposableCollection implements Disposable { 9 | protected readonly disposables: Disposable[] = []; 10 | 11 | dispose(): void { 12 | while (this.disposables.length !== 0) { 13 | this.disposables.pop()!.dispose(); 14 | } 15 | } 16 | 17 | push(disposable: Disposable): Disposable { 18 | const disposables = this.disposables; 19 | disposables.push(disposable); 20 | return { 21 | dispose(): void { 22 | const index = disposables.indexOf(disposable); 23 | if (index !== -1) { 24 | disposables.splice(index, 1); 25 | } 26 | } 27 | }; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /packages/vscode-ws-jsonrpc/src/index.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | export * from './disposable.js'; 7 | export * from './socket/index.js'; 8 | export * from './logger.js'; 9 | export * from './connection.js'; 10 | -------------------------------------------------------------------------------- /packages/vscode-ws-jsonrpc/src/logger.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | import type { Logger } from 'vscode-jsonrpc'; 6 | 7 | export class ConsoleLogger implements Logger { 8 | public error(message: string): void { 9 | console.error(message); 10 | } 11 | 12 | public warn(message: string): void { 13 | console.warn(message); 14 | } 15 | 16 | public info(message: string): void { 17 | console.info(message); 18 | } 19 | 20 | public log(message: string): void { 21 | console.log(message); 22 | } 23 | 24 | public debug(message: string): void { 25 | console.debug(message); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /packages/vscode-ws-jsonrpc/src/server/connection.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | import { MessageReader, MessageWriter, Disposable, Message } from 'vscode-jsonrpc'; 7 | import { DisposableCollection } from '../disposable.js'; 8 | 9 | export interface IConnection extends Disposable { 10 | readonly reader: MessageReader; 11 | readonly writer: MessageWriter; 12 | forward(to: IConnection, map?: (message: Message) => Message): void; 13 | onClose(callback: () => void): Disposable; 14 | } 15 | 16 | export function forward(clientConnection: IConnection, serverConnection: IConnection, map?: (message: Message) => Message): void { 17 | clientConnection.forward(serverConnection, map); 18 | serverConnection.forward(clientConnection, map); 19 | clientConnection.onClose(() => serverConnection.dispose()); 20 | serverConnection.onClose(() => clientConnection.dispose()); 21 | } 22 | 23 | export function createConnection(reader: MessageReader, writer: MessageWriter, onDispose: () => void, 24 | extensions: T = {} as T): IConnection & T { 25 | const disposeOnClose = new DisposableCollection(); 26 | reader.onClose(() => disposeOnClose.dispose()); 27 | writer.onClose(() => disposeOnClose.dispose()); 28 | return { 29 | reader, 30 | writer, 31 | forward(to: IConnection, map: (message: Message) => Message = (message) => message): void { 32 | reader.listen(input => { 33 | const output = map(input); 34 | to.writer.write(output); 35 | }); 36 | }, 37 | onClose(callback: () => void): Disposable { 38 | return disposeOnClose.push(Disposable.create(callback)); 39 | }, 40 | dispose: () => onDispose(), 41 | ...extensions 42 | }; 43 | } 44 | -------------------------------------------------------------------------------- /packages/vscode-ws-jsonrpc/src/server/index.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | export * from './connection.js'; 7 | export * from './launch.js'; 8 | -------------------------------------------------------------------------------- /packages/vscode-ws-jsonrpc/src/socket/connection.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | import type { MessageConnection, Logger } from 'vscode-jsonrpc'; 7 | import { createMessageConnection } from 'vscode-jsonrpc'; 8 | import type { IWebSocket } from './socket.js'; 9 | import { WebSocketMessageReader } from './reader.js'; 10 | import { WebSocketMessageWriter } from './writer.js'; 11 | 12 | export function createWebSocketConnection(socket: IWebSocket, logger: Logger): MessageConnection { 13 | const messageReader = new WebSocketMessageReader(socket); 14 | const messageWriter = new WebSocketMessageWriter(socket); 15 | const connection = createMessageConnection(messageReader, messageWriter, logger); 16 | connection.onClose(() => connection.dispose()); 17 | return connection; 18 | } 19 | -------------------------------------------------------------------------------- /packages/vscode-ws-jsonrpc/src/socket/index.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | export * from './socket.js'; 7 | export * from './reader.js'; 8 | export * from './writer.js'; 9 | export * from './connection.js'; 10 | -------------------------------------------------------------------------------- /packages/vscode-ws-jsonrpc/src/socket/socket.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | import { Disposable } from 'vscode-jsonrpc'; 7 | import type { IConnection } from '../server/connection.js'; 8 | 9 | export interface IWebSocket extends Disposable { 10 | send(content: string): void; 11 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 12 | onMessage(cb: (data: any) => void): void; 13 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 14 | onError(cb: (reason: any) => void): void; 15 | onClose(cb: (code: number, reason: string) => void): void; 16 | } 17 | 18 | export interface IWebSocketConnection extends IConnection { 19 | readonly socket: IWebSocket; 20 | } 21 | -------------------------------------------------------------------------------- /packages/vscode-ws-jsonrpc/src/socket/writer.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | import { Message } from 'vscode-jsonrpc/lib/common/messages.js'; 7 | import { AbstractMessageWriter, MessageWriter } from 'vscode-jsonrpc/lib/common/messageWriter.js'; 8 | import type { IWebSocket } from './socket.js'; 9 | 10 | export class WebSocketMessageWriter extends AbstractMessageWriter implements MessageWriter { 11 | protected errorCount = 0; 12 | protected readonly socket: IWebSocket; 13 | 14 | constructor(socket: IWebSocket) { 15 | super(); 16 | this.socket = socket; 17 | } 18 | 19 | end(): void { 20 | } 21 | 22 | async write(msg: Message): Promise { 23 | try { 24 | const content = JSON.stringify(msg); 25 | this.socket.send(content); 26 | } catch (e) { 27 | this.errorCount++; 28 | this.fireError(e, msg, this.errorCount); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /packages/vscode-ws-jsonrpc/tsconfig.json: -------------------------------------------------------------------------------- 1 | // this file is required for VSCode to work properly 2 | { 3 | "extends": "./tsconfig.src.json", 4 | "compilerOptions": { 5 | "noEmit": true, 6 | "rootDir": "." 7 | }, 8 | "include": [ 9 | "src/**/*", 10 | "test/**/*" 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /packages/vscode-ws-jsonrpc/tsconfig.src.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig", 3 | "compilerOptions": { 4 | "rootDir": "src", 5 | "outDir": "lib", 6 | "declarationDir": "lib", 7 | "skipLibCheck": true 8 | }, 9 | "include": [ 10 | "src/**/*.ts", 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /packages/wrapper-react/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright 2022 - present TypeFox GmbH 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /packages/wrapper-react/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@typefox/monaco-editor-react", 3 | "version": "6.8.0", 4 | "license": "MIT", 5 | "description": "React component for Monaco-Editor and Monaco Languageclient", 6 | "keywords": [ 7 | "monaco-editor", 8 | "monaco-languageclient", 9 | "typescript", 10 | "react" 11 | ], 12 | "type": "module", 13 | "main": "./dist/index.js", 14 | "module": "./dist/index.js", 15 | "exports": { 16 | ".": { 17 | "types": "./dist/index.d.ts", 18 | "default": "./dist/index.js" 19 | } 20 | }, 21 | "typesVersions": { 22 | "*": { 23 | ".": [ 24 | "dist/index" 25 | ] 26 | } 27 | }, 28 | "files": [ 29 | "dist", 30 | "src", 31 | "README.md", 32 | "CHANGELOG.md", 33 | "LICENSE" 34 | ], 35 | "scripts": { 36 | "clean": "shx rm -fr ./dist ./bundle *.tsbuildinfo", 37 | "compile": " tsc --build tsconfig.src.json", 38 | "build": "npm run clean && npm run compile" 39 | }, 40 | "engines": { 41 | "node": ">=20.10.0", 42 | "npm": ">=10.2.3" 43 | }, 44 | "volta": { 45 | "node": "22.16.0", 46 | "npm": "10.9.2" 47 | }, 48 | "dependencies": { 49 | "@codingame/monaco-vscode-editor-api": "~17.1.2", 50 | "monaco-editor-wrapper": "~6.8.0", 51 | "react": ">=18.0.0 || <20.0.0" 52 | }, 53 | "repository": { 54 | "type": "git", 55 | "url": "git+https://github.com/TypeFox/monaco-languageclient.git", 56 | "directory": "packages/monaco-editor-react" 57 | }, 58 | "homepage": "https://github.com/TypeFox/monaco-languageclient/blob/main/packages/wrapper-react/README.md", 59 | "bugs": "https://github.com/TypeFox/monaco-languageclient/issues", 60 | "author": { 61 | "name": "TypeFox", 62 | "url": "https://www.typefox.io" 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /packages/wrapper-react/test/helper.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | import { MessageTransports } from 'vscode-languageclient'; 7 | import { LogLevel } from '@codingame/monaco-vscode-api'; 8 | import type { CodeResources, LanguageClientConfig, WrapperConfig } from 'monaco-editor-wrapper'; 9 | import { configureDefaultWorkerFactory } from 'monaco-editor-wrapper/workers/workerLoaders'; 10 | 11 | export const createDefaultWrapperConfig = (codeResources: CodeResources, logLevel?: LogLevel): WrapperConfig => { 12 | return { 13 | $type: 'extended', 14 | logLevel, 15 | vscodeApiConfig: { 16 | loadThemes: false 17 | }, 18 | editorAppConfig: { 19 | codeResources, 20 | monacoWorkerFactory: configureDefaultWorkerFactory 21 | } 22 | }; 23 | }; 24 | 25 | export const createDefaultLcWorkerConfig = (worker: Worker, languageId: string, 26 | messageTransports?: MessageTransports): LanguageClientConfig => { 27 | return { 28 | name: 'test-worker-direct', 29 | clientOptions: { 30 | documentSelector: [languageId] 31 | }, 32 | connection: { 33 | options: { 34 | $type: 'WorkerDirect', 35 | // create a web worker to pass to the wrapper 36 | worker 37 | }, 38 | messageTransports 39 | } 40 | }; 41 | }; 42 | -------------------------------------------------------------------------------- /packages/wrapper-react/tsconfig.json: -------------------------------------------------------------------------------- 1 | // this file is required for VSCode to work properly 2 | { 3 | "extends": "./tsconfig.src.json", 4 | "compilerOptions": { 5 | "noEmit": true, 6 | "rootDir": "." 7 | }, 8 | "include": [ 9 | "src/**/*", 10 | "test/**/*" 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /packages/wrapper-react/tsconfig.src.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "rootDir": "src", 5 | "outDir": "dist", 6 | "declarationDir": "dist", 7 | // because vscode-jsonrpc requires DedicatedWorkerGlobalScope 8 | // we are required to include both DOM and WebWorker libs 9 | // the only way out currently is to disable lib checking 10 | "skipLibCheck": true 11 | }, 12 | "references": [{ 13 | "path": "../wrapper/tsconfig.src.json" 14 | }], 15 | "include": [ 16 | "src/**/*.ts", 17 | "src/**/*.tsx" 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /packages/wrapper-react/tsconfig.test.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.src.json", 3 | "compilerOptions": { 4 | "noEmit": true, 5 | "rootDir": "test", 6 | // because vscode-jsonrpc requires DedicatedWorkerGlobalScope 7 | // we are required to include both DOM and WebWorker libs 8 | // the only way out currently is to disable lib checking 9 | "skipLibCheck": true 10 | }, 11 | "references": [{ 12 | "path": "./tsconfig.src.json" 13 | }, { 14 | "path": "../examples/tsconfig.src.json", 15 | }], 16 | "include": [ 17 | "test/**/*.ts", 18 | "test/**/*.tsx", 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /packages/wrapper/.gitignore: -------------------------------------------------------------------------------- 1 | resources/themes 2 | resources/wasm 3 | -------------------------------------------------------------------------------- /packages/wrapper/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright 2022 - present TypeFox GmbH 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /packages/wrapper/src/index.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | export * from './editorApp.js'; 7 | export * from './languageClientWrapper.js'; 8 | export * from './wrapper.js'; 9 | -------------------------------------------------------------------------------- /packages/wrapper/src/vscode/index.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | export * from './services.js'; 7 | export * from './viewsService.js'; 8 | -------------------------------------------------------------------------------- /packages/wrapper/src/vscode/localeLoader.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | const localeLoader: Partial Promise>> = { 7 | cs: async () => { 8 | await import('@codingame/monaco-vscode-language-pack-cs'); 9 | }, 10 | de: async () => { 11 | await import('@codingame/monaco-vscode-language-pack-de'); 12 | }, 13 | es: async () => { 14 | await import('@codingame/monaco-vscode-language-pack-es'); 15 | }, 16 | fr: async () => { 17 | await import('@codingame/monaco-vscode-language-pack-fr'); 18 | }, 19 | it: async () => { 20 | await import('@codingame/monaco-vscode-language-pack-it'); 21 | }, 22 | ja: async () => { 23 | await import('@codingame/monaco-vscode-language-pack-ja'); 24 | }, 25 | ko: async () => { 26 | await import('@codingame/monaco-vscode-language-pack-ko'); 27 | }, 28 | pl: async () => { 29 | await import('@codingame/monaco-vscode-language-pack-pl'); 30 | }, 31 | 'pt-br': async () => { 32 | await import('@codingame/monaco-vscode-language-pack-pt-br'); 33 | }, 34 | 'qps-ploc': async () => { 35 | await import('@codingame/monaco-vscode-language-pack-qps-ploc'); 36 | }, 37 | ru: async () => { 38 | await import('@codingame/monaco-vscode-language-pack-ru'); 39 | }, 40 | tr: async () => { 41 | await import('@codingame/monaco-vscode-language-pack-tr'); 42 | }, 43 | 'zh-hans': async () => { 44 | await import('@codingame/monaco-vscode-language-pack-zh-hans'); 45 | }, 46 | 'zh-hant': async () => { 47 | await import('@codingame/monaco-vscode-language-pack-zh-hant'); 48 | } 49 | }; 50 | 51 | export const locales = Object.keys(localeLoader); 52 | 53 | export const initLocaleLoader = async (locale = new URLSearchParams(window.location.search).get('locale')) => { 54 | if (locale !== null) { 55 | const loader = localeLoader[locale]; 56 | if (loader) { 57 | await loader(); 58 | } else { 59 | console.error(`Unknown locale ${locale}`); 60 | } 61 | } 62 | }; 63 | -------------------------------------------------------------------------------- /packages/wrapper/src/workers/workerLoaders.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | import type { Logger } from 'monaco-languageclient/tools'; 7 | import { useWorkerFactory, type WorkerLoader } from 'monaco-languageclient/workerFactory'; 8 | 9 | export const defineDefaultWorkerLoaders: () => Record = () => { 10 | const defaultTextEditorWorker = () => new Worker( 11 | new URL('@codingame/monaco-vscode-editor-api/esm/vs/editor/editor.worker.js', import.meta.url), 12 | { type: 'module' } 13 | ); 14 | const defaultTextMateWorker = () => new Worker( 15 | new URL('@codingame/monaco-vscode-textmate-service-override/worker', import.meta.url), 16 | { type: 'module' } 17 | ); 18 | 19 | return { 20 | // if you import monaco api as 'monaco-editor': monaco-editor/esm/vs/editor/editor.worker.js 21 | TextEditorWorker: defaultTextEditorWorker, 22 | TextMateWorker: defaultTextMateWorker, 23 | // these are other possible workers not configured by default 24 | OutputLinkDetectionWorker: undefined, 25 | LanguageDetectionWorker: undefined, 26 | NotebookEditorWorker: undefined, 27 | LocalFileSearchWorker: undefined 28 | }; 29 | }; 30 | 31 | export const configureDefaultWorkerFactory = (logger?: Logger) => { 32 | useWorkerFactory({ 33 | workerLoaders: defineDefaultWorkerLoaders(), 34 | logger 35 | }); 36 | }; 37 | -------------------------------------------------------------------------------- /packages/wrapper/test/vscode/services.test.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | import { describe, expect, test } from 'vitest'; 7 | import { LogLevel } from '@codingame/monaco-vscode-api'; 8 | import { augmentVscodeApiConfig } from 'monaco-editor-wrapper/vscode/services'; 9 | 10 | describe('createUrl', () => { 11 | 12 | test('test configureServices logLevel trace', async () => { 13 | const vscodeApiConfig = await augmentVscodeApiConfig('extended', { 14 | vscodeApiConfig: { 15 | loadThemes: false 16 | }, 17 | logLevel: LogLevel.Trace 18 | }); 19 | 20 | expect(vscodeApiConfig.workspaceConfig?.developmentOptions?.logLevel).toBe(LogLevel.Trace); 21 | }); 22 | 23 | test('test configureServices logLevel and developmenet info', async () => { 24 | const vscodeApiConfig = await augmentVscodeApiConfig('extended', { 25 | vscodeApiConfig: { 26 | loadThemes: false, 27 | workspaceConfig: { 28 | developmentOptions: { 29 | logLevel: LogLevel.Info 30 | } 31 | } 32 | }, 33 | logLevel: LogLevel.Info 34 | }); 35 | 36 | expect(vscodeApiConfig.workspaceConfig?.developmentOptions?.logLevel).toBe(LogLevel.Info); 37 | }); 38 | 39 | test('test configureServices logLevel development mismatch', async () => { 40 | await expect(async () => { 41 | await augmentVscodeApiConfig('extended', { 42 | vscodeApiConfig: { 43 | loadThemes: false, 44 | workspaceConfig: { 45 | developmentOptions: { 46 | logLevel: LogLevel.Info 47 | } 48 | } 49 | }, 50 | logLevel: LogLevel.Trace 51 | }); 52 | }).rejects.toThrowError('You have configured mismatching logLevels: 1 (wrapperConfig) 3 (workspaceConfig.developmentOptions)'); 53 | }); 54 | 55 | }); 56 | -------------------------------------------------------------------------------- /packages/wrapper/tsconfig.json: -------------------------------------------------------------------------------- 1 | // this file is required for VSCode to work properly 2 | { 3 | "extends": "./tsconfig.src.json", 4 | "compilerOptions": { 5 | "noEmit": true, 6 | "rootDir": "." 7 | }, 8 | "include": [ 9 | "src/**/*", 10 | "test/**/*" 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /packages/wrapper/tsconfig.src.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "rootDir": "src", 5 | "outDir": "dist", 6 | "declarationDir": "dist", 7 | // because vscode-jsonrpc requires DedicatedWorkerGlobalScope 8 | // we are required to include both DOM and WebWorker libs 9 | // the only way out currently is to disable lib checking 10 | "skipLibCheck": true 11 | }, 12 | "references": [{ 13 | "path": "../client/tsconfig.src.json", 14 | }], 15 | "include": [ 16 | "src/**/*.ts", 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /packages/wrapper/tsconfig.test.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.src.json", 3 | "compilerOptions": { 4 | "noEmit": true, 5 | "rootDir": "test", 6 | // because vscode-jsonrpc requires DedicatedWorkerGlobalScope 7 | // we are required to include both DOM and WebWorker libs 8 | // the only way out currently is to disable lib checking 9 | "skipLibCheck": true 10 | }, 11 | "references": [{ 12 | "path": "./tsconfig.src.json", 13 | }, { 14 | "path": "../examples/tsconfig.src.json", 15 | }], 16 | "include": [ 17 | "test/**/*.ts", 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /scripts/auth.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [[ ! -z "${NPM_TOKEN}" ]]; then 4 | printf "//registry.npmjs.org/:_authToken=${NPM_TOKEN}\n" >> ~/.npmrc 5 | fi -------------------------------------------------------------------------------- /scripts/helper.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | import * as path from 'node:path'; 7 | import * as url from 'node:url'; 8 | 9 | /** 10 | * Solves: __dirname is not defined in ES module scope 11 | */ 12 | export function getLocalDirectory() { 13 | const __filename = url.fileURLToPath(import.meta.url); 14 | return path.dirname(__filename); 15 | } 16 | 17 | export function getRootDirectory() { 18 | return path.resolve(getLocalDirectory(), '..'); 19 | } 20 | 21 | export function getPathRelativeToRootDirectory(relativePath: string, pathToDelete?: string) { 22 | if (pathToDelete) { 23 | return path.resolve(getRootDirectory(), relativePath, pathToDelete); 24 | } else { 25 | return path.resolve(getRootDirectory(), relativePath); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "files": [], 3 | // watch everything except for: 4 | // - verify packages (no own source) 5 | "references": [ 6 | { "path": "./packages/client/tsconfig.src.json" }, 7 | { "path": "./packages/client/tsconfig.test.json" }, 8 | { "path": "./packages/vscode-ws-jsonrpc/tsconfig.src.json" }, 9 | { "path": "./packages/wrapper/tsconfig.src.json" }, 10 | { "path": "./packages/wrapper/tsconfig.test.json" }, 11 | { "path": "./packages/wrapper-react/tsconfig.src.json" }, 12 | { "path": "./packages/wrapper-react/tsconfig.test.json" }, 13 | { "path": "./packages/examples/tsconfig.src.json" } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2022", 4 | "module": "NodeNext", 5 | "moduleResolution": "NodeNext", 6 | "lib": [ 7 | "ES2022", 8 | "DOM", 9 | "DOM.Iterable" 10 | ], 11 | "esModuleInterop": true, 12 | "resolveJsonModule": true, 13 | // Enable project compilation 14 | "composite": true, 15 | "declaration": true, 16 | "declarationMap": true, 17 | "sourceMap": true, 18 | "inlineSources": false, 19 | "stripInternal": true, 20 | "strict": true, 21 | "strictPropertyInitialization": false, 22 | "importHelpers": true, 23 | "downlevelIteration": false, 24 | "noImplicitReturns": true, 25 | "noUnusedParameters": true, 26 | "noUnusedLocals": true, 27 | // Enable type checking of declaration files, skip in packages where needed 28 | "skipLibCheck": false, 29 | // Disallow inconsistently-cased references to the same file 30 | "forceConsistentCasingInFileNames": true, 31 | "noImplicitOverride": true, 32 | "experimentalDecorators": true, 33 | "jsx": "react", 34 | "verbatimModuleSyntax": true 35 | }, 36 | "include": [ 37 | "**/src/**/*.ts", 38 | "**/test/**/*.ts", 39 | "**/src/**/*.tsx", 40 | "**/test/**/*.tsx", 41 | "**/packages/*/*.ts", 42 | "**/packages/*/*.js", 43 | "**/build/**/*.mts", 44 | "*.js", 45 | "*.ts", 46 | "*.d.ts", 47 | ], 48 | "exclude": [ 49 | "dist/**/*", 50 | "lib/**/*", 51 | "node_modules/**/*" 52 | ] 53 | } 54 | -------------------------------------------------------------------------------- /verify/README.md: -------------------------------------------------------------------------------- 1 | # Verification Examples 2 | 3 | These examples are not part of the overall npm workspace and therefore they need to be installed seperately. 4 | -------------------------------------------------------------------------------- /verify/angular/.gitignore: -------------------------------------------------------------------------------- 1 | bundle 2 | dist 3 | lib 4 | node_modules 5 | *.tsbuildinfo 6 | -------------------------------------------------------------------------------- /verify/angular/README.md: -------------------------------------------------------------------------------- 1 | # Angular verification example 2 | 3 | It serves on the client here: . 4 | -------------------------------------------------------------------------------- /verify/angular/angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "ng-mlc": { 7 | "projectType": "application", 8 | "schematics": {}, 9 | "root": "", 10 | "sourceRoot": "src", 11 | "prefix": "app", 12 | "architect": { 13 | "build": { 14 | "builder": "@angular-builders/custom-esbuild:application", 15 | "options": { 16 | "outputPath": "dist/ng-mlc", 17 | "index": "src/index.html", 18 | "browser": "src/main.ts", 19 | "tsConfig": "tsconfig.json", 20 | // "plugins": ["./node_modules/@codingame/esbuild-import-meta-url-plugin/dist/esbuildImportMetaUrlPlugin.js"], 21 | "polyfills": [ 22 | "zone.js" 23 | ], 24 | "assets": [], 25 | "styles": [], 26 | "scripts": [], 27 | "aot": false, 28 | "optimization": false, 29 | "sourceMap": true, 30 | "namedChunks": false, 31 | "extractLicenses": false, 32 | "allowedCommonJsDependencies": [ 33 | "vscode-languageclient", 34 | "vscode-languageserver-protocol", 35 | "vscode-jsonrpc", 36 | "vscode-oniguruma", 37 | "vscode-textmate", 38 | "@vscode/iconv-lite-umd" 39 | ] 40 | }, 41 | "configurations": { 42 | "production": { 43 | "aot": true, 44 | "optimization": true, 45 | "sourceMap": false, 46 | "namedChunks": false, 47 | "extractLicenses": true 48 | }, 49 | "development": { 50 | } 51 | }, 52 | "defaultConfiguration": "development" 53 | }, 54 | "serve": { 55 | "builder": "@angular-builders/custom-esbuild:dev-server", 56 | "configurations": { 57 | "production": { 58 | "buildTarget": "ng-mlc:build:production" 59 | }, 60 | "development": { 61 | "buildTarget": "ng-mlc:build:development" 62 | } 63 | }, 64 | "defaultConfiguration": "development" 65 | }, 66 | "extract-i18n": { 67 | "builder": "@angular/build:extract-i18n" 68 | } 69 | } 70 | } 71 | }, 72 | "cli": { 73 | "analytics": false 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /verify/angular/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mlc-verify-angular", 3 | "version": "0.0.0", 4 | "private": "true", 5 | "type": "module", 6 | "engines": { 7 | "node": ">=20.10.0", 8 | "npm": ">=10.2.3" 9 | }, 10 | "volta": { 11 | "node": "22.16.0", 12 | "npm": "10.9.2" 13 | }, 14 | "dependencies": { 15 | "@angular/compiler": "~18.2.8", 16 | "@angular/core": "~18.2.8", 17 | "@angular/platform-browser": "~18.2.8", 18 | "@angular/platform-browser-dynamic": "~18.2.8", 19 | "@codingame/monaco-vscode-editor-api": "~17.1.2", 20 | "monaco-editor-wrapper": "~6.8.0", 21 | "monaco-languageclient-examples": "~2025.5.3", 22 | "rxjs": "~7.8.1", 23 | "zone.js": "~0.14.10" 24 | }, 25 | "devDependencies": { 26 | "@angular-builders/custom-esbuild": "~18.0.0", 27 | "@angular/cli": "~18.2.8", 28 | "@angular/compiler-cli": "~18.2.8", 29 | "@codingame/esbuild-import-meta-url-plugin": "~1.0.3", 30 | "@types/node": "~22.13.10", 31 | "css-loader": "~7.1.2", 32 | "shx": "~0.3.4", 33 | "style-loader": "~4.0.0", 34 | "typescript": "~5.5.4" 35 | }, 36 | "scripts": { 37 | "verify": "npm install && npm run start", 38 | "verify:ci": "npm install && npm run build", 39 | "clean": "shx rm -fr dist *.tsbuildinfo src/assets", 40 | "build:msg": "echo Building angular-client example:", 41 | "build": "npm run build:msg && npm run clean && ng build", 42 | "build:production": "npm run build:msg && npm run clean && ng build --configuration production", 43 | "start": "npm run clean && ng serve", 44 | "start:production": "npm run clean && ng serve --configuration production", 45 | "watch": "npm run clean && ng build --watch --configuration development", 46 | "reset:repo": "git clean -f -X -d" 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /verify/angular/src/app/app.component.html: -------------------------------------------------------------------------------- 1 |

Angular Monaco Editor demo with saving code to a mock HTTP server

2 |
3 | 9 | 10 | 11 |
12 | -------------------------------------------------------------------------------- /verify/angular/src/app/app.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TypeFox/monaco-languageclient/129a4f43d76d3687ca96785c2cc65e2f4bd481cd/verify/angular/src/app/app.component.scss -------------------------------------------------------------------------------- /verify/angular/src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | import { AfterViewInit, Component, inject, signal } from '@angular/core'; 7 | import { WrapperConfig } from 'monaco-editor-wrapper'; 8 | import { MonacoAngularWrapperComponent } from '../monaco-angular-wrapper/monaco-angular-wrapper.component'; 9 | import { buildJsonClientUserConfig } from 'monaco-languageclient-examples/json-client'; 10 | import { SaveCodeService } from '../save-code.service'; 11 | import { firstValueFrom } from 'rxjs'; 12 | @Component({ 13 | selector: 'app-root', 14 | templateUrl: './app.component.html', 15 | styleUrls: ['./app.component.scss'], 16 | standalone: true, 17 | imports: [MonacoAngularWrapperComponent], 18 | }) 19 | export class AppComponent implements AfterViewInit { 20 | private saveCodeService = inject(SaveCodeService); 21 | wrapperConfig = signal(undefined); // this can be updated at runtime 22 | 23 | title = 'angular demo for saving code'; 24 | editorId = 'monaco-editor-root'; // this can be parameterized or it can be in a loop to support multiple editors 25 | editorInlineStyle = signal('height: 50vh;'); 26 | readonly codeText = signal(''); 27 | 28 | async ngAfterViewInit(): Promise { 29 | const editorDom = document.getElementById(this.editorId); 30 | if (editorDom) { 31 | const config = buildJsonClientUserConfig(editorDom); 32 | this.wrapperConfig.set(config); 33 | } 34 | } 35 | 36 | onTextChanged(text: string) { 37 | this.codeText.set(text); 38 | } 39 | 40 | save = async () => { 41 | try { 42 | const response = await firstValueFrom( 43 | this.saveCodeService.saveCode(this.codeText()) 44 | ); 45 | alert('Code saved:' + JSON.stringify(response)); 46 | } catch (error) { 47 | console.error('Error saving code:', error); 48 | } 49 | }; 50 | } 51 | -------------------------------------------------------------------------------- /verify/angular/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | HelloWorld 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /verify/angular/src/main.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2023 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | import { bootstrapApplication } from '@angular/platform-browser'; 7 | import { provideHttpClient } from '@angular/common/http'; 8 | import { AppComponent } from './app/app.component'; 9 | bootstrapApplication(AppComponent, { 10 | providers: [provideHttpClient()], 11 | }); 12 | -------------------------------------------------------------------------------- /verify/angular/src/monaco-angular-wrapper/monaco-angular-wrapper.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 | -------------------------------------------------------------------------------- /verify/angular/src/monaco-angular-wrapper/monaco-angular-wrapper.component.scss: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /verify/angular/src/save-code.service.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | import { inject, Injectable } from '@angular/core'; 7 | import { HttpClient } from '@angular/common/http'; 8 | @Injectable({ providedIn: 'root' }) 9 | export class SaveCodeService { 10 | private http = inject(HttpClient); 11 | saveCode(codeText: string) { 12 | return this.http.post('http://localhost:3003/save-code', { code: codeText }); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /verify/angular/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "target": "ES2022", 5 | "module": "ES2022", 6 | "moduleResolution": "Bundler", 7 | "lib": [ 8 | "ES2022", 9 | "DOM", 10 | ], 11 | "esModuleInterop": true, 12 | "resolveJsonModule": true, 13 | "declaration": true, 14 | "declarationMap": true, 15 | "sourceMap": true, 16 | "inlineSources": false, 17 | "stripInternal": true, 18 | "strict": true, 19 | "strictPropertyInitialization": false, 20 | "importHelpers": true, 21 | "noImplicitReturns": true, 22 | "noUnusedParameters": true, 23 | "noUnusedLocals": true, 24 | // Disallow inconsistently-cased references to the same file 25 | "forceConsistentCasingInFileNames": true, 26 | "noImplicitOverride": true, 27 | "experimentalDecorators": true, 28 | "noPropertyAccessFromIndexSignature": true, 29 | "types": [ 30 | "vscode" 31 | ], 32 | "skipLibCheck": true 33 | }, 34 | "angularCompilerOptions": { 35 | "enableI18nLegacyMessageIdFormat": false, 36 | "strictInjectionParameters": true, 37 | "strictInputAccessModifiers": true, 38 | "strictTemplates": true 39 | }, 40 | "include": [ 41 | "src/**/*.ts" 42 | ], 43 | "exclude": [ 44 | "dist", 45 | "node_modules", 46 | "src/server/**/*.ts" 47 | ] 48 | } 49 | -------------------------------------------------------------------------------- /verify/buildAll.ps1: -------------------------------------------------------------------------------- 1 | $MyPath = Split-Path -Path $MyInvocation.MyCommand.Path -Parent 2 | 3 | Set-Location $MyPath/vite; npm run verify:ci 4 | Set-Location $MyPath/webpack; npm run verify:ci 5 | Set-Location $MyPath/angular; npm run verify:ci 6 | Set-Location $MyPath/next; npm run verify:ci 7 | 8 | Set-Location $MyPath 9 | -------------------------------------------------------------------------------- /verify/buildAll.sh: -------------------------------------------------------------------------------- 1 | MyPath=$(realpath $(dirname $0)) 2 | 3 | cd $MyPath/vite; npm run verify:ci 4 | cd $MyPath/webpack; npm run verify:ci 5 | cd $MyPath/angular; npm run verify:ci 6 | cd $MyPath/next; npm run verify:ci 7 | 8 | cd $MyPath 9 | -------------------------------------------------------------------------------- /verify/buildPeers.ps1: -------------------------------------------------------------------------------- 1 | $MyPath = Split-Path -Path $MyInvocation.MyCommand.Path -Parent 2 | 3 | # yarn first, because it usually has the most problems 4 | Set-Location $MyPath/peerYarn; npm run verify:ci 5 | Set-Location $MyPath/peerNpm; npm run verify:ci 6 | Set-Location $MyPath/peerPnpm; pnpm run verify:ci 7 | 8 | Set-Location $MyPath 9 | -------------------------------------------------------------------------------- /verify/buildPeers.sh: -------------------------------------------------------------------------------- 1 | MyPath=$(realpath $(dirname $0)) 2 | 3 | # yarn first, because it usually has the most problems 4 | cd $MyPath/peerYarn; npm run verify:ci 5 | cd $MyPath/peerNpm; npm run verify:ci 6 | cd $MyPath/peerPnpm; pnpm run verify:ci 7 | 8 | cd $MyPath 9 | -------------------------------------------------------------------------------- /verify/next/.gitignore: -------------------------------------------------------------------------------- 1 | bundle 2 | dist 3 | lib 4 | node_modules 5 | *.tsbuildinfo 6 | .next 7 | -------------------------------------------------------------------------------- /verify/next/app/layout.tsx: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | export default function RootLayout({ 7 | children, 8 | }: { 9 | children: React.ReactNode; 10 | }) { 11 | return ( 12 | 13 | {children} 14 | 15 | ); 16 | } 17 | -------------------------------------------------------------------------------- /verify/next/app/page.tsx: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | 'use client'; 7 | 8 | import React from 'react'; 9 | import dynamic from 'next/dynamic'; 10 | 11 | const DynamicMonacoEditorReact = dynamic(async () => { 12 | const { buildJsonClientUserConfig } = await import('monaco-languageclient-examples/json-client'); 13 | const comp = await import('@typefox/monaco-editor-react'); 14 | const wrapperConfig = buildJsonClientUserConfig(); 15 | return () => 18 | }, { 19 | ssr: false 20 | }); 21 | 22 | 23 | export default function Page() { 24 | return ( 25 |
26 | 27 |
28 | ); 29 | } 30 | -------------------------------------------------------------------------------- /verify/next/next-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | 4 | // NOTE: This file should not be edited 5 | // see https://nextjs.org/docs/app/api-reference/config/typescript for more information. 6 | -------------------------------------------------------------------------------- /verify/next/next.config.mjs: -------------------------------------------------------------------------------- 1 | /** 2 | * @type {import('next').NextConfig} 3 | */ 4 | export default { 5 | typescript: { 6 | tsconfigPath: './tsconfig.json', 7 | }, 8 | output: 'standalone', 9 | webpack: (config, { isServer }) => { 10 | if (!isServer) { 11 | config.resolve.fallback.fs = false; 12 | config.resolve.fallback.module = false; 13 | config.resolve.fallback.vm = false; 14 | } 15 | 16 | return config; 17 | }, 18 | }; 19 | -------------------------------------------------------------------------------- /verify/next/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "scripts": { 4 | "verify": "npm install && npm run dev", 5 | "verify:ci": "npm install && npm run build -d", 6 | "dev": "next dev -p 8081", 7 | "dev:turbo": "next dev --turbopack -p 8081", 8 | "build": "next build", 9 | "start": "next start", 10 | "clean": "shx rm -fr dist .next *.tsbuildinfo" 11 | }, 12 | "type": "module", 13 | "dependencies": { 14 | "@typefox/monaco-editor-react": "~6.8.0", 15 | "monaco-languageclient-examples": "~2025.5.3", 16 | "next": "~15.2.2", 17 | "react": "~19.0.0", 18 | "react-dom": "~19.0.0" 19 | }, 20 | "devDependencies": { 21 | "@types/node": "~22.13.10", 22 | "@types/react": "~19.0.10", 23 | "@types/react-dom": "~19.0.4", 24 | "shx": "~0.3.4", 25 | "typescript": "~5.8.2" 26 | }, 27 | "volta": { 28 | "node": "22.16.0", 29 | "npm": "10.9.2" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /verify/next/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2022", 4 | "module": "esnext", 5 | "moduleResolution": "Bundler", 6 | "lib": [ 7 | "ES2022", 8 | "DOM", 9 | "DOM.Iterable" 10 | ], 11 | "rootDir": ".", 12 | "allowJs": true, 13 | "skipLibCheck": true, 14 | "strict": true, 15 | "forceConsistentCasingInFileNames": true, 16 | "esModuleInterop": true, 17 | "resolveJsonModule": true, 18 | "isolatedModules": true, 19 | "jsx": "preserve", 20 | "incremental": true, 21 | "plugins": [ 22 | { 23 | "name": "next" 24 | } 25 | ], 26 | "noEmit": true 27 | }, 28 | "include": [ 29 | "dist/types/**/*.ts", 30 | "src/**/*.ts", 31 | "src/**/*.tsx", 32 | "src/next-env.d.ts", 33 | ".next/types/**/*.ts" 34 | ], 35 | "exclude": [ 36 | "dist/**/*", 37 | "lib/**/*", 38 | "node_modules/**/*" 39 | ] 40 | } 41 | -------------------------------------------------------------------------------- /verify/peerNpm/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@typefox/peer-check-npm", 3 | "version": "0.0.0", 4 | "private": true, 5 | "type": "module", 6 | "engines": { 7 | "node": ">=20.10.0", 8 | "npm": ">=10.2.3" 9 | }, 10 | "volta": { 11 | "node": "22.16.0", 12 | "npm": "10.9.2" 13 | }, 14 | "dependencies": { 15 | "monaco-languageclient-examples": "~2025.5.3", 16 | "vscode": "npm:@codingame/monaco-vscode-extension-api@~17.1.2" 17 | }, 18 | "devDependencies": { 19 | "typescript": "~5.8.2" 20 | }, 21 | "scripts": { 22 | "build": "tsc --build tsconfig.json", 23 | "verify:ci": "npm install && npm run build" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /verify/peerNpm/src/testerNpm.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See License.txt in the project root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | import * as vscode from 'vscode'; 7 | import { runJsonWrapper } from 'monaco-languageclient-examples/json-client'; 8 | 9 | console.log(vscode.workspace.name); 10 | runJsonWrapper(); 11 | -------------------------------------------------------------------------------- /verify/peerNpm/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2022", 4 | "module": "NodeNext", 5 | "moduleResolution": "NodeNext", 6 | "lib": [ 7 | "ES2022", 8 | "DOM", 9 | "DOM.Iterable" 10 | ], 11 | "rootDir": ".", 12 | "noEmit": true, 13 | "skipLibCheck": true 14 | }, 15 | "include": [ 16 | "**/src/**/*.ts" 17 | ], 18 | "exclude": [ 19 | "**/node_modules/**/*" 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /verify/peerPnpm/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@typefox/peer-check-pnpm", 3 | "version": "0.0.0", 4 | "private": true, 5 | "type": "module", 6 | "engines": { 7 | "node": ">=20.10.0", 8 | "pnpm": ">=9.15.0" 9 | }, 10 | "volta": { 11 | "node": "22.16.0", 12 | "pnpm": "10.3.0" 13 | }, 14 | "dependencies": { 15 | "monaco-languageclient-examples": "~2025.5.3", 16 | "vscode": "npm:@codingame/monaco-vscode-extension-api@~17.1.2" 17 | }, 18 | "devDependencies": { 19 | "typescript": "~5.8.2" 20 | }, 21 | "scripts": { 22 | "build": "tsc --build tsconfig.json", 23 | "verify:ci": "pnpm install && pnpm run build" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /verify/peerPnpm/src/testerPnpm.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See License.txt in the project root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | import * as vscode from 'vscode'; 7 | import { runJsonWrapper } from 'monaco-languageclient-examples/json-client'; 8 | 9 | console.log(vscode.workspace.name); 10 | runJsonWrapper(); 11 | 12 | -------------------------------------------------------------------------------- /verify/peerPnpm/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2022", 4 | "module": "NodeNext", 5 | "moduleResolution": "NodeNext", 6 | "lib": [ 7 | "ES2022", 8 | "DOM", 9 | "DOM.Iterable" 10 | ], 11 | "rootDir": ".", 12 | "noEmit": true, 13 | "skipLibCheck": true 14 | }, 15 | "include": [ 16 | "**/src/**/*.ts" 17 | ], 18 | "exclude": [ 19 | "**/node_modules/**/*" 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /verify/peerYarn/.gitignore: -------------------------------------------------------------------------------- 1 | bundle 2 | dist 3 | lib 4 | node_modules 5 | *.tsbuildinfo 6 | .yarn 7 | .pnp* 8 | -------------------------------------------------------------------------------- /verify/peerYarn/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@typefox/peer-check-yarn", 3 | "version": "0.0.0", 4 | "private": true, 5 | "type": "module", 6 | "engines": { 7 | "node": ">=20.10.0", 8 | "npm": ">=10.2.3", 9 | "yarn": ">=4.6.0" 10 | }, 11 | "volta": { 12 | "node": "22.16.0", 13 | "yarn": "4.6.0" 14 | }, 15 | "dependencies": { 16 | "@codingame/monaco-vscode-api": "~17.1.2", 17 | "@codingame/monaco-vscode-configuration-service-override": "~17.1.2", 18 | "@codingame/monaco-vscode-editor-api": "~17.1.2", 19 | "@codingame/monaco-vscode-editor-service-override": "~17.1.2", 20 | "@codingame/monaco-vscode-extension-api": "~17.1.2", 21 | "@codingame/monaco-vscode-extensions-service-override": "~17.1.2", 22 | "@codingame/monaco-vscode-languages-service-override": "~17.1.2", 23 | "@codingame/monaco-vscode-localization-service-override": "~17.1.2", 24 | "@codingame/monaco-vscode-log-service-override": "~17.1.2", 25 | "@codingame/monaco-vscode-model-service-override": "~17.1.2", 26 | "monaco-languageclient-examples": "~2025.5.3", 27 | "vscode": "npm:@codingame/monaco-vscode-extension-api@~17.1.2", 28 | "vscode-languageclient": "~9.0.1" 29 | }, 30 | "devDependencies": { 31 | "typescript": "~5.8.2" 32 | }, 33 | "scripts": { 34 | "build": "tsc --build tsconfig.json", 35 | "verify:ci": "yarn install && yarn run build" 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /verify/peerYarn/src/testerYarn.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See License.txt in the project root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | import * as vscode from 'vscode'; 7 | import { runJsonWrapper } from 'monaco-languageclient-examples/json-client'; 8 | 9 | console.log(vscode.workspace.name); 10 | runJsonWrapper(); 11 | -------------------------------------------------------------------------------- /verify/peerYarn/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2022", 4 | "module": "NodeNext", 5 | "moduleResolution": "NodeNext", 6 | "lib": [ 7 | "ES2022", 8 | "DOM", 9 | "DOM.Iterable" 10 | ], 11 | "rootDir": ".", 12 | "noEmit": true, 13 | "skipLibCheck": true 14 | }, 15 | "include": [ 16 | "**/src/**/*.ts" 17 | ], 18 | "exclude": [ 19 | "**/node_modules/**/*" 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /verify/vite/.gitignore: -------------------------------------------------------------------------------- 1 | bundle 2 | dist 3 | lib 4 | node_modules 5 | *.tsbuildinfo 6 | -------------------------------------------------------------------------------- /verify/vite/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Vite App 6 | 7 | 8 | 9 |

Vite Verification: JSON Client

10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /verify/vite/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example-client-vite", 3 | "version": "0.0.0", 4 | "private": true, 5 | "type": "module", 6 | "engines": { 7 | "node": ">=20.10.0", 8 | "npm": ">=10.2.3" 9 | }, 10 | "volta": { 11 | "node": "22.16.0", 12 | "npm": "10.9.2" 13 | }, 14 | "dependencies": { 15 | "monaco-languageclient-examples": "~2025.5.3" 16 | }, 17 | "devDependencies": { 18 | "shx": "~0.3.4", 19 | "vite": "~6.2.1" 20 | }, 21 | "scripts": { 22 | "verify": "npm install && npm run build && npm run start", 23 | "verify:ci": "npm install && npm run build", 24 | "clean": "shx rm -fr dist", 25 | "build:msg": "echo Building client-vite example:", 26 | "build": "npm run build:msg && npm run clean && vite build", 27 | "start": "vite preview" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /verify/vite/src/client/main.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | import { runJsonWrapper } from 'monaco-languageclient-examples/json-client'; 7 | 8 | runJsonWrapper(); 9 | -------------------------------------------------------------------------------- /verify/vite/vite.config.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | import { defineConfig } from 'vite'; 7 | 8 | export default defineConfig({ 9 | preview: { 10 | port: 8083 11 | }, 12 | worker: { 13 | format: 'es' 14 | } 15 | }); 16 | -------------------------------------------------------------------------------- /verify/webpack/.gitignore: -------------------------------------------------------------------------------- 1 | bundle 2 | dist 3 | lib 4 | node_modules 5 | *.tsbuildinfo 6 | -------------------------------------------------------------------------------- /verify/webpack/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Webpack App 6 | 7 | 8 | 9 |

Webpack Verification: JSON Client

10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /verify/webpack/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example-client-webpack", 3 | "version": "0.0.0", 4 | "private": true, 5 | "type": "module", 6 | "engines": { 7 | "node": ">=20.10.0", 8 | "npm": ">=10.2.3" 9 | }, 10 | "volta": { 11 | "node": "22.16.0", 12 | "npm": "10.9.2" 13 | }, 14 | "dependencies": { 15 | "monaco-languageclient-examples": "~2025.5.3" 16 | }, 17 | "devDependencies": { 18 | "css-loader": "~7.1.2", 19 | "http-server": "~14.1.1", 20 | "shx": "~0.3.4", 21 | "source-map-loader": "~5.0.0", 22 | "style-loader": "~4.0.0", 23 | "ts-loader": "~9.5.2", 24 | "webpack-cli": "~6.0.1" 25 | }, 26 | "scripts": { 27 | "verify": "npm install && npm run build && npm run start", 28 | "verify:ci": "npm install && npm run build", 29 | "clean": "shx rm -fr dist *.tsbuildinfo", 30 | "build:msg": "echo Building client-webpack example:", 31 | "build": "npm run build:msg && npm run clean && webpack", 32 | "start": "http-server ./ --port 8082" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /verify/webpack/src/client/main.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | import { runJsonWrapper } from 'monaco-languageclient-examples/json-client'; 7 | 8 | runJsonWrapper(); 9 | -------------------------------------------------------------------------------- /verify/webpack/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "rootDir": "src", 4 | "outDir": "dist", 5 | "declaration": true, 6 | "declarationDir": "dist", 7 | "types": [ 8 | "vscode" 9 | ], 10 | "target": "ES2022", 11 | "module": "ES2022", 12 | "moduleResolution": "Bundler", 13 | "lib": [ 14 | "ES2022", 15 | "DOM" 16 | ], 17 | "skipLibCheck": true 18 | }, 19 | "include": [ 20 | "src/**/*.ts", 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /verify/webpack/webpack.config.js: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | // solve: __dirname is not defined in ES module scope 7 | import { fileURLToPath } from 'node:url'; 8 | import { dirname, resolve } from 'node:path'; 9 | const __filename = fileURLToPath(import.meta.url); 10 | const __dirname = dirname(__filename); 11 | 12 | const config = { 13 | entry: resolve(__dirname, 'src', 'client', 'main.ts'), 14 | module: { 15 | rules: [ 16 | { 17 | test: /\.css$/, 18 | use: ['style-loader', 'css-loader'] 19 | }, 20 | { 21 | test: /\.ts?$/, 22 | use: ['ts-loader'] 23 | } 24 | ] 25 | }, 26 | experiments: { 27 | outputModule: true 28 | }, 29 | output: { 30 | filename: 'main.js', 31 | path: resolve(__dirname, 'dist', 'client'), 32 | module: true, 33 | workerChunkLoading: 'import', 34 | environment: { 35 | dynamicImportInWorker: true 36 | } 37 | }, 38 | target: 'web', 39 | resolve: { 40 | extensions: ['.ts', '.js', '.json', '.ttf'], 41 | fallback: { 42 | fs: false, 43 | module: false, 44 | vm: false 45 | } 46 | }, 47 | mode: 'development', 48 | devtool: 'source-map' 49 | }; 50 | 51 | export default config; 52 | -------------------------------------------------------------------------------- /vitest.config.ts: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------------------------- 2 | * Copyright (c) 2024 TypeFox and others. 3 | * Licensed under the MIT License. See LICENSE in the package root for license information. 4 | * ------------------------------------------------------------------------------------------ */ 5 | 6 | import { mergeConfig } from 'vite'; 7 | import { defineConfig as defineVitestConfig } from 'vitest/config'; 8 | import definedViteConfig from './vite.config.js'; 9 | 10 | /// 11 | 12 | export const vitestConfig = { 13 | test: { 14 | testTimeout: 40000, 15 | // fileParallelism: false, 16 | // threads: false, 17 | browser: { 18 | enabled: true, 19 | headless: true, 20 | provider: 'playwright', 21 | api: { 22 | port: 20101 23 | }, 24 | instances: [ 25 | { 26 | browser: 'chromium' 27 | } 28 | ] 29 | }, 30 | // keep an explicit list of tests to run, so they can be commented in case of problems 31 | include: [ 32 | '**/client/test/workerFactory.test.ts', 33 | '**/client/test/fs/endpoints/emptyEndpoint.test.ts', 34 | '**/client/test/tools/index.test.ts', 35 | '**/client/test/tools/utils.test.ts', 36 | '**/client/test/vscode/services.test.ts', 37 | '**/wrapper/test/editorApp.test.ts', 38 | '**/wrapper/test/languageClientWrapper.test.ts', 39 | '**/wrapper/test/utils.test.ts', 40 | '**/wrapper/test/wrapper.test.ts', 41 | '**/wrapper/test/vscode/services.test.ts', 42 | '**/wrapper/test/editorApp-classic.test.ts', 43 | '**/wrapper/test/wrapper-classic.test.ts', 44 | '**/wrapper/test/workers/workerLoaders.test.ts', 45 | '**/wrapper-react/test/index.test.tsx' 46 | ] 47 | } 48 | }; 49 | 50 | const definedVitestConfig = defineVitestConfig(vitestConfig); 51 | 52 | export default mergeConfig(definedVitestConfig, definedViteConfig); 53 | 54 | -------------------------------------------------------------------------------- /vitest.shims.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | --------------------------------------------------------------------------------