Skip to content

Commit

Permalink
πŸ“š Type ?something for docs
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsp committed Aug 30, 2020
1 parent 7be3b55 commit d402723
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
12 changes: 10 additions & 2 deletions frontend/components/CellInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,22 @@ export const CellInput = ({
}
} else {
const token = cm.getTokenAt(cm.getCursor())
if (token.type != null && token.type != "string") {
if(token.start === 0 && token.type === "operator" && token.string === "?"){
// https://github.com/fonsp/Pluto.jl/issues/321
const second_token = cm.getTokenAt({...cm.getCursor(), ch: 2})
on_update_doc_query(second_token.string)
} else if (token.type != null && token.type !== "string") {
on_update_doc_query(token.string)
}
}
})

cm.on("change", () => {
change_handler_ref.current(cm.getValue())
const new_value = cm.getValue()
if(new_value.length > 1 && new_value[0] === "?"){
window.dispatchEvent(new CustomEvent("open_live_docs"))
}
change_handler_ref.current(new_value)
})

// cm.on("focus", () => {
Expand Down
16 changes: 14 additions & 2 deletions frontend/components/LiveDocs.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,25 @@ export class LiveDocs extends Component {
this.state = {
shown_query: null,
searched_query: null,
body: "Start typing code to learn more!",
hidden: true,
body: "Start typing in a cell to learn more!",
hidden: false,
loading: false,
}
this.updateDocTimer = undefined
}

componentDidMount() {
window.addEventListener("open_live_docs", () => {
// https://github.com/fonsp/Pluto.jl/issues/321
this.setState({
hidden: false,
})
if (window.getComputedStyle(this.base).display === "none") {
alert("This browser window is too small to show docs.\n\nMake the window bigger, or try zooming out.")
}
})
}

componentDidUpdate() {
if (this.state.hidden || this.state.loading) {
return
Expand Down
1 change: 0 additions & 1 deletion frontend/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const whiteList = ["www.gstatic.com", "fonts.gstatic.com", "fonts.googleapis.com

function shouldCache(request) {
const url = new URL(request.url)
console.log(url.host)
return whiteList.includes(url.host)
}

Expand Down
6 changes: 6 additions & 0 deletions test/Dynamic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ stringify_keys(x::Any) = x
# TODO: we need to wait for all above command to finish before we can do this:
# send(:shutdown_notebook, Dict(:keep_in_session => false), Dict(:notebook_id => n))
end

@testset "Docs" begin
@test occursin("square root", Pluto.PlutoRunner.doc_fetcher("sqrt")[1])
@test occursin("square root", Pluto.PlutoRunner.doc_fetcher("Base.sqrt")[1])
@test occursin("No documentation found", Pluto.PlutoRunner.doc_fetcher("Base.findmeta")[1])
end
end

# TODO: test returned data

1 comment on commit d402723

@fonsp
Copy link
Owner Author

@fonsp fonsp commented on d402723 Aug 30, 2020

Choose a reason for hiding this comment

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

Please sign in to comment.