From 3052ea97fee79631b1f893b08ccd4055d3d4a6f8 Mon Sep 17 00:00:00 2001 From: Basile Burg Date: Sun, 10 Oct 2021 23:23:24 +0200 Subject: [PATCH] completion, partial support for subpackages used as dependencies --- CHANGELOG.md | 1 + src/u_dubproject.pas | 60 +++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b0271641..7d2ec3e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - messages, search results: exclude backticks if the option _backTicksHighlight_ is enabled. - GDB commander: double click on the call stack to select a frame and refresh the different views. This is especially useful to go back to the frame where a D Exception is thrown. (#52) +- completion: partial support for dependencies of type _package:subpackage_. ## Bugs fixed diff --git a/src/u_dubproject.pas b/src/u_dubproject.pas index 6fe031ff..5c714b18 100644 --- a/src/u_dubproject.pas +++ b/src/u_dubproject.pas @@ -1568,6 +1568,11 @@ procedure TDubProject.updateImportPathsFromJson; x: integer; c: TJSONObject; b: TStringList; + y: TStringList; + a: TJSONArray; + z: integer; + m: string; + w: string = ''; begin if obj.findObject('dependencies' + suffix, deps) then begin @@ -1585,20 +1590,25 @@ procedure TDubProject.updateImportPathsFromJson; begin // in case something has to be done with the subpackage... // c := subPackage[n[x + 1 .. n.length]]; - continue; + //continue; + w := n[x + 1 .. n.length]; + n := n[1 .. x-1]; end; // local path specified - if deps.findObject(n, c) and c.findAny('path', j) then + if (deps.findObject(n, c) or deps.findObject(n + ':' + w, c)) and + c.findAny('path', j) then begin s := expandFilenameEx(fBasePath, j.AsString) + DirectorySeparator; + if length(w) <> 0 then + s += w; // as auto detected by DUB if (s + 'source').dirExists then fImportPaths.Add(s) else if (s + 'src').dirExists then fImportPaths.Add(s) // when standard src content is directly in the repo root - else if (s + n).dirExists then + else if (s + n).dirExists or (w.length <> 0) then fImportPaths.Add(s); continue; end; @@ -1689,6 +1699,11 @@ procedure TDubProject.updateImportPathsFromJson; begin s := b[k] + n; p := s + '-' + u^.asString + DirectorySeparator + n + DirectorySeparator; + // e.g vibe-d:http -> /vibed-/http + if length(w) <> 0 then + p += w; + if not p.dirExists then + continue; if (p + 'source').dirExists then begin fImportPaths.Add(p + 'source') ; @@ -1698,6 +1713,45 @@ procedure TDubProject.updateImportPathsFromJson; begin fImportPaths.Add(p + 'src'); break; + end + else if p.dirExists and (w.length <> 0) then + begin + fImportPaths.Add(p); + break; + end + // non standard path, external subpackages receipts, search "sourcePaths" + else + begin + y := TStringList.Create(); + try + listFiles(y, p, true); + for s in y do + begin + if not isValidDubProject(s) then + continue; + EntitiesConnector.beginUpdate(); + try + with TDubProject.create(nil) do + try + loadFromFile(s); + if json.findArray('sourcePaths', a) then + begin + for z := 0 to a.Count-1 do + begin + m := p + a.Strings[z]; + fImportPaths.Add(m); + end; + end; + finally + free; + end; + finally + EntitiesConnector.endUpdate; + end; + end; + finally + y.free; + end; end; end; end;