summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/semdata.nim1
-rw-r--r--compiler/semtypes.nim4
-rw-r--r--compiler/suggest.nim9
3 files changed, 12 insertions, 2 deletions
diff --git a/compiler/semdata.nim b/compiler/semdata.nim
index f9a7c0cda..ef23e40f2 100644
--- a/compiler/semdata.nim
+++ b/compiler/semdata.nim
@@ -112,6 +112,7 @@ type
     signatures*: TStrTable
     recursiveDep*: string
     suggestionsMade*: bool
+    inTypeContext*: int
 
 proc makeInstPair*(s: PSym, inst: PInstantiation): TInstantiationPair =
   result.genericSym = s
diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim
index 77ccce5d4..83d0c83b2 100644
--- a/compiler/semtypes.nim
+++ b/compiler/semtypes.nim
@@ -1169,6 +1169,8 @@ proc fixupTypeOf(c: PContext, prev: PType, typExpr: PNode) =
 
 proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
   result = nil
+  when defined(nimsuggest):
+    inc c.inTypeContext
 
   if gCmd == cmdIdeTools: suggestExpr(c, n)
   case n.kind
@@ -1374,6 +1376,8 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
     localError(n.info, errTypeExpected)
     result = newOrPrevType(tyError, prev, c)
   n.typ = result
+  when defined(nimsuggest):
+    dec c.inTypeContext
 
 proc setMagicType(m: PSym, kind: TTypeKind, size: int) =
   m.typ.kind = kind
diff --git a/compiler/suggest.nim b/compiler/suggest.nim
index 7366b7ffd..e2aeb414e 100644
--- a/compiler/suggest.nim
+++ b/compiler/suggest.nim
@@ -20,8 +20,13 @@
 ## - If there is a prefix (foo|), symbols starting with this prefix come first.
 ## - If the prefix is part of the name (but the name doesn't start with it),
 ##   these symbols come second.
-## - Otherwise consider the context. We currently distinguish between type
-##   and non-type contexts.
+## - If we have a prefix, only symbols matching this prefix are returned and
+##   nothing else.
+## - If we have no prefix, consider the context. We currently distinguish
+##   between type and non-type contexts.
+## - Finally, sort matches by relevance. The relevance is determined by the
+##   number of usages, so ``strutils.replace`` comes before
+##   ``strutils.wordWrap``.
 
 # included from sigmatch.nim