-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DEV2-1707: add a snooze button for tabnine completions (#1341)
* DEV2-1707: add a pause button * handle self-hosted * add setting * fix lint * improve naming * track snooze toggled * CompletionState refactor (#1344) * remove unneccessary check --------- Co-authored-by: Dima Abramovich <[email protected]>
- Loading branch information
1 parent
c998175
commit c0655e1
Showing
11 changed files
with
160 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { EventEmitter } from "events"; | ||
import { workspace } from "vscode"; | ||
|
||
class CompletionState extends EventEmitter { | ||
private state: boolean = true; | ||
|
||
private enableTimeout: NodeJS.Timeout | null = null; | ||
|
||
get value(): boolean { | ||
return this.state; | ||
} | ||
|
||
set value(enabled: boolean) { | ||
this.state = enabled; | ||
this.emit("changed", enabled); | ||
|
||
if (this.enableTimeout) { | ||
clearTimeout(this.enableTimeout); | ||
this.enableTimeout = null; | ||
} | ||
|
||
if (!enabled) { | ||
const snoozeDuration = workspace | ||
.getConfiguration("tabnine") | ||
.get<number>("snoozeDuration", 1); | ||
|
||
this.enableTimeout = setTimeout(() => { | ||
this.state = true; | ||
}, snoozeDuration * 60 * 1000); | ||
} | ||
} | ||
} | ||
|
||
export const completionsState = new CompletionState(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { window, workspace } from "vscode"; | ||
import { completionsState } from "../state/completionsState"; | ||
import { sendEvent } from "../binary/requests/sendEvent"; | ||
|
||
const RESUME_TABNINE = "Resume Tabnine"; | ||
|
||
export function showStatusBarNotificationOptions( | ||
settingsButton: string, | ||
onSettingsClicked: () => void | ||
) { | ||
const snoozeDuration = workspace | ||
.getConfiguration("tabnine") | ||
.get<number>("snoozeDuration", 1); | ||
|
||
const snoozeTabnine = `Snooze Tabnine (${snoozeDuration}h)`; | ||
|
||
const currentAction = completionsState.value ? snoozeTabnine : RESUME_TABNINE; | ||
|
||
void window | ||
.showInformationMessage("Tabnine options", settingsButton, currentAction) | ||
.then((selection) => { | ||
switch (selection) { | ||
case settingsButton: | ||
onSettingsClicked(); | ||
break; | ||
case snoozeTabnine: | ||
trackSnoozeToggled(false, snoozeDuration); | ||
completionsState.value = false; | ||
break; | ||
case RESUME_TABNINE: | ||
trackSnoozeToggled(true, snoozeDuration); | ||
completionsState.value = true; | ||
break; | ||
default: | ||
console.warn("Unexpected selection"); | ||
break; | ||
} | ||
}); | ||
} | ||
|
||
function trackSnoozeToggled(showCompletions: boolean, duration: number) { | ||
void sendEvent({ | ||
name: "snooze-toggled", | ||
properties: { | ||
show_completions: showCompletions.toString(), | ||
duration: duration.toString(), | ||
}, | ||
}); | ||
} |