Skip to content

Commit

Permalink
fix: sign out command doesn't work
Browse files Browse the repository at this point in the history
Signed-off-by: Jack Cherng <[email protected]>
  • Loading branch information
jfcherng committed May 29, 2024
1 parent c1749f9 commit 9f1c0f8
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion plugin/commands.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
from __future__ import annotations

import os
from abc import ABC
from collections.abc import Callable
from functools import partial, wraps
from pathlib import Path
from typing import Any, cast

import sublime
from LSP.plugin import Request, Session
from LSP.plugin.core.registry import LspTextCommand, LspWindowCommand
from lsp_utils.helpers import rmtree_ex

from .constants import (
PACKAGE_NAME,
Expand Down Expand Up @@ -307,6 +310,16 @@ def run(self, plugin: CopilotPlugin, session: Session, _: sublime.Edit) -> None:
session.send_request(Request(REQ_SIGN_OUT, {}), self._on_result_sign_out)

def _on_result_sign_out(self, payload: CopilotPayloadSignOut) -> None:
if payload["status"] == "NotSignedIn":
if sublime.platform() == "windows":
session_dir = Path(os.environ.get("LOCALAPPDATA", "")) / "github-copilot"
else:
session_dir = Path.home() / ".config/github-copilot"

if not session_dir.is_dir():
message_dialog(f"Failed to find the session directory: {session_dir}", _error=True)
return

rmtree_ex(str(session_dir), ignore_errors=True)
if not session_dir.is_dir():
CopilotPlugin.set_account_status(signed_in=False, authorized=False)
message_dialog("Sign out OK. Bye!")

0 comments on commit 9f1c0f8

Please sign in to comment.