Adds support for setting custom defines in vscode settings.
This commit is contained in:
parent
220c6d0080
commit
b94ed45d9e
|
@ -36,6 +36,13 @@
|
||||||
],
|
],
|
||||||
"default": "off",
|
"default": "off",
|
||||||
"description": "Traces the communication between VS Code and the language server."
|
"description": "Traces the communication between VS Code and the language server."
|
||||||
|
},
|
||||||
|
"angelscript-languageserver.defines": {
|
||||||
|
"scope": "window",
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -108,6 +108,14 @@ connection.onInitialized(() => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
connection.workspace.getConfiguration('angelscript-languageserver.defines').then((config) => {
|
||||||
|
let defines = config as string[];
|
||||||
|
for (let index = 0; index < defines.length; index++) {
|
||||||
|
const define = defines[index];
|
||||||
|
database.addDefine(define);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
connection.workspace.getWorkspaceFolders().then((ws) => {
|
connection.workspace.getWorkspaceFolders().then((ws) => {
|
||||||
ws?.forEach(element => {
|
ws?.forEach(element => {
|
||||||
registerFiles(element.uri.substr(7))
|
registerFiles(element.uri.substr(7))
|
||||||
|
|
|
@ -11,6 +11,7 @@ Napi::Object Database::Init(Napi::Env env, Napi::Object exports) {
|
||||||
{InstanceMethod("reset", &Database::Reset), InstanceMethod("loadTypeDef", &Database::LoadTypeDef),
|
{InstanceMethod("reset", &Database::Reset), InstanceMethod("loadTypeDef", &Database::LoadTypeDef),
|
||||||
InstanceMethod("loadScript", &Database::LoadScript), InstanceMethod("build", &Database::Build),
|
InstanceMethod("loadScript", &Database::LoadScript), InstanceMethod("build", &Database::Build),
|
||||||
InstanceMethod("messages", &Database::GetMessages),
|
InstanceMethod("messages", &Database::GetMessages),
|
||||||
|
InstanceMethod("addDefine", &Database::AddDefine),
|
||||||
InstanceMethod("setEngineProperty", &Database::SetEngineProperty)});
|
InstanceMethod("setEngineProperty", &Database::SetEngineProperty)});
|
||||||
|
|
||||||
auto* constructor = new Napi::FunctionReference();
|
auto* constructor = new Napi::FunctionReference();
|
||||||
|
@ -37,6 +38,9 @@ void Database::SetupEngine() {
|
||||||
_engine->SetEngineProperty(asEP_REQUIRE_ENUM_SCOPE, true);
|
_engine->SetEngineProperty(asEP_REQUIRE_ENUM_SCOPE, true);
|
||||||
_engine->SetEngineProperty(asEP_PROPERTY_ACCESSOR_MODE, 2);
|
_engine->SetEngineProperty(asEP_PROPERTY_ACCESSOR_MODE, 2);
|
||||||
_engine->SetEngineProperty(asEP_COMPILER_WARNINGS, 2);
|
_engine->SetEngineProperty(asEP_COMPILER_WARNINGS, 2);
|
||||||
|
for (auto& flag : _defines) {
|
||||||
|
_builder.DefineWord(flag.c_str());
|
||||||
|
}
|
||||||
RegisterStdString(_engine);
|
RegisterStdString(_engine);
|
||||||
RegisterScriptArray(_engine, true);
|
RegisterScriptArray(_engine, true);
|
||||||
_builder.StartNewModule(_engine, "Module");
|
_builder.StartNewModule(_engine, "Module");
|
||||||
|
@ -103,4 +107,11 @@ Napi::Value Database::GetMessages(const Napi::CallbackInfo& info) {
|
||||||
|
|
||||||
return messages;
|
return messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Database::AddDefine(const Napi::CallbackInfo& info) {
|
||||||
|
if (info.Length() < 1)
|
||||||
|
throw std::logic_error("Not enough arguments");
|
||||||
|
auto name = info[0].As<Napi::String>().Utf8Value();
|
||||||
|
_defines.emplace_back(name);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
|
@ -12,6 +12,7 @@ private:
|
||||||
asIScriptEngine* _engine = nullptr;
|
asIScriptEngine* _engine = nullptr;
|
||||||
CScriptBuilder _builder;
|
CScriptBuilder _builder;
|
||||||
ASTypeDefParser::TypeDefResult _result;
|
ASTypeDefParser::TypeDefResult _result;
|
||||||
|
std::vector<std::string> _defines;
|
||||||
std::vector<const Diagnostic*> _messages;
|
std::vector<const Diagnostic*> _messages;
|
||||||
std::mutex _lock;
|
std::mutex _lock;
|
||||||
|
|
||||||
|
@ -22,6 +23,7 @@ public:
|
||||||
static Napi::Object Init(Napi::Env env, Napi::Object exports);
|
static Napi::Object Init(Napi::Env env, Napi::Object exports);
|
||||||
explicit Database(const Napi::CallbackInfo& info);
|
explicit Database(const Napi::CallbackInfo& info);
|
||||||
|
|
||||||
|
void AddDefine(const Napi::CallbackInfo& info);
|
||||||
void SetEngineProperty(const Napi::CallbackInfo& info);
|
void SetEngineProperty(const Napi::CallbackInfo& info);
|
||||||
void Reset(const Napi::CallbackInfo& info);
|
void Reset(const Napi::CallbackInfo& info);
|
||||||
void LoadScript(const Napi::CallbackInfo& info);
|
void LoadScript(const Napi::CallbackInfo& info);
|
||||||
|
|
|
@ -55,6 +55,7 @@ export interface ScriptDatabase {
|
||||||
loadScript(name: string, script: string): void;
|
loadScript(name: string, script: string): void;
|
||||||
build(): number;
|
build(): number;
|
||||||
messages(): Message[];
|
messages(): Message[];
|
||||||
|
addDefine(define: string) : void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function BuildDatabase(): ScriptDatabase {
|
export function BuildDatabase(): ScriptDatabase {
|
||||||
|
|
Loading…
Reference in New Issue