From a461a202af9e96aa8a476cb3b8ca6a7a1cbef348 Mon Sep 17 00:00:00 2001 From: mattias Date: Sat, 10 Dec 2011 19:05:44 +0000 Subject: [PATCH] codetools: identifier completion: show macros for IFDEF git-svn-id: trunk@34094 - --- .../codetools/ide/codyidentifiersdlg.pas | 1 + components/codetools/identcompletiontool.pas | 53 ++++++++++++++++--- 2 files changed, 48 insertions(+), 6 deletions(-) diff --git a/components/codetools/ide/codyidentifiersdlg.pas b/components/codetools/ide/codyidentifiersdlg.pas index ded1f432fe..142cc73ab8 100644 --- a/components/codetools/ide/codyidentifiersdlg.pas +++ b/components/codetools/ide/codyidentifiersdlg.pas @@ -25,6 +25,7 @@ Dialog to view and search the whole list. ToDo: + -put exact match at start -quickfix for identifier not found -use identifier: check package version -clean up old entries diff --git a/components/codetools/identcompletiontool.pas b/components/codetools/identcompletiontool.pas index ebf7c8d7d5..310c46a751 100644 --- a/components/codetools/identcompletiontool.pas +++ b/components/codetools/identcompletiontool.pas @@ -48,9 +48,9 @@ uses MemCheck, {$ENDIF} Classes, SysUtils, FileProcs, CodeTree, CodeAtom, CodeCache, CustomCodeTool, - CodeToolsStrConsts, KeywordFuncLists, BasicCodeTools, LinkScanner, - AVL_Tree, CodeToolMemManager, DefineTemplates, - SourceChanger, FindDeclarationTool, PascalReaderTool, PascalParserTool; + CodeToolsStrConsts, KeywordFuncLists, BasicCodeTools, LinkScanner, AVL_Tree, + CodeToolMemManager, DefineTemplates, SourceChanger, FindDeclarationTool, + PascalReaderTool, PascalParserTool, CodeToolsStructs, ExprEval; type TIdentCompletionTool = class; @@ -1948,11 +1948,37 @@ function TIdentCompletionTool.IsInCompilerDirective(CursorPos: TCodeXYPosition CurrentIdentifierList.Add(NewItem); end; + procedure AddMacros; + var + Macros: TStringToStringTree; + StrItem: PStringToStringTreeItem; + + procedure Add(e: TExpressionEvaluator); + var + i: Integer; + begin + for i:=0 to e.Count-1 do + Macros[e.Names(i)]:=e.Values(i); + end; + + begin + Macros:=TStringToStringTree.Create(false); + try + Add(Scanner.InitialValues); + Add(Scanner.Values); + for StrItem in Macros do + Key(StrItem^.Name); + finally + Macros.Free; + end; + end; + var Line: String; p: Integer; EndPos: Integer; InnerStart: Integer; + Directive: String; begin Result:=false; Line:=CursorPos.Code.GetLine(CursorPos.Y-1); @@ -1965,10 +1991,15 @@ begin // in a directive Result:=true; InnerStart:=p; - if Line[InnerStart]='{' then inc(InnerStart,2) - else inc(InnerStart,3); + if Line[InnerStart]='{' then + inc(InnerStart,2) + else + inc(InnerStart,3); //debugln(['TIdentCompletionTool.IsInCompilerDirective InnerStart=',InnerStart,' X=',CursorPos.X]); - if InnerStart=CursorPos.X then begin + if (InnerStart=CursorPos.X) + or ((CursorPos.X>=InnerStart) and (InnerStart<=length(Line)) + and (CursorPos.X<=InnerStart+GetIdentLen(@Line[InnerStart]))) + then begin Key('ALIGN'); Key('ALIGNASSERTIONS'); Key('ASMMODE'); @@ -2047,6 +2078,16 @@ begin Key('WARNING'); Key('WARNINGS'); Key('WRITABLECONST'); + end else if InnerStart<=length(Line) then begin + Directive:=lowercase(GetIdentifier(@Line[InnerStart])); + if (Directive='ifdef') + or (Directive='ifndef') + or (Directive='if') + or (Directive='elseif') + or (Directive='ifc') + then begin + AddMacros; + end; end; exit; end;