{"action":"created","comment":{"url":"https://api.github.com/repos/polynote/polynote/pulls/comments/259924628","pull_request_review_id":207517538,"id":259924628,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDI1OTkyNDYyOA==","diff_hunk":"@@ -29,78 +31,109 @@ import scala.tools.nsc.interactive.Global\n \n class PolyKernel private[kernel] (\n   private val getNotebook: () => IO[Notebook],\n-  val globalInfo: GlobalInfo,\n+  val kernelContext: KernelContext,\n   val outputDir: AbstractFile,\n   dependencies: Map[String, List[(String, File)]],\n   val statusUpdates: Publish[IO, KernelStatusUpdate],\n-  subKernels: Map[String, LanguageKernel.Factory[IO]] = Map.empty\n-) extends Kernel[IO] {\n+  subKernels: Map[String, LanguageInterpreter.Factory[IO]] = Map.empty\n+) extends KernelAPI[IO] {\n \n   protected val logger: Logger = getLogger\n \n   protected implicit val contextShift: ContextShift[IO] = IO.contextShift(ExecutionContext.fromExecutorService(Executors.newCachedThreadPool()))\n \n-  private val launchingKernel = Semaphore[IO](1).unsafeRunSync()\n-  private val kernels = new ConcurrentHashMap[String, LanguageKernel[IO]]()\n+  private val launchingInterpreter = Semaphore[IO](1).unsafeRunSync()\n+  private val interpreters = new ConcurrentHashMap[String, LanguageInterpreter[IO]]()\n \n \n   /**\n     * The symbol table, which stores all the currently existing runtime values\n     */\n-  protected lazy val symbolTable = new RuntimeSymbolTable(globalInfo, statusUpdates)\n+  protected lazy val symbolTable = new RuntimeSymbolTable(kernelContext, statusUpdates)\n \n   /**\n     * The task queue, which tracks currently running and queued kernel tasks (i.e. cells to run)\n     */\n   protected lazy val taskQueue: TaskQueue = TaskQueue(statusUpdates).unsafeRunSync()\n \n   // TODO: duplicates logic from runCell\n-  private def runPredef(kernel: LanguageKernel[IO], language: String): IO[Unit] =\n-    kernel.predefCode.fold(kernel.init()) {\n-      code => taskQueue.runTaskIO(s\"Predef $language\", s\"Predef ($language)\")(_ => kernel.runCode(\"Predef\", Nil, Nil, code)).flatMap {\n-        results => results.evalMap {\n-          case WrapSymbol(symbol) =>\n-            symbolTable.publishAll(symbolTable.RuntimeValue.fromSymbolDecl(symbol).toList)\n-          case _ => IO.unit\n-        }.compile.drain\n-      }\n-    }\n+  private def runPredef(interp: LanguageInterpreter[IO], language: String): IO[Stream[IO, Result]] =\n+    interp.init() *> {\n+      interp.predefCode match {\n+        case Some(code) => taskQueue.runTaskIO(s\"Predef $language\", s\"Predef ($language)\")(_ => interp.runCode(\"Predef\", Nil, Nil, code)).map {\n+          results => results.collect {\n+            case v: ResultValue => v\n+          }.evalTap {\n+            v => symbolTable.publishAll(List(symbolTable.RuntimeValue.fromResultValue(v, interp)))\n+          }\n+        }\n \n-  protected def getKernel(language: String): IO[LanguageKernel[IO]] = Option(kernels.get(language)).map(IO.pure).getOrElse {\n-    launchingKernel.acquire.bracket { _ =>\n-      Option(kernels.get(language)).map(IO.pure).getOrElse {\n-        for {\n-          factory <- IO.fromEither(Either.fromOption(subKernels.get(language), new RuntimeException(s\"No kernel for language $language\")))\n-          kernel  <- taskQueue.runTask(s\"Kernel$$$language\", s\"Starting $language kernel\")(_ => factory.apply(dependencies.getOrElse(language, Nil), symbolTable))\n-          _        = kernels.put(language, kernel)\n-          _       <- runPredef(kernel, language)\n-        } yield kernel\n+        case None => IO.pure(Stream.empty)\n       }\n-    } {\n-      _ => launchingKernel.release\n     }\n+\n+  protected def getInterpreter(language: String): Option[LanguageInterpreter[IO]] = Option(interpreters.get(language))\n+\n+  protected def getOrLaunchInterpreter(language: String): IO[(LanguageInterpreter[IO], Stream[IO, Result])] =\n+    Option(interpreters.get(language))\n+      .map(interp => IO.pure(interp -> Stream.empty))\n+      .getOrElse {\n+        launchingInterpreter.acquire.bracket { _ =>\n+          Option(interpreters.get(language)).map(interp => IO.pure(interp -> Stream.empty)).getOrElse {\n+            for {\n+              factory <- IO.fromEither(Either.fromOption(subKernels.get(language), new RuntimeException(s\"No interpreter for language $language\")))\n+              interp  <- taskQueue.runTask(s\"Kernel$$$language\", s\"Starting $language interpreter\")(_ => factory.apply(dependencies.getOrElse(language, Nil), symbolTable))","path":"polynote-kernel/src/main/scala/polynote/kernel/PolyKernel.scala","position":null,"original_position":102,"commit_id":"e925250fe0d3d0e7d224d559580a4c48d5d17f55","original_commit_id":"9b0e1c1ff17a89cdbccbbc9ad3696e30e05529fd","user":{"login":"jeremyrsmith","id":864869,"node_id":"MDQ6VXNlcjg2NDg2OQ==","avatar_url":"https://avatars0.githubusercontent.com/u/864869?v=4","gravatar_id":"","url":"https://api.github.com/users/jeremyrsmith","html_url":"https://github.com/jeremyrsmith","followers_url":"https://api.github.com/users/jeremyrsmith/followers","following_url":"https://api.github.com/users/jeremyrsmith/following{/other_user}","gists_url":"https://api.github.com/users/jeremyrsmith/gists{/gist_id}","starred_url":"https://api.github.com/users/jeremyrsmith/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jeremyrsmith/subscriptions","organizations_url":"https://api.github.com/users/jeremyrsmith/orgs","repos_url":"https://api.github.com/users/jeremyrsmith/repos","events_url":"https://api.github.com/users/jeremyrsmith/events{/privacy}","received_events_url":"https://api.github.com/users/jeremyrsmith/received_events","type":"User","site_admin":false},"body":"I couldn't find any evidence of magic, so I changed it.","created_at":"2019-02-25T17:06:06Z","updated_at":"2019-02-25T17:06:06Z","html_url":"https://github.com/polynote/polynote/pull/72#discussion_r259924628","pull_request_url":"https://api.github.com/repos/polynote/polynote/pulls/72","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/polynote/polynote/pulls/comments/259924628"},"html":{"href":"https://github.com/polynote/polynote/pull/72#discussion_r259924628"},"pull_request":{"href":"https://api.github.com/repos/polynote/polynote/pulls/72"}},"in_reply_to_id":259680063},"pull_request":{"url":"https://api.github.com/repos/polynote/polynote/pulls/72","id":255716492,"node_id":"MDExOlB1bGxSZXF1ZXN0MjU1NzE2NDky","html_url":"https://github.com/polynote/polynote/pull/72","diff_url":"https://github.com/polynote/polynote/pull/72.diff","patch_url":"https://github.com/polynote/polynote/pull/72.patch","issue_url":"https://api.github.com/repos/polynote/polynote/issues/72","number":72,"state":"open","locked":false,"title":"Symbols as results","user":{"login":"jeremyrsmith","id":864869,"node_id":"MDQ6VXNlcjg2NDg2OQ==","avatar_url":"https://avatars0.githubusercontent.com/u/864869?v=4","gravatar_id":"","url":"https://api.github.com/users/jeremyrsmith","html_url":"https://github.com/jeremyrsmith","followers_url":"https://api.github.com/users/jeremyrsmith/followers","following_url":"https://api.github.com/users/jeremyrsmith/following{/other_user}","gists_url":"https://api.github.com/users/jeremyrsmith/gists{/gist_id}","starred_url":"https://api.github.com/users/jeremyrsmith/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jeremyrsmith/subscriptions","organizations_url":"https://api.github.com/users/jeremyrsmith/orgs","repos_url":"https://api.github.com/users/jeremyrsmith/repos","events_url":"https://api.github.com/users/jeremyrsmith/events{/privacy}","received_events_url":"https://api.github.com/users/jeremyrsmith/received_events","type":"User","site_admin":false},"body":"Lots of work toward eliminating the UpdatedSymbols message as well as fixing the Global problem.\r\n\r\n- LanguageKernel is now renamed to LanguageInterpreter (TODO: oops, `LanguageKernelService` should also be renamed)\r\n   - Changed all instances I could find of `kernel` (referring to a `LanguageKernel`) to `interp` (since it's now a `LanguageInterpreter`)\r\n- GlobalInfo is renamed to KernelContext\r\n   - When you need the Global, import it from the KernelContext. Don't assign it to a new `val`!\r\n   - KernelContext should be the thing that's passed around (TODO: eliminate `Global` parameters and replace with `KernelContext`)\r\n   - TODO: KernelContext might become implicit, which would help syntax a lot (might be a problem in the case of a method that takes i.e. `ctx.global.Type`, as `ctx` has to be in the first parameter list. Whither dotty!)\r\n- Add `ResultValue` - a `Result` type which subsumes the idea of `SymbolInfo`. Client now listens to this result type in order to learn about symbols.\r\n- `RuntimeSymbolTable` no longer has the responsibility to push symbol info to the client. It's now purely tracking declared symbols. Should make it easier to replace it with a `CellContext` type of thing.\r\n- `PolyKernel` listens for `ResultValue` and pushes them to the symbol table.\r\n- `NotebookRef` listens for `ResultValue` and broadcasts them to clients.\r\n- Added `ValueRepr`, which defines representations of a value. Currently only `StringRepr` is used.\r\n   - TODO: create and implement a typeclass that defines reprs for a type\r\n   - TODO: implement kernel-side management of handle-based representations, and notebook-facing APIs for operating with them\r\n   - Removed type parametricity from `DataType` in order to make it easier to deal with. Typing will be handled separately; `DataType` is now purely a messaging concern.\r\n   - TODO: implement encoding scheme for binary data defined by a `DataType`\r\n   - TODO: should `StringRepr` and `HTMLRepr` be combined into `MIMERepr`, which would interop well with the `jvm-repr` project and ipynb format? I.E. just one `Repr` for all MIME-compatible types, of which a value could have many\r\n\r\nAlso fixed a few regressions:\r\n\r\n- Current symbols were no longer being sent with the notebook\r\n- Current tasks were no longer being sent with the notebook\r\n- Found a couple of bugs in the codec JS and fixed 'em","created_at":"2019-02-24T22:02:40Z","updated_at":"2019-02-25T17:06:06Z","closed_at":null,"merged_at":null,"merge_commit_sha":"136afd8dc2dc194c074848e83720a3bc137a76a8","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/polynote/polynote/pulls/72/commits","review_comments_url":"https://api.github.com/repos/polynote/polynote/pulls/72/comments","review_comment_url":"https://api.github.com/repos/polynote/polynote/pulls/comments{/number}","comments_url":"https://api.github.com/repos/polynote/polynote/issues/72/comments","statuses_url":"https://api.github.com/repos/polynote/polynote/statuses/e925250fe0d3d0e7d224d559580a4c48d5d17f55","head":{"label":"polynote:symbols-as-results","ref":"symbols-as-results","sha":"e925250fe0d3d0e7d224d559580a4c48d5d17f55","user":{"login":"polynote","id":46636556,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ2NjM2NTU2","avatar_url":"https://avatars1.githubusercontent.com/u/46636556?v=4","gravatar_id":"","url":"https://api.github.com/users/polynote","html_url":"https://github.com/polynote","followers_url":"https://api.github.com/users/polynote/followers","following_url":"https://api.github.com/users/polynote/following{/other_user}","gists_url":"https://api.github.com/users/polynote/gists{/gist_id}","starred_url":"https://api.github.com/users/polynote/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/polynote/subscriptions","organizations_url":"https://api.github.com/users/polynote/orgs","repos_url":"https://api.github.com/users/polynote/repos","events_url":"https://api.github.com/users/polynote/events{/privacy}","received_events_url":"https://api.github.com/users/polynote/received_events","type":"Organization","site_admin":false},"repo":{"id":165446099,"node_id":"MDEwOlJlcG9zaXRvcnkxNjU0NDYwOTk=","name":"polynote","full_name":"polynote/polynote","private":false,"owner":{"login":"polynote","id":46636556,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ2NjM2NTU2","avatar_url":"https://avatars1.githubusercontent.com/u/46636556?v=4","gravatar_id":"","url":"https://api.github.com/users/polynote","html_url":"https://github.com/polynote","followers_url":"https://api.github.com/users/polynote/followers","following_url":"https://api.github.com/users/polynote/following{/other_user}","gists_url":"https://api.github.com/users/polynote/gists{/gist_id}","starred_url":"https://api.github.com/users/polynote/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/polynote/subscriptions","organizations_url":"https://api.github.com/users/polynote/orgs","repos_url":"https://api.github.com/users/polynote/repos","events_url":"https://api.github.com/users/polynote/events{/privacy}","received_events_url":"https://api.github.com/users/polynote/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/polynote/polynote","description":"A better notebook for Scala (and more)","fork":false,"url":"https://api.github.com/repos/polynote/polynote","forks_url":"https://api.github.com/repos/polynote/polynote/forks","keys_url":"https://api.github.com/repos/polynote/polynote/keys{/key_id}","collaborators_url":"https://api.github.com/repos/polynote/polynote/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/polynote/polynote/teams","hooks_url":"https://api.github.com/repos/polynote/polynote/hooks","issue_events_url":"https://api.github.com/repos/polynote/polynote/issues/events{/number}","events_url":"https://api.github.com/repos/polynote/polynote/events","assignees_url":"https://api.github.com/repos/polynote/polynote/assignees{/user}","branches_url":"https://api.github.com/repos/polynote/polynote/branches{/branch}","tags_url":"https://api.github.com/repos/polynote/polynote/tags","blobs_url":"https://api.github.com/repos/polynote/polynote/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/polynote/polynote/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/polynote/polynote/git/refs{/sha}","trees_url":"https://api.github.com/repos/polynote/polynote/git/trees{/sha}","statuses_url":"https://api.github.com/repos/polynote/polynote/statuses/{sha}","languages_url":"https://api.github.com/repos/polynote/polynote/languages","stargazers_url":"https://api.github.com/repos/polynote/polynote/stargazers","contributors_url":"https://api.github.com/repos/polynote/polynote/contributors","subscribers_url":"https://api.github.com/repos/polynote/polynote/subscribers","subscription_url":"https://api.github.com/repos/polynote/polynote/subscription","commits_url":"https://api.github.com/repos/polynote/polynote/commits{/sha}","git_commits_url":"https://api.github.com/repos/polynote/polynote/git/commits{/sha}","comments_url":"https://api.github.com/repos/polynote/polynote/comments{/number}","issue_comment_url":"https://api.github.com/repos/polynote/polynote/issues/comments{/number}","contents_url":"https://api.github.com/repos/polynote/polynote/contents/{+path}","compare_url":"https://api.github.com/repos/polynote/polynote/compare/{base}...{head}","merges_url":"https://api.github.com/repos/polynote/polynote/merges","archive_url":"https://api.github.com/repos/polynote/polynote/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/polynote/polynote/downloads","issues_url":"https://api.github.com/repos/polynote/polynote/issues{/number}","pulls_url":"https://api.github.com/repos/polynote/polynote/pulls{/number}","milestones_url":"https://api.github.com/repos/polynote/polynote/milestones{/number}","notifications_url":"https://api.github.com/repos/polynote/polynote/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/polynote/polynote/labels{/name}","releases_url":"https://api.github.com/repos/polynote/polynote/releases{/id}","deployments_url":"https://api.github.com/repos/polynote/polynote/deployments","created_at":"2019-01-12T23:22:41Z","updated_at":"2019-02-22T18:39:02Z","pushed_at":"2019-02-25T17:04:07Z","git_url":"git://github.com/polynote/polynote.git","ssh_url":"git@github.com:polynote/polynote.git","clone_url":"https://github.com/polynote/polynote.git","svn_url":"https://github.com/polynote/polynote","homepage":null,"size":1578,"stargazers_count":4,"watchers_count":4,"language":"Scala","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":26,"license":null,"forks":1,"open_issues":26,"watchers":4,"default_branch":"master"}},"base":{"label":"polynote:master","ref":"master","sha":"99441d564fc68eca6c1c2e5008409dbf88274af4","user":{"login":"polynote","id":46636556,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ2NjM2NTU2","avatar_url":"https://avatars1.githubusercontent.com/u/46636556?v=4","gravatar_id":"","url":"https://api.github.com/users/polynote","html_url":"https://github.com/polynote","followers_url":"https://api.github.com/users/polynote/followers","following_url":"https://api.github.com/users/polynote/following{/other_user}","gists_url":"https://api.github.com/users/polynote/gists{/gist_id}","starred_url":"https://api.github.com/users/polynote/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/polynote/subscriptions","organizations_url":"https://api.github.com/users/polynote/orgs","repos_url":"https://api.github.com/users/polynote/repos","events_url":"https://api.github.com/users/polynote/events{/privacy}","received_events_url":"https://api.github.com/users/polynote/received_events","type":"Organization","site_admin":false},"repo":{"id":165446099,"node_id":"MDEwOlJlcG9zaXRvcnkxNjU0NDYwOTk=","name":"polynote","full_name":"polynote/polynote","private":false,"owner":{"login":"polynote","id":46636556,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ2NjM2NTU2","avatar_url":"https://avatars1.githubusercontent.com/u/46636556?v=4","gravatar_id":"","url":"https://api.github.com/users/polynote","html_url":"https://github.com/polynote","followers_url":"https://api.github.com/users/polynote/followers","following_url":"https://api.github.com/users/polynote/following{/other_user}","gists_url":"https://api.github.com/users/polynote/gists{/gist_id}","starred_url":"https://api.github.com/users/polynote/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/polynote/subscriptions","organizations_url":"https://api.github.com/users/polynote/orgs","repos_url":"https://api.github.com/users/polynote/repos","events_url":"https://api.github.com/users/polynote/events{/privacy}","received_events_url":"https://api.github.com/users/polynote/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/polynote/polynote","description":"A better notebook for Scala (and more)","fork":false,"url":"https://api.github.com/repos/polynote/polynote","forks_url":"https://api.github.com/repos/polynote/polynote/forks","keys_url":"https://api.github.com/repos/polynote/polynote/keys{/key_id}","collaborators_url":"https://api.github.com/repos/polynote/polynote/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/polynote/polynote/teams","hooks_url":"https://api.github.com/repos/polynote/polynote/hooks","issue_events_url":"https://api.github.com/repos/polynote/polynote/issues/events{/number}","events_url":"https://api.github.com/repos/polynote/polynote/events","assignees_url":"https://api.github.com/repos/polynote/polynote/assignees{/user}","branches_url":"https://api.github.com/repos/polynote/polynote/branches{/branch}","tags_url":"https://api.github.com/repos/polynote/polynote/tags","blobs_url":"https://api.github.com/repos/polynote/polynote/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/polynote/polynote/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/polynote/polynote/git/refs{/sha}","trees_url":"https://api.github.com/repos/polynote/polynote/git/trees{/sha}","statuses_url":"https://api.github.com/repos/polynote/polynote/statuses/{sha}","languages_url":"https://api.github.com/repos/polynote/polynote/languages","stargazers_url":"https://api.github.com/repos/polynote/polynote/stargazers","contributors_url":"https://api.github.com/repos/polynote/polynote/contributors","subscribers_url":"https://api.github.com/repos/polynote/polynote/subscribers","subscription_url":"https://api.github.com/repos/polynote/polynote/subscription","commits_url":"https://api.github.com/repos/polynote/polynote/commits{/sha}","git_commits_url":"https://api.github.com/repos/polynote/polynote/git/commits{/sha}","comments_url":"https://api.github.com/repos/polynote/polynote/comments{/number}","issue_comment_url":"https://api.github.com/repos/polynote/polynote/issues/comments{/number}","contents_url":"https://api.github.com/repos/polynote/polynote/contents/{+path}","compare_url":"https://api.github.com/repos/polynote/polynote/compare/{base}...{head}","merges_url":"https://api.github.com/repos/polynote/polynote/merges","archive_url":"https://api.github.com/repos/polynote/polynote/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/polynote/polynote/downloads","issues_url":"https://api.github.com/repos/polynote/polynote/issues{/number}","pulls_url":"https://api.github.com/repos/polynote/polynote/pulls{/number}","milestones_url":"https://api.github.com/repos/polynote/polynote/milestones{/number}","notifications_url":"https://api.github.com/repos/polynote/polynote/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/polynote/polynote/labels{/name}","releases_url":"https://api.github.com/repos/polynote/polynote/releases{/id}","deployments_url":"https://api.github.com/repos/polynote/polynote/deployments","created_at":"2019-01-12T23:22:41Z","updated_at":"2019-02-22T18:39:02Z","pushed_at":"2019-02-25T17:04:07Z","git_url":"git://github.com/polynote/polynote.git","ssh_url":"git@github.com:polynote/polynote.git","clone_url":"https://github.com/polynote/polynote.git","svn_url":"https://github.com/polynote/polynote","homepage":null,"size":1578,"stargazers_count":4,"watchers_count":4,"language":"Scala","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":26,"license":null,"forks":1,"open_issues":26,"watchers":4,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/polynote/polynote/pulls/72"},"html":{"href":"https://github.com/polynote/polynote/pull/72"},"issue":{"href":"https://api.github.com/repos/polynote/polynote/issues/72"},"comments":{"href":"https://api.github.com/repos/polynote/polynote/issues/72/comments"},"review_comments":{"href":"https://api.github.com/repos/polynote/polynote/pulls/72/comments"},"review_comment":{"href":"https://api.github.com/repos/polynote/polynote/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/polynote/polynote/pulls/72/commits"},"statuses":{"href":"https://api.github.com/repos/polynote/polynote/statuses/e925250fe0d3d0e7d224d559580a4c48d5d17f55"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"jeremyrsmith"}}