Skip to content

Commit

Permalink
[VB] Highlight Sub/Function name.
Browse files Browse the repository at this point in the history
  • Loading branch information
zufuliu committed Nov 2, 2024
1 parent 4404e54 commit 21e552b
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 19 deletions.
27 changes: 15 additions & 12 deletions scintilla/include/SciLexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -415,18 +415,21 @@
#define SCE_VB_PLACEHOLDER 10
#define SCE_VB_IDENTIFIER 11
#define SCE_VB_DATE 12
#define SCE_VB_KEYWORD 13
#define SCE_VB_KEYWORD2 14
#define SCE_VB_KEYWORD3 15
#define SCE_VB_CLASS 16
#define SCE_VB_INTERFACE 17
#define SCE_VB_ENUM 18
#define SCE_VB_ATTRIBUTE 19
#define SCE_VB_CONSTANT 20
#define SCE_VB_BASIC_FUNCTION 21
#define SCE_VB_PREPROCESSOR 22
#define SCE_VB_PREPROCESSOR_WORD 23
#define SCE_VB_LABEL 24
#define SCE_VB_FILENUMBER 13
#define SCE_VB_KEYWORD 14
#define SCE_VB_KEYWORD2 15
#define SCE_VB_KEYWORD3 16
#define SCE_VB_CLASS 17
#define SCE_VB_INTERFACE 18
#define SCE_VB_ENUM 19
#define SCE_VB_ATTRIBUTE 20
#define SCE_VB_CONSTANT 21
#define SCE_VB_BASIC_FUNCTION 22
#define SCE_VB_FUNCTION_DEFINITION 23
#define SCE_VB_FUNCTION 24
#define SCE_VB_PREPROCESSOR 25
#define SCE_VB_PREPROCESSOR_WORD 26
#define SCE_VB_LABEL 27
#define SCE_PROPS_DEFAULT 0
#define SCE_PROPS_COMMENT 1
#define SCE_PROPS_SECTION 2
Expand Down
3 changes: 3 additions & 0 deletions scintilla/include/SciLexer.iface
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,7 @@ val SCE_VB_FORMAT_SPECIFIER=
val SCE_VB_PLACEHOLDER=
val SCE_VB_IDENTIFIER=
val SCE_VB_DATE=
val SCE_VB_FILENUMBER=
val SCE_VB_KEYWORD=
val SCE_VB_KEYWORD2=
val SCE_VB_KEYWORD3=
Expand All @@ -547,6 +548,8 @@ val SCE_VB_ENUM=
val SCE_VB_ATTRIBUTE=
val SCE_VB_CONSTANT=
val SCE_VB_BASIC_FUNCTION=
val SCE_VB_FUNCTION_DEFINITION=
val SCE_VB_FUNCTION=
val SCE_VB_PREPROCESSOR=
val SCE_VB_PREPROCESSOR_WORD=
val SCE_VB_LABEL=
Expand Down
13 changes: 10 additions & 3 deletions scintilla/lexers/LexVB.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ using namespace Lexilla;

