Skip to content

Commit

Permalink
Added comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
janpfeifer committed Apr 21, 2023
1 parent 9fc0b15 commit a53ab67
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ Contributions are welcome!
* Run `goimports` before calling `gopls` to inspect a variable, or auto-complete. This
would be handy, but complicates tracking the position of the cursor on the changed
file.
* Create a JupyterLab extension to allows the Go code to create and interact with widgets. Or
alternatively open a WebSocket from the widget to the kernel. Some links:
* https://github.com/jupyterlab/extension-examples
* https://jupyter-notebook.readthedocs.io/en/4.x/comms.html
* https://jupyter-client.readthedocs.io/en/latest/api/jupyter_client.asynchronous.html#jupyter_client.asynchronous.client.AsyncKernelClient.comm_info
* https://discourse.jupyter.org/c/jupyterlab/extensions/43

# Implementation

Expand Down
13 changes: 12 additions & 1 deletion goexec/goexec.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ import (
"regexp"
)

// State holds information about Go code execution for this kernel. It's a singleton (for now).
// It hols the directory, ids, configuration, command line arguments to use and currently
// defined Go code.
//
// That is, if the user runs a cell that defines, let's say `func f(x int) int { return x+1 }`,
// the declaration of `f` will be stored in Decls field.
type State struct {
// Temporary directory where Go program is build at each execution.
UniqueID, Package, TempDir string
Expand Down Expand Up @@ -182,8 +188,9 @@ func (c *Cursor) CursorFrom(line, col int) Cursor {
return Cursor{Line: c.Line + line, Col: c.Col + col}
}

// ClearCursor resets the cursor to an invalid state.
func (c *Cursor) ClearCursor() {
c.Line = -1
c.Line = NoCursorLine
}

// Function definition.
Expand Down Expand Up @@ -249,6 +256,10 @@ func NewImport(importPath, alias string) *Import {
return &Import{Key: key, Path: importPath, Alias: alias}
}

// Reset clears all the memorized Go declarations. It becomes as if no cells had
// been executed so far -- except for configurations and arguments that remain unchanged.
//
// It is connected to the special command `%reset`.
func (s *State) Reset() {
s.Decls = NewDeclarations()
}

0 comments on commit a53ab67

Please sign in to comment.