From a1a115c2de52031b419e55604f20dd690c19c773 Mon Sep 17 00:00:00 2001 From: Rahul Kadyan Date: Thu, 2 Nov 2023 13:34:23 -0700 Subject: [PATCH 1/6] fix tree-sitter issue --- extension/src/StatusBarController.ts | 1 + package.json | 8 ++-- .../grammarly-languageclient/src/protocol.ts | 1 + .../grammarly-languageserver/package.json | 2 +- .../grammarly-richtext-encoder/package.json | 2 +- .../grammarly-richtext-encoder/src/index.ts | 40 ++++++++++++++---- .../tree-sitter-html.wasm | Bin .../tree-sitter-markdown.wasm | Bin pnpm-lock.yaml | 38 ++++++++++------- rollup.config.js | 2 +- scripts/build-wasm.mjs | 2 +- 11 files changed, 64 insertions(+), 32 deletions(-) rename {tree-sitter => parsers}/tree-sitter-html.wasm (100%) rename {tree-sitter => parsers}/tree-sitter-markdown.wasm (100%) diff --git a/extension/src/StatusBarController.ts b/extension/src/StatusBarController.ts index 44f37a022..403edd270 100644 --- a/extension/src/StatusBarController.ts +++ b/extension/src/StatusBarController.ts @@ -39,6 +39,7 @@ export class StatusBarController { commands.registerCommand('grammarly.pauseCheck', async (uri?: Uri) => { const id = uri ?? window.activeTextEditor?.document.uri if (id == null) return + await this.grammarly.client.protocol.pause(id.toString()) await this.update() }), diff --git a/package.json b/package.json index 7650fe44f..3e0eea456 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "private": true, "engines": { - "node": "^16.20.0", - "pnpm": "^8.1.1" + "node": "^18.18.2", + "pnpm": "^8.8.0" }, "scripts": { "build": "rollup -c && node scripts/build-web-extension.mjs", @@ -32,8 +32,8 @@ "rollup": "^2.71.1", "rollup-plugin-copy": "^3.4.0", "semver": "^7.3.7", - "tree-sitter-cli": "^0.20.6", - "tree-sitter-html": "^0.19.0", + "tree-sitter-cli": "^0.20.8", + "tree-sitter-html": "^0.20.0", "tree-sitter-markdown": "^0.7.1", "tslib": "^2.4.0", "typescript": "^4.6.4", diff --git a/packages/grammarly-languageclient/src/protocol.ts b/packages/grammarly-languageclient/src/protocol.ts index 4023b1252..74a07e7ad 100644 --- a/packages/grammarly-languageclient/src/protocol.ts +++ b/packages/grammarly-languageclient/src/protocol.ts @@ -23,6 +23,7 @@ export function createProtocol(client: BaseLanguageClient): Protocol { } else { return async (...args: unknown[]): Promise => { try { + await client.onReady() const result = await client.sendRequest(`$/${property}`, args) return result } catch (error) { diff --git a/packages/grammarly-languageserver/package.json b/packages/grammarly-languageserver/package.json index 5e24046ea..b294e3552 100644 --- a/packages/grammarly-languageserver/package.json +++ b/packages/grammarly-languageserver/package.json @@ -76,7 +76,7 @@ "reflect-metadata": "^0.1.13", "vscode-languageserver": "^7.0.0", "vscode-languageserver-textdocument": "^1.0.4", - "web-tree-sitter": "0.20.5" + "web-tree-sitter": "^0.20.8" }, "devDependencies": { "domhandler": "^5.0.3" diff --git a/packages/grammarly-richtext-encoder/package.json b/packages/grammarly-richtext-encoder/package.json index 2a622472f..b04307953 100644 --- a/packages/grammarly-richtext-encoder/package.json +++ b/packages/grammarly-richtext-encoder/package.json @@ -24,7 +24,7 @@ "dist" ], "dependencies": { - "web-tree-sitter": "0.20.5" + "web-tree-sitter": "^0.20.8" }, "devDependencies": { "@grammarly/sdk": "^2.3.17", diff --git a/packages/grammarly-richtext-encoder/src/index.ts b/packages/grammarly-richtext-encoder/src/index.ts index 130612aa1..1ade742e7 100644 --- a/packages/grammarly-richtext-encoder/src/index.ts +++ b/packages/grammarly-richtext-encoder/src/index.ts @@ -16,19 +16,36 @@ export async function createParser(language: string): Promise { return await parser async function createParserInner() { - await Parser.init() - - const parser = new Parser() - parser.setLanguage(await Parser.Language.load(getLanguageFile())) - parsers.set(language, parser) - parsersPending.delete(language) + if (isNodeJS()) { + const fetch = globalThis.fetch + try { + // @ts-ignore + globalThis.fetch = null + await Parser.init() + } catch (e) { + console.log('Error in TreeSitter parser:', e) + throw e + } finally { + globalThis.fetch = fetch + } + } else { + await Parser.init() + } - return parser + try { + const parser = new Parser() + parser.setLanguage(await Parser.Language.load(getLanguageFile())) + parsers.set(language, parser) + parsersPending.delete(language) + return parser + } catch (e) { + console.log(`Error in TreeSitter ${language} parser:`, e) + throw e + } } function getLanguageFile(): string | Uint8Array { - // @ts-ignore - Ignore if process does not exist. - if (typeof process !== 'undefined' && process.versions?.node != null) { + if (isNodeJS()) { // @ts-ignore if (process.env.NODE_ENV === 'test') { // @ts-ignore @@ -42,4 +59,9 @@ export async function createParser(language: string): Promise { } } +function isNodeJS(): boolean { + // @ts-ignore - Ignore if process does not exist. + return typeof process !== 'undefined' && process.versions?.node != null +} + export const transformers = { html, markdown } as const diff --git a/tree-sitter/tree-sitter-html.wasm b/parsers/tree-sitter-html.wasm similarity index 100% rename from tree-sitter/tree-sitter-html.wasm rename to parsers/tree-sitter-html.wasm diff --git a/tree-sitter/tree-sitter-markdown.wasm b/parsers/tree-sitter-markdown.wasm similarity index 100% rename from tree-sitter/tree-sitter-markdown.wasm rename to parsers/tree-sitter-markdown.wasm diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6740e4200..275f54646 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,5 +1,9 @@ lockfileVersion: '6.0' +settings: + autoInstallPeers: false + excludeLinksFromLockfile: false + neverBuiltDependencies: - keytar - tree-sitter-cli @@ -68,11 +72,11 @@ importers: specifier: ^7.3.7 version: 7.3.7 tree-sitter-cli: - specifier: ^0.20.6 - version: 0.20.6 + specifier: ^0.20.8 + version: 0.20.8 tree-sitter-html: - specifier: ^0.19.0 - version: 0.19.0 + specifier: ^0.20.0 + version: 0.20.0 tree-sitter-markdown: specifier: ^0.7.1 version: 0.7.1 @@ -142,8 +146,8 @@ importers: specifier: ^1.0.4 version: 1.0.4 web-tree-sitter: - specifier: 0.20.5 - version: 0.20.5 + specifier: ^0.20.8 + version: 0.20.8 devDependencies: domhandler: specifier: ^5.0.3 @@ -152,8 +156,8 @@ importers: packages/grammarly-richtext-encoder: dependencies: web-tree-sitter: - specifier: 0.20.5 - version: 0.20.5 + specifier: ^0.20.8 + version: 0.20.8 devDependencies: '@grammarly/sdk': specifier: ^2.3.17 @@ -5453,6 +5457,10 @@ packages: resolution: {integrity: sha512-8ZtvEnA2c5aYCZYd1cvgdnU6cqwixRoYg70xPLWUws5ORTa/lnw+u4amixRS/Ac5U5mQVgp9pnlSUnbNWFaWZQ==} dev: true + /nan@2.18.0: + resolution: {integrity: sha512-W7tfG7vMOGtD30sHoZSSc/JVYiyDPEyQVso/Zz+/uQd0B0L46gtC+pHha5FFMRpil6fm/AoEcRWyOVi4+E/f8w==} + dev: true + /napi-build-utils@1.0.2: resolution: {integrity: sha512-ONmRUqK7zj7DWX0D9ADe03wbwOBZxNAfF20PlGfCWQcD3+/MakShIHrMqx9YwPTfxDdF1zLeL+RGZiR9kGMLdg==} dev: true @@ -6867,15 +6875,15 @@ packages: punycode: 2.1.1 dev: true - /tree-sitter-cli@0.20.6: - resolution: {integrity: sha512-tjbAeuGSMhco/EnsThjWkQbDIYMDmdkWsTPsa/NJAW7bjaki9P7oM9TkLxfdlnm4LXd1wR5wVSM2/RTLtZbm6A==} + /tree-sitter-cli@0.20.8: + resolution: {integrity: sha512-XjTcS3wdTy/2cc/ptMLc/WRyOLECRYcMTrSWyhZnj1oGSOWbHLTklgsgRICU3cPfb0vy+oZCC33M43u6R1HSCA==} hasBin: true dev: true - /tree-sitter-html@0.19.0: - resolution: {integrity: sha512-xH6XGSBWzb4oU/aG6gouMRQKsd96iKuy0zboUqo3wcIWrA++q9a7CmQTSeIINiSfOXjT2ZLJciXFDgAh6h04Bw==} + /tree-sitter-html@0.20.0: + resolution: {integrity: sha512-KoK3BR1o5KWeYFGax1Dy8j+NHHhdgD64pjFU/JgnBrZjmdp4CfJg2HJiWnmB8OmFYQeb30Mm+lDVps2dNFJMdw==} dependencies: - nan: 2.15.0 + nan: 2.18.0 dev: true /tree-sitter-markdown@0.7.1: @@ -7199,8 +7207,8 @@ packages: engines: {node: '>= 8'} dev: true - /web-tree-sitter@0.20.5: - resolution: {integrity: sha512-mpXlqIeEBE5Q71cnBnt8w6XKhIiKmllPECqsIFBtMvzcfCxA8+614iyMJXBCQo95Vs3y1zORLqiLJn25pYZ4Tw==} + /web-tree-sitter@0.20.8: + resolution: {integrity: sha512-weOVgZ3aAARgdnb220GqYuh7+rZU0Ka9k9yfKtGAzEYMa6GgiCzW9JjQRJyCJakvibQW+dfjJdihjInKuuCAUQ==} dev: false /webidl-conversions@3.0.1: diff --git a/rollup.config.js b/rollup.config.js index a34279f59..f3c775e98 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -43,7 +43,7 @@ function wasm(file) { return copy({ targets: [ { - src: Path.resolve(__dirname, 'tree-sitter/tree-sitter-{html,markdown}.wasm'), + src: Path.resolve(__dirname, 'parsers/tree-sitter-{html,markdown}.wasm'), dest: Path.dirname(file), }, ], diff --git a/scripts/build-wasm.mjs b/scripts/build-wasm.mjs index dcefa7a8f..45b246c7a 100644 --- a/scripts/build-wasm.mjs +++ b/scripts/build-wasm.mjs @@ -17,5 +17,5 @@ for (const language in packageNameByLanguage) { execSync(`$(pnpm bin)/tree-sitter build-wasm ${resolve(rootDir, `node_modules/${packageName}`)}`, { stdio: 'inherit', }) - execSync(`mv ${packageName}.wasm tree-sitter/tree-sitter-${language}.wasm`, { stdio: 'inherit' }) + execSync(`mv ${packageName}.wasm parsers/tree-sitter-${language}.wasm`, { stdio: 'inherit' }) } From c7e8223cfa0cfd815c99909896b9ecc91bb400aa Mon Sep 17 00:00:00 2001 From: Rahul Kadyan Date: Thu, 2 Nov 2023 13:36:07 -0700 Subject: [PATCH 2/6] update pnpm in CI --- .github/workflows/ci.yaml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 7bd4c6d24..439f9af3a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -36,11 +36,11 @@ jobs: - name: Setup Node uses: actions/setup-node@v3 with: - node-version: 16 + node-version: 18 - name: Setup PNPM uses: pnpm/action-setup@v2 with: - version: 8.1.1 + version: 8.8.2 run_install: | - recursive: true args: [--frozen-lockfile] @@ -63,11 +63,11 @@ jobs: - name: Setup Node uses: actions/setup-node@v3 with: - node-version: 16 + node-version: 18 - name: Setup PNPM uses: pnpm/action-setup@v2 with: - version: 8.1.1 + version: 8.8.2 run_install: | - recursive: true args: [--frozen-lockfile] @@ -99,11 +99,11 @@ jobs: - name: Setup Node uses: actions/setup-node@v3 with: - node-version: 16 + node-version: 18 - name: Setup PNPM uses: pnpm/action-setup@v2 with: - version: 8.1.1 + version: 8.8.2 run_install: | - recursive: true args: [--frozen-lockfile] @@ -212,11 +212,11 @@ jobs: - name: Setup Node uses: actions/setup-node@v3 with: - node-version: 16 + node-version: 18 - name: Setup PNPM uses: pnpm/action-setup@v2 with: - version: 8.1.1 + version: 8.8.2 run_install: | - recursive: true args: [--frozen-lockfile] From feeb2515cc0a43851295776274dd28191adfabf2 Mon Sep 17 00:00:00 2001 From: Rahul Kadyan Date: Thu, 2 Nov 2023 13:45:50 -0700 Subject: [PATCH 3/6] use pnpm verison from package.json --- .github/workflows/ci.yaml | 7 +------ package.json | 4 ++-- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 439f9af3a..f971f11c9 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -40,7 +40,6 @@ jobs: - name: Setup PNPM uses: pnpm/action-setup@v2 with: - version: 8.8.2 run_install: | - recursive: true args: [--frozen-lockfile] @@ -67,7 +66,6 @@ jobs: - name: Setup PNPM uses: pnpm/action-setup@v2 with: - version: 8.8.2 run_install: | - recursive: true args: [--frozen-lockfile] @@ -103,7 +101,6 @@ jobs: - name: Setup PNPM uses: pnpm/action-setup@v2 with: - version: 8.8.2 run_install: | - recursive: true args: [--frozen-lockfile] @@ -143,11 +140,10 @@ jobs: - name: Setup Node uses: actions/setup-node@v3 with: - node-version: 16 + node-version: 18 - name: Setup PNPM uses: pnpm/action-setup@v2 with: - version: 8.1.1 run_install: | - recursive: true args: [--frozen-lockfile] @@ -216,7 +212,6 @@ jobs: - name: Setup PNPM uses: pnpm/action-setup@v2 with: - version: 8.8.2 run_install: | - recursive: true args: [--frozen-lockfile] diff --git a/package.json b/package.json index 3e0eea456..8b136636d 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "private": true, + "packageManager": "pnpm@8.10.2", "engines": { - "node": "^18.18.2", - "pnpm": "^8.8.0" + "node": "^18.18.2" }, "scripts": { "build": "rollup -c && node scripts/build-web-extension.mjs", From 94f1a136d9ff9199f9ef2b8f5d19bc06ba8cb1fe Mon Sep 17 00:00:00 2001 From: Rahul Kadyan Date: Thu, 2 Nov 2023 13:49:02 -0700 Subject: [PATCH 4/6] update actions/upload-artifact to v3 --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f971f11c9..f8c823eea 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -46,7 +46,7 @@ jobs: - name: Build run: pnpm run build - name: Upload build artefact - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: build-artefact retention-days: 30 From 08212342485f65e5d3d361f26957d41e3ec02da7 Mon Sep 17 00:00:00 2001 From: Rahul Kadyan Date: Thu, 2 Nov 2023 14:47:00 -0700 Subject: [PATCH 5/6] remove -y from publish --- scripts/publish-extension.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/publish-extension.mjs b/scripts/publish-extension.mjs index bffcdc0f5..0b12ac4a3 100644 --- a/scripts/publish-extension.mjs +++ b/scripts/publish-extension.mjs @@ -12,4 +12,4 @@ const VSCODE_MARKETPLACE_TOKEN = process.env.VSCODE_MARKETPLACE_TOKEN const OVSX_REGISTRY_TOKEN = process.env.OVSX_REGISTRY_TOKEN const args = RELEASE_CHANNEL === 'pre-release' ? '--pre-release' : '' execSync(`${bin} publish -p "${VSCODE_MARKETPLACE_TOKEN}" ${args} --packagePath grammarly.vsix`, execArgs) -execSync(`pnpx -y ovsx publish -p "${OVSX_REGISTRY_TOKEN}" --packagePath grammarly.vsix`, execArgs) // Does not support pre-release arg yet. +execSync(`pnpx ovsx publish -p "${OVSX_REGISTRY_TOKEN}" --packagePath grammarly.vsix`, execArgs) // Does not support pre-release arg yet. From a81aac2c7da571abdb3c22a3dbb5de254af62562 Mon Sep 17 00:00:00 2001 From: Rahul Kadyan Date: Thu, 2 Nov 2023 14:47:40 -0700 Subject: [PATCH 6/6] publish v0.24 --- extension/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension/package.json b/extension/package.json index d9711ed8e..06aaf4c8b 100644 --- a/extension/package.json +++ b/extension/package.json @@ -4,7 +4,7 @@ "publisher": "znck", "displayName": "Grammarly", "description": "A grammar checking for Visual Studio Code using Grammarly.", - "version": "0.22.1", + "version": "0.24.0", "icon": "assets/logo.png", "preview": true, "engines": {