Skip to content

Kotlin 2 #97

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 54 commits into
base: main
Choose a base branch
from
Open

Conversation

nicolas-guichard
Copy link

This is based on https://github.com/slycodemonkey/scip-kotlin, which replaces the AnalysisHandlerExtension with a FirAdditionalCheckersExtension to collect declarations and expressions and an IrGenerationExtension to analyze them (at the FIR level) after everything has been resolved.

Test plan

All existing tests pass (or were slightly adapted, eg. class and method signatures).

This is currently used in a test instance of Searchfox at https://kdab.searchfox.org/mozilla-central/source, see eg. https://kdab.searchfox.org/mozilla-central/source/mobile/android/android-components/components/browser/domains/src/main/java/mozilla/components/browser/domains/Domain.kt.
This means the output is accepted by scip-java index-semanticdb then Searchfox's scip-indexer on the whole Firefox for Android code base.

New tests were added based on my testing with Searchfox.

nicolas-guichard and others added 30 commits March 21, 2025 19:47
Run `gradle splotlessApply`, remove trailing whitesepace and file endings.
Also remove the in-repo copy of Semanticdb.java (it is autogenerated by
protoc outside the source tree), and the unused krotoconfig.json, but
keep the SemanticdbBuilders.kt that used to be autogenerated by Kroto+.
This was deprecated in Kotlin 1.9 already.
We don't want the output schema to change, otherwise we're not
outputing SemanticDB anymore and downstream tooling like scip-java
reject our output.

We start with 24 failing tests to fix.
According to existing tests, exceptions in the semanticdb-kotlinc
plugin should not propagate to the host.

Down to 23 failing tests.
We want the symbol for a class to be package/package/Class#, instead
this gave us `package/package/Class`#.

Now we have just Class#, packages will be added back in a future
commit.

The display name should just be the simple class name.

Still 23 failing tests.
This:
- Adds special handling for packages, which are represented by FqName
  rather than PackageDescriptor.

  → This gives package/package/Class# instead of just Class#.

- Removes FileKt# fake classes for toplevel methods and properties
  These don't appear in imports, so I don't think they are wanted.
  This changes the test expectations, but remains SemanticDB-compliant.

  → This gives kotlin/io/println(). instead of kotlin/io/ConsoleKt#println().

Down to 19 failing tests.
SemanticDB and SCIP don't disambiguate methods by adding their full
signature, instead they sort overloaded methods by declaration order,
the first one is `method().`, the next one is `method(+1).`, the next
one `method(+2).` etc.

Down to 14 failing tests.
Identify getters/setters using FirPropertyAccessorSymbol.isGetter and
FirPropertyAccessorSymbol.isSetter instead of doing string comparisons.

Still 14 failing tests.
Down to 13 failing tests.
Constructors should have the special `<init>`(). symbol.

Down to 11 failing tests.
We are generally interested in the identifier for each item, but
sometimes want some other token instead, such as the constructor, get
or set keywords.

Down to 5 failing tests.
We need to support the package directive and the imports so that:
- `package a.b.c` has 3 symbol occurences, for `a/`, `a/b/` and `a/b/c/`
- `import a.b.Klass` has 3 symbol occurences, for `a/`, `a/b/` and
  `a/b/Klass#`

Still 5 failing tests.
Down to 4 failing tests.
We don't want all types to list Any as their supertype.

Down to 3 failings tests.
When we have a reference to a FirPropertySymbol, it is not obvious if
it is used as a read or a write. Emit both just in case.

No more failing tests!
Class overriddenSymbols were not pointing to actual symbols.

Function overriddenSymbols were missing.
We don't want to call all anonymous objects <anonymous>, or we can't
desambiguate between two anonymous objects from the same package.

We emit anonymous objects just like regular classes, but take care to
point at the `object` keyword for the class and primary constructor.
This was caught by Searchfox's scip-indexer, which would error out:
```
[ERROR scip_indexer] InvalidLocalSymbol("local 84getCurrentIndex().")
```
@nicolas-guichard nicolas-guichard mentioned this pull request Apr 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant