Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for console property #10

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def open_alternate(self, file_name, folders=[], focus=None, mode=None):
template = ""

for projection in storage.get_projections():
template = projection.find_template(alternate)
template = projection.get("template", alternate)

if template is not None:
break
Expand Down
14 changes: 3 additions & 11 deletions plugin/projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,13 @@ def match(self, file):

return MatchedProjection(file, self, match)

def find_alternate_file(self, file):
if not bool(self.alternate):
def get(self, type, file):
if not bool(getattr(self, type)):
return None

match = self.match(file)

return match.alternate if match else None

def find_template(self, file):
if not bool(self.template):
return None

match = self.match(file)

return match.template if match else None
return getattr(match, type) if match else None


class MatchedProjection:
Expand Down
2 changes: 1 addition & 1 deletion plugin/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def find_alternate_file(self, file):
first_match = None

for projection in self.get_projections():
alternate_files = projection.find_alternate_file(file)
alternate_files = projection.get("alternate", file)

if alternate_files is None:
continue
Expand Down
23 changes: 23 additions & 0 deletions tests/test_projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,29 @@ def test_match_no_globstar(self):
"",
)

def test_get(self):
self.assertEqual(
list(
Projection("*", {"alternate": "{}"}).get(
"alternate", self.root.file("foo.py")
)
),
[self.root.file("foo.py")],
)

def test_get_missing(self):
self.assertIsNone(
Projection("*", {"template": "smth"}).get(
"alternate", self.root.file("foo.py")
)
)

def test_get_missing_attribute(self):
with self.assertRaises(AttributeError):
Projection("*", {"invalid": "smth"}).get(
"invalid", self.root.file("foo.py")
)


class TestMatchedProjection(unittest.TestCase):
def setUp(self):
Expand Down
Loading