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 { Text {
id: annotationText id: annotationText
anchors.right: parent.right anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
topPadding: 2 topPadding: 2
bottomPadding: 2 bottomPadding: 2
rightPadding: 15 rightPadding: 15
font.pixelSize: autocompleteText.font.pixelSize - 2
text: listFiltered.model[index].annotation text: listFiltered.model[index].annotation
color: parent.selected ? sysPaletteIn.highlightedText : sysPaletteIn.windowText color: parent.selected ? sysPaletteIn.highlightedText : sysPaletteIn.windowText
} }

View file

@ -448,7 +448,7 @@ Item {
itemSelected: parent.itemSelected itemSelected: parent.itemSelected
categoryItems: Parsing.FUNCTIONS_LIST categoryItems: Parsing.FUNCTIONS_LIST
autocompleteGenerator: (item) => {return { autocompleteGenerator: (item) => {return {
'text': item, 'annotation': '', 'text': item, 'annotation': Parsing.FUNCTIONS_USAGE[item].join(', '),
'autocomplete': item+'()', 'cursorFinalOffset': -1 'autocomplete': item+'()', 'cursorFinalOffset': -1
}} }}
baseText: parent.visible ? parent.currentToken.value : "" 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)) throw EvalError(qsTranslate('usage', 'Usage: %1').arg(usage2))
f = parser.parse(f).toJSFunction(variable, currentVars) f = parser.parse(f).toJSFunction(variable, currentVars)
} else } 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 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 usage2 = qsTranslate('usage', 'integral(<from: number>, <to: number>, <f: string>, <variable: string>)')
let f = parseArgumentsForFunction(args, usage1, usage2) let f = parseArgumentsForFunction(args, usage1, usage2)
if(a == null || b == null) 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 // https://en.wikipedia.org/wiki/Simpson%27s_rule
// Simpler, faster than tokenizing the expression // Simpler, faster than tokenizing the expression
@ -86,12 +86,12 @@ parser.functions.integral = function(a, b, ...args) {
} }
parser.functions.derivative = function(...args) { parser.functions.derivative = function(...args) {
let usage1 = qsTranslate('usage', 'derivative(<f: ExecutableObject>, <x: variable>)') let usage1 = qsTranslate('usage', 'derivative(<f: ExecutableObject>, <x: number>)')
let usage2 = qsTranslate('usage', 'derivative(<f: string>, <variable: string>, <x: variable>)') let usage2 = qsTranslate('usage', 'derivative(<f: string>, <variable: string>, <x: number>)')
let x = args.pop() let x = args.pop()
let f = parseArgumentsForFunction(args, usage1, usage2) let f = parseArgumentsForFunction(args, usage1, usage2)
if(x == null) 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 let derivative_precision = x/10
return (f(x+derivative_precision/2)-f(x-derivative_precision/2))/derivative_precision 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_LIST = Reference.FUNCTIONS_LIST
var FUNCTIONS = Reference.FUNCTIONS var FUNCTIONS = Reference.FUNCTIONS
var FUNCTIONS_USAGE = Reference.FUNCTIONS_USAGE
var CONSTANTS_LIST = Reference.CONSTANTS_LIST var CONSTANTS_LIST = Reference.CONSTANTS_LIST
var CONSTANTS = Reference.CONSTANTS var CONSTANTS = Reference.CONSTANTS

View file

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