forked from VimPlug/jedi
Fix a few more file name completion cases
This commit is contained in:
@@ -99,7 +99,14 @@ class Completion:
|
||||
self._call_signatures_method = call_signatures_method
|
||||
|
||||
def completions(self):
|
||||
completion_names = self._get_context_completions()
|
||||
leaf = self._module_node.get_leaf_for_position(self._position, include_prefixes=True)
|
||||
string = _extract_string_while_in_string(leaf, self._position)
|
||||
if string is not None:
|
||||
completions = list(file_name_completions(self._evaluator, string, self._like_name))
|
||||
if completions:
|
||||
return completions
|
||||
|
||||
completion_names = self._get_context_completions(leaf)
|
||||
|
||||
completions = filter_names(self._evaluator, completion_names,
|
||||
self.stack, self._like_name)
|
||||
@@ -108,7 +115,7 @@ class Completion:
|
||||
x.name.startswith('_'),
|
||||
x.name.lower()))
|
||||
|
||||
def _get_context_completions(self):
|
||||
def _get_context_completions(self, leaf):
|
||||
"""
|
||||
Analyzes the context that a completion is made in and decides what to
|
||||
return.
|
||||
@@ -126,13 +133,6 @@ class Completion:
|
||||
grammar = self._evaluator.grammar
|
||||
self.stack = stack = None
|
||||
|
||||
leaf = self._module_node.get_leaf_for_position(self._position, include_prefixes=True)
|
||||
string = _extract_string_while_in_string(leaf, self._position)
|
||||
if string is not None:
|
||||
completions = list(file_name_completions(self._evaluator, string, self._like_name))
|
||||
if completions:
|
||||
return completions
|
||||
|
||||
try:
|
||||
self.stack = stack = helpers.get_stack_at_position(
|
||||
grammar, self._code_lines, leaf, self._position
|
||||
|
||||
@@ -1,17 +1,32 @@
|
||||
import os
|
||||
|
||||
from jedi._compatibility import FileNotFoundError
|
||||
from jedi.evaluate.names import AbstractArbitraryName
|
||||
from jedi.api import classes
|
||||
|
||||
|
||||
def file_name_completions(evaluator, string, like_name):
|
||||
base_name = os.path.basename(string)
|
||||
like_name = base_name + like_name
|
||||
string = os.path.dirname(string)
|
||||
|
||||
base_path = os.path.join(evaluator.project._path, string)
|
||||
print(string, base_path)
|
||||
for name in os.listdir(base_path):
|
||||
try:
|
||||
listed = os.listdir(base_path)
|
||||
except FileNotFoundError:
|
||||
return
|
||||
for name in listed:
|
||||
if name.startswith(like_name):
|
||||
path_for_name = os.path.join(base_path, name)
|
||||
if os.path.isdir(path_for_name):
|
||||
name += os.path.sep
|
||||
yield FileName(evaluator, name)
|
||||
|
||||
yield classes.Completion(
|
||||
evaluator,
|
||||
FileName(evaluator, name),
|
||||
stack=None,
|
||||
like_name_length=len(like_name),
|
||||
)
|
||||
|
||||
|
||||
class FileName(AbstractArbitraryName):
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import pydoc
|
||||
|
||||
from jedi.evaluate.utils import ignored
|
||||
from jedi.evaluate.names import AbstractNameDefinition
|
||||
from jedi.evaluate.names import AbstractArbitraryName
|
||||
|
||||
try:
|
||||
from pydoc_data import topics as pydoc_topics
|
||||
@@ -19,7 +19,7 @@ def get_operator(evaluator, string, pos):
|
||||
return Keyword(evaluator, string, pos)
|
||||
|
||||
|
||||
class KeywordName(AbstractNameDefinition):
|
||||
class KeywordName(AbstractArbitraryName):
|
||||
api_type = u'keyword'
|
||||
|
||||
def infer(self):
|
||||
|
||||
Reference in New Issue
Block a user