2727
2828from dataclasses import dataclass
2929from pathlib import Path
30- from typing import Union
30+ from typing import Union , List
3131from shutil import which
3232from sys import platform
3333from xml .etree import ElementTree
3434from albert import *
3535
36- md_iid = '2.5'
37- md_version = "2.1 "
36+ md_iid = "3.0"
37+ md_version = "3.0 "
3838md_name = "Jetbrains projects"
3939md_description = "Open your JetBrains projects"
4040md_license = "MIT"
@@ -62,13 +62,14 @@ def __init__(self, name: str, icon: Path, config_dir_prefix: str, binaries: list
6262 self .config_dir_prefix = config_dir_prefix
6363 self .binary = self ._find_binary (binaries )
6464
65- def _find_binary (self , binaries : list [str ]) -> Union [str , None ]:
65+ @staticmethod
66+ def _find_binary (binaries : list [str ]) -> Union [str , None ]:
6667 for binary in binaries :
6768 if which (binary ):
6869 return binary
6970 return None
7071
71- def list_projects (self ) -> list [Project ]:
72+ def list_projects (self ) -> List [Project ]:
7273 config_dir = Path .home () / ".config"
7374 if platform == "darwin" :
7475 config_dir = Path .home () / "Library" / "Application Support"
@@ -79,7 +80,8 @@ def list_projects(self) -> list[Project]:
7980 latest = sorted (dirs )[- 1 ]
8081 return self ._parse_recent_projects (Path (latest ) / "options" / "recentProjects.xml" )
8182
82- def _parse_recent_projects (self , recent_projects_file : Path ) -> list [Project ]:
83+ @staticmethod
84+ def _parse_recent_projects (recent_projects_file : Path ) -> list [Project ]:
8385 try :
8486 root = ElementTree .parse (recent_projects_file ).getroot ()
8587 entries = root .findall (".//component[@name='RecentProjectsManager']//entry[@key]" )
@@ -113,10 +115,9 @@ class Plugin(PluginInstance, TriggerQueryHandler):
113115
114116 def __init__ (self ):
115117 PluginInstance .__init__ (self )
116- TriggerQueryHandler .__init__ (
117- self , self .id , self .name , self .description ,
118- defaultTrigger = 'jb '
119- )
118+ TriggerQueryHandler .__init__ (self )
119+
120+ self .fuzzy = False
120121
121122 plugin_dir = Path (__file__ ).parent
122123 editors = [
@@ -196,22 +197,32 @@ def __init__(self):
196197 ]
197198 self .editors = [e for e in editors if e .binary is not None ]
198199
200+ def supportsFuzzyMatching (self ):
201+ return True
202+
203+ def setFuzzyMatching (self , enabled ):
204+ self .fuzzy = enabled
205+
206+ def defaultTrigger (self ):
207+ return "jb "
208+
199209 def handleTriggerQuery (self , query : Query ):
200210 editor_project_pairs = []
201211
202- m = Matcher (query .string )
212+ m = Matcher (query .string , MatchConfig (fuzzy = self .fuzzy ))
213+
203214 for editor in self .editors :
204- projects = editor .list_projects ()
205- projects = [p for p in projects if Path (p .path ).exists ()]
206- projects = [p for p in projects if m .match (p .name , p .path )]
207- editor_project_pairs .extend ([(editor , p ) for p in projects ])
215+ for project in editor .list_projects ():
216+ if Path (project .path ).exists () and m .match (project .name , project .path ):
217+ editor_project_pairs .append ((editor , project ))
208218
209219 # sort by last opened
210220 editor_project_pairs .sort (key = lambda pair : pair [1 ].last_opened , reverse = True )
211221
212222 query .add ([self ._make_item (editor , project , query ) for editor , project in editor_project_pairs ])
213223
214- def _make_item (self , editor : Editor , project : Project , query : Query ) -> Item :
224+ @staticmethod
225+ def _make_item (editor : Editor , project : Project , query : Query ) -> Item :
215226 return StandardItem (
216227 id = "%s-%s-%s" % (editor .binary , project .path , project .last_opened ),
217228 text = project .name ,
0 commit comments