Add TypeScript language

Fix #10353, close #10361
This commit is contained in:
0xlay 2021-08-09 15:39:55 +03:00 committed by Don Ho
parent 2576bf884b
commit 9a3152faa2
11 changed files with 87 additions and 4 deletions

View File

@ -95,6 +95,7 @@
<association id= "spice.xml" langID= "82"/>
<association id= "txt2tags.xml" langID= "83"/>
<association id= "visualprolog.xml" langID= "84"/>
<association id= "typescript.xml" langID= "85"/>
If you create your own parse rule of supported languages (above) for your specific need,
you can copy it without modifying the original one, and make it point to your rule.

View File

@ -32,7 +32,7 @@ enum LangType {L_TEXT, L_PHP , L_C, L_CPP, L_CS, L_OBJC, L_JAVA, L_RC,\
L_ASN1, L_AVS, L_BLITZBASIC, L_PUREBASIC, L_FREEBASIC, \
L_CSOUND, L_ERLANG, L_ESCRIPT, L_FORTH, L_LATEX, \
L_MMIXAL, L_NIM, L_NNCRONTAB, L_OSCRIPT, L_REBOL, \
L_REGISTRY, L_RUST, L_SPICE, L_TXT2TAGS, L_VISUALPROLOG,\
L_REGISTRY, L_RUST, L_SPICE, L_TXT2TAGS, L_VISUALPROLOG, L_TYPESCRIPT,\
// Don't use L_JS, use L_JAVASCRIPT instead
// The end of enumated language type, so it should be always at the end
L_EXTERNAL};

View File

