Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix information dialogs with info #1559

Merged
merged 48 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
a2b7aad
build update
drkameleon Jan 26, 2024
5c0f802
build update
drkameleon Jan 26, 2024
11c88da
build update
drkameleon Jan 26, 2024
a17c4e0
build update
drkameleon Jan 26, 2024
4f796cc
build update
drkameleon Jan 26, 2024
4e572f8
build update
drkameleon Jan 26, 2024
f27b9ee
build update
drkameleon Jan 26, 2024
4f16157
build update
drkameleon Jan 26, 2024
2e09b13
fixed function argument types
drkameleon Jan 26, 2024
7703aad
build update
drkameleon Jan 26, 2024
1e5dfa3
build update
drkameleon Jan 26, 2024
c84ba78
Helpers/helper: created new `getReturnsForFunction` helper + fixed "R…
drkameleon Jan 26, 2024
8fc1a80
build update
drkameleon Jan 26, 2024
d2224f4
build update
drkameleon Jan 26, 2024
bfa107a
build update
drkameleon Jan 26, 2024
3e8bba0
build update
drkameleon Jan 26, 2024
a1d4073
build update
drkameleon Jan 26, 2024
708b8eb
build update
drkameleon Jan 26, 2024
afd2122
fixed attribute descriptions too
drkameleon Jan 26, 2024
9050c95
make `info` work for Method's too (as it does for Function values)
drkameleon Jan 31, 2024
c07e59a
build update
drkameleon Jan 31, 2024
7699e0e
Merge branch 'master' of https://github.com/arturo-lang/arturo into f…
drkameleon Jan 31, 2024
ee97b98
build update
drkameleon Jan 31, 2024
878b815
build update
drkameleon Jan 31, 2024
9797df7
minor fix to eliminate `@[:nothing]` when no arguments are available
drkameleon Jan 31, 2024
8689e37
build update
drkameleon Jan 31, 2024
3789f0a
build update
drkameleon Jan 31, 2024
6d75540
build update
drkameleon Jan 31, 2024
84de745
build update
drkameleon Jan 31, 2024
c73b182
make `info` function for methods as it does for functions
drkameleon Jan 31, 2024
cddf935
build update
drkameleon Jan 31, 2024
99d606f
properly copy `.info`
drkameleon Jan 31, 2024
ec8eff2
build update
drkameleon Jan 31, 2024
b5bb22d
build update
drkameleon Feb 2, 2024
2630c16
attempt no 1 to properly align Usage param types
drkameleon Feb 2, 2024
55864e6
build update
drkameleon Feb 2, 2024
664201b
build update
drkameleon Feb 2, 2024
2be65b3
minor fix
drkameleon Feb 2, 2024
7984006
build update
drkameleon Feb 2, 2024
e512551
build update
drkameleon Feb 2, 2024
e633815
build update
drkameleon Feb 2, 2024
c3ad4ea
write a more correct `wrapLines` variant
drkameleon Feb 2, 2024
4605ecd
build update
drkameleon Feb 2, 2024
d1a098c
minor adjustment
drkameleon Feb 2, 2024
c6d69ef
build update
drkameleon Feb 2, 2024
d79f5cf
build update
drkameleon Feb 2, 2024
1d9541f
also fix subsequent arguments
drkameleon Feb 2, 2024
9e6c030
remove commented out code
drkameleon Feb 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 65 additions & 14 deletions src/helpers/helper.nim
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# Libraries
#=======================================

import sequtils, strformat
import math, sequtils, strformat
import strutils, tables
import sugar

