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

feat: add NewObject completion #7605

Open
wants to merge 80 commits into
base: master
Choose a base branch
from

Conversation

jaschdoc
Copy link
Member

Closes #6326

@jaschdoc
Copy link
Member Author

Was testing out the completers and got an error from the program below (which is not a valid program but I was midway through typing it).

pub def main(): Unit \ IO =
    println("The sum from 0..42 is")


pub def f(x: Option[a]): Option[a] = match
#
# An unexpected error has been detected by the Flix compiler:
#
#   head of empty list
#
# This is a bug in the Flix compiler. Please report it here:
#
# https://github.com/flix/flix/issues
#
# -- Flix Compiler --
#
# Flix Version : 0.46.0
#   incremental: All
#
# -- Java Virtual Machine --
#
# JVM Version  : 21.0.1 (2023-10-17)
# JVM Vendor   : GraalVM Community
# JAVA_HOME    : /home/_/.sdkman/candidates/java/21.0.1-graalce
# System       : Linux
#
# -- Stack Trace --
java.util.NoSuchElementException: head of empty list
	at scala.collection.immutable.Nil$.head(List.scala:662)
	at scala.collection.immutable.Nil$.head(List.scala:661)
	at ca.uwaterloo.flix.language.phase.TypeReconstruction$.visitExp(TypeReconstruction.scala:195)
	at ca.uwaterloo.flix.language.phase.TypeReconstruction$.visitDef(TypeReconstruction.scala:35)
	at ca.uwaterloo.flix.language.phase.Typer$.$anonfun$visitDef$1(Typer.scala:179)
	at ca.uwaterloo.flix.util.Validation$.mapN(Validation.scala:429)
	at ca.uwaterloo.flix.language.phase.Typer$.visitDef(Typer.scala:178)
	at ca.uwaterloo.flix.language.phase.Typer$.$anonfun$visitDefs$2(Typer.scala:162)
	at ca.uwaterloo.flix.util.ParOps$.$anonfun$parTraverseValues$1(ParOps.scala:106)
	at ca.uwaterloo.flix.util.ParOps$.$anonfun$parMap$2(ParOps.scala:64)
	at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1423)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:387)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1312)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1843)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1808)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:188)

@magnus-madsen
Copy link
Member

Thanks-- can you open a ticket for the bug?

@magnus-madsen
Copy link
Member

For the completer, it should fill in all methods you have to implement.

@magnus-madsen
Copy link
Member

For example, if you write new java.util.Comparator then it should fill in the compare method you have to implement.

@jaschdoc
Copy link
Member Author

For example, if you write new java.util.Comparator then it should fill in the compare method you have to implement.

Thanks! Working on it 😄 🏃 🔨
Just had to figure out what I was doing and what the goal was hehe

@magnus-madsen
Copy link
Member

Goal is like Intellij IDEA when you get it to fill out everything you have to implement. So a bit like InstanceCompleter.

@jaschdoc
Copy link
Member Author

Hmm it's kind of awkward to do completions as the new parser fails when writing new ##java.lang.Runnable or just new java.lang.Runnable so it seems the completion is not even run? I'm not sure if the parser has anything to do with the LSP side of things, though.

@jaschdoc
Copy link
Member Author

jaschdoc commented Apr 29, 2024

Ok this is close to done. The only thing I'm not sure how to approach is that formatType doesn't prepend ## to native types. This means that NewObjectCompleter has to do it manually. However, Arrays pose a bit of a challenge, since we want formatType to format these but also add ## if the type argument is a native class. E.g., Array[Array[java.lang.Object]] should be Array[Array[##java.lang.Object]] (not adding regions).
Maybe @mlutze has a suggestion for a fix?

@jaschdoc jaschdoc marked this pull request as ready for review April 29, 2024 13:33
@magnus-madsen
Copy link
Member

A few screenshots of different completions?

@mlutze
Copy link
Member

mlutze commented Apr 30, 2024

Ok this is close to done. The only thing I'm not sure how to approach is that formatType doesn't prepend ## to native types. This means that NewObjectCompleter has to do it manually. However, Arrays pose a bit of a challenge, since we want formatType to format these but also add ## if the type argument is a native class. E.g., Array[Array[java.lang.Object]] should be Array[Array[##java.lang.Object]] (not adding regions). Maybe @mlutze has a suggestion for a fix?

I think our best option is probably to make a new formatter for generated code. We might be able to use the SimpleType interface.

@jaschdoc
Copy link
Member Author

Ok this is close to done. The only thing I'm not sure how to approach is that formatType doesn't prepend ## to native types. This means that NewObjectCompleter has to do it manually. However, Arrays pose a bit of a challenge, since we want formatType to format these but also add ## if the type argument is a native class. E.g., Array[Array[java.lang.Object]] should be Array[Array[##java.lang.Object]] (not adding regions). Maybe @mlutze has a suggestion for a fix?

I think our best option is probably to make a new formatter for generated code. We might be able to use the SimpleType interface.

Roger that. I was afraid you were going to say that hehe :D

@magnus-madsen
Copy link
Member

magnus-madsen commented Apr 30, 2024

Before writing a lot of code, just reuse FormatType. Perfect is the enemy of good here. We don't want yet another formatter to maintain.

@jaschdoc
Copy link
Member Author

jaschdoc commented May 1, 2024

Screenshot from 2024-05-01 11-56-50
Screenshot from 2024-05-01 11-56-55
Screenshot from 2024-05-01 11-57-09
Screenshot from 2024-05-01 11-57-34

Copy link
Member

@magnus-madsen magnus-madsen left a comment

Choose a reason for hiding this comment

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

General comments:

  • We should also add support to Parser2. Maybe @herluf-ba can help?
  • Add some doc comments for the helper functions.
  • I don't think you need System.lineSeparator. I think \n is sufficient because it is interpreted by VSCode.

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.

Add NewObject completer
3 participants