285 Commits
Author SHA1 Message Date
Irina Fediaevaandintellij-monorepo-bot 92365f2246 PY-52574: Update tests after removing Epytext docstring format
(cherry picked from commit d4a90a8da56ca889cf380aa5bc72ac82b0716abc)

IJ-CR-148150

GitOrigin-RevId: 235a0e447d84c96e9963235615b07a1caf371e74
2024-11-28 01:35:54 +00:00
Petrandintellij-monorepo-bot 93b9066edf PY-34617 Support version check
GitOrigin-RevId: 3318ff79cdcc5ba0ce5e4feb65abad5ad0f4acfa
2024-07-28 00:24:15 +00:00
Mikhail Golubevandintellij-monorepo-bot eb63148798 PY-73246 Don't insert square brackets after classes not having free type parameters
Even if they transitively extend typing.Generic, such as the builtin str.

GitOrigin-RevId: 9389ef5846e21ba5e0fed8b835beb2d458e42f13
2024-07-02 14:08:48 +00:00
Mikhail Golubevandintellij-monorepo-bot ebba681c85 PY-62208 Don't suggest names shorter than five characters unless it's an extended completion
Otherwise, we end up with dozens of unintentionally public names such as "s", "i", "k"
even in the standard library (e.g. `this.s` or `pickletools.i`).

Ideally, we should rely on .pyi stubs and the content of `__all__` to offer only explicitly
exposed API, but not every module has any of those two, and it's not clear how to match
.py files and the corresponding .pyi stubs fast enough for completion.

GitOrigin-RevId: 163c472654e60ae63ff893142b8ddb9accc56393
2024-07-02 14:08:48 +00:00
Mikhail Golubevandintellij-monorepo-bot 1a3e6c2a64 PY-73246 Automatically insert square brackets on completion of parameterized types
GitOrigin-RevId: 5e81bc984fa3c7b4f83c564c85d872c5a49cf391
2024-07-02 14:08:48 +00:00
Mikhail Golubevandintellij-monorepo-bot 52850e21d8 PY-62208 Include importable names in basic completion results
Previously, such names were visible only on so-called "extended" completion,
activated when the hotkey for the basic completion was hit twice. The main reason
was that collecting such variants from indexes was a slow process, and we
didn't want to harm the responsiveness of completion for basic names.
Now it becomes possible thanks to a number of performance optimizations:

* Instead of using three separate indexes for classes, functions and variables,
we use one -- PyExportedModuleAttributeIndex. By definition, it includes only top-level
"importable" names, so we additionally save time by not filtering out irrelevant
entries. Also, it doesn't contain private definitions starting with an underscore.
It might bother some users, but given that the previous completion was used
extremely rarely, and the new one is going to be visible everywhere, it seems
that pruning unlikely entries as much as possible is a fare tradeoff. In the future,
we might enable them back on the "extended" completion if there is a demand.
Also, this index binds its keys to the project (`traceKeyHashToVirtualFileMapping`),
further eliminating useless index lookups.

* Thanks to the recent fixes in the platform (IJPL-265), it's now possible to
simultaneously iterate over all keys in an index and request values for a given key
without deadlocks, which is much faster than eagerly fetching all keys first.

* While scanning through all matching entries from indexes, we terminate
the lookup if the number of items exceeds the size of the lookup list.
We can further reduce this number by adjusting the "ide.completion.variant.limit"
registry value.

* Calculating expensive "canonical" import paths (e.g. "pkg.private.Name" is importable as
"pkg.Name") is offloaded to a background thread thanks to the `withExpensiveRenderer` API.
We still calculate these paths synchronously, though, for names whose raw qualified names
contain components starting with an underscore to decide whether these private names are
publicly re-exported and, hence, should be displayed.

The rest of the work has been put into reducing the number of entries on the list, e.g.

