nimsuggest: maxresults limit; fixed local symbol usages priorizations

This commit is contained in:
Andreas Rumpf 2017-03-10 11:29:16 +01:00
commit 68181e6da2
4 changed files with 62 additions and 49 deletions

View file

@ -40,6 +40,7 @@ Options:
--log enable verbose logging to nimsuggest.log file
--v1 use version 1 of the protocol; for backwards compatibility
--refresh perform automatic refreshes to keep the analysis precise
--maxresults:N limit the number of suggestions to N
--tester implies --stdin and outputs a line
'""" & DummyEof & """' for the tester
@ -550,6 +551,8 @@ proc processCmdLine*(pass: TCmdLinePass, cmd: string) =
gRefresh = parseBool(p.val)
else:
gRefresh = true
of "maxresults":
suggestMaxResults = parseInt(p.val)
else: processSwitch(pass, p)
of cmdArgument:
options.gProjectName = unixToNativePath(p.key)

View file

@ -304,8 +304,7 @@ proc runTest(filename: string): int =
proc main() =
var failures = 0
if os.paramCount() > 0:
let f = os.paramStr(1)
let x = getAppDir() / f
let x = os.paramStr(1)
let xx = expandFilename x
failures += runTest(xx)
failures += runEpcTest(xx)

View file

@ -0,0 +1,16 @@
discard """
$nimsuggest --tester --maxresults:2 $file
>sug $1
sug;;skProc;;tdot4.main;;proc (inp: string): string;;$file;;10;;5;;"";;100;;None
sug;;skProc;;strutils.replace;;proc (s: string, sub: string, by: string): string{.noSideEffect, gcsafe, locks: 0.};;$lib/pure/strutils.nim;;1497;;5;;"Replaces `sub` in `s` by the string `by`.";;100;;None
"""
import strutils
proc main(inp: string): string =
# use replace here and see if it occurs in the result, it should gain
# priority:
result = inp.replace(" ", "a").replace("b", "c")
echo "string literal here".#[!]#