Skip to content

Commit cc6c0a6

Browse files
committed
Fix attr completions in the context of param error recovery, fixes #313
1 parent 15bc56f commit cc6c0a6

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

crates/parsa_python/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ create_grammar!(
405405
| ",".(kwarg | double_starred_expression)+ ","?
406406
starred_expression: "*" expression
407407
double_starred_expression: "**" expression
408-
kwarg: Name "=" expression
408+
kwarg: Name "=" expression | atom "." NeverMatch
409409

410410
// ASSIGNMENT TARGETS
411411
// ==================

crates/parsa_python/src/tokenizer.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ pub fn is_identifier(s: &str) -> bool {
8282

8383
create_terminals!(struct PyTerminal, enum TerminalType,
8484
[Name, Operator, String, Bytes, Number, Endmarker, Newline, ErrorToken,
85-
Indent, Dedent, ErrorDedent, FStringStart, FStringString, FStringEnd]);
85+
Indent, Dedent, ErrorDedent, FStringStart, FStringString, FStringEnd,
86+
// This is never generated by the tokenizer, but can be used in the grammar to
87+
// generate error statements
88+
NeverMatch]);
8689

8790
#[derive(Default, Debug)]
8891
pub struct PythonTokenizer<'a> {

crates/zuban_python/tests/jedilike/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ lazy_static::lazy_static! {
4242
("__init__.py", 1),
4343
("isinstance.py", 2),
4444
("lambdas.py", 18),
45-
("named_param.py", 10),
45+
("named_param.py", 12),
4646
("ordering.py", 4),
4747
("pep0484_typing.py", 3),
4848
("pep0484_decorators.py", 2),

crates/zuban_python/tests/mypylike/tests/completion.test

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,3 +442,23 @@ import zuba
442442
[file zuban-folder/something.py]
443443
[out]
444444
__main__.py:5:complete -> []
445+
446+
[case enum_completion_in_function_call_context]
447+
# flags: --no-typecheck
448+
# From GH #313
449+
from enum import StrEnum
450+
451+
class FooStr(StrEnum):
452+
SOME_FIELD: str
453+
ANOTHER_FIELD: int
454+
455+
def some_function():
456+
pass
457+
458+
#? complete --filter SOME_FIELD --filter ANOTHER_FIELD --filter strip --filter value
459+
some_function(FooStr.
460+
#? complete
461+
some_function(FooStr.SOME
462+
[out]
463+
__main__.py:13:complete -> [ANOTHER_FIELD, SOME_FIELD, strip, value]
464+
__main__.py:15:complete -> [SOME_FIELD]

0 commit comments

Comments
 (0)