diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index cad01175cda..ef084f4913e 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -420,9 +420,9 @@ "resolved": "https://registry.npmjs.org/vscode-ripgrep/-/vscode-ripgrep-0.0.11.tgz" }, "vscode-textmate": { - "version": "3.1.2", - "from": "vscode-textmate@3.1.2", - "resolved": "https://registry.npmjs.org/vscode-textmate/-/vscode-textmate-3.1.2.tgz" + "version": "3.1.3", + "from": "vscode-textmate@3.1.3", + "resolved": "https://registry.npmjs.org/vscode-textmate/-/vscode-textmate-3.1.3.tgz" }, "windows-foreground-love": { "version": "0.1.0", diff --git a/package.json b/package.json index 220d5d34c8a..41b903ff8e1 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "v8-profiler": "jrieken/v8-profiler#vscode", "vscode-debugprotocol": "1.18.0", "vscode-ripgrep": "0.0.11", - "vscode-textmate": "^3.1.2", + "vscode-textmate": "^3.1.3", "winreg": "1.2.0", "xterm": "Tyriar/xterm.js#vscode-release/1.11", "yauzl": "2.3.1" diff --git a/src/vs/editor/electron-browser/textMate/TMHelper.ts b/src/vs/editor/electron-browser/textMate/TMHelper.ts index 8858abbc678..74c5b48f0c2 100644 --- a/src/vs/editor/electron-browser/textMate/TMHelper.ts +++ b/src/vs/editor/electron-browser/textMate/TMHelper.ts @@ -71,14 +71,40 @@ export class ThemeRule { return ThemeRule._matches(this.scope, this.parentScopes, scope, parentScopes); } + private static _cmp(a: ThemeRule, b: ThemeRule): number { + if (a === null && b === null) { + return 0; + } + if (a === null) { + // b > a + return -1; + } + if (b === null) { + // a > b + return 1; + } + if (a.scope.length !== b.scope.length) { + // longer scope length > shorter scope length + return a.scope.length - b.scope.length; + } + const aParentScopesLen = a.parentScopes.length; + const bParentScopesLen = b.parentScopes.length; + if (aParentScopesLen !== bParentScopesLen) { + // more parents > less parents + return aParentScopesLen - bParentScopesLen; + } + for (let i = 0; i < aParentScopesLen; i++) { + var aLen = a.parentScopes[i].length; + var bLen = b.parentScopes[i].length; + if (aLen !== bLen) { + return aLen - bLen; + } + } + return 0; + } + public isMoreSpecific(other: ThemeRule): boolean { - if (other === null) { - return true; - } - if (other.scope.length === this.scope.length) { - return this.parentScopes.length > other.parentScopes.length; - } - return (this.scope.length > other.scope.length); + return (ThemeRule._cmp(this, other) > 0); } private static _matchesOne(selectorScope: string, scope: string): boolean {