Adds support for setting engine options from code settings.

This commit is contained in:
Deukhoofd 2021-10-24 12:35:26 +02:00
parent b94ed45d9e
commit ac841d81db
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
4 changed files with 195 additions and 23 deletions

View File

@ -43,6 +43,170 @@
"items": {
"type": "string"
}
},
"angelscript-languageserver.engine-settings": {
"scope": "window",
"type": "object",
"properties": {
"asEP_ALLOW_UNSAFE_REFERENCES": {
"type": "boolean",
"default": false
},
"asEP_OPTIMIZE_BYTECODE": {
"type": "boolean",
"default": true
},
"asEP_COPY_SCRIPT_SECTIONS": {
"type": "boolean",
"default": true
},
"asEP_MAX_STACK_SIZE ": {
"type": "integer",
"default": 0
},
"asEP_USE_CHARACTER_LITERALS": {
"type": "boolean",
"default": false
},
"asEP_ALLOW_MULTILINE_STRINGS ": {
"type": "boolean",
"default": false
},
"asEP_ALLOW_IMPLICIT_HANDLE_TYPES": {
"type": "boolean",
"default": false
},
"asEP_BUILD_WITHOUT_LINE_CUES": {
"type": "boolean",
"default": false
},
"asEP_INIT_GLOBAL_VARS_AFTER_BUILD": {
"type": "boolean",
"default": true
},
"asEP_REQUIRE_ENUM_SCOPE": {
"type": "boolean",
"default": true
},
"asEP_SCRIPT_SCANNER": {
"type": "integer",
"default": 1,
"enum": [
0,
1
]
},
"asEP_INCLUDE_JIT_INSTRUCTIONS": {
"type": "boolean",
"default": false
},
"asEP_STRING_ENCODING": {
"type": "integer",
"default": 0,
"enum": [
0,
1
]
},
"asEP_PROPERTY_ACCESSOR_MODE": {
"type": "integer",
"default": 3,
"enum": [
0,
1,
2,
3
]
},
"asEP_EXPAND_DEF_ARRAY_TO_TMPL": {
"type": "boolean",
"default": false
},
"asEP_AUTO_GARBAGE_COLLECT": {
"type": "boolean",
"default": true
},
"asEP_DISALLOW_GLOBAL_VARS": {
"type": "boolean",
"default": false
},
"asEP_ALWAYS_IMPL_DEFAULT_CONSTRUCT": {
"type": "boolean",
"default": false
},
"asEP_COMPILER_WARNINGS": {
"type": "integer",
"default": 1,
"enum": [
0,
1,
2
]
},
"asEP_DISALLOW_VALUE_ASSIGN_FOR_REF_TYPE": {
"type": "boolean",
"default": false
},
"asEP_ALTER_SYNTAX_NAMED_ARGS": {
"type": "integer",
"default": 0,
"enum": [
0,
1,
2
]
},
"asEP_DISABLE_INTEGER_DIVISION": {
"type": "boolean",
"default": false
},
"asEP_DISALLOW_EMPTY_LIST_ELEMENTS": {
"type": "boolean",
"default": false
},
"asEP_PRIVATE_PROP_AS_PROTECTED": {
"type": "boolean",
"default": false
},
"asEP_ALLOW_UNICODE_IDENTIFIERS": {
"type": "boolean",
"default": false
},
"asEP_HEREDOC_TRIM_MODE": {
"type": "integer",
"default": 1,
"enum": [
0,
1,
2
]
},
"asEP_MAX_NESTED_CALLS": {
"type": "integer",
"default": 100
},
"asEP_GENERIC_CALL_MODE": {
"type": "integer",
"default": 1,
"enum": [
0,
1
]
},
"asEP_INIT_STACK_SIZE": {
"type": "integer",
"default": 4096
},
"asEP_INIT_CALL_STACK_SIZE ": {
"type": "integer",
"default": 10
},
"asEP_MAX_CALL_STACK_SIZE": {
"type": "integer",
"default": 0
}
},
"additionalProperties": false
}
}
},

View File

