diff --git a/SQLTools.py b/SQLTools.py index 858da13..f8d6fd2 100644 --- a/SQLTools.py +++ b/SQLTools.py @@ -437,24 +437,18 @@ def on_query_completions(view, prefix, locations): if not len(locations): return None - # disable completions for specific selectors - # disabled_for_selectors = ST.completion.selectors() - disabled_for_selectors = ['string.quoted.single.sql', 'string.quoted.single.pgsql'] - if disabled_for_selectors: - for selector in disabled_for_selectors: + ignoreSelectors = ST.completion.getIgnoreSelectors() + if ignoreSelectors: + for selector in ignoreSelectors: if view.match_selector(locations[0], selector): return None - # show completions only for specific selectors - selectors = ST.completion.getSelectors() - selectorMatched = False - if selectors: - for selector in selectors: + activeSelectors = ST.completion.getActiveSelectors() + if activeSelectors: + for selector in activeSelectors: if view.match_selector(locations[0], selector): - selectorMatched = True break - - if not selectorMatched: + else: return None # sublimePrefix = prefix diff --git a/SQLTools.sublime-settings b/SQLTools.sublime-settings index de973b6..44d5bd7 100644 --- a/SQLTools.sublime-settings +++ b/SQLTools.sublime-settings @@ -87,10 +87,10 @@ }, /** - * The list of syntax selectors for which the plugin autocompletion will be active. + * The list of syntax selectors for which the autocompletion will be active. * An empty list means autocompletion always active. */ - "selectors": [ + "autocomplete_selectors_active": [ "source.sql", "source.pgsql", "source.plpgsql.postgres", @@ -98,6 +98,17 @@ "source.tsql" ], + /** + * The list of syntax selectors for which the autocompletion will be disabled. + */ + "autocomplete_selectors_ignore": [ + "string.quoted.single.sql", + "string.quoted.single.pgsql", + "string.quoted.single.postgres", + "string.quoted.single.oracle", + "string.group.quote.oracle" + ], + /** * Command line interface options for each RDBMS. * In this file, the section `cli` above has the names you can use here. diff --git a/SQLToolsAPI/Completion.py b/SQLToolsAPI/Completion.py index cf68c8b..e0332ea 100644 --- a/SQLToolsAPI/Completion.py +++ b/SQLToolsAPI/Completion.py @@ -172,8 +172,17 @@ def __init__(self, allTables, allColumns, allFunctions, settings=None): if settings is None: settings = {} - # get completion selectors from settings - self.selectors = settings.get('selectors', []) + # check old setting name ('selectors') first for compatibility + activeSelectors = settings.get('selectors', None) + if not activeSelectors: + activeSelectors = settings.get( + 'autocomplete_selectors_active', + ['source.sql']) + self.activeSelectors = activeSelectors + + self.ignoreSelectors = settings.get( + 'autocomplete_selectors_ignore', + ['string.quoted.single.sql']) # determine type of completions self.completionType = settings.get('autocompletion', 'smart') @@ -198,8 +207,11 @@ def __init__(self, allTables, allColumns, allFunctions, settings=None): self.allKeywords.append(CompletionItem('Keyword', keyword)) - def getSelectors(self): - return self.selectors + def getActiveSelectors(self): + return self.activeSelectors + + def getIgnoreSelectors(self): + return self.ignoreSelectors def isDisabled(self): return self.completionType is None