added autocompletion suport for all the record formulas present in the workspace; extended httpInterface externalScripts functionality

This commit is contained in:
Alexandru Stefan committed 2021-11-11 15:47:02 +02:00
1 parent bf67554065
commit 1491c2b93e
3 files changed
+191 -114

No files matched your search

+123 -96
View File
@@ -44,18 +44,18 @@ exports.newHttpInterface = function newHttpInterface() {
let endpointOrFile = requestPath[1]
switch (endpointOrFile) {
case 'Environment':
{
case 'Environment': {
SA.projects.foundations.utilities.httpResponses.respondWithContent(JSON.stringify(global.env), httpResponse)
}
break
case 'WEB3':
{
case 'WEB3': {
SA.projects.foundations.utilities.httpRequests.getRequestBody(httpRequest, httpResponse, processRequest)
async function processRequest(body) {
try {
if (body === undefined) { return }
if (body === undefined) {
return
}
let params = JSON.parse(body)
switch (params.method) {
@@ -129,7 +129,7 @@ exports.newHttpInterface = function newHttpInterface() {
return
}
default: {
SA.projects.foundations.utilities.httpResponses.respondWithContent(JSON.stringify({ error: 'Method ' + params.method + ' is invalid.' }), httpResponse)
SA.projects.foundations.utilities.httpResponses.respondWithContent(JSON.stringify({error: 'Method ' + params.method + ' is invalid.'}), httpResponse)
}
}
} catch (err) {
@@ -147,13 +147,14 @@ exports.newHttpInterface = function newHttpInterface() {
}
}
break
case 'CCXT':
{
case 'CCXT': {
SA.projects.foundations.utilities.httpRequests.getRequestBody(httpRequest, httpResponse, processRequest)
async function processRequest(body) {
try {
if (body === undefined) { return }
if (body === undefined) {
return
}
let params = JSON.parse(body)
switch (params.method) {
@@ -187,9 +188,13 @@ exports.newHttpInterface = function newHttpInterface() {
verbose: false
}
let ccxtExchange
try { ccxtExchange = new exchangeClass(exchangeConstructorParams) }
catch (err) { }
if (ccxtExchange === undefined) { continue }
try {
ccxtExchange = new exchangeClass(exchangeConstructorParams)
} catch (err) {
}
if (ccxtExchange === undefined) {
continue
}
if (ccxtExchange.has.fetchOHLCV === params.has.fetchOHLCV) {
@@ -225,8 +230,7 @@ exports.newHttpInterface = function newHttpInterface() {
}
}
break
case 'Webhook':
{
case 'Webhook': {
switch (requestPath[2]) { // switch by command
case 'Fetch-Messages': {
let exchange = requestPath[3]
@@ -264,7 +268,9 @@ exports.newHttpInterface = function newHttpInterface() {
SA.projects.foundations.utilities.httpRequests.getRequestBody(httpRequest, httpResponse, processRequest)
function processRequest(messageReceived) {
if (messageReceived === undefined) { return }
if (messageReceived === undefined) {
return
}
let timestamp = (new Date()).valueOf()
let source = requestPath[3]
@@ -303,20 +309,22 @@ exports.newHttpInterface = function newHttpInterface() {
console.log('[INFO] httpInterface -> Webhook -> New-Message -> Messages waiting to be Fetched by Webhooks Sensor Bot = ' + webhookMessages.length)
SA.projects.foundations.utilities.httpResponses.respondWithContent(JSON.stringify(global.DEFAULT_OK_RESPONSE), httpResponse)
}
break
}
}
}
break
case 'Docs':
{
case 'Docs': {
switch (requestPath[2]) { // switch by command
case 'Save-Node-Schema': {
SA.projects.foundations.utilities.httpRequests.getRequestBody(httpRequest, httpResponse, processRequest)
async function processRequest(body) {
try {
if (body === undefined) { return }
if (body === undefined) {
return
}
let docsSchema = JSON.parse(body)
let project = requestPath[3]
@@ -341,6 +349,7 @@ exports.newHttpInterface = function newHttpInterface() {
SA.projects.foundations.utilities.httpResponses.respondWithContent(JSON.stringify(error), httpResponse)
}
}
break
}
@@ -349,7 +358,9 @@ exports.newHttpInterface = function newHttpInterface() {
async function processRequest(body) {
try {
if (body === undefined) { return }
if (body === undefined) {
return
}
let docsSchema = JSON.parse(body)
let project = requestPath[3]
@@ -374,6 +385,7 @@ exports.newHttpInterface = function newHttpInterface() {
SA.projects.foundations.utilities.httpResponses.respondWithContent(JSON.stringify(error), httpResponse)
}
}
break
}
@@ -382,7 +394,9 @@ exports.newHttpInterface = function newHttpInterface() {
async function processRequest(body) {
try {
if (body === undefined) { return }
if (body === undefined) {
return
}
let docsSchema = JSON.parse(body)
let project = requestPath[3]
@@ -407,6 +421,7 @@ exports.newHttpInterface = function newHttpInterface() {
SA.projects.foundations.utilities.httpResponses.respondWithContent(JSON.stringify(error), httpResponse)
}
}
break
}
@@ -415,7 +430,9 @@ exports.newHttpInterface = function newHttpInterface() {
async function processRequest(body) {
try {
if (body === undefined) { return }
if (body === undefined) {
return
}
let docsSchema = JSON.parse(body)
let project = requestPath[3]
@@ -440,6 +457,7 @@ exports.newHttpInterface = function newHttpInterface() {
SA.projects.foundations.utilities.httpResponses.respondWithContent(JSON.stringify(error), httpResponse)
}
}
break
}
@@ -448,7 +466,9 @@ exports.newHttpInterface = function newHttpInterface() {
async function processRequest(body) {
try {
if (body === undefined) { return }
if (body === undefined) {
return
}
let docsSchema = JSON.parse(body)
let project = requestPath[3]
@@ -473,6 +493,7 @@ exports.newHttpInterface = function newHttpInterface() {
SA.projects.foundations.utilities.httpResponses.respondWithContent(JSON.stringify(error), httpResponse)
}
}
break
}
@@ -481,7 +502,9 @@ exports.newHttpInterface = function newHttpInterface() {
async function processRequest(body) {
try {
if (body === undefined) { return }
if (body === undefined) {
return
}
let docsSchema = JSON.parse(body)
let project = requestPath[3]
@@ -506,6 +529,7 @@ exports.newHttpInterface = function newHttpInterface() {
SA.projects.foundations.utilities.httpResponses.respondWithContent(JSON.stringify(error), httpResponse)
}
}
break
}
}
@@ -637,8 +661,7 @@ exports.newHttpInterface = function newHttpInterface() {
}
}
break
case 'App':
{
case 'App': {
// If running the electron app do not try to get git tool. I don't allow it.
if (process.env.SA_MODE === 'gitDisable') {
console.log('[WARN] No contributions on binary distributions. Do manual installation')
@@ -664,7 +687,7 @@ exports.newHttpInterface = function newHttpInterface() {
contribute()
async function contribute() {
const { lookpath } = SA.nodeModules.lookpath
const {lookpath} = SA.nodeModules.lookpath
const gitpath = await lookpath('git')
if (gitpath === undefined) {
console.log('[ERROR] `git` not installed.')
@@ -735,7 +758,7 @@ exports.newHttpInterface = function newHttpInterface() {
async function doGithub() {
const { Octokit } = SA.nodeModules.octokit
const {Octokit} = SA.nodeModules.octokit
const octokit = new Octokit({
auth: token,
@@ -799,7 +822,7 @@ exports.newHttpInterface = function newHttpInterface() {
update()
async function update() {
const { lookpath } = SA.nodeModules.lookpath
const {lookpath} = SA.nodeModules.lookpath
const gitpath = await lookpath('git');
if (gitpath === undefined) {
console.log('[ERROR] `git` not installed.')
@@ -840,11 +863,11 @@ exports.newHttpInterface = function newHttpInterface() {
let message
try {
message = await git.pull('https://github.com/Superalgos/Superalgos', currentBranch)
return { message: message }
return {message: message}
} catch (err) {
console.log('[ERROR] Error updating ' + currentBranch)
console.log(err.stack)
return { error: err }
return {error: err}
}
}
@@ -870,7 +893,7 @@ exports.newHttpInterface = function newHttpInterface() {
checkout()
async function checkout() {
const { lookpath } = SA.nodeModules.lookpath
const {lookpath} = SA.nodeModules.lookpath
const gitpath = await lookpath('git');
if (gitpath === undefined) {
console.log('[ERROR] `git` not installed.')
@@ -968,7 +991,7 @@ exports.newHttpInterface = function newHttpInterface() {
branch()
async function branch() {
const { lookpath } = SA.nodeModules.lookpath
const {lookpath} = SA.nodeModules.lookpath
const gitpath = await lookpath('git');
if (gitpath === undefined) {
console.log('[ERROR] `git` not installed.')
@@ -1049,7 +1072,6 @@ exports.newHttpInterface = function newHttpInterface() {
let project = projects[i]
const fs = SA.nodeModules.fs
let folder = 'App-Schema'
let filePath = global.env.PATH_TO_PROJECTS + '/' + project + '/Schemas/'
@@ -1204,8 +1226,7 @@ exports.newHttpInterface = function newHttpInterface() {
}
}
break
case 'GOV':
{
case 'GOV': {
/*
This is the Governance endpoint at the Http Interface. All methods
related to the Governance System are implemented here and routed
@@ -1215,7 +1236,9 @@ exports.newHttpInterface = function newHttpInterface() {
async function processRequest(body) {
try {
if (body === undefined) { return }
if (body === undefined) {
return
}
let params = JSON.parse(body)
@@ -1310,7 +1333,7 @@ exports.newHttpInterface = function newHttpInterface() {
async function doGithubUser() {
const { Octokit } = SA.nodeModules.octokit
const {Octokit} = SA.nodeModules.octokit
const octokit = new Octokit({
auth: token,
@@ -1322,11 +1345,11 @@ exports.newHttpInterface = function newHttpInterface() {
const head = username + ':' + contributionsBranch
const base = currentBranch
const title = 'Contribution: ' + mess
const path = 'Projects/Governance/Plugins/User-Profiles/' + username + '.json' ;
const path = 'Projects/Governance/Plugins/User-Profiles/' + username + '.json';
const sha = await getSHA(path);
if (sha === undefined){
if (sha === undefined) {
console.log('***** Abort GOV.USERPROFILE *****')
return
}
@@ -1396,14 +1419,14 @@ exports.newHttpInterface = function newHttpInterface() {
async function getSHA(path) {
let sha = ''
const { graphql } = SA.nodeModules.graphql
const {graphql} = SA.nodeModules.graphql
try{
try {
const { repository } = await graphql(
const {repository} = await graphql(
'{ ' +
' repository(name: "SuperAlgos", owner: "' + username + '") {' +
' object(expression: "develop:' + path +'") {' +
' object(expression: "develop:' + path + '") {' +
' ... on Blob {' +
' oid' +
' }' +
@@ -1418,14 +1441,14 @@ exports.newHttpInterface = function newHttpInterface() {
}
)
if (repository.name === undefined){
if (repository.name === undefined) {
console.log('***** Token permission needed : User:READ *****')
sha = undefined
error = '***** Token permission needed : User:READ *****'
return sha
}
if(repository.object === null ){
if (repository.object === null) {
console.log("[User Not Found] -> Creating new user")
return sha
}
@@ -1485,7 +1508,7 @@ exports.newHttpInterface = function newHttpInterface() {
return
}
default: {
SA.projects.foundations.utilities.httpResponses.respondWithContent(JSON.stringify({ error: 'Method ' + params.method + ' is invalid.' }), httpResponse)
SA.projects.foundations.utilities.httpResponses.respondWithContent(JSON.stringify({error: 'Method ' + params.method + ' is invalid.'}), httpResponse)
}
}
} catch (err) {
@@ -1507,13 +1530,11 @@ exports.newHttpInterface = function newHttpInterface() {
}
}
break
case 'LegacyPlotter.js':
{
case 'LegacyPlotter.js': {
SA.projects.foundations.utilities.httpResponses.respondWithFile(global.env.PATH_TO_PLATFORM + '/WebServer/LegacyPlotter.js', httpResponse)
}
break
case 'PlotterPanel.js':
{
case 'PlotterPanel.js': {
SA.projects.foundations.utilities.httpResponses.respondWithFile(global.env.PATH_TO_PLATFORM + '/WebServer/PlotterPanel.js', httpResponse)
}
break
@@ -1610,12 +1631,31 @@ exports.newHttpInterface = function newHttpInterface() {
let fullPath = ''
for (let i = 2; i < requestPath.length; i++) {
fullPath += requestPath[i]
if( i !== requestPath.length - 1) {
if (i !== requestPath.length - 1) {
fullPath += '/'
}
}
/**
* Sometimes libs will call fonts/images etc. by themselves thus we should have a filter for file type to respond with the correct content and headers, but from the externalScripts folder
* This code should be improved when needed with specific file types
*/
let requestedFileExtension = requestPath[requestPath.length - 1].split('.').pop()
switch (requestedFileExtension) {
case 'otf':
case 'ttf':
case 'eot':
case 'woff':
case 'woff2':
SA.projects.foundations.utilities.httpResponses.respondWithFont(global.env.PATH_TO_PLATFORM + '/WebServer/externalScripts/' + fullPath, httpResponse)
break
default:
console.log("Default file")
SA.projects.foundations.utilities.httpResponses.respondWithFile(global.env.PATH_TO_PLATFORM + '/WebServer/externalScripts/' + fullPath, httpResponse)
}
}
break
case 'Plotters': // This means the plotter folder, not to be confused with the Plotters script!
{
@@ -1627,23 +1667,19 @@ exports.newHttpInterface = function newHttpInterface() {
SA.projects.foundations.utilities.httpResponses.respondWithFile(filePath, httpResponse)
}
break
case 'ChartLayers':
{
case 'ChartLayers': {
SA.projects.foundations.utilities.httpResponses.respondWithFile(global.env.PATH_TO_PLATFORM + '/UI/' + endpointOrFile + '/' + requestPath[2], httpResponse)
}
break
case 'Files':
{
case 'Files': {
SA.projects.foundations.utilities.httpResponses.respondWithFile(global.env.PATH_TO_PLATFORM + '/UI/Data-Files/' + requestPath[2], httpResponse)
}
break
case 'Fonts':
{
case 'Fonts': {
SA.projects.foundations.utilities.httpResponses.respondWithFont(global.env.PATH_TO_FONTS + '/' + requestPath[2], httpResponse)
}
break
case 'Schema':
{
case 'Schema': {
sendSchema(global.env.PATH_TO_PROJECTS + '/' + requestPath[2] + '/Schemas/', requestPath[3])
function sendSchema(filePath, schemaType) {
@@ -1681,6 +1717,7 @@ exports.newHttpInterface = function newHttpInterface() {
}
}
SA.projects.foundations.utilities.filesAndDirectories.getAllFilesInDirectoryAndSubdirectories(filePath + folder, onFilesReady)
function onFilesReady(files) {
let schemaArray = []
@@ -1717,8 +1754,7 @@ exports.newHttpInterface = function newHttpInterface() {
}
}
break
case 'DirContent':
{
case 'DirContent': {
let folderPath = unescape(requestPath[2])
if (requestPath[3] !== undefined) {
folderPath = folderPath + '/' + requestPath[3]
@@ -1745,8 +1781,7 @@ exports.newHttpInterface = function newHttpInterface() {
}
}
break
case 'IconNames':
{
case 'IconNames': {
let projects = SA.projects.foundations.utilities.filesAndDirectories.getDirectories(global.env.PATH_TO_PROJECTS)
let icons = []
let totalProjects = projects.length
@@ -1776,8 +1811,7 @@ exports.newHttpInterface = function newHttpInterface() {
}
}
break
case 'PluginFileNames':
{
case 'PluginFileNames': {
processRequest()
async function processRequest(body) {
@@ -1809,8 +1843,7 @@ exports.newHttpInterface = function newHttpInterface() {
}
}
break
case 'LoadPlugin':
{
case 'LoadPlugin': {
processRequest()
async function processRequest(body) {
@@ -1857,13 +1890,14 @@ exports.newHttpInterface = function newHttpInterface() {
}
}
break
case 'SavePlugin':
{
case 'SavePlugin': {
SA.projects.foundations.utilities.httpRequests.getRequestBody(httpRequest, httpResponse, processRequest)
async function processRequest(body) {
try {
if (body === undefined) { return }
if (body === undefined) {
return
}
let plugin = JSON.parse(body)
let project = requestPath[2]
@@ -1889,8 +1923,7 @@ exports.newHttpInterface = function newHttpInterface() {
}
}
break
case 'Workspace.js':
{
case 'Workspace.js': {
let fs = SA.nodeModules.fs
try {
@@ -1910,8 +1943,7 @@ exports.newHttpInterface = function newHttpInterface() {
}
}
break
case 'ListWorkspaces':
{
case 'ListWorkspaces': {
let allWorkspaces = []
let projects = SA.projects.foundations.utilities.filesAndDirectories.getDirectories(global.env.PATH_TO_PROJECTS)
let projectsCount = 0
@@ -1919,6 +1951,7 @@ exports.newHttpInterface = function newHttpInterface() {
for (let i = 0; i < projects.length; i++) {
let project = projects[i]
readPluginWorkspaces()
function readPluginWorkspaces() {
let dirPath = global.env.PATH_TO_PROJECTS + '/' + project + '/Plugins/Workspaces'
try {
@@ -1986,20 +2019,20 @@ exports.newHttpInterface = function newHttpInterface() {
}
}
break
case 'LoadMyWorkspace':
{
case 'LoadMyWorkspace': {
let fileName = unescape(requestPath[2])
let filePath = global.env.PATH_TO_MY_WORKSPACES + '/' + fileName + '.json'
SA.projects.foundations.utilities.httpResponses.respondWithFile(filePath, httpResponse)
}
break
case 'SaveWorkspace':
{
case 'SaveWorkspace': {
SA.projects.foundations.utilities.httpRequests.getRequestBody(httpRequest, httpResponse, processRequest)
async function processRequest(body) {
if (body === undefined) { return }
if (body === undefined) {
return
}
let fileContent = body
let fileName = unescape(requestPath[2])
@@ -2044,14 +2077,12 @@ exports.newHttpInterface = function newHttpInterface() {
}
}
break
case 'ProjectsSchema':
{
case 'ProjectsSchema': {
let path = global.env.PATH_TO_PROJECTS + '/' + 'ProjectsSchema.json'
SA.projects.foundations.utilities.httpResponses.respondWithFile(path, httpResponse)
}
break
case 'ListSpaceFiles':
{
case 'ListSpaceFiles': {
let fs = SA.nodeModules.fs
let allFiles = []
let projects = SA.projects.foundations.utilities.filesAndDirectories.getDirectories(global.env.PATH_TO_PROJECTS)
@@ -2088,7 +2119,9 @@ exports.newHttpInterface = function newHttpInterface() {
let updatedFileList = []
for (let k = 0; k < fileList.length; k++) {
let name = fileList[k]
if (name.indexOf('.js') < 0) { continue }
if (name.indexOf('.js') < 0) {
continue
}
updatedFileList.push(path + '/' + name)
}
allFiles = allFiles.concat(updatedFileList)
@@ -2108,23 +2141,19 @@ exports.newHttpInterface = function newHttpInterface() {
}
}
break
case 'ListFunctionLibraries':
{
case 'ListFunctionLibraries': {
SA.projects.foundations.utilities.httpResponses.respondWithProjectFolderFileList(httpResponse, 'Function-Libraries', 'UI')
}
break
case 'ListUtilitiesFiles':
{
case 'ListUtilitiesFiles': {
SA.projects.foundations.utilities.httpResponses.respondWithProjectFolderFileList(httpResponse, 'Utilities', 'UI')
}
break
case 'ListGlobalFiles':
{
case 'ListGlobalFiles': {
SA.projects.foundations.utilities.httpResponses.respondWithProjectFolderFileList(httpResponse, 'Globals', 'UI')
}
break
case 'Projects':
{
case 'Projects': {
let path = ''
for (let i = 2; i < 10; i++) {
if (requestPath[i] !== undefined) {
@@ -2137,8 +2166,7 @@ exports.newHttpInterface = function newHttpInterface() {
SA.projects.foundations.utilities.httpResponses.respondWithFile(filePath, httpResponse)
}
break
case 'Storage':
{
case 'Storage': {
let pathToFile = httpRequest.url.substring(9)
/* Unsavping # */
for (let i = 0; i < 10; i++) {
@@ -2147,8 +2175,7 @@ exports.newHttpInterface = function newHttpInterface() {
SA.projects.foundations.utilities.httpResponses.respondWithFile(global.env.PATH_TO_DATA_STORAGE + '/' + pathToFile, httpResponse)
}
break
default:
{
default: {
SA.projects.foundations.utilities.httpResponses.respondWithWebFile(httpResponse, endpointOrFile, global.env.PATH_TO_PLATFORM)
}
}
@@ -62,7 +62,6 @@ function newFoundationsCodeEditorSpace() {
function openSpaceArea(originatingNode) {
thisObject.sidePanelTab.open()
thisObject.editorPage.render(originatingNode)
}
@@ -11,6 +11,7 @@ function newFoundationsCodeEditorEditorPage() {
let recordFormulaString = ''
let codeString = ''
let tradingEngineObj = undefined
let recordFormulasObj = {}
return thisObject
@@ -76,7 +77,7 @@ function newFoundationsCodeEditorEditorPage() {
* The reason we are doing the monaco initialization here is simply because monaco will set his own width at the moment it's rendered
* Rendering it earlier when the code panel is closed will result in a very narrow width
* Thus we choose to render it after the panel has his width set correctly
* Probably there is a better way but at the time this has been coded, nothing seemed to work
* Probably there is a better way but at the time this has been coded, nothing else seemed to work
**/
require(["vs/editor/editor.main"], function () {
@@ -94,7 +95,7 @@ function newFoundationsCodeEditorEditorPage() {
monaco.editor.createModel(recordFormulaString, "javascript")
showAutocompletionFor(tradingEngineObj)
showAutocompletionFor(recordFormulasObj)
monaco.languages.typescript.javascriptDefaults.setEagerModelSync(true)
@@ -114,10 +115,9 @@ function newFoundationsCodeEditorEditorPage() {
})
function showAutocompletionFor(obj) {
// Disable default autocompletion for javascript
monaco.languages.typescript.javascriptDefaults.setCompilerOptions({ noLib: true });
monaco.languages.typescript.javascriptDefaults.setCompilerOptions({noLib: true});
// Helper function to return the monaco completion item type of a thing
function getType(thing, isMember) {
@@ -131,7 +131,7 @@ function newFoundationsCodeEditorEditorPage() {
return (isMember) ? monaco.languages.CompletionItemKind.Method : monaco.languages.CompletionItemKind.Function;
default:
return (isMember) ? monaco.languages.CompletionItemKind.Property : monaco.languages.CompletionItemKind.letiable;
return (isMember) ? monaco.languages.CompletionItemKind.Property : monaco.languages.CompletionItemKind.Variable;
}
}
@@ -141,14 +141,19 @@ function newFoundationsCodeEditorEditorPage() {
triggerCharacters: ['.', '('],
// Function to generate autocompletion results
provideCompletionItems: function(model, position, token) {
provideCompletionItems: function (model, position, token) {
// Split everything the user has typed on the current line up at each space, and only look at the last word
let last_chars = model.getValueInRange({startLineNumber: position.lineNumber, startColumn: 0, endLineNumber: position.lineNumber, endColumn: position.column});
let last_chars = model.getValueInRange({
startLineNumber: position.lineNumber,
startColumn: 0,
endLineNumber: position.lineNumber,
endColumn: position.column
});
let words = last_chars.replace("\t", "").split(" ");
let active_typing = words[words.length - 1]; // What the user is currently typing (everything after the last space)
if (active_typing.includes('(')) {
let split = active_typing.split('(');
active_typing = split[split.length-1]
active_typing = split[split.length - 1]
}
// If the last character typed is a period then we need to look at member objects of the obj object
@@ -195,7 +200,7 @@ function newFoundationsCodeEditorEditorPage() {
// Create completion object
let to_push = {
label: prefix + prop,
label: prop,
kind: getType(last_token[prop], is_member),
detail: details,
insertText: prop
@@ -225,30 +230,76 @@ function newFoundationsCodeEditorEditorPage() {
/**
* The autocomplete models will be based on:
* 1. all data mines loaded into workspace - by creating a model in monaco (basically is like opening a file containing all the variables in vs-code, thus it will make them available in other files as well)
* 2. trading engine loaded into the workspace - we create an obj. representation using getProtocolNode and we are using monaco registerCompletionItemProvider
* 1. Existing code in the data mines -> we will create models for each code node (it's like opening multiple files in vscode)
* 2. Formulas from data mines by creating an object representation of all formulas see implementation below than passing it to the monaco registerCompletionItemProvider
* 2. Trading engine loaded into the workspace - we create an obj. representation using getProtocolNode and we are using monaco registerCompletionItemProvider
*
*/
function buildIntelliSenseModels() {
UI.projects.foundations.spaces.designSpace.workspace.workspaceNode.rootNodes.forEach(node => {
if (node.type === 'Data Mine') {
//Getting all the Javascript code into one single letiable
// Getting all the Javascript code nodes into one single model
UI.projects.visualScripting.utilities.branches.nodeBranchToArray(node, 'Procedure Javascript Code').forEach(node => {
codeString += '\n'
codeString += node.code
})
//Getting all the Formula code into one single letiable
/**
* Getting all the Formula codes and create an object representation, all non-object children will be initialized with strings
*
* e.g : we will end with something like {
* variable: {
* last24hsDirection: "",
* last24HsMax: ""
* },
* record: {
* current: {
* direction: ""
* }
* }
* }
* the above object will have as many properties as we can find in the entire workspace
*
*/
UI.projects.visualScripting.utilities.branches.nodeBranchToArray(node, 'Record Formula').forEach(node => {
recordFormulaString += '\n'
recordFormulaString += node.code
/**
* Extract each code formula as an object to be merged with the next one until we end up with an object containing all the objects present in the formula with proper children
* The resulting object will be later used as model for autocompletion
*/
console.log(node.code)
objectMerge(recordFormulasObj, node.code.split('.').reduceRight((o, x) => ({[x]: o}), ""))
})
} else if (node.type === 'Trading Engine') {
// Create an object representation for
tradingEngineObj = {tradingEngine : UI.projects.visualScripting.functionLibraries.protocolNode.getProtocolNode(node, false, false, false, false, false, undefined)}
// Create an object representation for the engine
tradingEngineObj = {tradingEngine: UI.projects.visualScripting.functionLibraries.protocolNode.getProtocolNode(node, false, false, false, false, false, undefined)}
}
})
function objectMerge(target, source) {
for (const key of Object.keys(source)) {
const currTarget = target[key];
const currSource = source[key];
if (currTarget) {
const objSource = typeof currSource === 'object';
const objTarget = typeof currTarget === 'object';
if (objSource && objTarget) {
void objectMerge(currTarget, currSource)
continue;
}
}
target[key] = currSource;
}
return target;
}
}