properly detect hidden (.extension-only) files
This commit is contained in:
@@ -196,16 +196,10 @@ class Grammar(NamedTuple):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def blank(cls) -> 'Grammar':
|
def blank(cls) -> 'Grammar':
|
||||||
return cls(
|
return cls.from_data({'scopeName': 'source.unknown', 'patterns': []})
|
||||||
scope_name='source.unknown',
|
|
||||||
first_line_match=None,
|
|
||||||
file_types=frozenset(),
|
|
||||||
patterns=(),
|
|
||||||
repository=FDict({}),
|
|
||||||
)
|
|
||||||
|
|
||||||
def matches_file(self, filename: str, first_line: str) -> bool:
|
def matches_file(self, filename: str, first_line: str) -> bool:
|
||||||
_, ext = os.path.splitext(filename)
|
_, _, ext = os.path.basename(filename).rpartition('.')
|
||||||
if ext.lstrip('.') in self.file_types:
|
if ext.lstrip('.') in self.file_types:
|
||||||
return True
|
return True
|
||||||
elif self.first_line_match is not None:
|
elif self.first_line_match is not None:
|
||||||
|
|||||||
@@ -4,6 +4,12 @@ from babi.highlight import highlight_line
|
|||||||
from babi.highlight import Region
|
from babi.highlight import Region
|
||||||
|
|
||||||
|
|
||||||
|
def test_grammar_matches_extension_only_name():
|
||||||
|
data = {'scopeName': 'test', 'patterns': [], 'fileTypes': ['bashrc']}
|
||||||
|
grammar = Grammar.from_data(data)
|
||||||
|
assert grammar.matches_file('.bashrc', 'alias nano=babi')
|
||||||
|
|
||||||
|
|
||||||
def _compiler_state(grammar_dct, *others):
|
def _compiler_state(grammar_dct, *others):
|
||||||
grammar = Grammar.from_data(grammar_dct)
|
grammar = Grammar.from_data(grammar_dct)
|
||||||
grammars = [grammar, *(Grammar.from_data(dct) for dct in others)]
|
grammars = [grammar, *(Grammar.from_data(dct) for dct in others)]
|
||||||
|
|||||||
Reference in New Issue
Block a user