Commit Graph

49 Commits

Author SHA1 Message Date
Yan Zhulanow 1b7d1dd08a [Analysis API] Simplify 'getNotUnderContentRootModule()'
In the resulting implementation of dangling file modules,
'getNotUnderContentRootModule()' is never called with a not-null file.
2024-01-05 16:04:14 +00:00
Yan Zhulanow 452d22e14f [Analysis API] Add IGNORE_SELF dangling file resolution mode
In the 'IGNORE_SELF' mode, dangling files don't have their own
declarations in providers. As a result, all references there resolve to
declarations of the original file. It is conceptually similar to that we
had in on-air resolve, however, now it's possible to work with the whole
content of the in-memory 'FirFile'.

As it can be seen in 'ProjectStructureProvider.kt'
(KtFile.danglingFileResolutionMode), the 'IGNORE_SELF' mode is
automatically applied for non-physical files with an original file being
set. For other scenarios, now there is a new 'analyzeCopy()' function
that allows to pass the analysis mode explicitly.
2024-01-05 16:04:14 +00:00
Yan Zhulanow 6bbd252c07 [Analysis API] Implement separate caching for unstable dangling files
PSI events do not arrive for dangling files with no backing
'VirtualFile', so its partial invalidation becomes non-trivial.
In the change, a short-living cache is implemented for these 'unstable'
dangling files.
2024-01-05 16:04:14 +00:00
Yan Zhulanow 2899822102 [Analysis API] Extract dangling file module computation
Use the same code for creating dangling file modules inside tests,
the stand-alone API, and in the IDE.
2024-01-05 16:04:14 +00:00
Yan Zhulanow b7c774b9e5 [Analysis API] Generify 'KtCodeFragmentModule' to support ordinary files
This commit introduces dangling file modules, which may be either
code fragments or ordinary Kotlin files. As before, code fragments are
analyzed against some context element, however ordinary files only
have a context module.

Code fragments can also have a dangling file module as a contextual one,
including other code fragment. This is done to support potential usages
in completion, intentions and refactorings.
2024-01-05 16:04:14 +00:00
Yan Zhulanow 07aad38c69 [Analysis API] Do not hold a reference to 'KtCodeFragment' from modules
'KtModule' references may be cached for indefinite time. If so,
unused fake documents will wait long before being cleaned up.

^KT-62562 Fixed
2023-12-13 20:29:39 +00:00
Roman Golyshev a1155204c7 KT-63096 [LL] Remove KtModuleScopeProvider
It has no usages anymore
2023-11-09 23:39:32 +00:00
Marco Pennekamp 50fdc2128f [AA] Improve documentation of ProjectStructureProvider.getModule
- Since this documentation was written, the usages of contextual modules
  have expanded beyond outsider files, for example to support `KtModule`
  disambiguation for library elements. Hence, it was necessary to update
  the documentation accordingly.
2023-10-31 17:34:44 +00:00
Ilya Kirillov ba37ad9b85 [build] remove obsolete -opt-in=kotlin.ExperimentalStdlibApi from :analysis:proejct-structure module 2023-10-13 11:49:55 +00:00
Yan Zhulanow 36df749697 [LL API] Invalidate code fragment sessions on PSI modifications
Code fragments depend not only on their context module, but also on
body of the context declaration.
2023-09-22 12:20:05 +00:00
Yan Zhulanow 715f7d1a35 [LL API] Analyze code fragment in a separate 'FirSession'
Before, `KtCodeFragment`/`FirCodeFragment` was analyzed as a part of
its context `KtModule`. This has the following complications:

- In non-source sessions, diagnostic reporting is globally disabled.
  For code fragments, however, checking the code before passing it to
  the backend is essential.

- Special treatment for call ambiguities in libraries
  (`LLLibraryScopeAwareCallConflictResolverFactory`) becomes complicated
  as the conflict resolver has to be applied to a library module.

- `KtCodeFragment`s usually have a shorter lifetime than their own
  context. Caching may potentially be implemented differently for them.

^KT-61783 Fixed
2023-09-22 12:20:05 +00:00
Yan Zhulanow 4c3d414067 [LL API] Minor, fix documentation for 'globalLanguageVersionSettings' 2023-08-30 06:38:44 +00:00
Yan Zhulanow dbb7e788b2 [LL API] Provide customizable default language version settings 2023-08-30 06:38:44 +00:00
Marco Pennekamp 03c8654fe3 [AA] KT-58257 Improve modification event API and documentation
- Module state modification events now have a modification kind, which
  allows adding additional kinds of modification in the future (e.g.
  separating module property and content root updates, if the workspace
  model ever supports it).
  - Splitting off modification kinds was also a good opportunity to
    better document when module state modification occurs.
- Changed the documentation of modification events to be (1) less
  reliant on the IDE implementation and (2) more detailed in the
  intended effect of each event.
- Removed the notion of "stable" modules again and replaced it with
  "libraries". Even though an SDK is technically not a library, the
  term "library modules" should be more friendly to API consumers.