* The prefix under caret is now matched from the beginning of a name, e.g. `Bar<caret>`
matches `BarBaz`, but not `FooBar`.
* We don't suggest imported names clashing with those already available in scope.
* Some kinds of definitions are not suggested in specific contexts, e.g.
functions and variables are not suggested inside patterns and type hints.
* Nothing is suggested at the top-level of a class body, where dangling
reference expressions or calls are not normally expected.

Additionally, we don't suggest names from .pyi stubs at the moment, because
it pollutes the suggestion list with entries coming from the stubs for
third-party packages in Typeshed. We should probably enable them back once
we are able to properly disable Typeshed entries for not installed packages.

Some legacy forms of completion are left in the extended mode. In particular,
qualified names of classes are offered inside string literals only in this mode.
Also, module and package names are suggested only in the extended mode, because
top-level packages and modules are already suggested for the basic completion
by PyModuleNameCompletionContributor.

A few tests in PyClassNameCompletionTest were updated or removed entirely because
* we no longer suggest private names
* we no longer suggest names from private modules not re-exported in a public module
* we no longer suggest names clashing with those already available in scope
* prefix matching policy was changed to start at the beginning of an identifier

The whole feature can be disabled with the option "Suggest importable classes,
functions and variables in basic completion" in settings.

GitOrigin-RevId: 0787d42ce337b73b01a60f0bb7aa434fee43e659
2024-07-02 14:08:48 +00:00
Petrandintellij-monorepo-bot ee91d6a211 PY-72661 Literal completion inside nested parenthesis
GitOrigin-RevId: 14f18efcbaa520ac36ddd4892b774ed60a01cfdc
2024-06-17 20:36:23 +00:00
Petrandintellij-monorepo-bot aefaeaa52a PY-54151 TypedDict completion at callee does not work for methods
GitOrigin-RevId: 5a037490d8c24ccdd354e8396540a21294148a7e
2024-05-14 22:52:52 +00:00
Petrandintellij-monorepo-bot feb3bdc4c2 PY-52502 Duplicate completion variants when local variable is used as map key
GitOrigin-RevId: 463225922b2f0201b5d1ed2749f4175a77fd543f
2024-05-14 01:09:52 +00:00
Petrandintellij-monorepo-bot 7965dde4a4 PY-56004 Completion for expected literal types in assignments
GitOrigin-RevId: 06cacc62e068d902b174e5208837959cbd92ed88
2024-05-13 14:59:57 +00:00
Petrandintellij-monorepo-bot e01b0b6beb PY-40480 Completion for argument passed to parameter hinted as Literal
GitOrigin-RevId: 462b03dc35eef70bc873b568cae239d40f1d4974
2024-04-18 20:55:14 +00:00
Mikhail Golubevandintellij-monorepo-bot cef42660a3 PY-17627 PY-17733 Resolve class attributes defined in @classmethods
The logic is similar to that for instance attributes. Top-level class
attributes and methods defined in the class body get the precedence,
followed by class attributes defined with assignments in @classmethods
unless the latter would resolve to the same assignments as in

cls.attr = cls.attr + 1

finally, we scan through all other class methods resolving the name
to the first definition inside one of them.

So far, I intentionally didn't expose such attributes in findClassAttribute()
or getClassAttributes() because users of these methods assume that
this API considers only attributes defined immediately in the class body.
Adding extra definitions from class methods might break these usages.

I had to update the inspection about typing.Final, because it relied
on the fact that resolve() on assignment targets on class objects can
lead only to those top-level class attributes, where type hints are normally
located, but now it can lead to assignments to a qualified attribute inside
a containing class method.

GitOrigin-RevId: 0ca5bdaa4efca127ac187e822a49df6795e1028a
2024-03-28 12:17:37 +00:00
Mikhail Golubevandintellij-monorepo-bot 63d24cbb9d PY-34493 Enable back copying annotations from third-party .py files on Override/Implement
Since disabling turned out to be controversial. Even in the ticket some users were
against this decision claiming that it heavily annotated code bases it might be necessary
to retain all annotations from inherited method signatures. We need to think of a better
solution for controlling this behavior on case-to-case basis.

