compiler/tools/suggest

  Source   Edit

This file implements features required for IDE support.

Due to Nim's nature and the fact that system.nim is always imported, there are lots of potential symbols. Furthermore thanks to templates and macros even context based analysis does not help much: In a context like let x: | where a type has to follow, that type might be constructed from a template like extractField(MyObject, fieldName). We deal with this problem by smart sorting so that the likely symbols come first. This sorting is done this way:

  • 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.
  • 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.
  • In any case, sorting also considers scoping information. Local variables get high priority.

Types

TCheckPointResult = enum
  cpNone, cpFuzzy, cpExact
  Source   Edit

Procs

proc executeCmd(cmd: IdeCmd; file, dirtyfile: AbsoluteFile; line, col: int;
                graph: ModuleGraph) {....raises: [KeyError, Exception,
    ERecoverableError, OSError, IOError, ValueError, EOFError], tags: [
    ReadDirEffect, RootEffect, ReadEnvEffect, ReadIOEffect, WriteDirEffect,
    WriteIOEffect].}
executes the given suggest command, cmd, for a given file, at the position described by line and column. If dirtyFile is non-empty, then its contents are used as part of the analysis.   Source   Edit
proc findTrackedSym(g: ModuleGraph): PSym {....raises: [], tags: [].}
  Source   Edit
proc inCheckpoint(current, trackPos: TLineInfo): TCheckPointResult {....raises: [],
    tags: [].}
  Source   Edit
proc isTracked(current, trackPos: TLineInfo; tokenLen: int): bool {....raises: [],
    tags: [].}
  Source   Edit
proc safeSemExpr(c: PContext; n: PNode): PNode {....raises: [Exception],
    tags: [RootEffect].}
  Source   Edit
proc suggestDecl(c: PContext; n: PNode; s: PSym) {.
    ...raises: [Exception, KeyError, ValueError, ERecoverableError, ESuggestDone],
    tags: [RootEffect, ReadIOEffect, ReadDirEffect].}
  Source   Edit
proc suggestEnum(c: PContext; n: PNode; t: PType) {.
    ...raises: [Exception, KeyError, ValueError, ESuggestDone],
    tags: [RootEffect, ReadIOEffect].}
  Source   Edit
proc suggestExpr(c: PContext; n: PNode) {.
    ...raises: [Exception, KeyError, ValueError, ERecoverableError, ESuggestDone],
    tags: [RootEffect, ReadIOEffect, ReadDirEffect].}
  Source   Edit
proc suggestExprNoCheck(c: PContext; n: PNode) {.
    ...raises: [Exception, KeyError, ValueError, ERecoverableError, ESuggestDone],
    tags: [RootEffect, ReadIOEffect, ReadDirEffect].}
  Source   Edit
proc suggestSentinel(c: PContext) {....raises: [KeyError, Exception, ValueError], tags: [
    ReadDirEffect, RootEffect, ReadIOEffect].}
  Source   Edit
proc suggestStmt(c: PContext; n: PNode) {.
    ...raises: [Exception, KeyError, ValueError, ERecoverableError, ESuggestDone],
    tags: [RootEffect, ReadIOEffect, ReadDirEffect].}
  Source   Edit
proc suggestSym(g: ModuleGraph; info: TLineInfo; s: PSym; usageSym: var PSym;
                isDecl = true) {.inline, ...raises: [], tags: [].}
misnamed: should be 'symDeclared'   Source   Edit