2023-07-31 15:58:01 +00:00
Marco Pennekamp 24045067bf [LL FIR] KT-58257 Keep library (source) sessions on global source invalidation
- `LLFirSessionCache.sourceCache` can contain library and library
  sources sessions. However, global source modification events should
  not remove such sessions from the cache, because they belong to
  "stable" modules.
- The commit introduces the term "stable module" as a combined term for
  binary and library source modules. Library sources are not binaries,
  but nevertheless they cannot cause nor be affected by out-of-block
  modification.
- The term "source modules" as used by global "source" modification is
  slightly imprecise, as it does *not* include library sources, but for
  the sake of conciseness, I don't plan to change that.
2023-07-31 15:58:01 +00:00
Marco Pennekamp 1f556589a2 [AA] KT-58257 Add module dependents exception for KtBuiltinsModule and KtSdkModule
- The IDE implementation of `KotlinModuleDependentsProvider` cannot
  easily find all dependents for a builtins or SDK module. Instead,
  builtins and SDK changes can be handled via global module state
  modification events, because most modules will depend on builtins and
  SDK modules.
2023-07-31 15:58:00 +00:00
Marco Pennekamp 027fd5600f [AA] KT-58257 Implement KtStaticModuleDependentsProvider (standalone) 2023-07-31 15:58:00 +00:00
Marco Pennekamp fe3f7feae4 [AA] KT-58257 Introduce KotlinModuleDependentsProvider
- Event-based session invalidation requires knowledge about the
  dependents of a `KtModule`. This is because, when the session for a
  module is invalidated, all sessions for modules which depend on that
  module, directly or indirectly, must also be invalidated.
- Note that the approach with modification trackers relied on module
  dependencies. Events have an opposite flow of information compared to
  modification trackers: Modification trackers request whether a change
  occurred, while events publish that a change occurred. Thus, the
  modules which need to be incorporated into the invalidation dynamic
  are also flipped: dependents instead of dependencies.
- `KotlinModuleDependentsProvider` is designed to work generally. It can
  be used for purposes beyond session invalidation.
2023-07-31 15:58:00 +00:00
Jinseong Jeon 5596c3ae80 AA: better error message for file w/o containing module
...instead of throwing NoSuchElementException
2023-07-13 11:51:23 +02:00
Yan Zhulanow c6d8876f9f [LL API] Pass the project instance to ProjectStructureProvider
Eliminate unnecessary PSI tree traversal by providing the 'Project'
instance explicitly.
2023-05-16 08:42:57 +00:00
Yan Zhulanow a93e9c3c19 [LL API] Remove incorrect ways to get modules/sessions
^KT-57559 Fixed
2023-05-16 08:42:57 +00:00
Yan Zhulanow c90d094af6 [LL API] Pass a contextual module to ProjectStructureProvider
In certain cases, it's impossible to determine which module owns a
particular file without knowing the analysis context. For instance,
the file might be a part of a physical module, and be also included into
a virtual ad-hoc module (to be analyzed in separate, e.g. a VCS diff).

The new API allows to pass a contextual module. Basically it means
"give me a module for this element, implying that we are now analyzing a
contextual module".

^KT-57559 Fixed
2023-05-16 08:42:57 +00:00
Yahor Berdnikau d57623891d Fix explicit api issues in analysis modules
Explicit api mode was not working due to the bug.

^KT-57653
2023-05-08 19:43:43 +00:00
Jinseong Jeon 501ec4fdbf AA: fix typo in KtLibrarySourceModule description 2023-05-01 16:26:54 +02:00
Andrei Klunnyi 1e0115aef8 KT-57468 Kotlin assignment plugin: operation name cannot be found
The problem results in broken import quick fix and import optimizer on
the IDE side [1].

`AssignResolutionAltererExtension` introduced a possibility to override
 resolution of assignment statements. The inconsistency though is
 that `KtSimpleNameReference.getResolvesByNames` doesn't return a name
 for the overridden `=`. Kotlin as a language doesn't support this [2].

This commit eliminates the drawback above:
1. It fixes the name `assign` the `=` can be resolved to [3].
   This eliminates the need to search for the name, bypassing the
   plugins.
2. `KtSimpleNameReference.getResolvesByNames` returns `assign` among
   other names in case it deals with binary `=` and assignment is
   resolved.
3. `KtCompilerPluginsProvider` was extended to check plugins' presence.
   K1 implementation added.

----------------------------------------------------------------
[1]: https://youtrack.jetbrains.com/issue/KTIJ-24390
[2]: OperatorConventions.getNameForOperationSymbol
     https://kotlinlang.org/docs/operator-overloading.html#augmented-assignments
