Skip to content

Commit

Permalink
Update NativeWebview title only if the title changes (sourcegraph#5861)
Browse files Browse the repository at this point in the history
`cody-agent-trace.json` looks like this now:
```
[Trace - 01:03:47 PM] Received notification 'webview/setTitle'
Params: {
  "handle": "native-webview-panel-df3675ed-b3d7-4051-94ff-78a569945443",
  "title": "Explain what @src/main/ja..."
}


[Trace - 01:03:47 PM] Received notification 'webview/setTitle'
Params: {
  "handle": "native-webview-panel-df3675ed-b3d7-4051-94ff-78a569945443",
  "title": "Explain what @src/main/ja..."
}


[Trace - 01:03:47 PM] Received notification 'webview/setTitle'
Params: {
  "handle": "native-webview-panel-df3675ed-b3d7-4051-94ff-78a569945443",
  "title": "Explain what @src/main/ja..."
}


[Trace - 01:03:47 PM] Received notification 'webview/setTitle'
Params: {
  "handle": "native-webview-panel-df3675ed-b3d7-4051-94ff-78a569945443",
  "title": "Explain what @src/main/ja..."
}


[Trace - 01:03:47 PM] Received notification 'webview/setTitle'
Params: {
  "handle": "native-webview-panel-df3675ed-b3d7-4051-94ff-78a569945443",
  "title": "Explain what @src/main/ja..."
}


[Trace - 01:03:47 PM] Received notification 'webview/setTitle'
Params: {
  "handle": "native-webview-panel-df3675ed-b3d7-4051-94ff-78a569945443",
  "title": "Explain what @src/main/ja..."
}


[Trace - 01:03:47 PM] Received notification 'webview/setTitle'
Params: {
  "handle": "native-webview-panel-df3675ed-b3d7-4051-94ff-78a569945443",
  "title": "Explain what @src/main/ja..."
}


[Trace - 01:03:47 PM] Received notification 'webview/setTitle'
Params: {
  "handle": "native-webview-panel-df3675ed-b3d7-4051-94ff-78a569945443",
  "title": "Explain what @src/main/ja..."
}


[Trace - 01:03:47 PM] Received notification 'webview/setTitle'
Params: {
  "handle": "native-webview-panel-df3675ed-b3d7-4051-94ff-78a569945443",
  "title": "Explain what @src/main/ja..."
}


[Trace - 01:03:47 PM] Received notification 'webview/setTitle'
Params: {
  "handle": "native-webview-panel-df3675ed-b3d7-4051-94ff-78a569945443",
  "title": "Explain what @src/main/ja..."
}


[Trace - 01:03:47 PM] Received notification 'webview/setTitle'
Params: {
  "handle": "native-webview-panel-df3675ed-b3d7-4051-94ff-78a569945443",
  "title": "Explain what @src/main/ja..."
}
```

I think there is no need to send the notification if the title does not
change actually.

## Test plan
1. Run IDE. 
2. Run Explain a few times. 
3. Review `cody-agent-trace.json`
The number of notifications should be reasonable. 

<!-- Required. See
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles.
-->

## Changelog

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
  • Loading branch information
mkondratek authored Jan 8, 2025
1 parent 63fc83c commit 35d181a
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions agent/src/NativeWebview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,11 @@ class NativeWebviewPanel implements vscode.WebviewPanel {
}

public set title(value: string) {
this.delegate.setTitle(this.handle, value)
this._title = value
if (value !== this._title) {
this.delegate.setTitle(this.handle, value)
this._title = value
}
}

public get iconPath(): vscode.Uri | { light: vscode.Uri; dark: vscode.Uri } | undefined {
if (!this._iconPath) {
return undefined
Expand Down

0 comments on commit 35d181a

Please sign in to comment.