Skip to content

Commit

Permalink
Add a setting to disable completion for selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
Taras Kopets committed Mar 4, 2019
1 parent 622eb80 commit 8dd1dc6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 19 deletions.
20 changes: 7 additions & 13 deletions SQLTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 13 additions & 2 deletions SQLTools.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,28 @@
},

/**
* 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",
"source.plsql.oracle",
"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.
Expand Down
20 changes: 16 additions & 4 deletions SQLToolsAPI/Completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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
Expand Down

0 comments on commit 8dd1dc6

Please sign in to comment.