mirror of https://gitlab.com/basile.b/dexed.git
Improve detection of a library item sources path, close #95
This commit is contained in:
parent
db87798694
commit
73b4b4a9e5
|
@ -286,6 +286,11 @@ type
|
||||||
*)
|
*)
|
||||||
function indentationMode(const fname: string): TIndentationMode;
|
function indentationMode(const fname: string): TIndentationMode;
|
||||||
|
|
||||||
|
(**
|
||||||
|
* Removes duplicate items in strings
|
||||||
|
*)
|
||||||
|
procedure deleteDups(strings: TStrings);
|
||||||
|
|
||||||
(**
|
(**
|
||||||
* like LCLIntf eponymous function but includes a woraround that's gonna
|
* like LCLIntf eponymous function but includes a woraround that's gonna
|
||||||
* be in Lazarus from version 1.8 (anchor + file:/// protocol under win).
|
* be in Lazarus from version 1.8 (anchor + file:/// protocol under win).
|
||||||
|
@ -1326,6 +1331,18 @@ begin
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure deleteDups(strings: TStrings);
|
||||||
|
var
|
||||||
|
i,j: integer;
|
||||||
|
begin
|
||||||
|
for i := strings.Count-1 downto 0 do
|
||||||
|
begin
|
||||||
|
j := strings.IndexOf(strings[i]);
|
||||||
|
if (j <> -1) and (j <> i) then
|
||||||
|
strings.Delete(i);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
initialization
|
initialization
|
||||||
registerClasses([TCEPersistentShortcut]);
|
registerClasses([TCEPersistentShortcut]);
|
||||||
end.
|
end.
|
||||||
|
|
|
@ -6,11 +6,11 @@ interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
|
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
|
||||||
Menus, ComCtrls, Buttons, LazFileUtils, strutils, fphttpclient, StdCtrls,
|
Menus, ComCtrls, Buttons, LazFileUtils, fphttpclient, StdCtrls,
|
||||||
xfpjson, xjsonparser,
|
xfpjson, xjsonparser,
|
||||||
ce_widget, ce_interfaces, ce_ceproject, ce_dmdwrap, ce_common, ce_dialogs,
|
ce_widget, ce_interfaces, ce_ceproject, ce_dmdwrap, ce_common, ce_dialogs,
|
||||||
ce_sharedres, process, ce_dubproject, ce_observer, ce_dlang, ce_libman,
|
ce_sharedres, process, ce_dubproject, ce_observer, ce_dlang, ce_libman,
|
||||||
ce_projutils, ce_dsgncontrols;
|
ce_projutils, ce_dsgncontrols, ce_stringrange;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
|
@ -864,9 +864,12 @@ var
|
||||||
mnme: string;
|
mnme: string;
|
||||||
path: string;
|
path: string;
|
||||||
base: string;
|
base: string;
|
||||||
|
fldn: array of string;
|
||||||
lst: TStringList;
|
lst: TStringList;
|
||||||
srcc: TStringList;
|
srcc: TStringList;
|
||||||
toks: TLexTokenList;
|
toks: TLexTokenList;
|
||||||
|
rng: TStringRange = (ptr: nil; pos: 0; len: 0);
|
||||||
|
sym: boolean;
|
||||||
begin
|
begin
|
||||||
|
|
||||||
// 1 source, same folder
|
// 1 source, same folder
|
||||||
|
@ -881,11 +884,11 @@ begin
|
||||||
lst := TStringList.Create;
|
lst := TStringList.Create;
|
||||||
srcc := TStringList.Create;
|
srcc := TStringList.Create;
|
||||||
toks := TLexTokenList.Create;
|
toks := TLexTokenList.Create;
|
||||||
lst.Duplicates:= dupIgnore;
|
|
||||||
try
|
try
|
||||||
// get module name and store the parent.parent.parent... dir
|
// get module name and store the parent.parent.parent... dir
|
||||||
for i := 0 to project.sourcesCount-1 do
|
for i := 0 to project.sourcesCount-1 do
|
||||||
begin
|
begin
|
||||||
|
sym := true;
|
||||||
path := project.sourceAbsolute(i);
|
path := project.sourceAbsolute(i);
|
||||||
if not hasDlangSyntax(path.extractFileExt) then
|
if not hasDlangSyntax(path.extractFileExt) then
|
||||||
continue;
|
continue;
|
||||||
|
@ -893,16 +896,42 @@ begin
|
||||||
srcc.LoadFromFile(path);
|
srcc.LoadFromFile(path);
|
||||||
lex(srcc.Text, toks, @lexFindToken, [lxoNoComments]);
|
lex(srcc.Text, toks, @lexFindToken, [lxoNoComments]);
|
||||||
mnme := getModuleName(toks);
|
mnme := getModuleName(toks);
|
||||||
|
if path.extractFileName = 'package.d' then
|
||||||
|
mnme := mnme + '.p';
|
||||||
toks.Clear;
|
toks.Clear;
|
||||||
for j := 0 to WordCount(mnme, ['.'])-1 do
|
setLength(fldn, 0);
|
||||||
|
rng.init(mnme);
|
||||||
|
while true do
|
||||||
|
begin
|
||||||
|
setLength(fldn, length(fldn) + 1);
|
||||||
|
fldn[high(fldn)] := rng.takeUntil(['.', #0]).yield;
|
||||||
|
if rng.empty then
|
||||||
|
break
|
||||||
|
else
|
||||||
|
rng.popFront;
|
||||||
|
end;
|
||||||
|
for j:= high(fldn)-1 downto 0 do
|
||||||
|
begin
|
||||||
|
path := path.extractFileDir;
|
||||||
|
if path.extractFileName <> fldn[j] then
|
||||||
|
begin
|
||||||
|
sym := false;
|
||||||
|
break;
|
||||||
|
end
|
||||||
|
end;
|
||||||
|
if sym then
|
||||||
|
begin
|
||||||
path := path.extractFileDir;
|
path := path.extractFileDir;
|
||||||
lst.Add(path);
|
lst.Add(path);
|
||||||
end;
|
end;
|
||||||
|
end;
|
||||||
|
deleteDups(lst);
|
||||||
if project.sourcesCount = 0 then
|
if project.sourcesCount = 0 then
|
||||||
result := ''
|
result := ''
|
||||||
else
|
else
|
||||||
result := lst[0];
|
result := lst[0];
|
||||||
if (project.sourcesCount > 1) and (lst.Count > 1) then
|
if ((project.sourcesCount > 1) and (lst.Count > 1))
|
||||||
|
or (not sym) then
|
||||||
begin
|
begin
|
||||||
lst.Clear;
|
lst.Clear;
|
||||||
for j := 0 to project.sourcesCount-1 do
|
for j := 0 to project.sourcesCount-1 do
|
||||||
|
|
Loading…
Reference in New Issue