diff --git a/uppsrc/ide/ContextGoto.cpp b/uppsrc/ide/ContextGoto.cpp index 07d139a53..06f74e8da 100644 --- a/uppsrc/ide/ContextGoto.cpp +++ b/uppsrc/ide/ContextGoto.cpp @@ -25,6 +25,7 @@ bool IsPendif(const String& l) return l.Find("#endif") >= 0; } +/* TODO remove void Ide::FindId(const String& id) { int pos = editor.GetCursor(); @@ -48,6 +49,7 @@ void Ide::FindId(const String& id) pos++; } } +*/ bool Ide::OpenLink(const String& s, int pos) { // try to find link at cursor, either http, https or file @@ -184,6 +186,7 @@ void Ide::ContextGoto0(int pos) found_nest = m.nest; } } + if(found_path.GetCount()) { AddHistory(); EditFile(found_path); @@ -226,40 +229,46 @@ void Ide::CtrlClick(int64 pos) ContextGoto0((int)pos); } -bool Ide::GotoDesignerFile(const String& path, const String& scope, const String& name, int line) +void Ide::FindDesignerItemReferences(const String& id, const String& name) { - if(ToLower(GetFileExt(path)) == ".lay") { - AddHistory(); - EditFile(path); - LayDesigner *l = dynamic_cast(~designer); - if(l) { - if(scope.StartsWith("With")) - l->FindLayout(scope.Mid(4), name); - else - if(name.StartsWith("SetLayout_")) - l->FindLayout(name.Mid(10), Null); + String path = NormalizePath(editfile); + int q = CodeIndex().Find(path); + if(q >= 0) { + AnnotationItem cm; + for(const AnnotationItem& m : CodeIndex()[q].items) + if(m.id.EndsWith(id) && + (m.id.GetCount() <= id.GetCount() || !iscid(m.id[m.id.GetCount() - id.GetCount() - 1]))) { + cm = m; + break; + } + + if(cm.id.GetCount()) { + Vector> set; + for(const auto& f : ~CodeIndex()) { + if(f.key != path) { + for(const AnnotationItem& m : f.value.items) + if(FindId(m.type, cm.id) >= 0 || FindId(m.bases, cm.id) >= 0 || FindId(m.pretty, cm.id) >= 0) + set.Add({ f.key, m.pos }); + for(const ReferenceItem& m : f.value.refs) + if(FindId(m.id, id) >= 0) + set.Add({ f.key, m.pos }); + } + } + if(set.GetCount()) { + if(set.GetCount() > 1) { + SetFFound(ffoundi_next); + FFound().Clear(); + for(auto& m : set) + AddReferenceLine(m.a, m.b, name); + SortByKey(CodeIndex()); + FFoundFinish(); + } + GotoPos(set[0].a, set[0].b); + return; + } } - else { - editor.SetCursor(editor.GetPos64(line - 1)); - editor.TopCursor(4); - editor.SetFocus(); - } - AddHistory(); - return true; } - else - if(ToLower(GetFileExt(path)) == ".iml") { - AddHistory(); - EditFile(path); - IdeIconDes *l = dynamic_cast(~designer); - if(l) - l->FindId(name); - else - editor.SetFocus(); - AddHistory(); - return true; - } - return false; + Exclamation("No usage has been found."); } void Ide::GotoFileAndId(const String& path, const String& id) diff --git a/uppsrc/ide/LayDes/laywin.cpp b/uppsrc/ide/LayDes/laywin.cpp index 32792648a..e05701b7c 100644 --- a/uppsrc/ide/LayDes/laywin.cpp +++ b/uppsrc/ide/LayDes/laywin.cpp @@ -1,6 +1,7 @@ #include "LayDes.h" #include +#include #define LTIMING(x) //TIMING(x) @@ -165,23 +166,11 @@ void LayDes::GotoUsing() { if(IsNull(currentlayout)) return; - - String lid = "With" + CurrentLayout().name; - const Workspace& wspc = GetIdeWorkspace(); - for(int i = 0; i < wspc.GetCount(); i++) { // find lowest file time - const Package& pk = wspc.GetPackage(i); - String n = wspc[i]; - for(int i = 0; i < pk.GetCount(); i++) { - String path = SourcePath(n, pk.file[i]); - if(IsSourceFile(path) || IsHeaderFile(path)) { - if(false) { // TODO - IdeGotoFileAndId(path, lid); - return; - } - } - } - } - Exclamation("No code found using this layout."); + + if(item.IsCursor()) // TODO not for label + TheIde()->FindDesignerItemReferences("With" + CurrentLayout().name, ~item.Get(1)); + else + TheIde()->FindDesignerItemReferences(CurrentLayout().name + "__layid", "With" + CurrentLayout().name); } void LayDes::OptionBar(Bar& bar) diff --git a/uppsrc/ide/Swaps.cpp b/uppsrc/ide/Swaps.cpp index abbb230d0..2be052e5e 100644 --- a/uppsrc/ide/Swaps.cpp +++ b/uppsrc/ide/Swaps.cpp @@ -78,6 +78,23 @@ String GetFileLine(const String& path, int linei) return linei >= 0 && linei < line.GetCount() ? line[linei] : String(); } +void Ide::AddReferenceLine(const String& path, Point mpos, const String& name) +{ + String ln = GetFileLine(path, mpos.y); + int count = 0; + int pos = 0; + if(name.GetCount()) { + pos = FindId(ln.Mid(mpos.x), name); + if(pos >= 0) { + count = name.GetCount(); + pos += mpos.x; + } + else + pos = 0; + } + AddFoundFile(path, mpos.y + 1, ln, pos, count); +} + void Ide::References() { if(designer) @@ -90,17 +107,6 @@ void Ide::References() SortByKey(CodeIndex()); for(const auto& f : ~CodeIndex()) { auto Add = [&](Point mpos) { - String ln = GetFileLine(f.key, mpos.y); - int count = 0; - int pos = 0; - if(cm.name.GetCount()) { - pos = ::FindId(ln + mpos.x, cm.name); - if(pos >= 0) - count = cm.name.GetCount(); - else - pos = 0; - } - AddFoundFile(f.key, mpos.y + 1, ln, pos, count); }; for(const AnnotationItem& m : f.value.items) if(m.id == cm.id) diff --git a/uppsrc/ide/clang/Indexer.cpp b/uppsrc/ide/clang/Indexer.cpp index 8191cf66c..2118f8f41 100644 --- a/uppsrc/ide/clang/Indexer.cpp +++ b/uppsrc/ide/clang/Indexer.cpp @@ -103,7 +103,7 @@ void DumpIndex() for(const auto& m : ~x) { out << m.key << "\n"; for(const auto& n : m.value.items) - out << '\t' << n.name << " " << n.type << " " << n.id << " " << n.pretty << "\n"; + out << '\t' << n.name << " " << n.type << " " << n.id << " " << n.pretty << " " << n.bases << "\n"; for(const auto& n : m.value.refs) out << '\t' << n.pos << " " << n.id << "\n"; } diff --git a/uppsrc/ide/clang/clang.h b/uppsrc/ide/clang/clang.h index 7dc343909..fb55f6a8e 100644 --- a/uppsrc/ide/clang/clang.h +++ b/uppsrc/ide/clang/clang.h @@ -50,7 +50,7 @@ bool IsStruct(int kind); bool IsTemplate(int kind); bool IsFunction(int kind); bool IsVariable(int kind); -int FindId(const char *s, const String& id); +int FindId(const String& s, const String& id); enum { ITEM_TEXT, diff --git a/uppsrc/ide/clang/todo.txt b/uppsrc/ide/clang/todo.txt index fcd48d8dd..00d72bcc5 100644 --- a/uppsrc/ide/clang/todo.txt +++ b/uppsrc/ide/clang/todo.txt @@ -162,6 +162,10 @@ ISUES: - remove bool Ide::GotoDesignerFile(const String& path, const String& scope, const String& name, int line) +- Usage .lay of FileSel::dir adds some strange lines + +- Alt-J at CtrlLib/CtrlUtil.cpp:143 does not + GREAT CODEBASE PURGE: - ReferenceDlg @@ -179,8 +183,6 @@ GREAT CODEBASE PURGE: - IdeGotoCodeRef -- thisbacks - NONCLANG: - Wind/MetTimeProf.cpp:881 jump on CUtil:: @@ -240,6 +242,8 @@ LATER: DONE: +- thisbacks + - virtuals - different master header currentfile / index issue diff --git a/uppsrc/ide/clang/util.cpp b/uppsrc/ide/clang/util.cpp index 5b49d93d8..fbc37b6d2 100644 --- a/uppsrc/ide/clang/util.cpp +++ b/uppsrc/ide/clang/util.cpp @@ -40,18 +40,9 @@ bool IsVariable(int kind) return findarg(kind, CXCursor_VarDecl, CXCursor_FieldDecl) >= 0; } -int FindId(const char *s, const String& id) -{ - try { - CParser p(s); - while(!p.IsEof()) { - const char *q = p.GetPtr(); - if(p.Id(id)) - return q - s; - else - p.Skip(); - } - } - catch(CParser::Error) {} - return -1; -} +int FindId(const String& s, const String& id) { + int q = s.Find(id); + return q < 0 || + q > 0 && iscid(s[q - 1]) || + q + id.GetCount() < s.GetCount() && iscid(s[q + id.GetCount()]) ? -1 : q; +}; diff --git a/uppsrc/ide/ide.h b/uppsrc/ide/ide.h index 322d247d3..ac19f882a 100644 --- a/uppsrc/ide/ide.h +++ b/uppsrc/ide/ide.h @@ -985,8 +985,9 @@ public: void NavigatorDlg(); void Cycle(const AnnotationItem& cm); void SwapS(); + void AddReferenceLine(const String& path, Point pos, const String& name); void References(); - void FindId(const String& id); +// void FindId(const String& id); TODO remove bool OpenLink(const String& s, int pos); void ContextGoto0(int pos); void ContextGoto(); @@ -1001,6 +1002,7 @@ public: void DoPatchDiff(); void AsErrors(); void RemoveDs(); + void FindDesignerItemReferences(const String& id, const String& name); void HelpMenu(Bar& menu); void ViewIdeLogFile(); @@ -1163,8 +1165,8 @@ public: bool OpenMainPackage(); void NewMainPackage(); - bool GotoDesignerFile(const String& path, const String& scope, const String& name, int line); void GotoFileAndId(const String& path, const String& id); + void GotoDesignerItem(const String& path, const String& id); void SearchTopics(); void ShowTopics(); void ShowTopicsWin();