Skip to content

Commit eea4df4

Browse files
authored
Merge pull request #1913 from puneetdixit200/fix-set-prefix-highlighting
Fix highlighting for set-prefixed identifiers
2 parents df74f06 + a2cdfc7 commit eea4df4

3 files changed

Lines changed: 19 additions & 2 deletions

File tree

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Upcoming (TBD)
44
Bug Fixes
55
---------
66
* Keep completion-menu Escape cancellation eager only in Vi mode so Emacs Alt-key bindings keep working while completions are open.
7+
* Keep identifiers that start with `set` highlighted as names.
78

89

910
Internal

mycli/lexer.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
from pygments.lexer import inherit
22
from pygments.lexers.sql import MySqlLexer
3-
from pygments.token import Keyword
3+
from pygments.token import Keyword, Name
44

55

66
class MyCliLexer(MySqlLexer):
77
"""Extends MySQL lexer to add keywords."""
88

99
tokens = {
10-
"root": [(r"\brepair\b", Keyword), (r"\boffset\b", Keyword), inherit],
10+
"root": [
11+
# TODO: Remove once Pygments is upgraded above v2.20.0.
12+
(r"\bset[\w$]+\b", Name),
13+
(r"\brepair\b", Keyword),
14+
(r"\boffset\b", Keyword),
15+
inherit,
16+
],
1117
}

test/pytests/test_lexer.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from pygments.token import Keyword, Name
2+
3+
from mycli.lexer import MyCliLexer
4+
5+
6+
def test_mysql_lexer_keeps_identifiers_starting_with_set_together():
7+
tokens = list(MyCliLexer().get_tokens("SELECT * FROM settings_123 WHERE id = 123;"))
8+
9+
assert (Name, "settings_123") in tokens
10+
assert (Keyword, "set") not in tokens

0 commit comments

Comments
 (0)