Skip to content
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

Fix type alias completion, unify completion tests style #15047

Merged
merged 4 commits into from
Apr 28, 2022

Conversation

rochala
Copy link
Contributor

@rochala rochala commented Apr 27, 2022

Fixes #14984
Also unifies style in completion test as there were different styles of writing same test which made it harded to analyze and read.

@@ -1565,6 +1549,21 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
val selType = rawSelectorTpe match
case c: ConstantType if tree.isInline => c
case otherTpe => otherTpe.widen
/** Extractor for match types hidden behind an AppliedType/MatchAlias */
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverts changes from https://github.com/lampepfl/dotty/pull/14639/files#diff-8c9ece1772bd78160fc1c31e988664586c9df566a1d22ff99ef99dd6d5627a90R1518

Match Type completion is also fixed by this commit without using this extractor.

.completion(m1, Set(("example", Module, "example")))
}

@Test def typeAliasCompletions: Unit = {
Copy link
Contributor Author

@rochala rochala Apr 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests below check the issue of missing type alias completion. Changes above are style changes to unify them in this file.

@@ -106,15 +114,16 @@ class CompletionTest {
}

@Test def importCompleteIncludesSynthetic: Unit = {
val expected = Set(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I'm not a big fan of putting the expected values before the code snippets. IMHO this makes the tests harder to read (to understand what a test is about I read the snippet first and then Ι go back to the expected results) so I would rather leave expected values inlined at the end. However to make things more readable than currently we could:

  • unify formatting (e.g. don't put multiple expected values in the same line)
  • get rid of the very repetitive code"""...""".withSource pattern (e.g. by adding an implicit conversion)
  • overload completion to accept varargs so that we get rid of Set(...) - also we could make m1 default as in most cases we need only one code marker
    After these changes this test could look something like
  @Test def importCompleteIncludesSynthetic: Unit = {
    code"""case class MyCaseClass(foobar: Int)
           object O {
             val x = MyCaseClass(0)
             import x.c${m1}
           }"""
      .completion(
        ("copy", Method, "(foobar: Int): MyCaseClass"),
        ("canEqual", Method, "(that: Any): Boolean")
      )
  }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I totally agree. I made quite a makeover there but all language server tests can now omit .withSource. Furthermore completions now take marker m1 as default one and allows completions to be passed as varargs.

@prolativ prolativ merged commit 9d6e87a into scala:main Apr 28, 2022
@tgodzik
Copy link
Contributor

tgodzik commented Apr 28, 2022

Awesome! Thanks @rochala !

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.

No completion on type alias
3 participants