IDE: quick fix ad warn off directive: add message pattern as comment

git-svn-id: trunk@51789 -
This commit is contained in:
mattias 2016-03-01 15:41:58 +00:00
parent 17f571cf26
commit 8a70101ec3
3 changed files with 19 additions and 10 deletions

View File

@ -394,7 +394,7 @@ type
const NewSrc: string = ''): boolean; deprecated;
function AddIncludeDirectiveForInit(Code: TCodeBuffer; const Filename: string;
const NewSrc: string = ''): boolean;
function AddUnitWarnDirective(Code: TCodeBuffer; aParam: string;
function AddUnitWarnDirective(Code: TCodeBuffer; WarnID, Comment: string;
TurnOn: boolean): boolean;
function RemoveDirective(Code: TCodeBuffer; NewX, NewY: integer;
RemoveEmptyIFs: boolean): boolean;
@ -3283,8 +3283,8 @@ begin
end;
end;
function TCodeToolManager.AddUnitWarnDirective(Code: TCodeBuffer;
aParam: string; TurnOn: boolean): boolean;
function TCodeToolManager.AddUnitWarnDirective(Code: TCodeBuffer; WarnID,
Comment: string; TurnOn: boolean): boolean;
begin
Result:=false;
{$IFDEF CTDEBUG}
@ -3292,7 +3292,7 @@ begin
{$ENDIF}
if not InitCurCodeTool(Code) then exit;
try
Result:=FCurCodeTool.AddUnitWarnDirective(aParam,TurnOn,SourceChangeCache);
Result:=FCurCodeTool.AddUnitWarnDirective(WarnID,Comment,TurnOn,SourceChangeCache);
except
on e: Exception do Result:=HandleException(e);
end;

View File

@ -280,7 +280,7 @@ type
function AddIncludeDirectiveForInit(const Filename: string;
SourceChangeCache: TSourceChangeCache; const NewSrc: string = ''
): boolean;
function AddUnitWarnDirective(WarnID: string; TurnOn: boolean;
function AddUnitWarnDirective(WarnID, Comment: string; TurnOn: boolean;
SourceChangeCache: TSourceChangeCache): boolean;
function FixIncludeFilenames(Code: TCodeBuffer;
SourceChangeCache: TSourceChangeCache;
@ -6483,13 +6483,12 @@ begin
Result:=true;
end;
function TStandardCodeTool.AddUnitWarnDirective(WarnID: string;
function TStandardCodeTool.AddUnitWarnDirective(WarnID, Comment: string;
TurnOn: boolean; SourceChangeCache: TSourceChangeCache): boolean;
const
DirectiveFlagValue: array[boolean] of string = ('on','off');
var
ACleanPos, DirEndPos, InsertStartPos,
MaxPos: Integer;
ACleanPos, DirEndPos, InsertStartPos, MaxPos: Integer;
Node: TCodeTreeNode;
p, IDStartPos, IDEndPos, ParamPos: PChar;
NewCode: String;
@ -6501,6 +6500,14 @@ begin
BuildTree(lsrMainUsesSectionStart);
SourceChangeCache.MainScanner:=Scanner;
// fix comment
if Comment<>'' then begin
for ACleanPos:=1 to length(Comment) do
if Comment[ACleanPos] in [#0..#8,#11,#12,#14..#31,'{','}'] then
Comment[ACleanPos]:='?';
if not (Comment[1] in [' ',#9,#10,#13]) then Comment:=' '+Comment;
end;
MaxPos:=0;
Node:=Tree.Root.NextBrother;
if Node<>nil then
@ -6551,7 +6558,7 @@ begin
// there was no such directive yet -> find nice insert pos
InsertStartPos:=FindLineEndOrCodeInFrontOfPosition(MaxPos,true,true);
NewCode:='{$WARN '+WarnID+' '+DirectiveFlagValue[TurnOn]+'}';
NewCode:='{$WARN '+WarnID+' '+DirectiveFlagValue[TurnOn]+Comment+'}';
if not SourceChangeCache.Replace(gtNewLine,gtNewLine,
InsertStartPos,InsertStartPos,NewCode)
then

View File

@ -322,6 +322,7 @@ var
MsgID: integer;
Tool: TCodeTool;
Code: TCodeBuffer;
Comment: String;
begin
if not IsApplicable(Msg,MsgID,Tool) then exit;
@ -336,7 +337,8 @@ begin
exit;
end;
if not CodeToolBoss.AddUnitWarnDirective(Code,IntToStr(MsgID),true) then
Comment:=' : '+TIDEFPCParser.GetFPCMsgPattern(Msg);
if not CodeToolBoss.AddUnitWarnDirective(Code,IntToStr(MsgID),Comment,true) then
begin
DebugLn(['TQuickFix_HideWithCompilerDirective CodeToolBoss.AddUnitWarnDirective failed']);
LazarusIDE.DoJumpToCodeToolBossError;