mirror of
https://github.com/gorhill/uBlock.git
synced 2024-09-21 21:36:18 +02:00
Fine tune auto-completion for !#if
directives
Auto-completion will work only for uBO's own tokens, compatibility-related tokens[1] will not be taken into account for auto-completion. The reason is to not have the compatibility-related tokens get in the way of auto-completion in order to not inconvenience uBO's filter list maintainers. [1] `adguard_ext_chromium`, `adguard_ext_firefox`, etc.
This commit is contained in:
parent
a11571c666
commit
ebf7fb145e
3 changed files with 30 additions and 11 deletions
|
@ -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));
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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' ],
|
||||
|
|
Loading…
Reference in a new issue