[3]: OperatorConventions#ASSIGN_METHOD + AssignmentPluginNames
2023-04-27 14:05:02 +00:00
aleksandrina-streltsova c956b4aeae [Analysis API FIR] Use stable module name when mangling internal name
^KTIJ-25046
2023-04-27 12:36:20 +00:00
Roman Golyshev d4cffb8a5a [213] Switch to 213 platform
KTI-1114
2023-04-21 13:19:04 +00:00
Ilya Kirillov d68587de77 [Analysis API] implement API to extend Kotlin resolution by generated declarations
^KT-57930 fixed
2023-04-19 16:09:04 +00:00
Justin Paupore 6604627fa8 Use registered FIR compiler extensions in Analysis API.
This will allow IDE plugins to contribute compiler plugins to analysis,
above and beyond those used for the actual compilation step. These
plugins can be used to, for example, provide declarations for code that
is generated during build by an external tool.

^KT-57763 fixed
2023-04-05 07:31:08 +00:00
Yan Zhulanow ae40ddcf03 [LL API] Provide basic support for scripts in K2 (KTIJ-21108) 2023-03-05 19:18:19 +00:00
Marco Pennekamp d6cb75ca91 [LL FIR] KT-55329 Support transitive dependsOn dependencies in LL FIR
- In contrast to other kinds of dependencies, `dependsOn` dependencies
  must be followed transitively.
- Add `transitiveDependsOnDependencies` to `KtModule`. These
  dependencies are calculated lazily with a topological sort. They are
  added to the dependency provider when it's built in
  `LLFirSessionFactory`.

^KT-55329 fixed
2023-01-30 17:17:58 +00:00
Marco Pennekamp 7c96124a38 [LL FIR] KT-55329 Rename refinementDependency to dependsOnDependency
- The new Kotlin MPP name for `refinementDependency` is
  `dependsOnDependency`.
2023-01-30 17:17:57 +00:00
Yan Zhulanow f199671c4d [LL API] Make 'KtNotUnderContentRootModuleForTest' depend on built-ins 2023-01-25 08:04:39 +00:00
Yan Zhulanow 9bd1a24c13 [LL API] Add KDoc for 'KtNotUnderContentRootModule#file'. 2023-01-25 08:04:39 +00:00
Yan Zhulanow 00a266fd88 [AAPI] Introduce PsiFile in KtNotUnderContentRootModule
Indices are not available in the IDE for files outside content roots,
and the newly introduced 'PsiFile' can be used for searching
classifiers instead.
2023-01-25 08:04:35 +00:00
Dmitrii Gridin 5c9aa88617 [AA] KtModule#project shouldn't be null
^KT-55336
2022-12-07 14:18:44 +00:00
Ilya Kirillov b72dbb7819 [Analysis] fix invalid implementation of getKtModuleOfTypeSafe 2022-09-30 12:19:35 +02:00
Jinseong Jeon 1b79ee89ba AA: drop ProjectStructureProvider#getKtBinaryModules
Instead, provide an option to register PSI declaration provider inside
Analysis API session builder where we can retrieve all necessary pieces,
including CoreJarFileSystem, PackagePartProvider, and binary modules
from internal project structure provider.
2022-08-17 19:16:18 +02:00
Ilya Kirillov dd00062559 [analysis] introduce KtBuiltinsModule and remove hacks related to the stdlib module search 2022-07-19 17:17:33 +02:00
Ilya Kirillov dc4527462f [LL FIR] create separate library session for each library 2022-07-19 17:17:33 +02:00
Dmitriy Novozhilov 0c6a9d3eac [LL API] Provide proper way for automatic registration of compiler plugins 2022-06-29 11:59:59 +00:00
Jinseong Jeon 3f05ba04a9 AA: add JDK_HOME as dependent SDK module 2022-05-09 00:22:52 +02:00
Ilya Kirillov 2649788b87 [analysis api fir] put every library into a separate KtModule in tests 2022-04-13 12:53:22 +02:00
Ilya Kirillov 252d8e283b [low level fir] create separate FirModuleData for every library module dependency 2022-04-13 12:53:21 +02:00
Jinseong Jeon cbef3faae7 AA: expose library modules in the project structure 2022-03-22 15:44:46 +01:00
Roman Golyshev ca72790962 [FIR IDE] Hack checkIsInheritor until KT-51240 is fixed
We do not know for sure if there is any dependency between the
two classes passed to `checkIsInheritor`. To avoid the problem described
in KT-51240, we try to analyse them both and hope that the dependency
in some direction exists.

`NoCacheForModuleException` is introduced to signal about this
particular problem and avoid catching just any `NoSuchElementException`.

This hack is mainly done to fix very annoying KT-51240 for the time
being.

^KTIJ-20852 Fixed
2022-02-10 16:24:44 +03:00
Jinseong Jeon 26e923e3ae AA: introduce static project structure provider by compiler configuration
Also add standalone mode utils to configure Application/Project environments
2022-02-09 23:11:43 +01:00
Vyacheslav Gerasimov f7a9065b75 Build: Use intellij maven repo instead of downloaded IDEA
#KTI-82
2021-12-16 21:48:23 +03:00
Ilya Kirillov 678b931ba3 Analysis API: introduce Project Structure 2021-09-22 12:57:14 +02:00