Expand Down Expand Up @@ -105,16 +105,38 @@ proc printMultiData(
printOneData("", item, resetColor, colorb)


func getShortData(initial: string): seq[string] =
func getShortData(initial: string, cutoff=50): seq[string] =
result = @[initial]
if result[0].len > 50:
if result[0].len > cutoff:
let parts = result[0].splitWhitespace()
let middle = (parts.len div 2)
result = @[
parts[0..middle].join(" "),
parts[(middle + 1)..^1].join(" ")
]

func wrapLines(initial: string, limit=50): seq[string] =
if initial.len <= limit:
return @[initial]
else:
let words = initial.splitWhitespace()
var lineOne: seq[string]
var lineTwo: seq[string]
var cnt = 0
while ((lineOne.map((x) => x.len)).sum + lineOne.len-1) < limit and cnt < words.len:
lineOne.add(words[cnt])
cnt += 1

lineTwo.add(lineOne.pop())

while cnt < words.len:
lineTwo.add(words[cnt])
cnt += 1

return @[
lineOne.join(" "),
lineTwo.join(" ")
]

func getTypeString(valueSpec: ValueSpec): string =
## Returns the representation of a type into a string
Expand All @@ -129,7 +151,6 @@ proc getUsageForFunction(obj: ValueObj): seq[string] =
let
args = toSeq(obj.val.info.args.pairs)
templateName = fmt"{bold()}{obj.name}{resetColor}"
templateType = fmt"{fg(grayColor)}{getTypeString(args[0][1])}"

var
spaceBefore: string
Expand All @@ -138,16 +159,32 @@ proc getUsageForFunction(obj: ValueObj): seq[string] =
spaceBefore &= " "

if args[0][0] != "":
let templateArg = fmt"{args[0][0]}"
result.add fmt"{templateName} {templateArg} {templateType}"
let
templateArg = fmt"{args[0][0]}"
templateType = wrapLines(getTypeString(args[0][1]), lineLength - labelAlignment - initialPadding.len - templateName.len - templateArg.len)

result.add fmt "{templateName} {templateArg} {fg(grayColor)}{templateType[0]}{resetColor}"
if templateType.len > 1:
var extraSpaceBefore: string
for _ in 0..templateArg.len:
extraSpaceBefore &= " "
for tt in templateType[1..^1]:
result.add fmt"{spaceBefore}{extraSpaceBefore}{fg(grayColor)}{tt}{resetColor}"
else:
result.add fmt"{templateName} {templateType}"
result.add fmt"{templateName} {getTypeString(args[0][1])}"

for arg in args[1..^1]:
let
templateArg = fmt"{arg[0]}"
templateType = fmt"{fg(grayColor)}{getTypeString(arg[1])}"
result.add fmt"{spaceBefore}{templateArg} {templateType}"
templateType = wrapLines(getTypeString(arg[1]), lineLength - labelAlignment - initialPadding.len - templateName.len - templateArg.len - spaceBefore.len)

result.add fmt "{spaceBefore}{templateArg} {fg(grayColor)}{templateType[0]}{resetColor}"
if templateType.len > 1:
var extraSpaceBefore: string
for _ in 0..templateArg.len:
extraSpaceBefore &= " "
for tt in templateType[1..^1]:
result.add fmt"{spaceBefore}{extraSpaceBefore}{fg(grayColor)}{tt}{resetColor}"


proc getOptionsForFunction(value: Value): seq[string] =
Expand Down Expand Up @@ -181,8 +218,22 @@ proc getOptionsForFunction(value: Value): seq[string] =
leftSide = fmt"{fg(cyanColor)}.{attr[0]}"
myLen += len(fmt"{fg(cyanColor)}")

result.add fmt"{alignLeft(leftSide, myLen)} {resetColor}-> {attr[1][1]}"
let lines = getShortData(attr[1][1])
result.add fmt"{alignLeft(leftSide, myLen)} {resetColor}-> {lines[0]}"

var spaceBefore: string
for _ in 0..((fmt"{alignLeft(leftSide, myLen)} -> ").len - 8):
spaceBefore &= " "

if lines.len > 1:
for line in lines[1..^1]:
result.add fmt"{spaceBefore}{line}"

proc getReturnsForFunction(obj: ValueObj): seq[string] =
let lines = getShortData(getTypeString(obj.val.info.returns))

for line in lines:
result.add fmt"{fg(grayColor)}{line}{resetColor}"

when defined(DOCGEN):

Expand Down Expand Up @@ -350,8 +401,8 @@ proc printFunction(obj: ValueObj) {. inline .} =
printMultiData("options", opts, bold(greenColor))

printEmptyLine()
printOneData("returns", getTypeString(obj.val.info.returns),
bold(greenColor), fg(grayColor))
printMultiData("returns", obj.getReturnsForFunction(),
bold(greenColor))
printLine()


Expand Down Expand Up @@ -379,7 +430,7 @@ proc getInfo*(objName: string, objValue: Value, aliases: SymbolDict): ValueDict
if obj.val.info.descr != "": result["description"] = newString(obj.val.info.descr)
if obj.val.info.module != "": result["module"] = newString(obj.val.info.module)

if obj.val.info.kind == Function:
if obj.val.info.kind in {Function,Method}:
result.insertFunctionInfo(obj, aliases)

when defined(DOCGEN):
Expand Down Expand Up @@ -410,5 +461,5 @@ proc printInfo*(objName: string, objValue: Value, aliases: SymbolDict) =

# If it's a function,
# print more details
if obj.val.info.kind == Function:
if obj.val.info.kind in {Function,Method}:
obj.printFunction()
2 changes: 1 addition & 1 deletion src/vm/values/types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ type
line* : int

case kind*: ValueKind:
of Function:
of Function, Method:
args* : OrderedTable[string,ValueSpec]
attrs* : OrderedTable[string,(ValueSpec,string)]
returns* : ValueSpec
Expand Down
6 changes: 6 additions & 0 deletions src/vm/values/value.nim
Original file line number Diff line number Diff line change
Expand Up @@ -968,13 +968,19 @@ proc copyValue*(v: Value): Value {.inline.} =
of Function:
if v.fnKind == UserFunction:
result = newFunction(v.params, v.main, v.imports, v.exports, v.memoize, v.inline)
if not v.info.isNil:
result.info = ValueInfo()
result.info[] = v.info[]
else:
when defined(DOCGEN):
result = newBuiltin(v.info.descr, v.info.module, v.info.line, v.arity, v.info.args, v.info.attrs, v.info.returns, v.info.example, v.op, v.action)
else:
result = newBuiltin(v.info.descr, v.info.module, 0, v.arity, v.info.args, v.info.attrs, v.info.returns, "", v.op, v.action)
of Method:
result = newMethod(v.mparams, v.mmain, v.mdistinct, injectThis=false)
if not v.info.isNil:
result.info = ValueInfo()
result.info[] = v.info[]

of Database:
when not defined(NOSQLITE):
Expand Down
2 changes: 1 addition & 1 deletion version/build
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2276
2310
Loading