Skip to content

[search] nimgrep option to only search for declarations of a given symbol #7419

@timotheecour

Description

@timotheecour

I'd like to have an equivalent of D's dscanner --declaration (cf https://github.com/dlang-community/D-Scanner), also present in other languages ; I couldn't find it in nimgrep

my workaround is to use:

nimgrep -w --ignoreStyle lines **/*.nim| grep -E '(iterator|proc|template|macro)'

but that's very brittle (eg doesn't doesn't work with other types of declarations (eg macros, types, variables, constants etc) and gets fooled by comments.

This is needed for integration with other tools (eg go to declaration)

EDIT

  • also, finding certain symbols can be tricky, eg: defer which seems like it could be a macro but is instead something magic defined here:compiler/transf.nim ; a tool should be able to find the defnition of these as well, eg using lexer.TokTypeToStr
  • for starred symbols, this can be tried:
    nimgrep --ignoreStyle --ext:nim --recursive --oneline "newException\*"
  • also, need a way to find declarations of symbols defined in blocks, eg enum, type etc.

  • also, need a way to find definitions of magic symbols, eg:

proc instantiationInfo*(index = -1, fullPaths = false): tuple[
    filename: string, line: int, column: int] {.magic: "InstantiationInfo", noSideEffect.}
# is actually implemented in compiler/semmagic.nim:
proc semInstantiationInfo(c: PContext, n: PNode)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions