Tab completion after def results in an NPE #257
Comments
This wasn't actually fixed it seems. |
Interesting, when running head using sbt shell/test:run or repl/run |
I ran the standalone distribution https://github.com/lihaoyi/Ammonite/releases/tag/0.4.9, which should have your things in it because I merged your stuff earlier? Unless I screwed it up... |
No worries, I just checked the source for that standalone distribution and the fix isn't in there. So I suppose it just wasn't included in the distribution. See the diff: git diff 0.4.9..HEAD diff --git a/repl/src/main/scala/ammonite/repl/interp/Pressy.scala b/repl/src/main/scala/ammonite/repl/interp/Pressy.scala
index b94183f..b8db3fb 100644
--- a/repl/src/main/scala/ammonite/repl/interp/Pressy.scala
+++ b/repl/src/main/scala/ammonite/repl/interp/Pressy.scala
@@ -203,27 +212,29 @@ object Pressy {
def complete(snippetIndex: Int, previousImports: String, snippet: String) = {
val prefix = previousImports + "\nobject AutocompleteWrapper{\n"
val suffix = "\n}"
- val allCode = prefix + snippet + suffix
+ val allCode = prefix + snippet + suffix
val index = snippetIndex + prefix.length
if (cachedPressy == null) cachedPressy = initPressy
val pressy = cachedPressy
val currentFile = new BatchSourceFile(
Compiler.makeFile(allCode.getBytes, name = "Current.scala"),
- allCode
- )
+ allCode)
val r = new Response[Unit]
pressy.askReload(List(currentFile), r)
r.get.fold(x => x, e => throw e)
- val run = new Run(pressy, currentFile, allCode, index)
+ val run = Try(new Run(pressy, currentFile, allCode, index))
- val (i, all) = run.prefixed
+ val (i, all): (Int, Seq[(String, Option[String])]) = run match {
+ case Success(runSuccess) => runSuccess.prefixed
+ case Failure(throwable) => (0, Seq.empty)
+ }
- val allNames = all.collect{ case (name, None) => name}.sorted.distinct
+ val allNames = all.collect { case (name, None) => name }.sorted.distinct
- val signatures = all.collect{ case (name, Some(defn)) => defn }.sorted.distinct
+ val signatures = all.collect { case (name, Some(defn)) => defn }.sorted.distinct
(i - prefix.length, allNames, signatures)
} (I thought I was going insane), because I reproduced it with a failing test before I fixed it It also appears the tests weren't included: diff --git a/repl/src/test/scala/ammonite/repl/AutocompleteTests.scala b/repl/src/test/scala/ammonite/repl/AutocompleteTests.scala
index 999fc42..efdf7d4 100644
--- a/repl/src/test/scala/ammonite/repl/AutocompleteTests.scala
+++ b/repl/src/test/scala/ammonite/repl/AutocompleteTests.scala
@@ -132,6 +132,8 @@ object AutocompleteTests extends TestSuite{
"def >(x: Byte): Boolean"
) ^
)
+
+
// https://issues.scala-lang.org/browse/SI-9153
//
// complete("""val x = 123; x + x.m<caret>""",
@@ -145,6 +147,14 @@ object AutocompleteTests extends TestSuite{
// complete("""Seq(1, 2, 3).map(_.co<caret>mpa)""", compares ^)
// complete("""Seq(1, 2, 3).map(_.<caret>compa)""", compares, ^)
}
+ 'defTab {
+ //Assert no NullPointerException was thrown. Does not verify any completions.
+ complete( """def<caret>""", Set.empty -- _)
+ }
+ 'Array {
+ //Test around https://github.com/lihaoyi/Ammonite/issues/252
+ complete("""new Array<caret>""", Set() ^)
+ }
}
}
} |
Ah ok, I must have borked the release then, maybe I forgot to pull after merging your stuff on the website. It'll go out next release then =) |
|
If you type
def
and hit tab to invoke completion (without a space) a Null Pointer Exception occurs and Ammonite exits.For example:
The full stack trace can be seen in the attached file.
amm-def-tab-npe.txt
The text was updated successfully, but these errors were encountered: