@@ -14,7 +14,8 @@ LuaCodeFormat& LuaCodeFormat::GetInstance()
1414
1515LuaCodeFormat::LuaCodeFormat ()
1616 : _defaultOptions(std::make_shared<LuaCodeStyleOptions>()),
17- _codeSpellChecker(std::make_shared<CodeSpellChecker>())
17+ _codeSpellChecker(std::make_shared<CodeSpellChecker>()),
18+ _customParser(std::make_shared<LuaCustomParser>())
1819{
1920}
2021
@@ -63,6 +64,14 @@ void LuaCodeFormat::SetDefaultCodeStyle(ConfigMap& configMap)
6364 }
6465}
6566
67+ void LuaCodeFormat::SetSupportNonStandardSymbol (const std::string& tokenType,const std::vector<std::string>& tokens)
68+ {
69+ if (tokenType.size () == 1 )
70+ {
71+ _customParser->SetTokens (tokenType.front (), tokens);
72+ }
73+ }
74+
6675void LuaCodeFormat::LoadSpellDictionary (const std::string& path)
6776{
6877 _codeSpellChecker->LoadDictionary (path);
@@ -76,6 +85,9 @@ void LuaCodeFormat::LoadSpellDictionaryFromBuffer(const std::string& buffer)
7685std::string LuaCodeFormat::Reformat (const std::string& uri, std::string&& text, ConfigMap& configMap)
7786{
7887 auto parser = LuaParser::LoadFromBuffer (std::move (text));
88+ if (_customParser->IsSupportCustomTokens ()) {
89+ parser->GetTokenParser ()->SetCustomParser (_customParser);
90+ }
7991 parser->BuildAstWithComment ();
8092
8193 if (!parser->GetErrors ().empty ())
@@ -93,6 +105,9 @@ std::string LuaCodeFormat::RangeFormat(const std::string& uri, LuaFormatRange& r
93105 ConfigMap& configMap)
94106{
95107 auto parser = LuaParser::LoadFromBuffer (std::move (text));
108+ if (_customParser->IsSupportCustomTokens ()) {
109+ parser->GetTokenParser ()->SetCustomParser (_customParser);
110+ }
96111 parser->BuildAstWithComment ();
97112
98113 if (!parser->GetErrors ().empty ())
@@ -111,6 +126,9 @@ std::string LuaCodeFormat::RangeFormat(const std::string& uri, LuaFormatRange& r
111126std::pair<bool , std::vector<LuaDiagnosisInfo>> LuaCodeFormat::Diagnose (const std::string& uri, std::string&& text)
112127{
113128 auto parser = LuaParser::LoadFromBuffer (std::move (text));
129+ if (_customParser->IsSupportCustomTokens ()) {
130+ parser->GetTokenParser ()->SetCustomParser (_customParser);
131+ }
114132 parser->BuildAstWithComment ();
115133
116134 if (!parser->GetErrors ().empty ())
@@ -137,6 +155,10 @@ std::vector<LuaDiagnosisInfo> LuaCodeFormat::SpellCheck(const std::string& uri,
137155 const CodeSpellChecker::CustomDictionary& tempDict)
138156{
139157 auto parser = LuaParser::LoadFromBuffer (std::move (text));
158+ if (_customParser->IsSupportCustomTokens ()) {
159+ parser->GetTokenParser ()->SetCustomParser (_customParser);
160+ }
161+ parser->GetTokenParser ()->Parse ();
140162
141163 auto options = GetOptions (uri);
142164
0 commit comments