GitOrigin-RevId: c68763f0cad23de8975085e9bc8a6fd99013de3b
2023-08-09 20:53:35 +00:00
Mikhail Golubevandintellij-monorepo-bot a2af264b63 PY-45588 Add necessary imports on completing methods of superclasses to override
I had to move addImports to PyClassRefactoringUtil because PySuperMethodCompletionContributor
resides in python-psi-impl and, thus, has no access to PyOverrideImplementUtil.

GitOrigin-RevId: cf2ac19da779977649144b2477bac3f8ae78bbcd
2023-08-09 20:53:35 +00:00
Mikhail Golubevandintellij-monorepo-bot b50c617b7c PY-34493 Don't copy annotations from .pyi stubs and libraries on super method completion
GitOrigin-RevId: 65787827f5df5aa80986107dda0ba555b0942d40
2023-08-09 20:53:35 +00:00
lada.gaginaandintellij-monorepo-bot f3da5e58ae PY-58374 Fix dict keys completion when editing an existing key
GitOrigin-RevId: 41434300f6ea0f776a115a869fb9578a84015471
2023-01-17 19:01:56 +00:00
lada.gaginaandintellij-monorepo-bot ef2f607f5f PY-42637 Fix quotes for TypedDict keys completion in dict literals
- when there are other keys present in the literal, use quotes from there
- when the literal is empty, use double quotes by default
- when there already are quotes, suggest just the key names

GitOrigin-RevId: 5f37cd25c0e47521e78a01ab84053571369b24a8
2023-01-10 17:39:26 +00:00
andrey.matveevandintellij-monorepo-bot cad1138e59 PY-53104 Support PEP 673 typing.Self type
GitOrigin-RevId: 8efc65725580510dc3e9a93e1242e1a69032c8f1
2022-10-19 09:45:15 +00:00
Daniil Kalininandintellij-monorepo-bot fb11ee327c PY-53200 do not autocomplete parameter list if method already have one
Test for PY-53200

Better tests for PY-53200

PY-53200 Removed unnecessary test.

`testMethodNamesDoNotDuplicateParameterList` renamed and moved closer to the corresponding ones
Removed test for method names in suggestions restored

GitOrigin-RevId: 51b0721190718c44810c16e198bad583c2af67d0
2022-05-05 11:18:29 +00:00
Mikhail Golubevandintellij-monorepo-bot db8e5c2e2e PY-47962 Start-match non-imported module names in completion
This way we further reduce the number of irrelevant completion items suggested
effectively in every expression context, e.g. not suggesting "parser" and
"calendar" modules for the "ar" prefix, only something like "argparse" or
"array". The same applies to the completion of attributes with unresolved
qualifiers.

GitOrigin-RevId: 7a58053c4744c3d0066c379a4f190ffd09bfabd1
2022-02-23 11:55:19 +00:00
Mikhail Golubevandintellij-monorepo-bot 5ca605ccab PY-47962 Put non-imported module names last among completion variants
By giving them an explicit priority lower than the default. Unfortunately,
it doesn't remedy the problem with short module names, such as "re" or "sys",
always being on top when they completely match the entered prefix.
At the moment this behavior is hard-coded in the platform and cannot be
altered by language plugins. It's not caused by the "liftShorter" classifier.

Also, explicitly prioritizing various lookup elements has become quite messy
and scattered across PyCompletionWeigher and specific contributors. It begs
to be refactored, but will be addressed separately.

GitOrigin-RevId: d6f6ad06f5d68f3de7b866b8240a95b785604649
2022-02-23 11:55:15 +00:00
Mikhail Golubevandintellij-monorepo-bot ff82f4e058 PY-47254 Don't duplicate already imported module names in completion
By running the completion contributor for non-imported modules after everything
else, including the LegacyCompletionContributor offering names present in
the scope, and filtering out duplicate variants.

