From bb3f8bd77bb4cb261a5c707ae626465c7107bf9d Mon Sep 17 00:00:00 2001 From: Taras Kopets Date: Wed, 8 Nov 2017 14:25:06 +0200 Subject: [PATCH] Fix completions for indentifiers with dollar sign Fixes #152 --- SQLTools.py | 2 +- SQLToolsAPI/Completion.py | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/SQLTools.py b/SQLTools.py index f6964dc..45bf772 100644 --- a/SQLTools.py +++ b/SQLTools.py @@ -368,7 +368,7 @@ def on_query_completions(view, prefix, locations): lineStartToLocation = sublime.Region(lineStartPoint, currentPoint) try: lineStr = view.substr(lineStartToLocation) - prefix = re.split('[^`\"\w.]+', lineStr).pop() + prefix = re.split('[^`\"\w.\$]+', lineStr).pop() except Exception as e: Log(e) diff --git a/SQLToolsAPI/Completion.py b/SQLToolsAPI/Completion.py index 187be51..0a1b43d 100644 --- a/SQLToolsAPI/Completion.py +++ b/SQLToolsAPI/Completion.py @@ -39,6 +39,11 @@ def _stripPrefix(text, prefix): return text +# escape $ sign when formatting output +def _escapeDollarSign(ident): + return ident.replace("$", "\$") + + class CompletionItem(namedtuple('CompletionItem', ['type', 'ident'])): """ Represents a potential or actual completion item. @@ -149,10 +154,10 @@ def format(self, stripQuotes=False): part = self.ident.split('.') if len(part) > 1: return ("{0}\t({1} {2})".format(part[1], part[0], typeDisplay), - _stripQuotesOnDemand(part[1], stripQuotes)) + _stripQuotesOnDemand(_escapeDollarSign(part[1]), stripQuotes)) return ("{0}\t({1})".format(self.ident, typeDisplay), - _stripQuotesOnDemand(self.ident, stripQuotes)) + _stripQuotesOnDemand(_escapeDollarSign(self.ident), stripQuotes)) class Completion: