|
1 | 1 | #include "CodeFormatServer/LanguageService.h" |
| 2 | +#include <fstream> |
| 3 | +#include <sstream> |
| 4 | +#include "nlohmann/json.hpp" |
2 | 5 | #include "CodeFormatServer/VSCode.h" |
3 | 6 | #include "CodeService/LuaCodeStyleOptions.h" |
4 | 7 | #include "CodeService/LuaFormatter.h" |
@@ -64,6 +67,33 @@ std::shared_ptr<vscode::InitializeResult> LanguageService::OnInitialize(std::sha |
64 | 67 | LanguageClient::GetInstance().UpdateOptions(configFile.workspace, configFile.path); |
65 | 68 | } |
66 | 69 |
|
| 70 | + std::filesystem::path localePath = param->initializationOptions.localeRoot; |
| 71 | + localePath /= param->locale + ".json"; |
| 72 | + |
| 73 | + if (std::filesystem::exists(localePath) && std::filesystem::is_regular_file(localePath)) |
| 74 | + { |
| 75 | + std::fstream fin(localePath.string(), std::ios::in); |
| 76 | + |
| 77 | + if (fin.is_open()) |
| 78 | + { |
| 79 | + std::stringstream s; |
| 80 | + s << fin.rdbuf(); |
| 81 | + std::string jsonText = s.str(); |
| 82 | + auto json = nlohmann::json::parse(jsonText); |
| 83 | + |
| 84 | + if (json.is_object()) |
| 85 | + { |
| 86 | + std::map<std::string, std::string> languageMap; |
| 87 | + for (auto [key,value] : json.items()) |
| 88 | + { |
| 89 | + languageMap.insert({key, value}); |
| 90 | + } |
| 91 | + |
| 92 | + LanguageTranslator::GetInstance().SetLanguageMap(std::move(languageMap)); |
| 93 | + } |
| 94 | + } |
| 95 | + } |
| 96 | + |
67 | 97 |
|
68 | 98 | return result; |
69 | 99 | } |
@@ -194,7 +224,7 @@ std::shared_ptr<vscode::Serializable> LanguageService::OnTypeFormatting( |
194 | 224 | auto position = param->position; |
195 | 225 |
|
196 | 226 | auto result = std::make_shared<vscode::DocumentFormattingResult>(); |
197 | | - if(parser->IsEmptyLine(position.line - 1)) |
| 227 | + if (parser->IsEmptyLine(position.line - 1)) |
198 | 228 | { |
199 | 229 | result->hasError = true; |
200 | 230 | return result; |
|
0 commit comments