GitOrigin-RevId: 98982b2c33d1fc11d70b144de556a6825bd3febc
2022-02-23 11:55:12 +00:00
Lada Gaginaandintellij-monorepo-bot c7d12e929d PY-40007 PY-41546 Add completion for keys of dict literals marked as TypedDicts
- in call expressions
- in assignment statements
- in return statements

GitOrigin-RevId: aea2063f7cd7ffc68903c79fa16a25fdf4ff0f8f
2022-02-21 21:13:02 +00:00
Mikhail Golubevandintellij-monorepo-bot 4dbe727d87 EA-404000 Fix NPE in case of unresolved class names in class patterns
GitOrigin-RevId: c1805f264367e026c22b12a714eb97b6acd8edec
2021-11-23 12:34:15 +00:00
Mikhail Golubevandintellij-monorepo-bot 1421975c96 PY-48012 Resolve and complete attributes in PEP 634 class patterns
Both are implemented other the type of the corresponding class.
References resolve to any readable attribute of a class, however
some obviously wrong variants such as special "dunder" attributes
and methods are intentionally excluded from completion suggestions.

GitOrigin-RevId: 5edac14f47cba39840b15b0dd7f21e2e46077261
2021-10-15 17:36:56 +00:00
Mikhail Golubevandintellij-monorepo-bot d1066811a7 PY-47941 Add a test on completion of pytest.mark
The problem itself was fixed together with PY-48219 by switching to types to
find possible attributes of a module/package.

GitOrigin-RevId: 587b1c96610375836417655f0feb74f38edb4c69
2021-08-23 10:14:16 +00:00
Mikhail Golubevandintellij-monorepo-bot 6726f799ad PY-48198 PY-48220 Use PyResolveImportUtil to find not imported modules for completion
It allows to properly take into account .pyi stubs for module and packages and
find namespace packages in addition to ordinary Python packages as both of them
don't get into PyModuleNameIndex.

GitOrigin-RevId: 4afdf6d61e1f2e426ce65b0d04c6727caaeada2b
2021-08-23 10:14:13 +00:00
Mikhail Golubevandintellij-monorepo-bot 7fc1f80e2e PY-48219 Use PyModuleType to get attributes of a not imported module
It gives more accurate results and allows to bypass the problem
of PyFile#iterateNames(), which limits the results by the content
of "__all__" (as the method is used to resolve names in star imports).

GitOrigin-RevId: b19604d9e25a738909a02a1d81e4716675417430
2021-08-23 10:14:10 +00:00
Semyon Proshevandintellij-monorepo-bot 049680d7cf Remove dataclasses.py from test data after enabling corresponding pyi stub from typeshed
GitOrigin-RevId: fbb411d4ee07c3119e9c03892f5b3001d9e44a20
2021-08-19 17:20:30 +00:00
andrey.matveevandintellij-monorepo-bot 6e910f2023 PY-49156 Fix problem with no completion for os.path
(cherry picked from commit 38148e31c6cb3db1c4515d0c184eac5f8675e2e1)

IJ-MR-10435

GitOrigin-RevId: b679bdff186348baac062fcb8cb1550f35876612
2021-06-25 14:17:13 +00:00
Mikhail Golubevandintellij-monorepo-bot 09c9fc2898 PY-48665 Disable f-string-like completion in literal string patterns
Since f-strings are not supported inside patterns.

GitOrigin-RevId: f96b8b6e999c893930203f933c6f55aec6e60869
2021-06-17 20:08:03 +00:00
Lada Gaginaandintellij-monorepo-bot 2cf82cbee5 PY-47253 Suggest only immediate attributes for known package aliases
IJ-MR-7390

GitOrigin-RevId: 43a919a19d9b0be9e9e83478c2da8a26b351fd54
2021-04-19 22:57:06 +03:00
Lada Gaginaandintellij-monorepo-bot 78048abb15 PY-47247 Suggest subpackages and submodules in module attributes completion
IJ-MR-7312

