mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-29 01:14:41 +00:00
Fix nimsuggest not showing suggestions for imported tuples (#22241)
* Add tests
Also test if exported all tuple fields works. This seems like a hacky solution so will try and dive further to find a better solution
* Always suggest tuple fields if it passes the filter
If the tuple we are accessing is in scope then all the fields will also be in scope
* Update tests so line numbers are correct
(cherry picked from commit 1b132ddaa2)
This commit is contained in:
@@ -439,7 +439,15 @@ proc suggestFieldAccess(c: PContext, n, field: PNode, outputs: var Suggestions)
|
||||
if t[0] == nil: break
|
||||
t = skipTypes(t[0], skipPtrs)
|
||||
elif typ.kind == tyTuple and typ.n != nil:
|
||||
suggestSymList(c, typ.n, field, n.info, outputs)
|
||||
# All tuple fields are in scope
|
||||
# So go through each field and add it to the suggestions (If it passes the filter)
|
||||
for node in typ.n:
|
||||
if node.kind == nkSym:
|
||||
let s = node.sym
|
||||
var pm: PrefixMatch
|
||||
if filterSym(s, field, pm):
|
||||
outputs.add(symToSuggest(c.graph, s, isLocal=true, ideSug, n.info,
|
||||
s.getQuality, pm, c.inTypeContext > 0, 0))
|
||||
|
||||
suggestOperations(c, n, field, orig, outputs)
|
||||
if typ != orig:
|
||||
|
||||
6
nimsuggest/tests/module_20265.nim
Normal file
6
nimsuggest/tests/module_20265.nim
Normal file
@@ -0,0 +1,6 @@
|
||||
type A* = tuple
|
||||
a: int
|
||||
b: int
|
||||
|
||||
var x*: A = (a: 2, b: 10)
|
||||
var y* = (a: 2, b: 10)
|
||||
8
nimsuggest/tests/t20265_1.nim
Normal file
8
nimsuggest/tests/t20265_1.nim
Normal file
@@ -0,0 +1,8 @@
|
||||
discard """
|
||||
$nimsuggest --tester $file
|
||||
>sug $1
|
||||
sug;;skField;;a;;int;;*module_20265.nim;;6;;10;;"";;100;;None
|
||||
sug;;skField;;b;;int;;*module_20265.nim;;6;;16;;"";;100;;None
|
||||
"""
|
||||
import module_20265
|
||||
y.#[!]#
|
||||
8
nimsuggest/tests/t20265_2.nim
Normal file
8
nimsuggest/tests/t20265_2.nim
Normal file
@@ -0,0 +1,8 @@
|
||||
discard """
|
||||
$nimsuggest --tester $file
|
||||
>sug $1
|
||||
sug;;skField;;a;;int;;*module_20265.nim;;2;;2;;"";;100;;None
|
||||
sug;;skField;;b;;int;;*module_20265.nim;;3;;2;;"";;100;;None
|
||||
"""
|
||||
import module_20265
|
||||
x.#[!]#
|
||||
Reference in New Issue
Block a user