@ -3448,7 +3448,9 @@ LangType Notepad_plus::menuID2LangType(int cmdID)
return L_TXT2TAGS;
case IDM_LANG_VISUALPROLOG:
return L_VISUALPROLOG;
case IDM_LANG_USER :
case IDM_LANG_TYPESCRIPT:
return L_TYPESCRIPT;
case IDM_LANG_USER:
return L_USER;
default:
{

View File

@ -946,6 +946,7 @@ BEGIN
MENUITEM "Tektronix extended HEX", IDM_LANG_TEHEX
MENUITEM "TeX", IDM_LANG_TEX
MENUITEM "txt2tags", IDM_LANG_TXT2TAGS
MENUITEM "TypeScript", IDM_LANG_TYPESCRIPT
MENUITEM "Verilog", IDM_LANG_VERILOG
MENUITEM "VHDL", IDM_LANG_VHDL
MENUITEM "Visual Basic", IDM_LANG_VB
@ -1087,6 +1088,7 @@ BEGIN
MENUITEM "Tektronix extended HEX",IDM_LANG_TEHEX
MENUITEM "TeX", IDM_LANG_TEX
MENUITEM "txt2tags", IDM_LANG_TXT2TAGS
MENUITEM "TypeScript", IDM_LANG_TYPESCRIPT
END
POPUP "V"
BEGIN

View File

@ -3333,6 +3333,7 @@ void Notepad_plus::command(int id)
case IDM_LANG_SPICE :
case IDM_LANG_TXT2TAGS :
case IDM_LANG_VISUALPROLOG:
case IDM_LANG_TYPESCRIPT:
case IDM_LANG_USER :
{
setLanguage(menuID2LangType(id));

View File

@ -6968,6 +6968,9 @@ int NppParameters::langTypeToCommandID(LangType lt) const
case L_VISUALPROLOG:
id = IDM_LANG_VISUALPROLOG; break;
case L_TYPESCRIPT:
id = IDM_LANG_TYPESCRIPT; break;
case L_SEARCHRESULT :
id = -1; break;

View File

@ -59,7 +59,7 @@ const int ScintillaEditView::_markersArray[][NB_FOLDER_STATE] = {
// Array with all the names of all languages
// The order of lang type (enum LangType) must be respected
LanguageName ScintillaEditView::langNames[L_EXTERNAL+1] = {
LanguageName ScintillaEditView::langNames[L_EXTERNAL + 1] = {
{TEXT("normal"), TEXT("Normal text"), TEXT("Normal text file"), L_TEXT, SCLEX_NULL},
{TEXT("php"), TEXT("PHP"), TEXT("PHP Hypertext Preprocessor file"), L_PHP, SCLEX_HTML},
{TEXT("c"), TEXT("C"), TEXT("C source file"), L_C, SCLEX_CPP},
@ -145,6 +145,7 @@ LanguageName ScintillaEditView::langNames[L_EXTERNAL+1] = {
{TEXT("spice"), TEXT("Spice"), TEXT("spice file"), L_SPICE, SCLEX_SPICE},
{TEXT("txt2tags"), TEXT("txt2tags"), TEXT("txt2tags file"), L_TXT2TAGS, SCLEX_TXT2TAGS},
{TEXT("visualprolog"), TEXT("Visual Prolog"), TEXT("Visual Prolog file"), L_VISUALPROLOG, SCLEX_VISUALPROLOG},
{TEXT("typescript"), TEXT("TypeScript"), TEXT("TypeScript file"), L_TYPESCRIPT, SCLEX_CPP},
{TEXT("ext"), TEXT("External"), TEXT("External"), L_EXTERNAL, SCLEX_NULL}
};
@ -1166,6 +1167,50 @@ void ScintillaEditView::setObjCLexer(LangType langType)
execute(SCI_SETPROPERTY, reinterpret_cast<WPARAM>("fold.preprocessor"), reinterpret_cast<LPARAM>("1"));
}
void ScintillaEditView::setTypeScriptLexer()
{
const TCHAR* doxygenKeyWords = NppParameters::getInstance().getWordList(L_CPP, LANG_INDEX_TYPE2);
execute(SCI_SETLEXER, SCLEX_CPP);
if (doxygenKeyWords)
{
WcharMbcsConvertor& wmc = WcharMbcsConvertor::getInstance();
const char* doxygenKeyWords_char = wmc.wchar2char(doxygenKeyWords, CP_ACP);
execute(SCI_SETKEYWORDS, 2, reinterpret_cast<LPARAM>(doxygenKeyWords_char));
}
const TCHAR* pKwArray[10] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
makeStyle(L_TYPESCRIPT, pKwArray);
auto getKeywordList = [&pKwArray](const int i)
{
if (pKwArray[i])
{
basic_string<wchar_t> kwlW = pKwArray[i];
return wstring2string(kwlW, CP_ACP);
}
return basic_string<char>("");
};
auto keywordListInstruction = getKeywordList(LANG_INDEX_INSTR);
const char* tsInstructions = getCompleteKeywordList(keywordListInstruction, L_TYPESCRIPT, LANG_INDEX_INSTR);
string keywordListType = getKeywordList(LANG_INDEX_TYPE);
const char* tsTypes = getCompleteKeywordList(keywordListType, L_TYPESCRIPT, LANG_INDEX_TYPE);
execute(SCI_SETKEYWORDS, 0, reinterpret_cast<LPARAM>(tsInstructions));
execute(SCI_SETKEYWORDS, 1, reinterpret_cast<LPARAM>(tsTypes));
execute(SCI_SETPROPERTY, reinterpret_cast<WPARAM>("fold"), reinterpret_cast<LPARAM>("1"));
execute(SCI_SETPROPERTY, reinterpret_cast<WPARAM>("fold.compact"), reinterpret_cast<LPARAM>("0"));
execute(SCI_SETPROPERTY, reinterpret_cast<WPARAM>("fold.comment"), reinterpret_cast<LPARAM>("1"));
execute(SCI_SETPROPERTY, reinterpret_cast<WPARAM>("fold.preprocessor"), reinterpret_cast<LPARAM>("1"));
execute(SCI_SETPROPERTY, reinterpret_cast<WPARAM>("lexer.cpp.track.preprocessor"), reinterpret_cast<LPARAM>("0"));
execute(SCI_SETPROPERTY, reinterpret_cast<WPARAM>("lexer.cpp.backquoted.strings"), reinterpret_cast<LPARAM>("1"));
}
void ScintillaEditView::setKeywords(LangType langType, const char *keywords, int index)
{
std::basic_string<char> wordList;
@ -1711,6 +1756,9 @@ void ScintillaEditView::defineDocType(LangType typeDoc)
case L_VISUALPROLOG:
setVisualPrologLexer(); break;
case L_TYPESCRIPT:
setTypeScriptLexer(); break;
case L_TEXT :
default :
if (typeDoc >= L_EXTERNAL && typeDoc < NppParameters::getInstance().L_END)

View File

@ -674,6 +674,8 @@ protected:
void setEmbeddedPhpLexer();
void setEmbeddedAspLexer();
void setJsonLexer();
void setTypeScriptLexer();
//Simple lexers
void setCssLexer() {
setLexer(SCLEX_CSS, L_CSS, LIST_0 | LIST_1);

View File

@ -194,7 +194,7 @@
<Language name="javascript" ext="" commentLine="//" commentStart="/*" commentEnd="*/">
<Keywords name="instre1">abstract async await boolean break byte case catch char class const continue debugger default delete do double else enum export extends final finally float for function goto if implements import in instanceof int interface let long native new null of package private protected public return short static super switch synchronized this throw throws transient try typeof var void volatile while with true false prototype yield</Keywords>
</Language>
<Language name="javascript.js" ext="js jsm jsx ts tsx" commentLine="//" commentStart="/*" commentEnd="*/">
<Language name="javascript.js" ext="js jsm jsx" commentLine="//" commentStart="/*" commentEnd="*/">
<Keywords name="instre1">abstract async await boolean break byte case catch char class const continue debugger default delete do double else enum export extends final finally float for function goto if implements import in instanceof int interface let long native new null of package private protected public return short static super switch synchronized this throw throws transient try typeof var void volatile while with true false prototype yield</Keywords>
<Keywords name="type1">Array Date eval hasOwnProperty Infinity isFinite isNaN isPrototypeOf Math NaN Number Object prototype String toString undefined valueOf</Keywords>
<Keywords name="instre2">alert all anchor anchors area assign blur button checkbox clearInterval clearTimeout clientInformation close closed confirm constructor crypto decodeURI decodeURIComponent defaultStatus document element elements embed embeds encodeURI encodeURIComponent escape event fileUpload focus form forms frame innerHeight innerWidth layer layers link location mimeTypes navigate navigator frames frameRate hidden history image images offscreenBuffering onblur onclick onerror onfocus onkeydown onkeypress onkeyup onmouseover onload onmouseup onmousedown onsubmit open opener option outerHeight outerWidth packages pageXOffset pageYOffset parent parseFloat parseInt password pkcs11 plugin prompt propertyIsEnum radio reset screenX screenY scroll secure select self setInterval setTimeout status submit taint text textarea top unescape untaint window</Keywords>
@ -371,6 +371,10 @@
<Keywords name="instre1">addhandler addressof alias and andalso as boolean by byref byte byval call case catch cbool cbyte cchar cdate cdbl cdec char cint class clng cobj const continue csbyte cshort csng cstr ctype cuint culng cushort date decimal declare default delegate dim directcast do double each else elseif end endif enum erase error event exit false finally for friend function get gettype global gosub goto handles if implements imports in inherits integer interface is isnot let lib like long loop me mod module mustinherit mustoverride mybase myclass namespace narrowing new next not nothing notinheritable notoverridable object of on operator option optional or orelse out overloads overridable overrides paramarray partial private property protected public raiseevent readonly redim rem removehandler resume return sbyte select set shadows shared short single static step stop strict string structure sub synclock then throw to true try trycast typeof uinteger ulong ushort using variant wend when while widening with withevents writeonly xor attribute begin currency implement load lset rset type unload aggregate ansi assembly async auto await binary compare custom distinct equals explicit from group into isfalse istrue iterator join key mid off order preserve skip take text unicode until where yield</Keywords>
</Language>
<Language name="txt2tags" ext="t2t" commentLine="" commentStart="" commentEnd=""/>
<Language name="typescript" ext="ts tsx" commentLine="//" commentStart="/*" commentEnd="*/">
<Keywords name="instre1">abstract package symbol get module require set as declare type null NaN undefined from async await break case catch class const continue debugger default delete do else enum export extends finally for function goto if implements import in instanceof int interface let new of private protected public return static super switch synchronized this throw throws transient try typeof var volatile while with true false prototype yield</Keywords>
<Keywords name="type1">Array String number string boolean void any bigint Date</Keywords>
</Language>
<Language name="verilog" ext="v sv vh svh" commentLine="//" commentStart="/*" commentEnd="*/">
<Keywords name="instre1">accept_on alias always always_comb always_ff always_latch and assert assign assume attribute automatic before begin bind bins binsof bit break buf bufif0 bufif1 byte case casex casez cell chandle checker class clocking cmos config const constraint context continue cover covergroup coverpoint cross deassign default defparam design disable dist do edge else end endattribute endcase endchecker endclass endclocking endconfig endfunction endgenerate endgroup endinterface endmodule endpackage endprimitive endprogram endproperty endsequence endspecify endtable endtask enum event eventually expect export extends extern final first_match for force foreach forever fork forkjoin function generate genvar global highz0 highz1 if iff ifnone ignore_bins illegal_bins implements implies import incdir include initial inout input inside instance int integer interconnect interface intersect join join_any join_none large let liblist library local localparam logic longint macromodule matches medium modport module nand negedge nettype new nexttime nmos nor noshowcancelled not notif0 notif1 null or output package packed parameter pmos posedge primitive priority program property protected pull0 pull1 pulldown pullup pulsestyle_ondetect pulsestyle_onevent pure rand randc randcase randsequence rcmos real realtime ref reg reject_on release repeat restrict return rnmos rpmos rtran rtranif0 rtranif1 scalared sequence shortint shortreal showcancelled signed small soft solve specify specparam static string strong strong0 strong1 struct super supply0 supply1 sync_accept_on sync_reject_on s_always s_eventually s_nexttime s_until s_until_with table tagged task this throughout time timeprecision timeunit tran tranif0 tranif1 tri tri0 tri1 triand trior trireg type typedef union unique unique0 unsigned until until_with untyped use var vectored virtual void wait wait_order wand weak weak0 weak1 while wildcard wire with within wor xnor xor</Keywords>
<Keywords name="instre2">$acos $acosh $asin $asinh $assertcontrol $assertkill $assertoff $asserton $assertpasson $assertpassoff $assertfailon $assertfailoff $assertnonvacuouson $assertvacuousoff $async$and$array $async$and$plane $async$nand$array $async$nand$plane $async$nor$array $async$nor$plane $async$or$array $async$or$plane $atan $atan2 $atanh $bits $bitstoreal $bitstoshortreal $cast $ceil $changed_gclk $changing_gclk $clog2 $comment $cos $cosh $countdrivers $countones $coverage_control $coverage_get $coverage_get_max $coverage_merge $coverage_save $date $dimensions $display $displayb $displayh $displayo $dist_chi_square $dist_erlang $dist_exponential $dist_normal $dist_poisson $dist_t $dist_uniform $dumpall $dumpfile $dumpflush $dumplimit $dumpoff $dumpon $dumpportsall $dumpportsflush $dumpportslimit $dumpportsoff $dumpportson $dumpvars $end $enddefinitions $error $exit $exp $falling_gclk $fatal $fclose $fdisplay $fdisplayb $fdisplayh $fdisplayo $fell $fell_gclk $feof $ferror $fflush $fgetc $fgets $finish $floor $fmonitor $fmonitorb $fmonitorh $fmonitoro $fopen $fread $fscanf $fseek $fstrobe $ftell $fullskew $future_gclk $fwrite $fwriteb $fwriteh $fwriteo $getpattern $get_coverage $high $history $hold $hypot $increment $incsave $info $input $isunbounded $isunknown $itor $key $left $list $ln $load_coverage_db $log $log10 $low $monitor $monitorb $monitorh $monitoro $monitoroff $monitoron $nochange $nokey $nolog $onehot $onehot0 $past $past_gclk $period $pow $printtimescale $q_add $q_exam $q_full $q_initialize $q_remove $random $readmemb $readmemh $realtime $realtobits $recovery $recrem $removal $reset $reset_count $reset_value $restart $rewind $right $rising_gclk $root $rose $rose_gclk $rtoi $sampled $save $scale $scope $setup $setuphold $set_coverage_db_name $sformat $sformatf $shortrealtobits $showscopes $showvariables $showvars $signed $sin $sinh $size $skew $sqrt $sreadmemb $sreadmemh $sscanf $stable $stable_gclk $steady_gclk $stime $stop $strobe $strobeb $strobeh $strobeo $swrite $sync$and$array $sync$and$plane $sync$nand$array $sync$nand$plane $sync$nor$array $sync$nor$plane $sync$or$array $sync$or$plane $system $tan $tanh $test$plusargs $time $timeformat $timescale $timeskew $typename $typeof $uandom $ungetc $unit $unpacked_dimensions $unsigned $upscope $urandom_range $value$plusargs $var $vcdclose $version $warning $width $write $writeb $writeh $writememb $writememh $writeo</Keywords>

View File

@ -517,6 +517,7 @@
#define IDM_LANG_SPICE (IDM_LANG + 81)
#define IDM_LANG_TXT2TAGS (IDM_LANG + 82)
#define IDM_LANG_VISUALPROLOG (IDM_LANG + 83)
#define IDM_LANG_TYPESCRIPT (IDM_LANG + 84)
#define IDM_LANG_EXTERNAL (IDM_LANG + 165)
#define IDM_LANG_EXTERNAL_LIMIT (IDM_LANG + 179)

View File

@ -1265,6 +1265,25 @@
<WordsStyle name="OPTION" styleID="23" fgColor="C0036E" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" />
<WordsStyle name="PREPROC" styleID="24" fgColor="848B00" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" />
<WordsStyle name="POSTPROC" styleID="25" fgColor="C05600" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" />
</LexerType>
<LexerType name="typescript" desc="TypeScript" ext="">
<WordsStyle name="DEFAULT" styleID="11" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" />
<WordsStyle name="INSTRUCTION WORD" styleID="5" fgColor="0000FF" bgColor="FFFFFF" fontName="" fontStyle="1" fontSize="" keywordClass="instre1" />
<WordsStyle name="TYPE WORD" styleID="16" fgColor="8000FF" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" keywordClass="type1" />
<WordsStyle name="WINDOW INSTRUCTION" styleID="19" fgColor="804000" bgColor="FFFFFF" fontName="" fontStyle="1" fontSize=""/>
<WordsStyle name="NUMBER" styleID="4" fgColor="FF8000" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" />
<WordsStyle name="STRING" styleID="6" fgColor="c94949" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" />
<WordsStyle name="STRINGRAW" styleID="20" fgColor="000080" bgColor="C0C0C0" fontName="" fontStyle="0" fontSize="" />
<WordsStyle name="CHARACTER" styleID="7" fgColor="c94949" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" />
<WordsStyle name="OPERATOR" styleID="10" fgColor="000080" bgColor="FFFFFF" fontName="" fontStyle="1" fontSize="" />
<WordsStyle name="VERBATIM" styleID="13" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" />
<WordsStyle name="REGEX" styleID="14" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="1" fontSize="" />
<WordsStyle name="COMMENT" styleID="1" fgColor="008000" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" />
<WordsStyle name="COMMENT LINE" styleID="2" fgColor="008000" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" />
<WordsStyle name="COMMENT DOC" styleID="3" fgColor="008080" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" />
<WordsStyle name="COMMENT LINE DOC" styleID="15" fgColor="008080" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" />
<WordsStyle name="COMMENT DOC KEYWORD" styleID="17" fgColor="008080" bgColor="FFFFFF" fontName="" fontStyle="1" fontSize="" />
<WordsStyle name="COMMENT DOC KEYWORD ERROR" styleID="18" fgColor="008080" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" />
</LexerType>
<LexerType name="vb" desc="VB / VBS" ext="">
<WordsStyle name="DEFAULT" styleID="7" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" fontSize="" />