GitOrigin-RevId: 2333fdc6ef9974b0f80bbe4d829c1211dde722ac
2021-03-26 13:38:45 +00:00
Mikhail Golubevandintellij-monorepo-bot b3daaed02f PY-46178 Protect against illegal fragment expression in f-string-like completion
It's not enough to just prepend an arbitrary string with "f" to treat it like
a well-formed f-string. If its part following "IntellijIdeaRulezzz " placeholder
contains special characters, such as "&" in URLs, it can break parsing of
a generated fragment to the extent we are no longer able to recover a string
literal from it (it all gets treated as a single embedded expression).
Forcibly closing a started fragment with "} " seems sufficient to guard against
the subsequent string content.

GitOrigin-RevId: fe682511475b800f013ace5e6e52fca9286cd418
2021-03-16 19:37:02 +00:00
Mikhail Golubevandintellij-monorepo-bot 8faf6e47bb PY-47304 Keep showing direct (non-fuzzy) module attributes after dot in completion
Previously, we accidentally offered immediate attributes of a module only right
after a dot in a non-imported qualified name (i.e., with an empty attribute name).
If a qualified name of a fuzzy variant matched that of a direct attribute, it went
unnoticed. However, if a name was non-trivially exported, as in case of
"_pytest.mark.structures.MARK_GEN" exported as "pytest.mark", its expected name,
as an attribute of pytest module, disappeared immediately as one started typing
anything past the dot in "pytest.".

GitOrigin-RevId: 5fbd7bd77fd1629f4d852b757d350cc182b991d7
2021-03-16 16:28:31 +00:00
Lada Gaginaandintellij-monorepo-bot b3e4cc8ba9 PY-47307 Do not insert dot after module name in completion, drop aliases completion
Aliases were completed only when the prefix was a fully-typed alias, and it became useless without inserting a dot and calling PyUnresolvedModuleAttributeCompletionContributor afterwards
IJ-MR-6806

GitOrigin-RevId: fc5b5e91911bbc85bda4da0753ad8e6da69951cb
2021-03-15 13:52:43 +00:00
Semyon Proshevandintellij-monorepo-bot 2465b8a67d Enable pyi stubs for several modules (PY-41509, PY-46229)
_ast, _dummy_thread, datetimerange, dummy_thread, dummy_threading, formatter, jwt, platform, string, thread

GitOrigin-RevId: a8010a0bd2381712599be0f96b35ce74e3e0c7d2
2021-03-03 22:46:06 +00:00
andrey.matveevandintellij-monorepo-bot c49b372edd PY-46056 Fix wrong same directory and library elements prioritization in completion
(cherry picked from commit 0189cf588066af3c0f133caa599d1f1bc50caec0)

IJ-MR-4895

GitOrigin-RevId: d8918a1530c612138c80850e41ad140d61300f4b
2021-02-26 11:11:16 +00:00
andrey.matveevandintellij-monorepo-bot 01f2002956 PY-46054 Fix missing same directory completion variants
(cherry picked from commit fb17e9285a39846b93708fb33c9822bff0a8da35)

IJ-MR-4823

GitOrigin-RevId: 1e0b31e14ff2c1ee95358b7bf68576f413fed71c
2021-02-25 05:04:46 +00:00
Mikhail Golubevandintellij-monorepo-bot 6f9013eb6b PY-47281 Exclude names from internal modules of libraries from auto-importing
Namely, names such as "numpy.random._examples.numba.extending.numbacall" or
"numpy.testing._private.noseclasses.NumpyDoctest" should no longer be suggested,
unless they are also exported in a public package higher in the hierarchy.

It doesn't not affect definitions from internal modules that belong to project
sources, these are still offered in the lookup.

