mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 14:34:31 +08:00
file managment
This commit is contained in:
49
functions.py
49
functions.py
@@ -1,5 +1,43 @@
|
||||
|
||||
import parsing
|
||||
|
||||
class File(object):
|
||||
"""
|
||||
Manages all files, that are parsed and caches them.
|
||||
Important are the params source and module_name, one of them has to
|
||||
be there.
|
||||
|
||||
:param source: The source code of the file.
|
||||
:param module_name: The module name of the file.
|
||||
:param row: The row, the user is currently in. Only important for the \
|
||||
main file.
|
||||
"""
|
||||
def __init__(self, source=None, module_name=None, row=None):
|
||||
self.source = source
|
||||
self.module_name = module_name
|
||||
self.row = row
|
||||
self.line_cache = None
|
||||
|
||||
if not self.module_name and not self.source:
|
||||
raise AttributeError("Submit a module name or the source code")
|
||||
elif self.module_name:
|
||||
self.load_module()
|
||||
|
||||
self.parser = parsing.PyFuzzyParser(source, row)
|
||||
|
||||
def load_module(self):
|
||||
pass
|
||||
|
||||
def get_line(self, line):
|
||||
if not self.line_cache:
|
||||
self.line_cache = self.source.split('\n')
|
||||
|
||||
if 1 <= line <= len(self.line_cache):
|
||||
return self.line_cache[line-1]
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
def complete(source, row, colum, file_callback=None):
|
||||
"""
|
||||
An auto completer for python files.
|
||||
@@ -13,11 +51,12 @@ def complete(source, row, colum, file_callback=None):
|
||||
:return: list
|
||||
:rtype: list
|
||||
"""
|
||||
row = 38
|
||||
p = parsing.PyFuzzyParser(source, row)
|
||||
row = 89
|
||||
f = File(source=source, row=row)
|
||||
|
||||
print
|
||||
print
|
||||
print p.user_scope
|
||||
print p.user_scope.get_simple_for_line(row)
|
||||
return p.user_scope.get_set_vars()
|
||||
print f.get_line(row)
|
||||
print f.parser.user_scope
|
||||
print f.parser.user_scope.get_simple_for_line(row)
|
||||
return f.parser.user_scope.get_set_vars()
|
||||
|
||||
Reference in New Issue
Block a user