mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-18 19:45:57 +08:00
Keyword completion is now possible in a semantic way. This includes better testing and documentation.
This commit is contained in:
@@ -93,30 +93,12 @@ class Completion:
|
|||||||
Analyzes the context that a completion is made in and decides what to
|
Analyzes the context that a completion is made in and decides what to
|
||||||
return.
|
return.
|
||||||
|
|
||||||
Could specialized completions for:
|
Technically this works by generating a parser stack and analysing the
|
||||||
- from/import completions
|
current stack for possible grammar nodes.
|
||||||
- as nothing
|
|
||||||
- statements that start always on new line
|
|
||||||
'import', 'class', 'def', 'try', 'except',
|
|
||||||
'finally', 'while', with
|
|
||||||
- statements that start always on new line or after ; or after :
|
|
||||||
return raise continue break del pass global nonlocal assert
|
|
||||||
- def/class nothing
|
|
||||||
- async for/def/with
|
|
||||||
- \n@/del/return/raise no keyword (after keyword no keyword)?
|
|
||||||
- after keyword
|
|
||||||
- continue/break/pass nothing
|
|
||||||
- global/nonlocal search global
|
|
||||||
- after operator no keyword: return
|
|
||||||
- yield like return + after ( and =
|
|
||||||
- almost always ok
|
|
||||||
'and', 'for', 'if', 'else', 'in', 'is', 'lambda', 'not', 'or'
|
|
||||||
- after operations no keyword:
|
|
||||||
+ = * ** - etc Maybe work with the parser state?
|
|
||||||
|
|
||||||
# hard:
|
Possible enhancements:
|
||||||
- await
|
- global/nonlocal search global
|
||||||
- yield from / raise from / from import difference
|
- yield from / raise from <- could be only exceptions/generators
|
||||||
- In args: */**: no completion
|
- In args: */**: no completion
|
||||||
- In params (also lambda): no completion before =
|
- In params (also lambda): no completion before =
|
||||||
"""
|
"""
|
||||||
@@ -164,8 +146,9 @@ class Completion:
|
|||||||
level,
|
level,
|
||||||
only_modules
|
only_modules
|
||||||
)
|
)
|
||||||
elif nodes and nodes[-1] == 'as':
|
elif nodes and nodes[-1] in ('as', 'def', 'class'):
|
||||||
# No completions for ``with x as foo`` and ``import x as foo``.
|
# No completions for ``with x as foo`` and ``import x as foo``.
|
||||||
|
# Also true for defining names as a class or function.
|
||||||
return []
|
return []
|
||||||
else:
|
else:
|
||||||
completion_names += self._simple_complete(completion_parts)
|
completion_names += self._simple_complete(completion_parts)
|
||||||
|
|||||||
@@ -26,6 +26,34 @@ a + break
|
|||||||
#? ['break']
|
#? ['break']
|
||||||
b; break
|
b; break
|
||||||
|
|
||||||
# Should not complete after as.
|
# -----------------
|
||||||
|
# Keywords should not appear everywhere.
|
||||||
|
# -----------------
|
||||||
|
|
||||||
#? []
|
#? []
|
||||||
with open() as f
|
with open() as f
|
||||||
|
#? []
|
||||||
|
def i
|
||||||
|
#? []
|
||||||
|
class i
|
||||||
|
|
||||||
|
#? []
|
||||||
|
continue i
|
||||||
|
|
||||||
|
# More syntax details, e.g. while only after newline, but not after semicolon,
|
||||||
|
# continue also after semicolon
|
||||||
|
#? ['while']
|
||||||
|
while
|
||||||
|
#? []
|
||||||
|
x while
|
||||||
|
#? []
|
||||||
|
x; while
|
||||||
|
#? ['continue']
|
||||||
|
x; continue
|
||||||
|
|
||||||
|
#? []
|
||||||
|
and
|
||||||
|
#? ['and']
|
||||||
|
x and
|
||||||
|
#? []
|
||||||
|
x * and
|
||||||
|
|||||||
Reference in New Issue
Block a user