namespace {

// Internal state, highlighted as number
#define SCE_VB_FILENUMBER (SCE_VB_LABEL + 1)

enum class Language {
VBNET,
VBA,
Expand All @@ -38,7 +35,9 @@ enum class Language {

enum class KeywordType {
None,
End,
AccessModifier,
Function,
};

enum {
Expand Down Expand Up @@ -169,6 +168,12 @@ void ColouriseVBDoc(Sci_PositionU startPos, Sci_Position length, int initStyle,
if (visibleChars == len || kwType == KeywordType::AccessModifier) {
lineState = VBLineType_VB6TypeLine;
}
} else if (StrEqual(s, "end")) {
kwType = KeywordType::End;
} else if (StrEqualsAny(s, "sub", "function")) {
if (kwType != KeywordType::End) {
kwType = KeywordType::Function;
}
} else if (StrEqualsAny(s, "public", "protected", "private", "friend")) {
kwType = KeywordType::AccessModifier;
}
Expand All @@ -187,6 +192,8 @@ void ColouriseVBDoc(Sci_PositionU startPos, Sci_Position length, int initStyle,
sc.ChangeState(SCE_VB_ATTRIBUTE);
} else if (keywords6.InList(s)) {
sc.ChangeState(SCE_VB_CONSTANT);
} else if (kwType == KeywordType::Function) {
sc.ChangeState(SCE_VB_FUNCTION_DEFINITION);
}
stylePrevNonWhite = sc.state;
if (sc.state != SCE_VB_KEYWORD) {
Expand Down
5 changes: 3 additions & 2 deletions src/EditLexers/stlVB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ static EDITSTYLE Styles_VB[] = {
{ SCE_VB_KEYWORD2, NP2StyleX_TypeKeyword, L"fore:#0000FF" },
{ MULTI_STYLE(SCE_VB_PREPROCESSOR, SCE_VB_PREPROCESSOR_WORD, 0, 0), NP2StyleX_Preprocessor, L"fore:#FF8000" },
{ SCE_VB_ATTRIBUTE, NP2StyleX_Attribute, L"fore:#FF8000" },
{ SCE_VB_FUNCTION_DEFINITION, NP2StyleX_FunctionDefinition, L"bold; fore:#A46000" },
{ SCE_VB_CONSTANT, NP2StyleX_Constant, L"fore:#B000B0" },
{ SCE_VB_COMMENTLINE, NP2StyleX_Comment, L"fore:#608060" },
{ MULTI_STYLE(SCE_VB_STRING, SCE_VB_INTERPOLATED_STRING, 0, 0), NP2StyleX_String, L"fore:#008000" },
Expand All @@ -92,8 +93,8 @@ EDITLEXER lexVisualBasic = {
LexerAttr_NoBlockComment |
LexerAttr_CppPreprocessor,
TAB_WIDTH_4, INDENT_WIDTH_4,
(1 << 0) | (1 << 1), // class, function
0,
(1 << 0) | (1 << 1) | (1 << 2), // namespace, class, function
SCE_VB_FUNCTION_DEFINITION,
'\0', SCE_VB_ESCAPECHAR, SCE_VB_FORMAT_SPECIFIER,
0,
0, SCE_VB_COMMENTLINE,
Expand Down
3 changes: 2 additions & 1 deletion src/EditLexers/stlVBS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ static EDITSTYLE Styles_VBS[] = {
EDITSTYLE_DEFAULT,
{ MULTI_STYLE(SCE_VB_KEYWORD, SCE_VB_KEYWORD3, 0, 0), NP2StyleX_Keyword, L"fore:#0000FF" },
{ SCE_VB_KEYWORD2, NP2StyleX_TypeKeyword, L"fore:#0000FF" },
{ SCE_VB_FUNCTION_DEFINITION, NP2StyleX_FunctionDefinition, L"bold; fore:#A46000" },
{ SCE_VB_CONSTANT, NP2StyleX_Constant, L"fore:#B000B0" },
{ SCE_VB_COMMENTLINE, NP2StyleX_Comment, L"fore:#608060" },
{ SCE_VB_STRING, NP2StyleX_String, L"fore:#008000" },
Expand All @@ -74,7 +75,7 @@ EDITLEXER lexVBScript = {
LexerAttr_NoBlockComment,
TAB_WIDTH_4, INDENT_WIDTH_4,
(1 << 0), // function
0,
SCE_VB_FUNCTION_DEFINITION,
'\0', SCE_VB_ESCAPECHAR, SCE_VB_FORMAT_SPECIFIER,
0,
0, SCE_VB_COMMENTLINE,
Expand Down
4 changes: 3 additions & 1 deletion tools/LexerConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,7 @@ class KeywordAttr(IntFlag):
'line_comment_string': "'",
'comment_style_marker': 'SCE_VB_COMMENTLINE',
'default_fold_level': ['function'],
'default_fold_ignore_inner': 'SCE_VB_FUNCTION_DEFINITION',
'format_specifier_style': 'SCE_VB_FORMAT_SPECIFIER',
'escape_char_start': NoEscapeCharacter,
'escape_char_style': 'SCE_VB_ESCAPECHAR',
Expand Down Expand Up @@ -1088,7 +1089,8 @@ class KeywordAttr(IntFlag):
'NP2LEX_VISUALBASIC': {
'line_comment_string': "'",
'comment_style_marker': 'SCE_VB_COMMENTLINE',
'default_fold_level': ['class', 'function'],
'default_fold_level': ['namespace', 'class', 'function'],
'default_fold_ignore_inner': 'SCE_VB_FUNCTION_DEFINITION',
'format_specifier_style': 'SCE_VB_FORMAT_SPECIFIER',
'escape_char_start': NoEscapeCharacter,
'escape_char_style': 'SCE_VB_ESCAPECHAR',
Expand Down

0 comments on commit 21e552b

Please sign in to comment.