From 2f82b546538bc3f9cd5eedfb171723f0f02ca6ff Mon Sep 17 00:00:00 2001 From: olivier Dufour Date: Fri, 29 Mar 2024 10:49:46 +0100 Subject: [PATCH] apex: improove suggestion --- addon/apex-runner.css | 13 +++++++++- addon/apex-runner.js | 59 +++++++++++++++++++++++++++++++++++++------ 2 files changed, 63 insertions(+), 9 deletions(-) diff --git a/addon/apex-runner.css b/addon/apex-runner.css index fe4d065a..3509659b 100644 --- a/addon/apex-runner.css +++ b/addon/apex-runner.css @@ -14,4 +14,15 @@ } .editor { display: flex; - } \ No newline at end of file + } + + +.class .autocomplete-icon { + -webkit-mask-image: url('chrome-extension://__MSG_@@extension_id__/images/relate.svg'); + background-color: #04844B; +} + +.namespace .autocomplete-icon { + -webkit-mask-image: url('chrome-extension://__MSG_@@extension_id__/images/textarea.svg'); + background-color: #04844B; +} diff --git a/addon/apex-runner.js b/addon/apex-runner.js index f95786d3..051d218b 100644 --- a/addon/apex-runner.js +++ b/addon/apex-runner.js @@ -278,36 +278,77 @@ class Model { if (vm.autocompleteResults && vm.autocompleteResults.results && vm.autocompleteResults.results.length > 0) { let ar = vm.autocompleteResults.results; vm.scriptInput.focus(); - vm.scriptInput.setRangeText(ar[0].value, selStart, selEnd, "end"); + vm.scriptInput.setRangeText(ar[0].value + ar[0].suffix, selStart, selEnd, "end"); + vm.scriptAutocompleteHandler(); } return; } + let keywords = [ + {value: "Blob", title: "Blob", suffix: " ", rank: 3, autocompleteType: "fieldName", dataType: "double"}, + {value: "Boolean", title: "Boolean", suffix: " ", rank: 3, autocompleteType: "fieldName", dataType: "boolean"}, + {value: "Date", title: "Date", suffix: " ", rank: 3, autocompleteType: "fieldName", dataType: "date"}, + {value: "Datetime", title: "Datetime", suffix: " ", rank: 3, autocompleteType: "fieldName", dataType: "datetime"}, + {value: "Decimal", title: "Decimal", suffix: " ", rank: 3, autocompleteType: "fieldName", dataType: "double"}, + {value: "Double", title: "Double", suffix: " ", rank: 3, autocompleteType: "fieldName", dataType: "double"}, + {value: "ID", title: "ID", suffix: " ", rank: 3, autocompleteType: "fieldName", dataType: "id"}, + {value: "Integer", title: "Integer", suffix: " ", rank: 3, autocompleteType: "fieldName", dataType: "int"}, + {value: "Long", title: "Long", suffix: " ", rank: 3, autocompleteType: "fieldName", dataType: "long"}, + {value: "Object", title: "Object", suffix: " ", rank: 3, autocompleteType: "fieldName", dataType: "reference"}, + {value: "String", title: "String", suffix: " ", rank: 3, autocompleteType: "fieldName", dataType: "string"}, + {value: "Time", title: "Time", suffix: " ", rank: 3, autocompleteType: "fieldName", dataType: "time"}, + + {value: "List", title: "List", suffix: " ", rank: 1, autocompleteType: "class", dataType: ""}, + {value: "Map", title: "Map", suffix: " ", rank: 1, autocompleteType: "class", dataType: ""}, + {value: "Set", title: "Set", suffix: " ", rank: 1, autocompleteType: "class", dataType: ""}, + {value: "Enum", title: "Enum", suffix: " ", rank: 1, autocompleteType: "class", dataType: ""}, + + {value: "while", title: "while", suffix: " {}", rank: 2, autocompleteType: "snippet", dataType: ""}, + {value: "for", key: "foreach", title: "foreach", suffix: "(Object item:lists) {}", rank: 2, autocompleteType: "snippet", dataType: ""}, + {value: "for", key: "fori", title: "fori", suffix: "(Integer i = 0; i c.NamespacePrefix) .filter(n => (n && n.toLowerCase().includes(searchTerm.toLowerCase()))) .groupBy(n => n) - .map(n => ({"value": n, "title": n, "suffix": ".", "rank": 1, "autocompleteType": "fieldName"})) + .map(n => ({"value": n, "title": n, "suffix": " ", "rank": 5, "autocompleteType": "namespace"})) + ) + .concat(//SOBJECT + new Enumerable(globalStatus == "ready" ? globalDescribe.sobjects : []) + .filter(sobjectDescribe => (sobjectDescribe.name.toLowerCase().includes(searchTerm.toLowerCase()))) + .map(sobjectDescribe => sobjectDescribe.name) + .map(n => ({"value": n, "title": n, "suffix": " ", "rank": 6, "autocompleteType": "object"})) + ) + .concat( + new Enumerable(keywords) //keywords + .filter(keyword => keyword.title.toLowerCase().includes(searchTerm.toLowerCase())) ) .toArray() - .slice(0, 10) //only 10 first result .sort(vm.resultsSort(searchTerm)) + .slice(0, 20) //only 10 first result }; } @@ -841,6 +882,8 @@ class App extends React.Component { .catch(error => { console.error(error); }); + //call to get all Sobject during load + model.describeInfo.describeGlobal(false); model.setScriptInput(scriptInput); //Set the cursor focus on script text area use the same than query @@ -983,7 +1026,7 @@ class App extends React.Component { ), h("div", {className: "autocomplete-results"}, model.autocompleteResults.results.map(r => - h("div", {className: "autocomplete-result", key: r.value}, h("a", {tabIndex: 0, title: r.title, onClick: e => { e.preventDefault(); model.autocompleteClick(r); model.didUpdate(); }, href: "#", className: r.autocompleteType + " " + r.dataType}, h("div", {className: "autocomplete-icon"}), r.value), " ") + h("div", {className: "autocomplete-result", key: r.key ? r.key : r.value}, h("a", {tabIndex: 0, title: r.title, onClick: e => { e.preventDefault(); model.autocompleteClick(r); model.didUpdate(); }, href: "#", className: r.autocompleteType + " " + r.dataType}, h("div", {className: "autocomplete-icon"}), r.title), " ") ) ), ),