Skip to content

Commit

Permalink
Merge pull request #161 from janpfeifer/refactor
Browse files Browse the repository at this point in the history
v0.10.11
  • Loading branch information
janpfeifer authored Feb 2, 2025
2 parents 1724d57 + a78e6fd commit 2604250
Show file tree
Hide file tree
Showing 21 changed files with 218 additions and 157 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ RUN go install golang.org/x/tools/cmd/goimports@latest && \
go install golang.org/x/tools/gopls@latest

# Clone from main, build&install gonb binary, and then install it as a kernel in Jupyter.
# - First introduce the cache-busting argument. This number can be bumped whenever we only want
# to rebuild the gonb part.
ARG CACHEBUST=2
WORKDIR ${HOME}
RUN git clone 'https://github.com/janpfeifer/gonb.git'
WORKDIR ${HOME}/gonb
Expand Down
6 changes: 6 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# GoNB Changelog

## v0.10.11, 2025/02/02

* New --version and -V flags to print version; Improved `%version` output. (#158)
* Clean up, refactorings and fixed context leakage.
* Added `version.txt` with target version for build.

## v0.10.10, 2025/01/28

* Reverted `replace` directive: contrary to what the AI suggested, it doesn't work when running from outside a cloned repository.
Expand Down
23 changes: 16 additions & 7 deletions docs/coverage.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
github.com/janpfeifer/gonb/main.go init 100.0%
github.com/janpfeifer/gonb/main.go main 60.0%
github.com/janpfeifer/gonb/main.go SetUpLogging 66.7%
github.com/janpfeifer/gonb/main.go main 63.2%
github.com/janpfeifer/gonb/main.go install 66.7%
github.com/janpfeifer/gonb/main.go printVersion 42.9%
github.com/janpfeifer/gonb/main.go setUpExtraLog 15.4%
github.com/janpfeifer/gonb/main.go setUpLogging 66.7%
github.com/janpfeifer/gonb/main.go prepend 100.0%
github.com/janpfeifer/gonb/main.go UniqueIDFilter.Filter 100.0%
github.com/janpfeifer/gonb/main.go UniqueIDFilter.FilterF 100.0%
github.com/janpfeifer/gonb/main.go UniqueIDFilter.FilterS 0.0%
github.com/janpfeifer/gonb/main.go SetUpKlog 66.7%
github.com/janpfeifer/gonb/main.go setUpKlog 83.3%
github.com/janpfeifer/gonb/main.go runKernel 78.3%
github.com/janpfeifer/gonb/version.go must 50.0%
github.com/janpfeifer/gonb/version.go init 100.0%
github.com/janpfeifer/gonb/cache/cache.go New 75.0%
Expand Down Expand Up @@ -289,8 +293,8 @@ github.com/janpfeifer/gonb/internal/goexec/wasm.go *State.ExportWasmConstants
github.com/janpfeifer/gonb/internal/goexec/wasm.go *State.RemoveWasmConstants 0.0%
github.com/janpfeifer/gonb/internal/goexec/goplsclient/conn.go *Client.ConnClose 0.0%
github.com/janpfeifer/gonb/internal/goexec/goplsclient/conn.go *Client.connCloseLocked 100.0%
github.com/janpfeifer/gonb/internal/goexec/goplsclient/conn.go minTimeout 100.0%
github.com/janpfeifer/gonb/internal/goexec/goplsclient/conn.go *Client.Connect 63.4%
github.com/janpfeifer/gonb/internal/goexec/goplsclient/conn.go minTimeout 83.3%
github.com/janpfeifer/gonb/internal/goexec/goplsclient/conn.go *Client.Connect 64.3%
github.com/janpfeifer/gonb/internal/goexec/goplsclient/conn.go *Client.NotifyDidOpenOrChange 0.0%
github.com/janpfeifer/gonb/internal/goexec/goplsclient/conn.go *Client.notifyDidOpenOrChangeLocked 0.0%
github.com/janpfeifer/gonb/internal/goexec/goplsclient/conn.go *Client.CallDefinition 0.0%
Expand Down Expand Up @@ -415,11 +419,16 @@ github.com/janpfeifer/gonb/internal/specialcmd/definitions.go removeDefinitionI
github.com/janpfeifer/gonb/internal/specialcmd/definitions.go removeDefinitions 91.7%
github.com/janpfeifer/gonb/internal/specialcmd/specialcmd.go Parse 84.6%
github.com/janpfeifer/gonb/internal/specialcmd/specialcmd.go joinLine 87.5%
github.com/janpfeifer/gonb/internal/specialcmd/specialcmd.go execSpecialConfig 55.1%
github.com/janpfeifer/gonb/internal/specialcmd/specialcmd.go execSpecialConfig 56.9%
github.com/janpfeifer/gonb/internal/specialcmd/specialcmd.go execShell 100.0%
github.com/janpfeifer/gonb/internal/specialcmd/specialcmd.go splitCmd 97.0%
github.com/janpfeifer/gonb/internal/specialcmd/track.go execTrack 27.3%
github.com/janpfeifer/gonb/internal/specialcmd/track.go execUntrack 54.5%
github.com/janpfeifer/gonb/internal/specialcmd/track.go showTrackedList 91.7%
github.com/janpfeifer/gonb/internal/version/version.go AppVersion 66.7%
github.com/janpfeifer/gonb/internal/version/version.go *VersionInfo.GetInfo 100.0%
github.com/janpfeifer/gonb/internal/version/version.go *VersionInfo.String 100.0%
github.com/janpfeifer/gonb/internal/version/version.go *VersionInfo.Print 100.0%
github.com/janpfeifer/gonb/internal/version/version.go *VersionInfo.Markdown 0.0%
github.com/janpfeifer/gonb/internal/websocket/websocket.go Javascript 83.3%
total (statements) 64.8%
total (statements) 64.7%
4 changes: 2 additions & 2 deletions examples/tests/bash_script.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"/tmp/gonb_dec188e3\n"
"/tmp/gonb_359acad8\n"
]
}
],
Expand All @@ -59,7 +59,7 @@
"output_type": "stream",
"text": [
"/home/janpf/Projects/gonb/examples/tests\n",
"/tmp/gonb_dec188e3\n",
"/tmp/gonb_359acad8\n",
"/home/janpf/Projects/gonb\n",
"/home/janpf/Projects/gonb\n"
]
Expand Down
4 changes: 2 additions & 2 deletions examples/tests/dom.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
{
"data": {
"text/html": [
"<div id=\"dom.transient_div_ed84d56c\"></div>"
"<div id=\"dom.transient_div_c665f31b\"></div>"
]
},
"metadata": {},
Expand Down Expand Up @@ -152,7 +152,7 @@
{
"data": {
"text/html": [
"<div id=\"dom.transient_div_fda1031a\"></div>"
"<div id=\"dom.transient_div_0de47007\"></div>"
]
},
"metadata": {},
Expand Down
8 changes: 4 additions & 4 deletions examples/tests/goflags.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@
"name": "stdout",
"output_type": "stream",
"text": [
"gonb_6d78d1c9/main.go:8:\tA\t\t100.0%\n",
"gonb_6d78d1c9/main.go:12:\tB\t\t0.0%\n",
"gonb_6d78d1c9/main.go:17:\tmain\t\t100.0%\n",
"gonb_334e1de4/main.go:8:\tA\t\t100.0%\n",
"gonb_334e1de4/main.go:12:\tB\t\t0.0%\n",
"gonb_334e1de4/main.go:17:\tmain\t\t100.0%\n",
"total\t\t\t\t(statements)\t75.0%\n"
]
}
Expand Down Expand Up @@ -238,7 +238,7 @@
"name": "stderr",
"output_type": "stream",
"text": [
"# gonb_6d78d1c9\n",
"# gonb_334e1de4\n",
"./main.go:10:6: can inline (*Point).ManhattanLen\n",
"./main.go:16:12: inlining call to flag.Parse\n",
"./main.go:18:27: inlining call to (*Point).ManhattanLen\n",
Expand Down
2 changes: 1 addition & 1 deletion examples/tests/gonbui.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"output_type": "stream",
"text": [
"%goflags=[\"--cover\" \"--covermode=set\"]\n",
"GOCOVERDIR=/tmp/gonb_test_coverage.MljL9OTplr\n"
"GOCOVERDIR=/tmp/gonb_test_coverage.SYm2UwcmTW\n"
]
}
],
Expand Down
12 changes: 6 additions & 6 deletions examples/tests/gotest.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -287,12 +287,12 @@
"text": [
"goos: linux\n",
"goarch: amd64\n",
"pkg: gonb_57055275\n",
"pkg: gonb_b37069f2\n",
"cpu: 12th Gen Intel(R) Core(TM) i9-12900K\n",
"BenchmarkFibonacciA32\n",
"BenchmarkFibonacciA32-24 \t 172\t 6559009 ns/op\n",
"BenchmarkFibonacciA32-24 \t 180\t 6594959 ns/op\n",
"BenchmarkFibonacciB32\n",
"BenchmarkFibonacciB32-24 \t350945394\t 3.942 ns/op\n",
"BenchmarkFibonacciB32-24 \t350331340\t 3.738 ns/op\n",
"PASS\n",
"coverage: [no statements]\n"
]
Expand Down Expand Up @@ -334,10 +334,10 @@
"text": [
"goos: linux\n",
"goarch: amd64\n",
"pkg: gonb_57055275\n",
"pkg: gonb_b37069f2\n",
"cpu: 12th Gen Intel(R) Core(TM) i9-12900K\n",
"BenchmarkFibonacciA32-24 \t 172\t 6583831 ns/op\n",
"BenchmarkFibonacciB32-24 \t309453978\t 3.894 ns/op\n",
"BenchmarkFibonacciA32-24 \t 176\t 6570623 ns/op\n",
"BenchmarkFibonacciB32-24 \t305383951\t 3.899 ns/op\n",
"PASS\n",
"coverage: [no statements]\n"
]
Expand Down
12 changes: 6 additions & 6 deletions examples/tests/gowork.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"/tmp/gonb_tests_gowork_Xocdresp"
"/tmp/gonb_tests_gowork_pVaoudJA"
]
}
],
Expand Down Expand Up @@ -64,7 +64,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Temporary test package: /tmp/gonb_tests_gowork_Xocdresp\n"
"Temporary test package: /tmp/gonb_tests_gowork_pVaoudJA\n"
]
}
],
Expand Down Expand Up @@ -136,7 +136,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"\t- Added replace rule for module \"a.com/a/pkg\" to local directory \"/tmp/gonb_tests_gowork_Xocdresp\".\n"
"\t- Added replace rule for module \"a.com/a/pkg\" to local directory \"/tmp/gonb_tests_gowork_pVaoudJA\".\n"
]
}
],
Expand All @@ -155,7 +155,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"module gonb_bedb8330\n",
"module gonb_5dc14c2a\n",
"\n",
"go 1.23.5\n",
"\n",
Expand Down Expand Up @@ -186,7 +186,7 @@
"text/html": [
"<b>List of files/directories being tracked:</b>\n",
"<ul>\n",
"<li>/tmp/gonb_tests_gowork_Xocdresp</li>\n",
"<li>/tmp/gonb_tests_gowork_pVaoudJA</li>\n",
"</ul>\n"
]
},
Expand All @@ -208,7 +208,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"module gonb_bedb8330\n",
"module gonb_5dc14c2a\n",
"\n",
"go 1.23.5\n"
]
Expand Down
2 changes: 1 addition & 1 deletion examples/tests/input_boxes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"output_type": "stream",
"text": [
"%goflags=[\"--cover\" \"--covermode=set\"]\n",
"GOCOVERDIR=/tmp/gonb_test_coverage.MljL9OTplr\n"
"GOCOVERDIR=/tmp/gonb_test_coverage.SYm2UwcmTW\n"
]
}
],
Expand Down
2 changes: 1 addition & 1 deletion examples/tests/vartuple.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"text/html": [
"<h4>Variables</h4>\n",
"<ul>\n",
"<li><pre>_~478741</pre></li>\n",
"<li><pre>_~462823</pre></li>\n",
"<li><pre>a</pre></li>\n",
"<li><pre>c</pre></li>\n",
"</ul>"
Expand Down
6 changes: 3 additions & 3 deletions examples/tests/widgets.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
{
"data": {
"text/html": [
"<div id=\"dom.transient_div_27aad3ca\"></div>"
"<div id=\"dom.transient_div_8dad60c4\"></div>"
]
},
"metadata": {},
Expand Down Expand Up @@ -189,7 +189,7 @@
{
"data": {
"text/html": [
"<div id=\"dom.transient_div_1b8a0aba\"></div>"
"<div id=\"dom.transient_div_adc38167\"></div>"
]
},
"metadata": {},
Expand Down Expand Up @@ -304,7 +304,7 @@
{
"data": {
"text/html": [
"<div id=\"dom.transient_div_df6ed517\"></div>"
"<div id=\"dom.transient_div_5f490f75\"></div>"
]
},
"metadata": {},
Expand Down
4 changes: 2 additions & 2 deletions examples/tests/writefile.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"name": "stderr",
"output_type": "stream",
"text": [
"Cell contents written to \"/tmp/gonb_nbtests_writefile_3076514072/poetry.txt\".\n"
"Cell contents written to \"/tmp/gonb_nbtests_writefile_2429412932/poetry.txt\".\n"
]
}
],
Expand All @@ -32,7 +32,7 @@
"name": "stderr",
"output_type": "stream",
"text": [
"Cell contents appended to \"/tmp/gonb_nbtests_writefile_3076514072/poetry.txt\".\n"
"Cell contents appended to \"/tmp/gonb_nbtests_writefile_2429412932/poetry.txt\".\n"
]
}
],
Expand Down
2 changes: 1 addition & 1 deletion internal/goexec/elementtype_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 16 additions & 8 deletions internal/goexec/goplsclient/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,22 @@ func (c *Client) connCloseLocked() {

// minTimeout extends (or returns a new context with extended Deadline), discarding the
// previous one -- not the correct use of context, but will do for now.
func minTimeout(ctx context.Context, timeout time.Duration) context.Context {
func minTimeout(ctx context.Context, timeout time.Duration) (context.Context, context.CancelFunc) {
var cancel context.CancelFunc
minDeadline := time.Now().Add(timeout)
if deadline, ok := ctx.Deadline(); !ok || deadline.After(minDeadline) {
ctx, _ = context.WithDeadline(ctx, minDeadline)
ctx, cancel = context.WithDeadline(ctx, minDeadline)
} else {
cancel = func() {} // No-op.
}
return ctx
return ctx, cancel
}

// Connect to the `gopls` in address given by `c.Address()`. It also starts
// a goroutine to monitor receiving requests.
func (c *Client) Connect(ctx context.Context) error {
ctx = minTimeout(ctx, ConnectTimeout)
ctx, cancel := minTimeout(ctx, ConnectTimeout)
defer cancel()
c.mu.Lock()
defer c.mu.Unlock()

Expand Down Expand Up @@ -129,7 +133,8 @@ func (c *Client) NotifyDidOpenOrChange(ctx context.Context, filePath string) (er
// Silently do nothing, if no connection available.
return
}
ctx = minTimeout(ctx, CommunicationTimeout)
ctx, cancel := minTimeout(ctx, CommunicationTimeout)
defer cancel()
c.mu.Lock()
defer c.mu.Unlock()
if c.conn == nil {
Expand Down Expand Up @@ -227,7 +232,8 @@ func (c *Client) CallDefinition(ctx context.Context, filePath string, line, col
// Silently do nothing, if no connection available.
return
}
ctx = minTimeout(ctx, CommunicationTimeout)
ctx, cancel := minTimeout(ctx, CommunicationTimeout)
defer cancel()
c.mu.Lock()
defer c.mu.Unlock()
if c.conn == nil {
Expand Down Expand Up @@ -277,7 +283,8 @@ func (c *Client) CallHover(ctx context.Context, filePath string, line, col int)
// Silently do nothing, if no connection available.
return
}
ctx = minTimeout(ctx, CommunicationTimeout)
ctx, cancel := minTimeout(ctx, CommunicationTimeout)
defer cancel()
c.mu.Lock()
defer c.mu.Unlock()
if c.conn == nil {
Expand Down Expand Up @@ -319,7 +326,8 @@ func (c *Client) CallComplete(ctx context.Context, filePath string, line, col in
// Silently do nothing, if no connection available.
return
}
ctx = minTimeout(ctx, CommunicationTimeout)
ctx, cancel := minTimeout(ctx, CommunicationTimeout)
defer cancel()
c.mu.Lock()
defer c.mu.Unlock()
if c.conn == nil {
Expand Down
Loading

0 comments on commit 2604250

Please sign in to comment.