GitOrigin-RevId: 2be393f30bd7d9905a31bdbe8db101807c136617
2021-02-19 16:19:51 +00:00
Mikhail Golubevandintellij-monorepo-bot a52c5b7a7d Remove PyAnacondaCompletionPerformanceTest accidentally ended up master
GitOrigin-RevId: 28a9dcf03bbaedd12acd3e08e101affca47777cd
2021-02-17 19:51:09 +00:00
Lada Gaginaandintellij-monorepo-bot 4acb02607a PY-44026 Use import priority when adding import
GitOrigin-RevId: 1e3a64b971a73283863e3aba1f8251d6673f62f9
2021-02-17 15:56:36 +00:00
Lada Gaginaandintellij-monorepo-bot 290c8ea4ab PY-44026 Add completion with auto-import for common package aliases
GitOrigin-RevId: 11d6f0df866ba3ae35cfdb1aed231a3e357bb4e7
2021-02-17 15:56:35 +00:00
Lada Gaginaandintellij-monorepo-bot e5bd01ff28 PY-44026 Add unit tests to completion with auto-import
GitOrigin-RevId: 7965daa063753606ea1d3de9f9bc0829c51fbabf
2021-02-17 15:56:33 +00:00
Mikhail Golubevandintellij-monorepo-bot 9ad52f13a4 PY-44026 Always match the first component of a qualified name in suggestions
For instance, "numpy.foo" should not match "pkg.test_numpy.foo".

GitOrigin-RevId: b3f3dfb17b0705eb3f93368eb281ba662ea92e3c
2021-02-17 15:56:31 +00:00
Mikhail Golubevandintellij-monorepo-bot b926a10139 PY-44026 Add examples of naive "env" correctness and performance tests using Anaconda
GitOrigin-RevId: 43e8cff8a8578614cb3e0fd6b7fa6a21222c5792
2021-02-17 15:56:23 +00:00
Mikhail Golubevandintellij-monorepo-bot 02fe07c5a9 PY-46381 Don't suggest internal parts of third-party packages to user
Namely, their bundled dependencies and tests.

Common names of test and "vendored" roots were collected based on
a base Anaconda interpreter.

Filtration is done over a module/package qualified name in its closest root,
sharing some parts of the implementation with QualifiedNameFinder.
It's likely to also be utilized in the upcoming auto-importing completion
of qualified names.

To make the customization of a search scope easier to use and extend in
the future, I introduced PySearchScopeBuilder API that allows to build
a custom search scope, excluding some irrelevant parts of a Python SDK.

I also updated the set of known standard library tests.
"idlelib/testcode.py" was removed as the only file entry that is
found only in Python 3.3, which we no longer support.

GitOrigin-RevId: 6676c59011d51371639ce24a5ac5c5b56d6b13fb
2021-01-27 16:34:15 +00:00
Mikhail Golubevandintellij-monorepo-bot dd56c1ce85 PY-45566 Exclude results from python-skeletons from extended completion
It has already been done for modules and packages, but not for definitions.

GitOrigin-RevId: a076e4bb1b7cc7dea6e6d5ebcec22e264e7efe39
2020-12-04 15:49:33 +00:00
Mikhail Golubevandintellij-monorepo-bot 591ccf3126 PY-45541 Display symbol's canonical import path as tail text in the lookup
Previously, we used the corresponding element's presentation for this purpose,
but it showed the shortest qualified name of its module, not necessarily the
"canonical" name that was actually used for importing. For instance, we could
have suggested `ndarray` from `numpy.core._multiarray_umath` but imported it
as `from numpy import ndarray`. It was both misleading and could have led to
duplicate entries for the same symbol among suggestions.

GitOrigin-RevId: abb350feeac9fd212d47dc0943442e0b16b21c9a
2020-12-04 15:49:31 +00:00
Mikhail Golubevandintellij-monorepo-bot 9590c3643e PY-45459 Make f-string like completion available after "{" on explicit invocation
GitOrigin-RevId: fe609b6a572f2ac971b2cf34eb92afe529708628
2020-11-15 16:10:47 +00:00