Skip to content

Commit 2e8d6c0

Browse files
committed
[vscode_projects:1.3] Use new Matcher introduced in interface version 2.3
1 parent d0f4044 commit 2e8d6c0

File tree

1 file changed

+27
-28
lines changed

1 file changed

+27
-28
lines changed

vscode_projects/__init__.py

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@
88
from dataclasses import dataclass
99
from albert import *
1010

11-
md_iid = "2.2"
12-
md_version = "1.2"
11+
md_iid = "2.3"
12+
md_version = "1.3"
1313
md_name = "VSCode projects"
1414
md_description = "Open VSCode projects"
1515
md_url = "https://github.com/albertlauncher/python/tree/master/vscode_projects"
1616
md_license = "MIT"
1717
md_bin_dependencies = ["code"]
1818
md_authors = ["@Sharsie"]
1919

20-
2120
@dataclass
2221
class Project:
2322
displayName: str
@@ -104,10 +103,11 @@ def projectManagerEnabled(self, value):
104103
if found == False:
105104
warning(
106105
"Project Manager search was enabled, but configuration file was not found")
107-
self.notification = Notification(
108-
title=f"{md_name}",
109-
body=f"Configuration file was not found for the Project Manager extension. Please make sure the extension is installed."
106+
notif = Notification(
107+
title=f"{self.name}",
108+
text=f"Configuration file was not found for the Project Manager extension. Please make sure the extension is installed."
110109
)
110+
notif.send()
111111

112112
# Priority settings for project manager results using name search
113113
@property
@@ -160,19 +160,19 @@ def terminalCommand(self, value):
160160
self.writeConfig("terminalCommand", value)
161161

162162
def __init__(self):
163+
self.iconUrls = [f"file:{Path(__file__).parent}/icon.svg"]
164+
165+
PluginInstance.__init__(self)
166+
163167
TriggerQueryHandler.__init__(
164168
self,
165-
id=md_id,
166-
name=md_name,
167-
description=md_description,
169+
id=self.id,
170+
name=self.name,
171+
description=self.description,
168172
defaultTrigger="code ",
169173
synopsis="project name or path"
170174
)
171175

172-
PluginInstance.__init__(self, extensions=[self])
173-
self.iconUrls = [f"file:{Path(__file__).parent}/icon.svg"]
174-
self.notification = None
175-
176176
configFound = False
177177

178178
for p in self._configStoragePaths:
@@ -312,19 +312,18 @@ def handleTriggerQuery(self, query):
312312
if not query.isValid:
313313
return
314314

315-
# Normalize user query
316-
normalizedQuery = self._normalizeString(query.string.strip())
317-
318-
if normalizedQuery == "":
315+
if query.string == "":
319316
return
320317

318+
matcher = Matcher(query.string)
319+
321320
results: dict[str, SearchResult] = {}
322321

323322
if self.recentEnabled:
324-
results = self._searchInRecentFiles(normalizedQuery, results)
323+
results = self._searchInRecentFiles(matcher, results)
325324

326325
if self.projectManagerEnabled:
327-
results = self._searchInProjectManager(normalizedQuery, results)
326+
results = self._searchInProjectManager(matcher, results)
328327

329328
sortedItems = sorted(results.values(), key=lambda item: "%s_%s_%s" % (
330329
'{:03d}'.format(item.priority), '{:03d}'.format(item.sortIndex), item.project.name), reverse=False)
@@ -333,7 +332,7 @@ def handleTriggerQuery(self, query):
333332
query.add(self._createItem(i.project, query))
334333

335334
# Creates an item for the query based on the project and plugin settings
336-
def _createItem(self, project: Project, query: TriggerQuery) -> StandardItem:
335+
def _createItem(self, project: Project, query: Query) -> StandardItem:
337336
actions: list[Action] = []
338337

339338
if self.terminalCommand != "":
@@ -362,18 +361,18 @@ def _createItem(self, project: Project, query: TriggerQuery) -> StandardItem:
362361
id=project.path,
363362
text=project.displayName,
364363
subtext=project.path,
365-
iconUrls=[f"file:{Path(__file__).parent}/icon.svg"],
364+
iconUrls=[f"file://{Path(__file__).parent}/icon.svg"],
366365
inputActionText=f"{query.trigger} {project.displayName}",
367366
actions=actions,
368367
)
369368

370-
def _searchInRecentFiles(self, search: str, results: dict[str, SearchResult]) -> dict[str, SearchResult]:
369+
def _searchInRecentFiles(self, matcher: Matcher, results: dict[str, SearchResult]) -> dict[str, SearchResult]:
371370
sortIndex = 1
372371

373372
for path in self._configStoragePaths:
374373
c = self._getStorageConfig(path)
375374
for proj in c.projects:
376-
if proj.name.find(search) != -1 or proj.path.find(search) != -1:
375+
if matcher.match(proj.name) or matcher.match(proj.path):
377376
results[proj.path] = self._getHigherPriorityResult(
378377
SearchResult(
379378
project=proj,
@@ -388,21 +387,21 @@ def _searchInRecentFiles(self, search: str, results: dict[str, SearchResult]) ->
388387

389388
return results
390389

391-
def _searchInProjectManager(self, search: str, results: dict[str, SearchResult]) -> dict[str, SearchResult]:
390+
def _searchInProjectManager(self, matcher: Matcher, results: dict[str, SearchResult]) -> dict[str, SearchResult]:
392391
for path in self._configProjectManagerPaths:
393392
c = self._getProjectManagerConfig(path)
394393
for proj in c.projects:
395-
if proj.name.find(search) != -1:
394+
if matcher.match(proj.name):
396395
results[proj.path] = self._getHigherPriorityResult(
397396
SearchResult(
398397
project=proj,
399398
priority=self.priorityPMName,
400-
sortIndex=0 if proj.name == search else 1
399+
sortIndex=0 if matcher.match(proj.name).isExactMatch() else 1
401400
),
402401
results.get(proj.path),
403402
)
404403

405-
if proj.path.find(search) != -1:
404+
if matcher.match(proj.path):
406405
results[proj.path] = self._getHigherPriorityResult(
407406
SearchResult(
408407
project=proj,
@@ -413,7 +412,7 @@ def _searchInProjectManager(self, search: str, results: dict[str, SearchResult])
413412
)
414413

415414
for tag in proj.tags:
416-
if tag.find(search) != -1:
415+
if matcher.match(tag):
417416
results[proj.path] = self._getHigherPriorityResult(
418417
SearchResult(
419418
project=proj,

0 commit comments

Comments
 (0)