greybel-languageserver-core
Version:
Core functionality of language server for GreyScript
75 lines • 3.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.aggregateImportsWithNamespaceFromGraph = exports.aggregateImportsWithNamespaceFromLocations = void 0;
const greybel_type_analyzer_1 = require("greybel-type-analyzer");
const greyscript_meta_1 = require("greyscript-meta");
const meta_utils_1 = require("meta-utils");
const types_1 = require("../types");
function injectParams(document) {
if (document.globals.hasProperty('params')) {
return;
}
document.globals.setProperty('params', new greybel_type_analyzer_1.ListType(document.typeStorage.generateId(greybel_type_analyzer_1.TypeKind.ListType), greybel_type_analyzer_1.Type.createBaseType(meta_utils_1.SignatureDefinitionBaseType.String, document.typeStorage, document, document.globals), document.typeStorage, document, document.globals));
}
function injectGetCustomObject(document, globalTypeStorage) {
const generalInterface = document.typeStorage.getTypeById(meta_utils_1.SignatureDefinitionBaseType.General);
if (generalInterface.hasProperty('get_custom_object')) {
return;
}
const gcoMap = greybel_type_analyzer_1.MapType.createDefault(document.typeStorage, document, document.globals);
const proxyGCOFn = (0, greybel_type_analyzer_1.persistTypeInNativeFunction)(meta_utils_1.SignatureDefinitionBaseType.General, 'get_custom_object', gcoMap, document, globalTypeStorage);
generalInterface.setProperty('get_custom_object', new greybel_type_analyzer_1.EntityInfo('get_custom_object', proxyGCOFn));
document.typeStorage.memory.set('$$get_custom_object', gcoMap);
}
const typeManager = new greybel_type_analyzer_1.TypeManager({
container: greyscript_meta_1.greyscriptMeta,
modifyTypeStorage: (document, globalTypeStorage) => {
injectParams(document);
injectGetCustomObject(document, globalTypeStorage);
}
});
exports.default = typeManager;
function aggregateImportsWithNamespaceFromLocations(dependencyLocation, refs) {
const result = [];
if (dependencyLocation == null) {
return result;
}
dependencyLocation.forEach((importDef) => {
const namespace = importDef.args[0];
if (namespace == null)
return;
const itemTypeDoc = refs.get(importDef.location)?.typeDocument;
if (itemTypeDoc == null)
return;
result.push({
namespace,
typeDoc: itemTypeDoc
});
});
return result;
}
exports.aggregateImportsWithNamespaceFromLocations = aggregateImportsWithNamespaceFromLocations;
function aggregateImportsWithNamespaceFromGraph(node, refs) {
const result = [];
if (node == null) {
return result;
}
const importUris = node.children
.filter((child) => child.item.location.type === types_1.DependencyType.Import)
.map((child) => child.item.location);
importUris.forEach((importDef) => {
const namespace = importDef.args[0];
if (namespace == null)
return;
const itemTypeDoc = refs.get(importDef.location);
if (itemTypeDoc == null)
return;
result.push({
namespace,
typeDoc: itemTypeDoc
});
});
return result;
}
exports.aggregateImportsWithNamespaceFromGraph = aggregateImportsWithNamespaceFromGraph;
//# sourceMappingURL=type-manager.js.map