@ -116,6 +116,17 @@ connection.onInitialized(() => {
}
});
connection.workspace.getConfiguration('angelscript-languageserver.engine-settings').then((config) => {
for (const key in config) {
if (Object.prototype.hasOwnProperty.call(config, key)) {
const element = config[key];
let keyValue : NativeWrapper.ASEngineProperty = NativeWrapper.ASEngineProperty[key as keyof typeof NativeWrapper.ASEngineProperty];
database.setEngineProperty(keyValue, element);
}
}
});
connection.workspace.getWorkspaceFolders().then((ws) => {
ws?.forEach(element => {
registerFiles(element.uri.substr(7))

View File

@ -6,12 +6,11 @@
#include "ASTypeDefParser/Parser.hpp"
Napi::Object Database::Init(Napi::Env env, Napi::Object exports) {
Napi::Function func =
DefineClass(env, "Database",
Napi::Function func = DefineClass(
env, "Database",
{InstanceMethod("reset", &Database::Reset), InstanceMethod("loadTypeDef", &Database::LoadTypeDef),
InstanceMethod("loadScript", &Database::LoadScript), InstanceMethod("build", &Database::Build),
InstanceMethod("messages", &Database::GetMessages),
InstanceMethod("addDefine", &Database::AddDefine),
InstanceMethod("messages", &Database::GetMessages), InstanceMethod("addDefine", &Database::AddDefine),
InstanceMethod("setEngineProperty", &Database::SetEngineProperty)});
auto* constructor = new Napi::FunctionReference();
@ -30,14 +29,9 @@ void Database::SetupEngine() {
_engine = asCreateScriptEngine();
_builder = {};
_engine->SetMessageCallback(asMETHOD(Database, MessageCallback), this, asCALL_THISCALL);
_engine->SetEngineProperty(asEP_DISALLOW_EMPTY_LIST_ELEMENTS, true);
_engine->SetEngineProperty(asEP_DISALLOW_VALUE_ASSIGN_FOR_REF_TYPE, false);
_engine->SetEngineProperty(asEP_ALLOW_UNSAFE_REFERENCES, true);
_engine->SetEngineProperty(asEP_ALWAYS_IMPL_DEFAULT_CONSTRUCT, true);
_engine->SetEngineProperty(asEP_AUTO_GARBAGE_COLLECT, false);
_engine->SetEngineProperty(asEP_REQUIRE_ENUM_SCOPE, true);
_engine->SetEngineProperty(asEP_PROPERTY_ACCESSOR_MODE, 2);
_engine->SetEngineProperty(asEP_COMPILER_WARNINGS, 2);
for (auto& prop : _engineProperties) {
_engine->SetEngineProperty(prop.first, prop.second);
}
for (auto& flag : _defines) {
_builder.DefineWord(flag.c_str());
}
@ -46,15 +40,17 @@ void Database::SetupEngine() {
_builder.StartNewModule(_engine, "Module");
}
Database::Database(const Napi::CallbackInfo& info) : ObjectWrap(info) {
Reset(info);
}
Database::Database(const Napi::CallbackInfo& info) : ObjectWrap(info) { Reset(info); }
void Database::SetEngineProperty(const Napi::CallbackInfo& info) {
auto property = info[0].As<Napi::Number>().Int32Value();
if (info[1].IsBoolean()) {
auto value = info[1].As<Napi::Boolean>().Value();
_engineProperties[(asEEngineProp)property] = value;
} else {
auto value = info[1].As<Napi::Number>().Int32Value();
_engine->SetEngineProperty(static_cast<asEEngineProp>(property), value);
_engineProperties[(asEEngineProp)property] = value;
}
}
void Database::Reset(const Napi::CallbackInfo&) {

View File

@ -13,6 +13,7 @@ private:
CScriptBuilder _builder;
ASTypeDefParser::TypeDefResult _result;
std::vector<std::string> _defines;
std::unordered_map<asEEngineProp, asPWORD> _engineProperties;
std::vector<const Diagnostic*> _messages;
std::mutex _lock;