Skip to content

"nix repl" cannot tab-complete names that contain a dash ('-') #1756

@dtzWill

Description

@dtzWill

The Problem

Consider default.nix:

{
  aaa-bbb = 1;
  aaa-ccc = 2;
}

Pointing nix-repl at this, completions are as follows:

a

nix-repl> a
aaa-bbb  aaa-ccc  abort

aaa-

nix-repl> aaa-
__add                            __findFile                       __langVersion                    __stringLength                   builtins
__addErrorContext                __foldl'                         __length                         __sub                            derivation
__all                            __fromJSON                       __lessThan                       __substring                      derivationStrict
__any                            __functionArgs                   __listToAttrs                    __tail                           dirOf
__attrNames                      __genList                        __match                          __toFile                         false
__attrValues                     __genericClosure                 __mul                            __toJSON                         fetchGit
__catAttrs                       __getAttr                        __nixPath                        __toPath                         fetchMercurial
__compareVersions                __getEnv                         __nixVersion                     __toXML                          fetchTarball
__concatLists                    __hasAttr                        __parseDrvName                   __trace                          import
__concatStringsSep               __hashString                     __partition                      __tryEval                        isNull
__currentSystem                  __head                           __pathExists                     __typeOf                         map
__currentTime                    __intersectAttrs                 __readDir                        __unsafeDiscardOutputDependency  null
__deepSeq                        __isAttrs                        __readFile                       __unsafeDiscardStringContext     placeholder
__div                            __isBool                         __replaceStrings                 __unsafeGetAttrPos               removeAttrs
__elem                           __isFloat                        __seq                            __valueSize                      scopedImport
__elemAt                         __isFunction                     __sort                           aaa-bbb                          throw
__fetchurl                       __isInt                          __split                          aaa-ccc                          toString
__filter                         __isList                         __storeDir                       abort                            true
__filterSource                   __isString                       __storePath                      baseNameOf

Essentially completion here is same as if no input was entered (since linenoise completion callback breaks at dashes on our behalf.)

This is unfortunate (too many suggestions) but not incorrect.

aaa-b

nix-repl> aaa-b
baseNameOf  builtins

This is just wrong :(.

Linenoise, linenoise-ng, readline?

AFAICT this behavior is the same when using linenoise or linenoise-ng, but does not occur in readline-based nix-repl.

Solution?

Not sure if there's an easy answer-- perhaps we can punt on linenoise breaking things for us entirely (instead of teaching it how to kinda parse Nix expressions) and handle this in our completion callback?

I'm not sure what other edge cases might be problematic... I suppose spaces after a "dot" should be ignored...? (readline gets this "wrong" as well)

Anyway it doesn't need to be perfect of course but I think a reasonable goal is to reasonably auto-complete the sorts of expressions/attributes commonly used in nixpkgs.

Metadata

Metadata

Assignees

Labels

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions