{"action":"created","comment":{"url":"https://api.github.com/repos/IRkernel/IRkernel/pulls/comments/98396905","pull_request_review_id":19033900,"id":98396905,"diff_hunk":"@@ -242,6 +243,71 @@ complete = function(request) {\n         cursor_end = start_position + nchar(c.info$token)))\n },\n \n+inspect = function(request) {\n+    # 5.0 protocol:\n+    code <- request$content$code\n+    cursor_pos <- request$content$cursor_pos\n+\n+    title_templates <- list(\n+        'text/plain' = '# %s:\\n',\n+        'text/html' = '<h1>%s:</h1>\\n')\n+    # Function to add a section to content.\n+    add_new_section <- function (data, section_name, new_data) {\n+        for (mime in names(new_section_adders)) {\n+            new_content <- new_data[[mime]]\n+            if (is.null(new_content)) next\n+            title <- sprintf(title_templates, section_name)\n+            # use paste0 since sprintf cannot deal with format strings > 8192 bytes\n+            data[[mime]] <- paste0(content, title, new_content, '\\n', sep = '\\n')\n+        }\n+        return(data)\n+    }\n+\n+    # Get token under the `cursor_pos`.\n+    # Since `.guessTokenFromLine()` does not check the characters after `cursor_pos`\n+    # check them by a loop.\n+    token <- ''\n+    for (i in seq(cursor_pos, nchar(code))) {\n+        token_candidate <- utils:::.guessTokenFromLine(code, i)\n+        if (nchar(token_candidate) == 0) break\n+        token <- token_candidate\n+    }\n+\n+    data <- namedlist()\n+    if (nchar(token) != 0) {\n+        tryCatch(\n+            {\n+                # In many cases `get(token)` works, but it does not\n+                # in the cases such as `token` is a numeric constant or reserved word.\n+                # Therefore `eval()` is used here.\n+                obj <- eval(parse(text = token))\n+\n+                class_data <- IRdisplay::prepare_mimebundle(class(obj))$data\n+                data <- add_new_section(data, 'Class attribute', class_data)\n+\n+                print_data <- IRdisplay::prepare_mimebundle(obj)$data\n+                data <- add_new_section(data, 'Printed form', print_data)\n+            },\n+            error = function (e) NULL)\n+        tryCatch(\n+            {\n+                # `help(token)` is  not used here because it does not works\n+                # in the cases `token` is in `pkg::topic`or `pkg:::topic` form.\n+                help_obj <- eval(parse(text = paste0('?', token)))\n+                help_data <- IRdisplay::prepare_mimebundle(help_obj)$data\n+                data <- add_new_section(data, 'Help document', help_data)\n+            },\n+            error = function (e) NULL)\n+    }\n+    found <- (length(data) != 0)\n+    send_response('inspect_reply', request, 'shell', list(\n+        status = 'ok',\n+        found = found,\n+        data = data,\n+        metadata = namedlist()\n+        ))","path":"R/kernel.r","position":74,"original_position":74,"commit_id":"c8bf76633d9159b770359be4d9ff318504a9ac68","original_commit_id":"c8bf76633d9159b770359be4d9ff318504a9ac68","user":{"login":"flying-sheep","id":291575,"avatar_url":"https://avatars.githubusercontent.com/u/291575?v=3","gravatar_id":"","url":"https://api.github.com/users/flying-sheep","html_url":"https://github.com/flying-sheep","followers_url":"https://api.github.com/users/flying-sheep/followers","following_url":"https://api.github.com/users/flying-sheep/following{/other_user}","gists_url":"https://api.github.com/users/flying-sheep/gists{/gist_id}","starred_url":"https://api.github.com/users/flying-sheep/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flying-sheep/subscriptions","organizations_url":"https://api.github.com/users/flying-sheep/orgs","repos_url":"https://api.github.com/users/flying-sheep/repos","events_url":"https://api.github.com/users/flying-sheep/events{/privacy}","received_events_url":"https://api.github.com/users/flying-sheep/received_events","type":"User","site_admin":false},"body":"style: put `))` on previous line","created_at":"2017-01-30T08:51:04Z","updated_at":"2017-01-30T08:52:23Z","html_url":"https://github.com/IRkernel/IRkernel/pull/441#discussion_r98396905","pull_request_url":"https://api.github.com/repos/IRkernel/IRkernel/pulls/441","_links":{"self":{"href":"https://api.github.com/repos/IRkernel/IRkernel/pulls/comments/98396905"},"html":{"href":"https://github.com/IRkernel/IRkernel/pull/441#discussion_r98396905"},"pull_request":{"href":"https://api.github.com/repos/IRkernel/IRkernel/pulls/441"}}},"pull_request":{"url":"https://api.github.com/repos/IRkernel/IRkernel/pulls/441","id":103342844,"html_url":"https://github.com/IRkernel/IRkernel/pull/441","diff_url":"https://github.com/IRkernel/IRkernel/pull/441.diff","patch_url":"https://github.com/IRkernel/IRkernel/pull/441.patch","issue_url":"https://api.github.com/repos/IRkernel/IRkernel/issues/441","number":441,"state":"open","locked":false,"title":"Support `inspect_request` type message.","user":{"login":"ngr-t","id":729653,"avatar_url":"https://avatars.githubusercontent.com/u/729653?v=3","gravatar_id":"","url":"https://api.github.com/users/ngr-t","html_url":"https://github.com/ngr-t","followers_url":"https://api.github.com/users/ngr-t/followers","following_url":"https://api.github.com/users/ngr-t/following{/other_user}","gists_url":"https://api.github.com/users/ngr-t/gists{/gist_id}","starred_url":"https://api.github.com/users/ngr-t/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ngr-t/subscriptions","organizations_url":"https://api.github.com/users/ngr-t/orgs","repos_url":"https://api.github.com/users/ngr-t/repos","events_url":"https://api.github.com/users/ngr-t/events{/privacy}","received_events_url":"https://api.github.com/users/ngr-t/received_events","type":"User","site_admin":false},"body":"Dear IRkernel maintainers,\r\n\r\nIn this PR I modified IRkernel to reply `inspect_request` type message, which is currently not supported. Therefore `shift+tab` key works now, to show a tooltip or page for object inspection as below.\r\n\r\n![tooltip](https://cloud.githubusercontent.com/assets/729653/22338256/47536036-e42a-11e6-9042-0113b5a1bacb.png)\r\n\r\nI intended this is just a draft proposal, there will be much to improve. Especially we should discuss about the format of object inspection.\r\n\r\n## Motivation\r\n\r\nThough there is already well-working pager to show help page within Jupyter Notebook, there are requests to get object inspection in a tooltip as #299. Also there are and will be some apps other than Jupyter Notebook which use Jupyter messaging protocol (like JupyterLab or Hydrogen package for Atom editor) and they would use `inspect_request` message. Therefore I think supporting it is so helpful.\r\n\r\n## Format of object inspection\r\n\r\nBelow is a brief description of the format of object inspection in my current implementation.\r\n\r\n### Sections of object inspection\r\n\r\nBasically an object inspection has sections as\r\n\r\n- \"Class attribute\"\r\n- \"Printed form\"\r\n- \"Help document\".\r\n\r\nSome sections will be omitted if we cannot extract the information.\r\n\r\nThe value of `base::class()` is used for \"Class attribute\" section.\r\n\r\nThe value of `IRdisplay::prepare_mimebundle()` is used for the content of \"Printed form\".\r\n\r\n\"Help document\" uses the value of `IRdisplay::prepare_mimebundle()`, but call it with putting `?` at the head of the inspected object name.\r\n\r\nMaybe there are several things we should add to it.\r\n\r\n### `data` types\r\n\r\n`data` object in `inspect_reply` message has two type, which are `text/plain` and `text/html`, for now.\r\n\r\n`IRdisplay::prepare_mimebundle()` returns also `text/latex` type and `text/markdown` type content, so supporting them should be not so difficult.\r\n\r\n---\r\n\r\nYou can try it with installing this branch from my repo.\r\n```{R}\r\n> devtools::install_github(\"ngr-t/IRkernel\", ref = \"support_inspect_request\")\r\n```\r\n\r\nI hope this PR interests you and helps IRkernel to support good object inspection.\r\n\r\nThanks!","created_at":"2017-01-26T16:41:38Z","updated_at":"2017-01-30T08:52:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c414c53c655dff175dfc9bb3eeda85d7cf99026c","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/IRkernel/IRkernel/pulls/441/commits","review_comments_url":"https://api.github.com/repos/IRkernel/IRkernel/pulls/441/comments","review_comment_url":"https://api.github.com/repos/IRkernel/IRkernel/pulls/comments{/number}","comments_url":"https://api.github.com/repos/IRkernel/IRkernel/issues/441/comments","statuses_url":"https://api.github.com/repos/IRkernel/IRkernel/statuses/c8bf76633d9159b770359be4d9ff318504a9ac68","head":{"label":"ngr-t:support_inspect_request","ref":"support_inspect_request","sha":"c8bf76633d9159b770359be4d9ff318504a9ac68","user":{"login":"ngr-t","id":729653,"avatar_url":"https://avatars.githubusercontent.com/u/729653?v=3","gravatar_id":"","url":"https://api.github.com/users/ngr-t","html_url":"https://github.com/ngr-t","followers_url":"https://api.github.com/users/ngr-t/followers","following_url":"https://api.github.com/users/ngr-t/following{/other_user}","gists_url":"https://api.github.com/users/ngr-t/gists{/gist_id}","starred_url":"https://api.github.com/users/ngr-t/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ngr-t/subscriptions","organizations_url":"https://api.github.com/users/ngr-t/orgs","repos_url":"https://api.github.com/users/ngr-t/repos","events_url":"https://api.github.com/users/ngr-t/events{/privacy}","received_events_url":"https://api.github.com/users/ngr-t/received_events","type":"User","site_admin":false},"repo":{"id":79920888,"name":"IRkernel","full_name":"ngr-t/IRkernel","owner":{"login":"ngr-t","id":729653,"avatar_url":"https://avatars.githubusercontent.com/u/729653?v=3","gravatar_id":"","url":"https://api.github.com/users/ngr-t","html_url":"https://github.com/ngr-t","followers_url":"https://api.github.com/users/ngr-t/followers","following_url":"https://api.github.com/users/ngr-t/following{/other_user}","gists_url":"https://api.github.com/users/ngr-t/gists{/gist_id}","starred_url":"https://api.github.com/users/ngr-t/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ngr-t/subscriptions","organizations_url":"https://api.github.com/users/ngr-t/orgs","repos_url":"https://api.github.com/users/ngr-t/repos","events_url":"https://api.github.com/users/ngr-t/events{/privacy}","received_events_url":"https://api.github.com/users/ngr-t/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ngr-t/IRkernel","description":"R kernel for Jupyter","fork":true,"url":"https://api.github.com/repos/ngr-t/IRkernel","forks_url":"https://api.github.com/repos/ngr-t/IRkernel/forks","keys_url":"https://api.github.com/repos/ngr-t/IRkernel/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ngr-t/IRkernel/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ngr-t/IRkernel/teams","hooks_url":"https://api.github.com/repos/ngr-t/IRkernel/hooks","issue_events_url":"https://api.github.com/repos/ngr-t/IRkernel/issues/events{/number}","events_url":"https://api.github.com/repos/ngr-t/IRkernel/events","assignees_url":"https://api.github.com/repos/ngr-t/IRkernel/assignees{/user}","branches_url":"https://api.github.com/repos/ngr-t/IRkernel/branches{/branch}","tags_url":"https://api.github.com/repos/ngr-t/IRkernel/tags","blobs_url":"https://api.github.com/repos/ngr-t/IRkernel/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ngr-t/IRkernel/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ngr-t/IRkernel/git/refs{/sha}","trees_url":"https://api.github.com/repos/ngr-t/IRkernel/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ngr-t/IRkernel/statuses/{sha}","languages_url":"https://api.github.com/repos/ngr-t/IRkernel/languages","stargazers_url":"https://api.github.com/repos/ngr-t/IRkernel/stargazers","contributors_url":"https://api.github.com/repos/ngr-t/IRkernel/contributors","subscribers_url":"https://api.github.com/repos/ngr-t/IRkernel/subscribers","subscription_url":"https://api.github.com/repos/ngr-t/IRkernel/subscription","commits_url":"https://api.github.com/repos/ngr-t/IRkernel/commits{/sha}","git_commits_url":"https://api.github.com/repos/ngr-t/IRkernel/git/commits{/sha}","comments_url":"https://api.github.com/repos/ngr-t/IRkernel/comments{/number}","issue_comment_url":"https://api.github.com/repos/ngr-t/IRkernel/issues/comments{/number}","contents_url":"https://api.github.com/repos/ngr-t/IRkernel/contents/{+path}","compare_url":"https://api.github.com/repos/ngr-t/IRkernel/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ngr-t/IRkernel/merges","archive_url":"https://api.github.com/repos/ngr-t/IRkernel/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ngr-t/IRkernel/downloads","issues_url":"https://api.github.com/repos/ngr-t/IRkernel/issues{/number}","pulls_url":"https://api.github.com/repos/ngr-t/IRkernel/pulls{/number}","milestones_url":"https://api.github.com/repos/ngr-t/IRkernel/milestones{/number}","notifications_url":"https://api.github.com/repos/ngr-t/IRkernel/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ngr-t/IRkernel/labels{/name}","releases_url":"https://api.github.com/repos/ngr-t/IRkernel/releases{/id}","deployments_url":"https://api.github.com/repos/ngr-t/IRkernel/deployments","created_at":"2017-01-24T14:51:56Z","updated_at":"2017-01-24T14:51:58Z","pushed_at":"2017-01-29T23:54:15Z","git_url":"git://github.com/ngr-t/IRkernel.git","ssh_url":"git@github.com:ngr-t/IRkernel.git","clone_url":"https://github.com/ngr-t/IRkernel.git","svn_url":"https://github.com/ngr-t/IRkernel","homepage":"https://irkernel.github.io/","size":601,"stargazers_count":0,"watchers_count":0,"language":"Jupyter Notebook","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"IRkernel:master","ref":"master","sha":"ff78a040cfbc963a78af670aa2df8627b8bd5b61","user":{"login":"IRkernel","id":11616939,"avatar_url":"https://avatars.githubusercontent.com/u/11616939?v=3","gravatar_id":"","url":"https://api.github.com/users/IRkernel","html_url":"https://github.com/IRkernel","followers_url":"https://api.github.com/users/IRkernel/followers","following_url":"https://api.github.com/users/IRkernel/following{/other_user}","gists_url":"https://api.github.com/users/IRkernel/gists{/gist_id}","starred_url":"https://api.github.com/users/IRkernel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/IRkernel/subscriptions","organizations_url":"https://api.github.com/users/IRkernel/orgs","repos_url":"https://api.github.com/users/IRkernel/repos","events_url":"https://api.github.com/users/IRkernel/events{/privacy}","received_events_url":"https://api.github.com/users/IRkernel/received_events","type":"Organization","site_admin":false},"repo":{"id":17196838,"name":"IRkernel","full_name":"IRkernel/IRkernel","owner":{"login":"IRkernel","id":11616939,"avatar_url":"https://avatars.githubusercontent.com/u/11616939?v=3","gravatar_id":"","url":"https://api.github.com/users/IRkernel","html_url":"https://github.com/IRkernel","followers_url":"https://api.github.com/users/IRkernel/followers","following_url":"https://api.github.com/users/IRkernel/following{/other_user}","gists_url":"https://api.github.com/users/IRkernel/gists{/gist_id}","starred_url":"https://api.github.com/users/IRkernel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/IRkernel/subscriptions","organizations_url":"https://api.github.com/users/IRkernel/orgs","repos_url":"https://api.github.com/users/IRkernel/repos","events_url":"https://api.github.com/users/IRkernel/events{/privacy}","received_events_url":"https://api.github.com/users/IRkernel/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/IRkernel/IRkernel","description":"R kernel for Jupyter","fork":false,"url":"https://api.github.com/repos/IRkernel/IRkernel","forks_url":"https://api.github.com/repos/IRkernel/IRkernel/forks","keys_url":"https://api.github.com/repos/IRkernel/IRkernel/keys{/key_id}","collaborators_url":"https://api.github.com/repos/IRkernel/IRkernel/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/IRkernel/IRkernel/teams","hooks_url":"https://api.github.com/repos/IRkernel/IRkernel/hooks","issue_events_url":"https://api.github.com/repos/IRkernel/IRkernel/issues/events{/number}","events_url":"https://api.github.com/repos/IRkernel/IRkernel/events","assignees_url":"https://api.github.com/repos/IRkernel/IRkernel/assignees{/user}","branches_url":"https://api.github.com/repos/IRkernel/IRkernel/branches{/branch}","tags_url":"https://api.github.com/repos/IRkernel/IRkernel/tags","blobs_url":"https://api.github.com/repos/IRkernel/IRkernel/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/IRkernel/IRkernel/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/IRkernel/IRkernel/git/refs{/sha}","trees_url":"https://api.github.com/repos/IRkernel/IRkernel/git/trees{/sha}","statuses_url":"https://api.github.com/repos/IRkernel/IRkernel/statuses/{sha}","languages_url":"https://api.github.com/repos/IRkernel/IRkernel/languages","stargazers_url":"https://api.github.com/repos/IRkernel/IRkernel/stargazers","contributors_url":"https://api.github.com/repos/IRkernel/IRkernel/contributors","subscribers_url":"https://api.github.com/repos/IRkernel/IRkernel/subscribers","subscription_url":"https://api.github.com/repos/IRkernel/IRkernel/subscription","commits_url":"https://api.github.com/repos/IRkernel/IRkernel/commits{/sha}","git_commits_url":"https://api.github.com/repos/IRkernel/IRkernel/git/commits{/sha}","comments_url":"https://api.github.com/repos/IRkernel/IRkernel/comments{/number}","issue_comment_url":"https://api.github.com/repos/IRkernel/IRkernel/issues/comments{/number}","contents_url":"https://api.github.com/repos/IRkernel/IRkernel/contents/{+path}","compare_url":"https://api.github.com/repos/IRkernel/IRkernel/compare/{base}...{head}","merges_url":"https://api.github.com/repos/IRkernel/IRkernel/merges","archive_url":"https://api.github.com/repos/IRkernel/IRkernel/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/IRkernel/IRkernel/downloads","issues_url":"https://api.github.com/repos/IRkernel/IRkernel/issues{/number}","pulls_url":"https://api.github.com/repos/IRkernel/IRkernel/pulls{/number}","milestones_url":"https://api.github.com/repos/IRkernel/IRkernel/milestones{/number}","notifications_url":"https://api.github.com/repos/IRkernel/IRkernel/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/IRkernel/IRkernel/labels{/name}","releases_url":"https://api.github.com/repos/IRkernel/IRkernel/releases{/id}","deployments_url":"https://api.github.com/repos/IRkernel/IRkernel/deployments","created_at":"2014-02-26T02:57:07Z","updated_at":"2017-01-28T15:18:10Z","pushed_at":"2017-01-29T23:54:17Z","git_url":"git://github.com/IRkernel/IRkernel.git","ssh_url":"git@github.com:IRkernel/IRkernel.git","clone_url":"https://github.com/IRkernel/IRkernel.git","svn_url":"https://github.com/IRkernel/IRkernel","homepage":"https://irkernel.github.io/","size":590,"stargazers_count":609,"watchers_count":609,"language":"Jupyter Notebook","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":115,"mirror_url":null,"open_issues_count":68,"forks":115,"open_issues":68,"watchers":609,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/IRkernel/IRkernel/pulls/441"},"html":{"href":"https://github.com/IRkernel/IRkernel/pull/441"},"issue":{"href":"https://api.github.com/repos/IRkernel/IRkernel/issues/441"},"comments":{"href":"https://api.github.com/repos/IRkernel/IRkernel/issues/441/comments"},"review_comments":{"href":"https://api.github.com/repos/IRkernel/IRkernel/pulls/441/comments"},"review_comment":{"href":"https://api.github.com/repos/IRkernel/IRkernel/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/IRkernel/IRkernel/pulls/441/commits"},"statuses":{"href":"https://api.github.com/repos/IRkernel/IRkernel/statuses/c8bf76633d9159b770359be4d9ff318504a9ac68"}}}}
{"actor":{"display_login":"flying-sheep"}}