Adding function usage to auto complete.
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Adsooi 2023-10-10 01:58:55 +02:00
parent 803416d08d
commit bf211df67d
Signed by: Ad5001
GPG key ID: EF45F9C6AFE20160
5 changed files with 17 additions and 11 deletions

View file

@ -113,9 +113,11 @@ ListView {
Text {
id: annotationText
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
topPadding: 2
bottomPadding: 2
rightPadding: 15
font.pixelSize: autocompleteText.font.pixelSize - 2
text: listFiltered.model[index].annotation
color: parent.selected ? sysPaletteIn.highlightedText : sysPaletteIn.windowText
}

View file

@ -448,7 +448,7 @@ Item {
itemSelected: parent.itemSelected
categoryItems: Parsing.FUNCTIONS_LIST
autocompleteGenerator: (item) => {return {
'text': item, 'annotation': '',
'text': item, 'annotation': Parsing.FUNCTIONS_USAGE[item].join(', '),
'autocomplete': item+'()', 'cursorFinalOffset': -1
}}
baseText: parent.visible ? parent.currentToken.value : ""

View file

@ -68,7 +68,7 @@ function parseArgumentsForFunction(args, usage1, usage2) {
throw EvalError(qsTranslate('usage', 'Usage: %1').arg(usage2))
f = parser.parse(f).toJSFunction(variable, currentVars)
} else
throw EvalError(qsTranslate('usage', 'Usage: %1 or\n%2').arg(usage1).arg(usage2)))
throw EvalError(qsTranslate('usage', 'Usage: %1 or\n%2').arg(usage1).arg(usage2))
return f
}
@ -78,7 +78,7 @@ parser.functions.integral = function(a, b, ...args) {
let usage2 = qsTranslate('usage', 'integral(<from: number>, <to: number>, <f: string>, <variable: string>)')
let f = parseArgumentsForFunction(args, usage1, usage2)
if(a == null || b == null)
throw EvalError(qsTranslate('usage', 'Usage: %1 or\n%2').arg(usage1).arg(usage2)))
throw EvalError(qsTranslate('usage', 'Usage: %1 or\n%2').arg(usage1).arg(usage2))
// https://en.wikipedia.org/wiki/Simpson%27s_rule
// Simpler, faster than tokenizing the expression
@ -86,12 +86,12 @@ parser.functions.integral = function(a, b, ...args) {
}
parser.functions.derivative = function(...args) {
let usage1 = qsTranslate('usage', 'derivative(<f: ExecutableObject>, <x: variable>)')
let usage2 = qsTranslate('usage', 'derivative(<f: string>, <variable: string>, <x: variable>)')
let usage1 = qsTranslate('usage', 'derivative(<f: ExecutableObject>, <x: number>)')
let usage2 = qsTranslate('usage', 'derivative(<f: string>, <variable: string>, <x: number>)')
let x = args.pop()
let f = parseArgumentsForFunction(args, usage1, usage2)
if(x == null)
throw EvalError(qsTranslate('usage', 'Usage: %1 or\n%2').arg(usage1).arg(usage2)))
throw EvalError(qsTranslate('usage', 'Usage: %1 or\n%2').arg(usage1).arg(usage2))
let derivative_precision = x/10
return (f(x+derivative_precision/2)-f(x-derivative_precision/2))/derivative_precision

View file

@ -29,5 +29,6 @@ var Tokenizer = TK.ExpressionTokenizer
var FUNCTIONS_LIST = Reference.FUNCTIONS_LIST
var FUNCTIONS = Reference.FUNCTIONS
var FUNCTIONS_USAGE = Reference.FUNCTIONS_USAGE
var CONSTANTS_LIST = Reference.CONSTANTS_LIST
var CONSTANTS = Reference.CONSTANTS

View file

@ -106,7 +106,7 @@ class P {
}
toString() {
base_string = this.type
let base_string = this.type
if(this.name != '')
base_string = `${this.name}: ${base_string}`
if(this.multipleAllowed)
@ -120,7 +120,7 @@ class P {
}
let string = new P('string')
let bool = new P('boolean')
let bool = new P('bool')
let number = new P('number')
let array = new P('array')
@ -153,9 +153,9 @@ const FUNCTIONS_USAGE = {
'log10': [number],
'log1p': [number],
'log2': [number],
'max': [number, number, new P('number', '', true, null, true)],
'min': [number, number, new P('number', '', true, null, true)],
'pow': [number, new P('number', 'exponent')],
'max': [number, number, new P('numbers', '', true, true)],
'min': [number, number, new P('numbers', '', true, true)],
'pow': [number, new P('number', 'exp')],
'random': [number, number],
'round': [number],
'sign': [number],
@ -170,5 +170,8 @@ const FUNCTIONS_USAGE = {
'gamma': [number],
'Γ': [number],
'roundTo': [number, new P('number')],
// Function manipulation
'derivative': [new P('f'), new P('string', 'var', true), number],
'integral': [new P('from'), new P('to'), new P('f'), new P('string', 'var', true)],
}