Skip to content

Commit

Permalink
Improve auto-completion for $variable.
Browse files Browse the repository at this point in the history
  • Loading branch information
zufuliu committed Apr 5, 2023
1 parent 17f2fdc commit 97a5846
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 53 deletions.
14 changes: 9 additions & 5 deletions scintilla/lexers/LexBash.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ using namespace Lexilla;

namespace {

//KeywordIndex++Autogenerated -- start of section automatically generated
enum {
KeywordIndex_Keyword = 0,
KeywordIndex_BashStruct = 1,
};
//KeywordIndex--Autogenerated -- end of section automatically generated

#define HERE_DELIM_MAX 256

// define this if you want 'invalid octals' to be marked as errors
Expand Down Expand Up @@ -174,9 +181,6 @@ constexpr bool IsBashCmdDelimiter(int ch, int chNext) noexcept {
}

void ColouriseBashDoc(Sci_PositionU startPos, Sci_Position length, int initStyle, LexerWordList keywordLists, Accessor &styler) {
const WordList &keywords = keywordLists[0];
const WordList &bashStruct = keywordLists[1];

class HereDocCls { // Class to manage HERE document elements
public:
int State; // 0: '<<' encountered
Expand Down Expand Up @@ -359,7 +363,7 @@ void ColouriseBashDoc(Sci_PositionU startPos, Sci_Position length, int initStyle
sc.ChangeState(SCE_SH_IDENTIFIER);
}
// detect bash construct keywords
else if (bashStruct.InList(s)) {
else if (keywordLists[KeywordIndex_BashStruct].InList(s)) {
if (cmdState == BASH_CMD_START && keywordEnds)
cmdStateNew = BASH_CMD_START;
else
Expand All @@ -379,7 +383,7 @@ void ColouriseBashDoc(Sci_PositionU startPos, Sci_Position length, int initStyle
}
// disambiguate keywords and identifiers
else if (cmdState != BASH_CMD_START
|| !(keywords.InList(s) && keywordEnds)) {
|| !(keywordLists[KeywordIndex_Keyword].InList(s) && keywordEnds)) {
sc.ChangeState(SCE_SH_IDENTIFIER);
}

Expand Down
2 changes: 1 addition & 1 deletion scintilla/lexers/LexPHP.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ bool PHPLexer::ClassifyPHPWord(LexerWordList keywordLists, int visibleChars) {
sc.GetCurrent(s, sizeof(s));
// variable, constant and enum name is case-sensitive
if (sc.state == SCE_PHP_VARIABLE) {
if (keywordLists[KeywordIndex_PredefinedVariable].InList(s)) {
if (keywordLists[KeywordIndex_PredefinedVariable].InList(s + 1)) {
sc.ChangeState(SCE_PHP_PREDEFINED_VARIABLE);
}
} else if (keywordLists[KeywordIndex_MagicConstant].InList(s)) {
Expand Down
64 changes: 42 additions & 22 deletions src/EditAutoC.c
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,7 @@ enum {
AutoIt3KeywordIndex_Macro = 2,
AutoIt3KeywordIndex_Directive = 4,
AutoIt3KeywordIndex_Special = 5,
BashKeywordIndex_Variable = 2,
CPPKeywordIndex_Preprocessor = 2,
CPPKeywordIndex_Directive = 3,
CSSKeywordIndex_AtRule = 1,
Expand Down Expand Up @@ -679,10 +680,13 @@ enum {
JuliaKeywordIndex_Macro = 6,
KotlinKeywordIndex_Annotation = 4,
KotlinKeywordIndex_Kdoc = 6,
NSISKeywordIndex_PredefinedVariable = 5,
PHPKeywordIndex_PredefinedVariable = 4,
PHPKeywordIndex_Phpdoc = 11,
PowerShellKeywordIndex_PredefinedVariable = 4,
PythonKeywordIndex_Decorator = 7,
RebolKeywordIndex_Directive = 1,
RubyKeywordIndex_PredefinedVariable = 4,
ScalaKeywordIndex_Annotation = 3,
ScalaKeywordIndex_Scaladoc = 5,
SmaliKeywordIndex_Directive = 9,
Expand Down Expand Up @@ -1091,6 +1095,13 @@ static AddWordResult AutoC_AddSpecWord(struct WordList *pWList, int iCurrentStyl
}
break;

case NP2LEX_BASH:
if (ch == '$') {
WordList_AddList(pWList, pLex->pKeyWords->pszKeyWords[BashKeywordIndex_Variable]);
return AddWordResult_IgnoreLexer;
}
break;

case NP2LEX_CSS:
if (ch == '@' && iCurrentStyle == SCE_CSS_DEFAULT) {
WordList_AddList(pWList, pLex->pKeyWords->pszKeyWords[CSSKeywordIndex_AtRule]);
Expand Down Expand Up @@ -1120,18 +1131,13 @@ static AddWordResult AutoC_AddSpecWord(struct WordList *pWList, int iCurrentStyl
}
} else if (iCurrentStyle == SCE_C_DEFAULT) {
if (ch == '#') { // #preprocessor
const char *pKeywords = pLex->pKeyWords->pszKeyWords[CPPKeywordIndex_Preprocessor];
if (StrNotEmptyA(pKeywords)) {
WordList_AddListEx(pWList, pKeywords);
return AddWordResult_Finish;
}
} else if (ch == '@') { // @directive, @annotation, @decorator
const char *pKeywords = pLex->pKeyWords->pszKeyWords[CPPKeywordIndex_Directive];
if (StrNotEmptyA(pKeywords)) {
WordList_AddListEx(pWList, pKeywords);
// user defined annotation
return AddWordResult_IgnoreLexer;
}
WordList_AddList(pWList, pLex->pKeyWords->pszKeyWords[CPPKeywordIndex_Preprocessor]);
return AddWordResult_Finish;
}
if (ch == '@') { // @directive, @annotation, @decorator
WordList_AddList(pWList, pLex->pKeyWords->pszKeyWords[CPPKeywordIndex_Directive]);
// user defined annotation
return AddWordResult_IgnoreLexer;
}
//else if (chPrev == ':' && ch == ':') {
// WordList_AddList(pWList, "C++/namespace C++/Java8/PHP/static SendMessage()");
Expand Down Expand Up @@ -1296,12 +1302,22 @@ static AddWordResult AutoC_AddSpecWord(struct WordList *pWList, int iCurrentStyl
}
break;

case NP2LEX_NSIS:
if (ch == '$') {
WordList_AddList(pWList, pLex->pKeyWords->pszKeyWords[NSISKeywordIndex_PredefinedVariable]);
return AddWordResult_IgnoreLexer;
}
break;

case NP2LEX_PHP:
if (ch == '@') {
if (iCurrentStyle >= SCE_PHP_COMMENTLINE && iCurrentStyle <= SCE_PHP_TASKMARKER) {
WordList_AddList(pWList, pLex->pKeyWords->pszKeyWords[PHPKeywordIndex_Phpdoc]);
return AddWordResult_Finish;
}
} else if (ch == '$') {
WordList_AddList(pWList, pLex->pKeyWords->pszKeyWords[PHPKeywordIndex_PredefinedVariable]);
return AddWordResult_IgnoreLexer;
}
break;

Expand All @@ -1314,11 +1330,8 @@ static AddWordResult AutoC_AddSpecWord(struct WordList *pWList, int iCurrentStyl

case NP2LEX_PYTHON:
if (ch == '@' && iCurrentStyle == SCE_PY_DEFAULT) {
const char *pKeywords = pLex->pKeyWords->pszKeyWords[PythonKeywordIndex_Decorator];
if (StrNotEmptyA(pKeywords)) {
WordList_AddListEx(pWList, pKeywords);
return AddWordResult_IgnoreLexer;
}
WordList_AddList(pWList, pLex->pKeyWords->pszKeyWords[PythonKeywordIndex_Decorator]);
return AddWordResult_IgnoreLexer;
}
break;

Expand All @@ -1329,6 +1342,13 @@ static AddWordResult AutoC_AddSpecWord(struct WordList *pWList, int iCurrentStyl
}
break;

case NP2LEX_RUBY:
if (ch == '$') {
WordList_AddList(pWList, pLex->pKeyWords->pszKeyWords[RubyKeywordIndex_PredefinedVariable]);
return AddWordResult_IgnoreLexer;
}
break;

case NP2LEX_SCALA:
if (ch == '@') {
if (iCurrentStyle == SCE_SCALA_DEFAULT) {
Expand Down Expand Up @@ -1378,14 +1398,14 @@ static AddWordResult AutoC_AddSpecWord(struct WordList *pWList, int iCurrentStyl

case NP2LEX_VISUALBASIC:
if (ch == '#' && iCurrentStyle == SCE_B_DEFAULT) {
const char *pKeywords = pLex->pKeyWords->pszKeyWords[VBKeywordIndex_Preprocessor];
if (StrNotEmptyA(pKeywords)) {
WordList_AddListEx(pWList, pKeywords);
return AddWordResult_Finish;
}
WordList_AddList(pWList, pLex->pKeyWords->pszKeyWords[VBKeywordIndex_Preprocessor]);
return AddWordResult_Finish;
}
break;
}
if ((ch == '$') && IsDocWordChar(ch)) {
return AddWordResult_IgnoreLexer;
}
return AddWordResult_None;
}

Expand Down
10 changes: 5 additions & 5 deletions src/EditLexers/stlBash.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ static KEYWORDLIST Keywords_Bash = {{
, // 1 bashStruct
"if elif fi while until else then do done esac eval"

, // 2
"$PATH $MANPATH $INFOPATH $USER $TMP $TEMP $PRINTER $HOSTNAME $PS1 $SHELL "
"$JAVA_HOME $JAVA_OPTS $CATALINA_HOME $CATALINA_BASE $CATALINA_OPTS "
, // 2 variables
"PATH MANPATH INFOPATH USER TMP TEMP PRINTER HOSTNAME PS1 SHELL "
"JAVA_HOME JAVA_OPTS CATALINA_HOME CATALINA_BASE CATALINA_OPTS "

, NULL, NULL, NULL, NULL, NULL, NULL

Expand Down Expand Up @@ -72,8 +72,8 @@ EDITLEXER lexBash = {
'\\', 0, 0,
SCE_SH_WORD,
0, 0,
SCE_SH_OPERATOR, 0,
KeywordAttr_Default
SCE_SH_OPERATOR, 0
, KeywordAttr32(2, KeywordAttr_NoLexer | KeywordAttr_NoAutoComp) // variables
},
//Settings--Autogenerated -- end of section automatically generated
EDITLEXER_HOLE(L"Shell Script", Styles_Bash),
Expand Down
11 changes: 5 additions & 6 deletions src/EditLexers/stlNsis.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,11 @@ static KEYWORDLIST Keywords_NSIS = {{
"onUninstFailed onUninstSuccess onUserAbort onVerifyInstDir "

, // 5 predefined variables
"$ADMINTOOLS $APPDATA $CDBURN_AREA $COOKIES $DESKTOP $DOCUMENTS $EXEDIR $EXEFILE $EXEPATH $FAVORITES $FONTS "
"$HISTORY $HWNDPARENT $INTERNET_CACHE $LOCALAPPDATA $MUSIC $NETHOOD "
"$PICTURES $PLUGINSDIR $PRINTHOOD $PROFILE $PROGRAMFILES $PROGRAMFILES32 $PROGRAMFILES64 $QUICKLAUNCH "
"$RECENT $RESOURCES $RESOURCES_LOCALIZED $SENDTO $SMPROGRAMS $SMSTARTUP $STARTMENU $SYSDIR $TEMP $TEMPLATES $VIDEOS "
"$WINDIR ${NSISDIR} ${NSIS_CHAR_SIZE} ${NSIS_PACKEDVERSION} ${NSIS_PTR_SIZE} ${NSIS_VERSION} "
"${__COUNTER__} ${__DATE__} ${__FILEDIR__} ${__FILE__} ${__LINE__} ${__TIMESTAMP__} ${__TIME__} "
"ADMINTOOLS APPDATA CDBURN_AREA COOKIES DESKTOP DOCUMENTS EXEDIR EXEFILE EXEPATH FAVORITES FONTS HISTORY HWNDPARENT "
"INTERNET_CACHE LOCALAPPDATA MUSIC NETHOOD NSISDIR NSIS_CHAR_SIZE NSIS_PACKEDVERSION NSIS_PTR_SIZE NSIS_VERSION "
"PICTURES PLUGINSDIR PRINTHOOD PROFILE PROGRAMFILES PROGRAMFILES32 PROGRAMFILES64 QUICKLAUNCH "
"RECENT RESOURCES RESOURCES_LOCALIZED SENDTO SMPROGRAMS SMSTARTUP STARTMENU SYSDIR TEMP TEMPLATES VIDEOS WINDIR "
"__COUNTER__ __DATE__ __FILEDIR__ __FILE__ __LINE__ __TIMESTAMP__ __TIME__ "

, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
//--Autogenerated -- end of section automatically generated
Expand Down
4 changes: 2 additions & 2 deletions src/EditLexers/stlPHP.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static KEYWORDLIST Keywords_PHP = {{
"Throwable Traversable UnitEnum "

, // 4 predefined variable
"$GLOBALS $_COOKIE $_ENV $_FILES $_GET $_POST $_REQUEST $_SERVER $_SESSION $argc $argv $http_response_header $this "
"GLOBALS _COOKIE _ENV _FILES _GET _POST _REQUEST _SERVER _SESSION argc argv http_response_header this "

, // 5 magic constant
"__CLASS__ __COMPILER_HALT_OFFSET__ __DIR__ __FILE__ __FUNCTION__ __LINE__ __METHOD__ __NAMESPACE__ __TRAIT__ "
Expand Down Expand Up @@ -451,7 +451,7 @@ EDITLEXER lexPHP = {
| KeywordAttr32(1, KeywordAttr_PreSorted) // type
| KeywordAttr32(2, KeywordAttr_MakeLower | KeywordAttr_PreSorted) // class
| KeywordAttr32(3, KeywordAttr_MakeLower | KeywordAttr_PreSorted) // interface
| KeywordAttr32(4, KeywordAttr_PreSorted) // predefined variable
| KeywordAttr32(4, KeywordAttr_PreSorted | KeywordAttr_NoAutoComp) // predefined variable
| KeywordAttr32(5, KeywordAttr_PreSorted) // magic constant
| KeywordAttr32(6, KeywordAttr_MakeLower | KeywordAttr_PreSorted) // magic method
| KeywordAttr64(7, KeywordAttr_NoLexer) // constant
Expand Down
4 changes: 2 additions & 2 deletions src/EditLexers/stlRuby.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ static KEYWORDLIST Keywords_Ruby = {{
"SCRIPT_LINES__ STDERR STDIN STDOUT TOPLEVEL_BINDING TRUE "

, // 4 pre-defined variables
"$DEBUG $FILENAME $LOADED_FEATURES $LOAD_PATH $VERBOSE $stderr $stdin $stdout "
"DEBUG FILENAME LOADED_FEATURES LOAD_PATH VERBOSE stderr stdin stdout "

, // 5 module
"AbstractSyntaxTree Comparable Constants Continuation Enumerable Errno FileUtils Formatter GC GID Kernel Marshal Math "
Expand Down Expand Up @@ -128,7 +128,7 @@ EDITLEXER lexRuby = {
| KeywordAttr32(1, KeywordAttr_PreSorted | KeywordAttr_NoAutoComp) // code folding
| KeywordAttr32(2, KeywordAttr_PreSorted | KeywordAttr_NoAutoComp) // regex
| KeywordAttr32(3, KeywordAttr_PreSorted) // pre-defined constants
| KeywordAttr32(4, KeywordAttr_NoLexer) // pre-defined variables
| KeywordAttr32(4, KeywordAttr_NoLexer | KeywordAttr_NoAutoComp) // pre-defined variables
| KeywordAttr32(5, KeywordAttr_PreSorted) // module
| KeywordAttr32(6, KeywordAttr_PreSorted) // class
| KeywordAttr64(7, KeywordAttr_PreSorted) // built-in function
Expand Down
4 changes: 2 additions & 2 deletions src/EditLexers/stlSwift.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ EDITLEXER lexSwift = {
0, 0,
SCE_SWIFT_OPERATOR, SCE_SWIFT_OPERATOR2
, KeywordAttr32(0, KeywordAttr_PreSorted) // keywords
| KeywordAttr32(1, KeywordAttr_PreSorted) // directive
| KeywordAttr32(2, KeywordAttr_PreSorted) // attribute
| KeywordAttr32(1, KeywordAttr_PreSorted | KeywordAttr_NoAutoComp) // directive
| KeywordAttr32(2, KeywordAttr_PreSorted | KeywordAttr_NoAutoComp) // attribute
| KeywordAttr32(3, KeywordAttr_PreSorted) // class
| KeywordAttr32(4, KeywordAttr_PreSorted) // struct
| KeywordAttr32(5, KeywordAttr_PreSorted) // protocol
Expand Down
24 changes: 17 additions & 7 deletions tools/KeywordCore.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,13 @@ def parse_awk_api_file(path):
('misc', keywordMap['misc'], KeywordAttr.NoLexer),
]

def parse_bash_api_file(path):
return [
('keywords', [], KeywordAttr.Default),
('bash struct', [], KeywordAttr.Default),
('variables', [], KeywordAttr.NoLexer | KeywordAttr.NoAutoComp | KeywordAttr.Special),
]

def parse_batch_api_file(path):
sections = read_api_file(path, '::')
keywordMap = {
Expand Down Expand Up @@ -1653,22 +1660,23 @@ def parse_nsis_api_file(path):
item = item[3:]
functions.append(item)
items = functions
elif key == 'predefined variables':
items = [item[2:-1] if item[-1] == '}' else item[1:] for item in items]
keywordMap[key] = items

RemoveDuplicateKeyword(keywordMap, [
'keywords',
'instructions',
'attributes',
'functions',
'predefined variables',
])
return [
('keywords', keywordMap['keywords'], KeywordAttr.MakeLower),
('preprocessor', keywordMap['preprocessor'], KeywordAttr.NoLexer),
('instruction', keywordMap['instructions'], KeywordAttr.NoLexer),
('attribute', keywordMap['attributes'], KeywordAttr.NoLexer),
('function', keywordMap['functions'], KeywordAttr.NoLexer),
('predefined variables', keywordMap['predefined variables'], KeywordAttr.NoLexer),
('predefined variables', keywordMap['predefined variables'], KeywordAttr.NoLexer | KeywordAttr.Special),
]

def parse_php_api_file(path):
Expand All @@ -1681,7 +1689,7 @@ def parse_php_api_file(path):
keywordMap[key] = doc.split()
elif key == 'predefined variable':
items = doc.split()
keywordMap[key] = [item for item in items if item[0] == '$']
keywordMap[key] = [item[1:] for item in items if item[0] == '$']
keywordMap['misc'] = [item for item in items if item[0].isalpha()]
elif key == 'api':
items = re.findall(r'\w+\(', doc)
Expand Down Expand Up @@ -1716,7 +1724,7 @@ def parse_php_api_file(path):
('type', keywordMap['type'], KeywordAttr.Default),
('class', keywordMap['class'], KeywordAttr.MakeLower),
('interface', keywordMap['interface'], KeywordAttr.MakeLower),
('predefined variable', keywordMap['predefined variable'], KeywordAttr.Default),
('predefined variable', keywordMap['predefined variable'], KeywordAttr.NoAutoComp | KeywordAttr.Special),
('magic constant', keywordMap['magic constant'], KeywordAttr.Default),
('magic method', keywordMap['magic method'], KeywordAttr.MakeLower),
('constant', keywordMap['constant'], KeywordAttr.NoLexer),
Expand Down Expand Up @@ -1943,6 +1951,8 @@ def parse_ruby_api_file(path):
keywordMap['function'].extend(items)
else:
items = set(doc.split())
if key == 'pre-defined variables':
items = [item[1:] for item in items]
keywordMap[key] = items

folding = keywordMap['code folding']
Expand All @@ -1962,7 +1972,7 @@ def parse_ruby_api_file(path):
('code folding', folding, KeywordAttr.NoAutoComp),
('regex', keywordMap['regex'], KeywordAttr.NoAutoComp),
('pre-defined constants', keywordMap['pre-defined constants'], KeywordAttr.Default),
('pre-defined variables', keywordMap['pre-defined variables'], KeywordAttr.NoLexer),
('pre-defined variables', keywordMap['pre-defined variables'], KeywordAttr.NoLexer | KeywordAttr.NoAutoComp | KeywordAttr.Special),
('module', keywordMap['module'], KeywordAttr.Default),
('class', keywordMap['class'], KeywordAttr.Default),
('built-in function', keywordMap['built-in function'], KeywordAttr.Default),
Expand Down Expand Up @@ -2197,8 +2207,8 @@ def parse_swift_api_file(path):
])
return [
('keywords', keywordMap['keywords'], KeywordAttr.Default),
('directive', keywordMap['directive'], KeywordAttr.Special),
('attribute', keywordMap['attribute'], KeywordAttr.Special),
('directive', keywordMap['directive'], KeywordAttr.NoAutoComp | KeywordAttr.Special),
('attribute', keywordMap['attribute'], KeywordAttr.NoAutoComp | KeywordAttr.Special),
('class', keywordMap['class'], KeywordAttr.Default),
('struct', keywordMap['struct'], KeywordAttr.Default),
('protocol', keywordMap['protocol'], KeywordAttr.Default),
Expand Down
2 changes: 1 addition & 1 deletion tools/KeywordUpdate.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
('NP2LEX_AVISYNTH', 'stlAviSynth.c', 'LexAviSynth.cxx', 'AviSynth.avs', 0, parse_avisynth_api_file),
('NP2LEX_AWK', 'stlAwk.c', 'LexAwk.cxx', 'Awk.awk', 1, parse_awk_api_file),

('NP2LEX_BASH', 'stlBash.c', 'LexBash.cxx', '', 0, None),
('NP2LEX_BASH', 'stlBash.c', 'LexBash.cxx', '', 0, parse_bash_api_file),
('NP2LEX_BATCH', 'stlBatch.c', 'LexBatch.cxx', 'Batch.bat', 0, parse_batch_api_file),

('NP2LEX_CIL', 'stlCIL.c', 'LexCIL.cxx', '', 0, None),
Expand Down

0 comments on commit 97a5846

Please sign in to comment.