Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

impose timeout when running tokenizeLine2() #35

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/verify-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Verify addons/ folder
on:
# Run on any branch to support ghstack's synthetic base/head branches.
pull_request:
workflow_dispatch:
push:
branches:
- main

jobs:
verify-addons:
runs-on: ubuntu-latest
container: 'ubuntu:22.04'
steps:
- name: apt update
run: apt-get -y update
- name: install Node.js
run: curl -fsSL https://deb.nodesource.com/setup_16.x | bash -
- name: install yarn
run: npm install -g yarn
- name: Checkout Code
uses: actions/checkout@v3
- name: Grant Access
run: git config --global --add safe.directory "$PWD"
- name: yarn install
run: yarn install
- name: build TypeScript
run: yarn run tsc --noEmit
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
},
"dependencies": {
"monaco-editor": "0.21.2",
"vscode-oniguruma": "1.3.0",
"vscode-textmate": "5.1.1"
"vscode-oniguruma": "^1.6.1",
"vscode-textmate": "^6.0.0"
},
"devDependencies": {
"css-loader": "3.5.3",
Expand Down
14 changes: 13 additions & 1 deletion src/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ export class SimpleLanguageInfoProvider {
}
}

const TOKENIZE_TIMEOUT_MS = 500;

class TokensProviderCache {
private scopeNameToGrammar: Map<string, Promise<IGrammar>> = new Map();

Expand All @@ -172,7 +174,17 @@ class TokensProviderCache {
line: string,
state: monaco.languages.IState,
): monaco.languages.IEncodedLineTokens {
const tokenizeLineResult2 = grammar.tokenizeLine2(line, state as StackElement);
const tokenizeLineResult2 = grammar.tokenizeLine2(
line,
state as StackElement,
TOKENIZE_TIMEOUT_MS,
);

// This is the strategy used by VS Code:
if (tokenizeLineResult2.stoppedEarly) {
return {tokens: tokenizeLineResult2.tokens, endState: state};
}

const {tokens, ruleStack: endState} = tokenizeLineResult2;
return {tokens, endState};
},
Expand Down
16 changes: 8 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4085,15 +4085,15 @@ vm-browserify@^1.0.1:
resolved "https://registry.yarnpkg.com/vm-browserify/-/vm-browserify-1.1.2.tgz#78641c488b8e6ca91a75f511e7a3b32a86e5dda0"
integrity sha512-2ham8XPWTONajOR0ohOKOHXkm3+gaBmGut3SRuu75xLd/RRaY6vqgh8NBYYk7+RW3u5AtzPQZG8F10LHkl0lAQ==

vscode-oniguruma@1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/vscode-oniguruma/-/vscode-oniguruma-1.3.0.tgz#6788a9db2f8b0781243b4eb8c7a1dd25f6c0e2c8"
integrity sha512-m4Br19v6XD4MRbVrgsLNSZgQrBzk1BCMCleL8+GrcoGxKEJJd62zOFcTaoQR3hCrSlLqoxWmJ7Cc0VieVV3iTQ==
vscode-oniguruma@^1.6.1:
version "1.6.2"
resolved "https://registry.yarnpkg.com/vscode-oniguruma/-/vscode-oniguruma-1.6.2.tgz#aeb9771a2f1dbfc9083c8a7fdd9cccaa3f386607"
integrity sha512-KH8+KKov5eS/9WhofZR8M8dMHWN2gTxjMsG4jd04YhpbPR91fUj7rYQ2/XjeHCJWbg7X++ApRIU9NUwM2vTvLA==

vscode-textmate@5.1.1:
version "5.1.1"
resolved "https://registry.yarnpkg.com/vscode-textmate/-/vscode-textmate-5.1.1.tgz#d88dbf271bee7cede455a21bd4894ba5724a4a7e"
integrity sha512-5VHjF+Fglf9d2JI5OyQ7FHutK6/29G0qYyD920K0SWO7uY8JTWbqyKAHEtfB/ZDk2fOe/E23n3wz9fHXKi63yg==
vscode-textmate@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/vscode-textmate/-/vscode-textmate-6.0.0.tgz#a3777197235036814ac9a92451492f2748589210"
integrity sha512-gu73tuZfJgu+mvCSy4UZwd2JXykjK9zAZsfmDeut5dx/1a7FeTk0XwJsSuqQn+cuMCGVbIBfl+s53X4T19DnzQ==

wasm-dce@^1.0.0:
version "1.0.2"
Expand Down