Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Nimsuggest: Suggestion doesn't work in templates defined outside the file #22116

Open
faldor20 opened this issue Jun 17, 2023 · 0 comments
Open

Comments

@faldor20
Copy link

Description

When doing a suggestion in a template defined outside a file it doesn't suggest correctly.
mainFile.nim

import other

type TestData* = object
  testVal*:int

var state=TestData(testVal:100)

when isMainModule:
  echo("Hello, World!")

template template2*(blk: untyped): untyped =
  proc template2*()  =
    blk

proc procTest():int =
  #This works fine
  let otherState=state
  template2():
    let a=otherState.testVal
  template_outside():
    let a=otherState.testVal

  return state.testVal+1 


template_outside():
  #This doesn't complete correctly
  let a=state.testVal

other.nim

template template_outside*(blk: untyped): untyped =
  proc app_main*()  =
    blk

When inside template2(): state. provides the appropriate completion state.testVal
When inside template_outside completion doesn't work for state. or for otherState. the completion list simply shows all symbols
image
image

Me reproducing this same issue with the cli:

\nimsuggestTests\src> nimsuggest --maxResults:5 ./nimsuggestTests.nim
usage: sug|con|def|use|dus|chk|mod|highlight|outline|known|project file.nim[;dirtyfile.nim]:line:col
type 'quit' to quit
type 'debug' to toggle debug mode on/off
type 'terse' to toggle terse mode on/off
> sug nimsuggestTests.nim:28:15
sug     skProc  nimsuggestTests.procTest        proc (): int    C:\Programming\nim\yogurt-nim\nimsuggestTests\src\nimsuggestTests.nim                                                                                                                                                                                                                                                                                                                                                      15       5       ""      100     None
sug     skVar   nimsuggestTests.state   TestData        C:\Programming\nim\yogurt-nim\nimsuggestTests\src\nimsuggestTests.nim                                                                                                                                                                                                                                                                                                                                                              64       ""      100     None
sug     skProc  nimsuggestTests.app_main        proc () C:\Programming\nim\yogurt-nim\nimsuggestTests\src\other.nim                                                                                                                                                                                                                                                                                                                                                                        27       ""      100     None
sug     skTemplate      nimsuggestTests.template2       template (blk: untyped): untyped                                                                                                                                                                                                                                                                                                                                                                                                   C:\Programming\nim\yogurt-nim\nimsuggestTests\src\nimsuggestTests.nim    11     9                                                                                                                                                                                                                                                                                                                                                                                                           ""       50      None
sug     skConst system.isMainModule     bool    C:\Users\Eli\.choosenim\toolchains\nim-#devel\lib\system\compilation.nim                                                                                                                                                                                                                                                                                                                                                                   24       2       "True only when accessed in the main module. This works thanks to\x0Acompiler magic. It is useful to embed testing code in a module."                                                                                                                                                                                                                                                                                                                                      100      None

> sug nimsuggestTests.nim:19:22
sug     skField testVal int     C:\Programming\nim\yogurt-nim\nimsuggestTests\src\nimsuggestTests.nim                                                                                                                                                                                                                                                                                                                                                                                      42       ""      100     Prefix

>

Nim Version

1.9.3

Current Output

sug     skProc  nimsuggestTests.procTest        proc (): int    C:\Programming\nim\yogurt-nim\nimsuggestTests\src\nimsuggestTests.nim                                                                                                                                                                                                                                                                                                                                                      15       5       ""      100     None
sug     skVar   nimsuggestTests.state   TestData        C:\Programming\nim\yogurt-nim\nimsuggestTests\src\nimsuggestTests.nim                                                                                                                                                                                                                                                                                                                                                              64       ""      100     None
sug     skProc  nimsuggestTests.app_main        proc () C:\Programming\nim\yogurt-nim\nimsuggestTests\src\other.nim                                                                                                                                                                                                                                                                                                                                                                        27       ""      100     None
sug     skTemplate      nimsuggestTests.template2       template (blk: untyped): untyped                                                                                                                                                                                                                                                                                                                                                                                                   C:\Programming\nim\yogurt-nim\nimsuggestTests\src\nimsuggestTests.nim    11     9                                                                                                                                                                                                                                                                                                                                                                                                           ""       50      None
sug     skConst system.isMainModule     bool    C:\Users\Eli\.choosenim\toolchains\nim-#devel\lib\system\compilation.nim                                                                                                                                                                                                                                                                                                                                                                   24       2       "True only when accessed in the main module. This works thanks to\x0Acompiler magic. It is useful to embed testing code in a module."                                                                                                                                                                                                                                                                                                                                      100      None

Expected Output

sug     skField testVal int     C:\Programming\nim\yogurt-nim\nimsuggestTests\src\nimsuggestTests.nim                                                                                                                                                                                                                                                                                                                                                                                      42       ""      100     Prefix

Possible Solution

I'm unsure, maybe something related to scoping within templates. Perhaps we don't look within the local scope inside a template when it comes from an import?

Additional Information

This is a duplicate of nim-lang/langserver#42

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant