diff --git a/src/js/codemirror/ubo-static-filtering.js b/src/js/codemirror/ubo-static-filtering.js index 2d21c0176..bbccf41a7 100644 --- a/src/js/codemirror/ubo-static-filtering.js +++ b/src/js/codemirror/ubo-static-filtering.js @@ -32,7 +32,8 @@ const redirectNames = new Map(); const scriptletNames = new Map(); -const preparseDirectiveNames = new Set(); +const preparseDirectiveTokens = new Set(); +const preparseDirectiveHints = []; /******************************************************************************/ @@ -64,8 +65,8 @@ CodeMirror.defineMode('ubo-static-filtering', function() { } stream.skipToEnd(); if ( - preparseDirectiveNames.size === 0 || - preparseDirectiveNames.has(match[2].trim()) + preparseDirectiveTokens.size === 0 || + preparseDirectiveTokens.has(match[2].trim()) ) { return 'variable strong'; } @@ -288,9 +289,10 @@ CodeMirror.defineMode('ubo-static-filtering', function() { scriptletNames.set(name.slice(0, -3), displayText); } } - details.preparseDirectives.forEach(a => { - preparseDirectiveNames.add(a); + details.preparseDirectiveTokens.forEach(a => { + preparseDirectiveTokens.add(a); }); + preparseDirectiveHints.push(...details.preparseDirectiveHints); initHints(); }, }; @@ -432,11 +434,12 @@ const initHints = function() { const matchLeft = /^!#if !?(\w*)$/.exec(line.slice(0, beg)); const matchRight = /^\w*/.exec(line.slice(beg)); if ( matchLeft === null || matchRight === null ) { return; } - const hints = []; - for ( const hint of preparseDirectiveNames ) { - hints.push(hint); - } - return pickBestHints(cursor, matchLeft[1], matchRight[0], hints); + return pickBestHints( + cursor, + matchLeft[1], + matchRight[0], + preparseDirectiveHints + ); } if ( line.startsWith('!#') && line !== '!#endif' ) { const matchLeft = /^!#(\w*)$/.exec(line.slice(0, beg)); diff --git a/src/js/messaging.js b/src/js/messaging.js index a814a3727..d0e18a1f2 100644 --- a/src/js/messaging.js +++ b/src/js/messaging.js @@ -1154,7 +1154,8 @@ const onMessage = function(request, sender, callback) { case 'getAutoCompleteDetails': response = { redirectResources: µb.redirectEngine.getResourceDetails(), - preparseDirectives: Array.from(µb.preparseDirectives.tokens.keys()), + preparseDirectiveTokens: µb.preparseDirectives.getTokens(), + preparseDirectiveHints: µb.preparseDirectives.getHints(), }; break; diff --git a/src/js/storage.js b/src/js/storage.js index 3ac401e3a..750079194 100644 --- a/src/js/storage.js +++ b/src/js/storage.js @@ -918,6 +918,21 @@ self.addEventListener('hiddenSettingsChanged', ( ) => { return out.join('\n'); }, + getHints: function() { + const out = []; + const vals = new Set(); + for ( const [ key, val ] of this.tokens ) { + if ( vals.has(val) ) { continue; } + vals.add(val); + out.push(key); + } + return out; + }, + + getTokens: function() { + return Array.from(this.tokens.keys()); + }, + tokens: new Map([ [ 'ext_ublock', 'ublock' ], [ 'env_chromium', 'chromium' ],