question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Incorrect flags for some completion items

See original GitHub issue

Compiler version

3.1.3

Minimized code

This code is from CompletionSnippetSuite in Metals which is run by the specified scala version. @@ represents the cursor position.

object Main {
    new scala.Iterabl@@
}

Output

calling Completion.completions(pos) from Dotty API, produces

List(
  Completion(
    label = "Iterable",
    description = "=> collection.Iterable.type",
    symbols = List(method Iterable)
  ),
  Completion(
    label = "IterableOnce",
    description = "scala.IterableOnce",
    symbols = List(type IterableOnce)
  ),
  Completion(label = "Iterable", description = "scala.Iterable", symbols = List(type Iterable))
) 

Now the problem with the flags is that, for the last two items on the list, which are traits actually,

  • the symbol.is(Flags.Trait) returns false;
  • while symbol.info.typeSymbol.is(Flags.Trait) and symbol.info.typeSymbol.is(Trait) return true.

This is problematic for using the API for completions, such as when deciding whether to insert {} or when filtering results.

You might be interested in taking a look at these comments on the this PR for Scala 3 type completions in Metals.

Expectation

It is better if the flags are correctly set and are consistent.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
prolativcommented, Aug 1, 2022

Not really. typeSymbol also returns a symbol Let’s consider a simple scenario:

trait Foo[A] // sym1
object Foo // sym2
def foo = new Foo[Int] {} // sym3
type Bar[A] = Foo[A] // sym4
val Bar = Foo // sym5
def bar = new Bar[Int] {} // sym6

This snippet declares 6 symbols. Here only sym1 is a trait symbol so sym1.is(Trait) should be true. sym4 is declared as type so sym4.is(Trait) is false. However as type Bar proxies to Foo I believe sym4.info.typeSymbol should return sym1 (and so should sym1.info.typeSymbol) so if you want to check if a type symbol sym is semantically a trait I think something like sym.info.typeSymbol.is(Trait) should do the work (although I haven’t tested it). sym3 is a term symbol representing a method and sym3.info is the type Foo[Int] so its type symbol sym3.info.typeSymbol is also sym1.

In your particular case you should however note that new Fo@@ should not always directly complete Foo[] as if some type was declared inside of Foo’s companion object the user might rather prefer to complete just new Foo so that the user continues typing like new Foo.Quux

1reaction
prolativcommented, Aug 1, 2022

In your second example scala.concurrent.ExecutionContext.Implicits.global is defined as def so it’s a method symbol (not a trait) but it has type scala.concurrent.ExecutionContext, and ExecutionContext is defined as a trait so its symbol is a trait. So the results you get are correct

Read more comments on GitHub >

github_iconTop Results From Across the Web

Outlook "clear flag" changes message to "mark
The main problem with the way Outlook is doing it now (converting a clear flag to mark completed) is that the messages with...
Read more >
Registration - Vehicle Flags - Pages - Maryland MVA
The presence of a flag on your vehicle's record will prevent you from completing certain types of MVA transactions such as renewing your...
Read more >
Deletion Flag setting Error message for production order
Hi Aparna,. This is absolutely fine to set the deletion flag to archieve the Production Orders. For this error, which you are getting,...
Read more >
Common Red Flags - Fannie Mae
However, several red flags in a file may ... Verifications completed on the same day they were ordered. ▫ Verifications completed on weekend...
Read more >
How to Remove Negative Items From Your Credit Report
Read on to learn how to remove erroneous information from your credit report — and some tips on how to handle those negative...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found