@@ -25,7 +25,8 @@ func NewNixCandidateSource(fs Filesystem, key string) CandidateSource {
2525 sources : map [string ]* PathSetIn {},
2626 key : key ,
2727 }
28- res .precompute ()
28+ res .crawlKnownPaths ()
29+ res .crawlPathLists ()
2930 return res
3031}
3132
@@ -37,7 +38,7 @@ func (s *NixCandidateSource) WhereSet(somePath string) *PathSetIn {
3738 return s .sources [normalizedPath ]
3839}
3940
40- func (s * NixCandidateSource ) precompute () {
41+ func (s * NixCandidateSource ) crawlKnownPaths () {
4142 ForEachKnownPath (func (originalSource , expandedSource string ) {
4243 // try getting the contents
4344 input , err := readAllText (expandedSource )
@@ -58,23 +59,7 @@ func (s *NixCandidateSource) precompute() {
5859 if s .key == x .Name .Value {
5960 harvestedPaths := s .harvestPaths (input [x .Value .Pos ().Offset ():x .Value .End ().Offset ()])
6061 for _ , harvestedPath := range harvestedPaths {
61- foundNormalizedPath := s .fs .GetAbsolutePath (harvestedPath )
62- sourcesForPath := s .sources [foundNormalizedPath ]
63- if sourcesForPath == nil {
64- sourcesForPath = & PathSetIn {
65- What : Location {harvestedPath , foundNormalizedPath },
66- WhereSet : []Location {},
67- }
68- }
69- sourcesForPath .WhereSet = appendIfNotInSlice (
70- sourcesForPath .WhereSet ,
71- Location {
72- originalSource ,
73- expandedSource ,
74- }, func (a , b Location ) bool {
75- return a .Expanded == b .Expanded && a .Original == b .Original
76- })
77- s .sources [foundNormalizedPath ] = sourcesForPath
62+ s .tryUpdatePathMap (harvestedPath , originalSource , expandedSource )
7863 }
7964 }
8065 }
@@ -83,6 +68,35 @@ func (s *NixCandidateSource) precompute() {
8368 })
8469}
8570
71+ func (s * NixCandidateSource ) tryUpdatePathMap (harvestedPath string , originalSource string , expandedSource string ) {
72+ foundNormalizedPath := s .fs .GetAbsolutePath (harvestedPath )
73+ sourcesForPath := s .sources [foundNormalizedPath ]
74+ if sourcesForPath == nil {
75+ sourcesForPath = & PathSetIn {
76+ What : Location {harvestedPath , foundNormalizedPath },
77+ WhereSet : []Location {},
78+ }
79+ }
80+ sourcesForPath .WhereSet = appendIfNotInSlice (
81+ sourcesForPath .WhereSet ,
82+ Location {
83+ originalSource ,
84+ expandedSource ,
85+ }, func (a , b Location ) bool {
86+ return a .Expanded == b .Expanded && a .Original == b .Original
87+ })
88+ s .sources [foundNormalizedPath ] = sourcesForPath
89+ }
90+
91+ func (s * NixCandidateSource ) crawlPathLists () {
92+ if runtime .GOOS == "windows" {
93+ return
94+ }
95+ ForEachPathsDPath (func (source , path string ) {
96+ s .tryUpdatePathMap (path , source , source )
97+ })
98+ }
99+
86100// input is some path definition
87101func (s * NixCandidateSource ) harvestPaths (input string ) []string {
88102 input = strings .TrimSpace (input )
0 commit comments