Skip to content
This repository was archived by the owner on Dec 25, 2023. It is now read-only.

Commit 3a7085a

Browse files
tascodesapexskier
andauthored
Use notification request instead of alert on search (#395)
Co-authored-by: Cameron Little <[email protected]>
1 parent a23b1a5 commit 3a7085a

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

src/searchResults.test.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,19 @@ import {
1010
register: jest.fn(),
1111
},
1212
workspace: {
13-
showInformativeMessage: jest.fn(),
1413
showErrorMessage(err: unknown) {
1514
throw err;
1615
},
1716
openFile: jest.fn(),
1817
},
18+
notifications: {
19+
add: jest.fn(),
20+
},
1921
});
2022

23+
class NotificationRequestMock {}
24+
(global as any).NotificationRequest = NotificationRequestMock;
25+
2126
class CompositeDisposableMock implements Disposable {
2227
private _disposables: Array<Disposable> = [];
2328
add(disposable: Disposable) {
@@ -57,7 +62,7 @@ beforeEach(() => {
5762
(nova.commands.register as jest.Mock)
5863
.mockReset()
5964
.mockReturnValue({ dispose: jest.fn() });
60-
(nova.workspace.showInformativeMessage as jest.Mock).mockReset();
65+
(nova.notifications.add as jest.Mock).mockReset();
6166
(nova.workspace.openFile as jest.Mock).mockReset();
6267
});
6368

@@ -104,7 +109,7 @@ describe("Symbol search results tree", () => {
104109
visible: false,
105110
}));
106111
createSymbolSearchResultsTree(symbols);
107-
expect(nova.workspace.showInformativeMessage).toHaveBeenCalledTimes(1);
112+
expect(nova.notifications.add).toHaveBeenCalledTimes(1);
108113
});
109114

110115
it("registers a double click command to open each search result", async () => {
@@ -279,7 +284,7 @@ it.each([
279284
visible: false,
280285
}));
281286
create();
282-
expect(nova.workspace.showInformativeMessage).toHaveBeenCalledTimes(1);
287+
expect(nova.notifications.add).toHaveBeenCalledTimes(1);
283288
});
284289

285290
it.each([
@@ -306,7 +311,7 @@ it.each([
306311
"apexskier.typescript.sidebar.symbols",
307312
expect.anything()
308313
);
309-
expect(nova.workspace.showInformativeMessage).not.toBeCalled();
314+
expect(nova.notifications.add).not.toBeCalled();
310315
const treeMock1 = TreeViewTypedMock.mock.results[0].value;
311316
expect(treeMock1.dispose).not.toBeCalled();
312317
expect(nova.commands.register).toBeCalledWith(

src/searchResults.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,13 @@ function showTreeView<T>(dataProvider: MyTreeProvider<T>) {
132132

133133
// can't figure out how to force open the view, but if most usage is from the sidebar directly it's okay?
134134
if (!treeView.visible) {
135-
nova.workspace.showInformativeMessage(
136-
"Done! View the TS/JS sidebar to see results."
137-
);
135+
const notification = new NotificationRequest("search-results-done");
136+
notification.title = "Find References";
137+
notification.body = "View the TS/JS sidebar to see results.";
138+
nova.notifications.add(notification);
139+
setTimeout(() => {
140+
nova.notifications.cancel(notification.identifier);
141+
}, 4000);
138142
}
139143

140144
const command = nova.commands.register(

typescript.novaextension/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## future
4+
5+
### Changed
6+
7+
- When search results are ready, display a notification instead of an alert.
8+
39
## v2.5.0
410

511
- Upgrade to TypeScript 4.7

0 commit comments

Comments
 (0)