Skip to content

Commit

Permalink
fix: fix crashing when entering plain text file preview panel (#247)
Browse files Browse the repository at this point in the history
  • Loading branch information
hnicke authored Aug 24, 2022
1 parent 8de2586 commit 053ae44
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions sodalite/ui/highlighting.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,20 @@ def compute_highlighting(entry: Entry) -> Generator[HighlightedLine, None, None]


def find_lexer(file: Path, content: str):
import pygments
from pygments.util import ClassNotFound
import pygments.lexers
try:
if file.name in ('.gitignore', '.dockerignore'):
from pygments.lexers.shell import BashLexer
lexer = BashLexer()
else:
lexer = pygments.lexers.guess_lexer_for_filename(str(file), content, stripnl=False, ensurenl=False)
logger.debug('Detected lexer by filename')
except pygments.util.ClassNotFound:
except ClassNotFound:
try:
lexer = pygments.lexers.guess_lexer(content, stripnl=False, ensurenl=False)
logger.debug('Detected lexer by file content')
except pygments.util.ClassNotFound:
except ClassNotFound:
lexer = BashLexer(stripnl=False, ensurenl=False)
logger.debug('Using fallback lexer')
return lexer
Expand Down

0 comments on commit 053ae44

Please sign in to comment.