forked from VimPlug/jedi
getnames for scopes
This commit is contained in:
@@ -222,7 +222,13 @@ showdbg()
|
|||||||
print cmpl.parser.top.get_code()
|
print cmpl.parser.top.get_code()
|
||||||
#print cmpl.parser.top.subscopes[1].subscopes[0].get_code()
|
#print cmpl.parser.top.subscopes[1].subscopes[0].get_code()
|
||||||
|
|
||||||
#print cmpl.parser.top.get_locals()
|
names = cmpl.parser.top.get_names()
|
||||||
|
for n in names:
|
||||||
|
try:
|
||||||
|
print n.names
|
||||||
|
except:
|
||||||
|
print n.name
|
||||||
|
|
||||||
|
|
||||||
p = cmpl.parser
|
p = cmpl.parser
|
||||||
s = p.top
|
s = p.top
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ of the python module 'tokenize'.
|
|||||||
This original codebase of this parser, which has been refactored and heavily
|
This original codebase of this parser, which has been refactored and heavily
|
||||||
changed, was programmed by Aaron Griffin <aaronmgriffin@gmail.com>.
|
changed, was programmed by Aaron Griffin <aaronmgriffin@gmail.com>.
|
||||||
|
|
||||||
*The structure of the following script:*
|
**The structure of the following script:**
|
||||||
A Scope has
|
A Scope has
|
||||||
- imports (Import)
|
- imports (Import)
|
||||||
- subscopes (Scope, Class, Function, Flow)
|
- subscopes (Scope, Class, Function, Flow)
|
||||||
@@ -97,6 +97,8 @@ class Scope(object):
|
|||||||
|
|
||||||
def add_docstr(self, str):
|
def add_docstr(self, str):
|
||||||
""" Clean up a docstring """
|
""" Clean up a docstring """
|
||||||
|
# TODO the docstring clean isn't good, because things like
|
||||||
|
# r""" test """ are not being handled
|
||||||
d = str.replace('\n', ' ')
|
d = str.replace('\n', ' ')
|
||||||
d = d.replace('\t', ' ')
|
d = d.replace('\t', ' ')
|
||||||
while d.find(' ') > -1:
|
while d.find(' ') > -1:
|
||||||
@@ -139,6 +141,20 @@ class Scope(object):
|
|||||||
string = indent_block(string, indention=indention)
|
string = indent_block(string, indention=indention)
|
||||||
return string
|
return string
|
||||||
|
|
||||||
|
def get_names(self):
|
||||||
|
"""
|
||||||
|
Get all the names, that are active and accessible in the current
|
||||||
|
scope.
|
||||||
|
|
||||||
|
:return: list of Name
|
||||||
|
:rtype: list
|
||||||
|
"""
|
||||||
|
n = []
|
||||||
|
for stmt in self.statements:
|
||||||
|
n += stmt.get_names()
|
||||||
|
n += self.subscopes
|
||||||
|
return n
|
||||||
|
|
||||||
def is_empty(self):
|
def is_empty(self):
|
||||||
"""
|
"""
|
||||||
:return: True if there are no subscopes, imports and statements.
|
:return: True if there are no subscopes, imports and statements.
|
||||||
@@ -207,6 +223,9 @@ class Flow(Scope):
|
|||||||
super(Flow, self).__init__(name, indent, line_nr, '')
|
super(Flow, self).__init__(name, indent, line_nr, '')
|
||||||
self.command = command
|
self.command = command
|
||||||
self.statement = statement
|
self.statement = statement
|
||||||
|
if set_args == None:
|
||||||
|
self.set_args = []
|
||||||
|
else:
|
||||||
self.set_args = set_args
|
self.set_args = set_args
|
||||||
self.next = None
|
self.next = None
|
||||||
|
|
||||||
@@ -227,6 +246,17 @@ class Flow(Scope):
|
|||||||
str += self.next.get_code()
|
str += self.next.get_code()
|
||||||
return str
|
return str
|
||||||
|
|
||||||
|
def get_names(self):
|
||||||
|
"""
|
||||||
|
Get the names for the flow. This includes also a call to the super
|
||||||
|
class.
|
||||||
|
"""
|
||||||
|
n = self.set_args
|
||||||
|
if self.next:
|
||||||
|
n += self.next.get_names()
|
||||||
|
n += super(Flow, self).get_names()
|
||||||
|
return n
|
||||||
|
|
||||||
def set_next(self, next):
|
def set_next(self, next):
|
||||||
""" Set the next element in the flow, those are else, except, etc. """
|
""" Set the next element in the flow, those are else, except, etc. """
|
||||||
if self.next:
|
if self.next:
|
||||||
@@ -342,6 +372,10 @@ class Statement(object):
|
|||||||
else:
|
else:
|
||||||
return self.code
|
return self.code
|
||||||
|
|
||||||
|
def get_names(self):
|
||||||
|
""" Get the names for the statement. """
|
||||||
|
return self.set_vars
|
||||||
|
|
||||||
|
|
||||||
class Name(object):
|
class Name(object):
|
||||||
"""
|
"""
|
||||||
|
|||||||
6
test.py
6
test.py
@@ -15,7 +15,7 @@ class Intro(object):
|
|||||||
return string+","
|
return string+","
|
||||||
|
|
||||||
class Supi(A, datetime.datetime):
|
class Supi(A, datetime.datetime):
|
||||||
""" test123 """
|
r""" test123 """
|
||||||
class 2
|
class 2
|
||||||
|
|
||||||
static_var = 0
|
static_var = 0
|
||||||
@@ -30,11 +30,15 @@ class A():
|
|||||||
#class B():
|
#class B():
|
||||||
def test(self):
|
def test(self):
|
||||||
return A()
|
return A()
|
||||||
|
class init:
|
||||||
|
def __init__(self, a):
|
||||||
|
self.a = a
|
||||||
|
|
||||||
a = A()
|
a = A()
|
||||||
|
|
||||||
b = a.test()
|
b = a.test()
|
||||||
c = a or b
|
c = a or b
|
||||||
|
c = a or c
|
||||||
|
|
||||||
class Empty():
|
class Empty():
|
||||||
pass
|
pass
|
||||||
|
|||||||
Reference in New Issue
Block a user