From ee8392eb0c73f8ff68b36c4345ff7f71c21ea40e Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Thu, 17 Sep 2020 22:44:16 +0200 Subject: [PATCH] Avoid using internals --- ...ices-semantic-tokens-provider-example.html | 30 ++++--------------- .../sample.js | 30 ++++--------------- 2 files changed, 12 insertions(+), 48 deletions(-) diff --git a/test/playground.generated/extending-language-services-semantic-tokens-provider-example.html b/test/playground.generated/extending-language-services-semantic-tokens-provider-example.html index dd991a39..c680a975 100644 --- a/test/playground.generated/extending-language-services-semantic-tokens-provider-example.html +++ b/test/playground.generated/extending-language-services-semantic-tokens-provider-example.html @@ -55,7 +55,9 @@ function getType(type) { /** @type {(modifier: string[]|string|null)=>number} */ function getModifier(modifiers) { - if (typeof modifiers === 'string') modifiers = [modifiers]; + if (typeof modifiers === 'string') { + modifiers = [modifiers]; + } if (Array.isArray(modifiers)) { let nModifiers = 0; for (let modifier of modifiers) { @@ -91,7 +93,9 @@ monaco.languages.registerDocumentSemanticTokensProvider('plaintext', { for (let match = null; match = tokenPattern.exec(line);) { // translate token and modifiers to number representations let type = getType(match[1]); - if (type === -1) continue; + if (type === -1) { + continue; + } let modifier = match[2].length ? getModifier(match[2].split('.').slice(1)) : 0; @@ -176,29 +180,7 @@ const editor = monaco.editor.create(document.getElementById("container"), { 'semanticHighlighting.enabled': true }); -// currently there isn't builtin token handling -editor._themeService._knownThemes.forEach(function (theme) { - theme.getTokenStyleMetadata = function (type, modifiers) { - // use theme rules match - const style = theme._tokenTheme._root.match([type].concat(modifiers).join('.')); - return { - foreground: style._foreground, - italic: style._fontStyle & 1, - bold: style._fontStyle & 2, - underline: style._fontStyle & 4 - }; - }; -}); -// press F4 to change theme -editor.addCommand(monaco.KeyCode.F4, function () { - switch (editor._themeService.getTheme().themeName) { - case 'vs': monaco.editor.setTheme('vs-dark'); break; - case 'vs-dark': monaco.editor.setTheme('hc-black'); break; - case 'hc-black': monaco.editor.setTheme('myCustomTheme'); break; - case 'myCustomTheme': monaco.editor.setTheme('vs'); break; - } -}); /*----------------------------------------SAMPLE JS END*/ diff --git a/website/playground/new-samples/extending-language-services/semantic-tokens-provider-example/sample.js b/website/playground/new-samples/extending-language-services/semantic-tokens-provider-example/sample.js index cb4bf446..790173ca 100644 --- a/website/playground/new-samples/extending-language-services/semantic-tokens-provider-example/sample.js +++ b/website/playground/new-samples/extending-language-services/semantic-tokens-provider-example/sample.js @@ -18,7 +18,9 @@ function getType(type) { /** @type {(modifier: string[]|string|null)=>number} */ function getModifier(modifiers) { - if (typeof modifiers === 'string') modifiers = [modifiers]; + if (typeof modifiers === 'string') { + modifiers = [modifiers]; + } if (Array.isArray(modifiers)) { let nModifiers = 0; for (let modifier of modifiers) { @@ -54,7 +56,9 @@ monaco.languages.registerDocumentSemanticTokensProvider('plaintext', { for (let match = null; match = tokenPattern.exec(line);) { // translate token and modifiers to number representations let type = getType(match[1]); - if (type === -1) continue; + if (type === -1) { + continue; + } let modifier = match[2].length ? getModifier(match[2].split('.').slice(1)) : 0; @@ -139,26 +143,4 @@ const editor = monaco.editor.create(document.getElementById("container"), { 'semanticHighlighting.enabled': true }); -// currently there isn't builtin token handling -editor._themeService._knownThemes.forEach(function (theme) { - theme.getTokenStyleMetadata = function (type, modifiers) { - // use theme rules match - const style = theme._tokenTheme._root.match([type].concat(modifiers).join('.')); - return { - foreground: style._foreground, - italic: style._fontStyle & 1, - bold: style._fontStyle & 2, - underline: style._fontStyle & 4 - }; - }; -}); -// press F4 to change theme -editor.addCommand(monaco.KeyCode.F4, function () { - switch (editor._themeService.getTheme().themeName) { - case 'vs': monaco.editor.setTheme('vs-dark'); break; - case 'vs-dark': monaco.editor.setTheme('hc-black'); break; - case 'hc-black': monaco.editor.setTheme('myCustomTheme'); break; - case 'myCustomTheme': monaco.editor.setTheme('vs'); break; - } -});