<commit_before>import sublime
import sublime_plugin
import os
import json

class PromptOpenRecentProjectCommand(sublime_plugin.WindowCommand):

    def run(self):
        recent_workspaces = self.recent_workspaces()
        if not recent_workspaces:
            sublime.status_message('No recent projects!')
            return

        self.window.show_quick_panel(recent_workspaces, self.on_done)

    def on_done(self, index):
        if index == -1:
            return

        self.window.run_command('open_recent_project_or_workspace', {'index': index})

    def recent_workspaces(self):
        """
        Returns an array > 0; otherwise None
        """

        session = self.load_session()
        if not session:
            return None

        workspaces = session.get('workspaces')
        if not workspaces:
            return None

        recent_workspaces = workspaces.get('recent_workspaces')
        if not recent_workspaces:
            return None

        # substitute user home dir with ~
        user_home_dir = os.getenv('HOME')
        recent_workspaces_list = []
        for recent_workspace in recent_workspaces:
            if recent_workspace.startswith(user_home_dir):
                recent_workspaces_list.append(recent_workspace.replace(user_home_dir, '~'))
            else:
                recent_workspaces_list.append(recent_workspace)

        if recent_workspaces_list and len(recent_workspaces_list) > 0:
            return recent_workspaces_list

        return None

    def load_session(self):
        local_session_path = os.path.join(os.path.dirname(sublime.packages_path()), 'Local')
        local_auto_save_session_file = os.path.join(local_session_path, 'Auto Save Session.sublime_session')
        local_session_file = os.path.join(local_session_path, 'Session.sublime_session')

        if os.path.isfile(local_auto_save_session_file):
            session_file_to_use = local_auto_save_session_file
        elif os.path.isfile(local_session_file):
            session_file_to_use = local_session_file
        else:
            return None

        with open(session_file_to_use) as f:
            local_session_content = f.read()

        session = json.loads(local_session_content, strict=False)

        return session
<commit_msg>Update open recent project command docs<commit_after>import sublime
import sublime_plugin
import os
import json

class PromptOpenRecentProjectCommand(sublime_plugin.WindowCommand):

    def run(self):
        recent_workspaces = self.recent_workspaces()
        if not recent_workspaces:
            sublime.status_message('No recent projects!')
            return

        self.window.show_quick_panel(recent_workspaces, self.on_done)

    def on_done(self, index):
        if index == -1:
            return

        self.window.run_command('open_recent_project_or_workspace', {'index': index})

    def recent_workspaces(self):
        """
        Returns an list > 0; otherwise None
        """

        session = self.load_session()
        if not session:
            return None

        workspaces = session.get('workspaces')
        if not workspaces:
            return None

        recent_workspaces = workspaces.get('recent_workspaces')
        if not recent_workspaces:
            return None

        # substitute user home dir with ~
        user_home_dir = os.getenv('HOME')
        recent_workspaces_list = []
        for recent_workspace in recent_workspaces:
            if recent_workspace.startswith(user_home_dir):
                recent_workspaces_list.append(recent_workspace.replace(user_home_dir, '~'))
            else:
                recent_workspaces_list.append(recent_workspace)

        if recent_workspaces_list and len(recent_workspaces_list) > 0:
            return recent_workspaces_list

        return None

    def load_session(self):
        """
        Returns dict or None if no session exists
        """

        local_session_path = os.path.join(os.path.dirname(sublime.packages_path()), 'Local')
        local_auto_save_session_file = os.path.join(local_session_path, 'Auto Save Session.sublime_session')
        local_session_file = os.path.join(local_session_path, 'Session.sublime_session')

        if os.path.isfile(local_auto_save_session_file):
            session_file_to_use = local_auto_save_session_file
        elif os.path.isfile(local_session_file):
            session_file_to_use = local_session_file
        else:
            return None

        with open(session_file_to_use) as f:
            local_session_content = f.read()

        session = json.loads(local_session_content, strict=False)

        return session

{'fraction_non_alphanumeric': 0.07534246575342465, 'fraction_numerical': 0.0012842465753424657, 'mean_word_length': 2.5808429118773946, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2620049', 'n_tokens_mistral': 1402, 'n_tokens_neox': 1303, 'n_words': 259}