Fixed auto complete issues for Python 2.6

This commit is contained in:
Aditya Toshniwal
2018-08-27 16:37:00 +05:30
committed by Akshay Joshi
parent 7a3f3046df
commit ea787b30eb
3 changed files with 24 additions and 20 deletions

View File

@@ -7,6 +7,7 @@
# #
########################################################################## ##########################################################################
from __future__ import print_function
import sys import sys
import random import random

View File

@@ -11,9 +11,15 @@
import re import re
import operator import operator
import sys
from itertools import count, repeat, chain from itertools import count, repeat, chain
from .completion import Completion from .completion import Completion
from collections import namedtuple, defaultdict, OrderedDict from collections import namedtuple, defaultdict
if sys.version_info < (2, 7):
from ordereddict import OrderedDict
else:
from collections import OrderedDict
from .sqlcompletion import ( from .sqlcompletion import (
FromClauseItem, suggest_type, Database, Schema, Table, FromClauseItem, suggest_type, Database, Schema, Table,
Function, Column, View, Keyword, Datatype, Alias, JoinCondition, Join) Function, Column, View, Keyword, Datatype, Alias, JoinCondition, Join)
@@ -286,15 +292,14 @@ class SQLAutoComplete(object):
# This is used when suggesting functions, to avoid the latency that # This is used when suggesting functions, to avoid the latency that
# would result if we'd recalculate the arg lists each time we suggest # would result if we'd recalculate the arg lists each time we suggest
# functions (in large DBs) # functions (in large DBs)
self._arg_list_cache = {
usage: { self._arg_list_cache = \
meta: self._arg_list(meta, usage) dict((usage,
for sch, funcs in self.dbmetadata['functions'].items() dict((meta, self._arg_list(meta, usage))
for func, metas in funcs.items() for sch, funcs in self.dbmetadata['functions'].items()
for meta in metas for func, metas in funcs.items()
} for meta in metas))
for usage in ('call', 'call_display', 'signature') for usage in ('call', 'call_display', 'signature'))
}
def extend_foreignkeys(self, fk_data): def extend_foreignkeys(self, fk_data):
@@ -532,11 +537,10 @@ class SQLAutoComplete(object):
c.name for t, cs in scoped_cols.items() if t.ref != ltbl c.name for t, cs in scoped_cols.items() if t.ref != ltbl
for c in cs for c in cs
) )
scoped_cols = { scoped_cols = \
t: [col for col in cols if col.name in other_tbl_cols] dict((t, [col for col in cols if col.name in other_tbl_cols])
for t, cols in scoped_cols.items() for t, cols in scoped_cols.items() if t.ref == ltbl)
if t.ref == ltbl
}
lastword = last_word(word_before_cursor, include='most_punctuations') lastword = last_word(word_before_cursor, include='most_punctuations')
if lastword == '*': if lastword == '*':
if suggestion.context == 'insert': if suggestion.context == 'insert':
@@ -547,10 +551,9 @@ class SQLAutoComplete(object):
p.match(col.default) p.match(col.default)
for p in self.insert_col_skip_patterns for p in self.insert_col_skip_patterns
) )
scoped_cols = { scoped_cols = \
t: [col for col in cols if filter(col)] dict((t, [col for col in cols if filter(col)])
for t, cols in scoped_cols.items() for t, cols in scoped_cols.items())
}
if self.asterisk_column_order == 'alphabetic': if self.asterisk_column_order == 'alphabetic':
for cols in scoped_cols.values(): for cols in scoped_cols.values():
cols.sort(key=operator.attrgetter('name')) cols.sort(key=operator.attrgetter('name'))

View File

@@ -458,7 +458,7 @@ def suggest_based_on_last_token(token, stmt):
if not schema: if not schema:
suggestions.append(Schema()) suggestions.append(Schema())
return tuple(suggestions) return tuple(suggestions)
elif token_v in {'alter', 'create', 'drop'}: elif token_v in ['alter', 'create', 'drop']:
return (Keyword(token_v.upper()),) return (Keyword(token_v.upper()),)
elif token.is_keyword: elif token.is_keyword:
# token is a keyword we haven't implemented any special handling for # token is a keyword we haven't implemented any special handling for