this is fun

This commit is contained in:
Mirek Fidler 2026-06-30 15:52:48 +02:00
parent d1f66b6a14
commit fcbed9a8dc
8 changed files with 142 additions and 2 deletions

View file

@ -484,7 +484,7 @@ String RichCellPos::ToString() const
{
String s;
s << "pos: " << pos << ", textlen: " << textlen << ", size: " << tabsize << ", tabpos: " << tabpos
<< ", tablen: " << tablen << ", cellpos: " << cellpos << ", celllen: " << celllen << ", level: " << level;
<< ", tablen: " << tablen << ", cellpos: " << cellpos << ", level: " << level;
return s;
}

125
uppsrc/ide/ClangTidy.cpp Normal file
View file

@ -0,0 +1,125 @@
#include "ide.h"
struct ClangTidyDlg : WithClangTidy<TopWindow> {
static String path;
static Index<String> options;
static Index<String> groups;
static bool HasClangTidy();
struct OptionWithLink : Option {
RichTextCtrl text;
};
ArrayMap<String, OptionWithLink> checks;
void Group();
ClangTidyDlg();
};
String ClangTidyDlg::path;
Index<String> ClangTidyDlg::options;
Index<String> ClangTidyDlg::groups;
ClangTidyDlg::ClangTidyDlg()
{
CtrlLayoutOKCancel(*this, "Clang Tidy");
group.AddColumn("Group");
group.NoHeader();
group.Add(AttrText("All").Italic().NormalInk(SLtBlue()));
for(String s : groups)
group.Add(s);
group.WhenSel = [=] {
Group();
};
option.NoHeader();
option.AddKey();
option.AddColumn();
option.NoCursor();
for(String s : options) {
OptionWithLink& opt = checks.Add(s);
opt.NoWantFocus();
opt << opt.text.NoSb().VCenter().HSizePos(DPI(18), 0).VSizePos();
String txt = "[g";
if(s.TrimStart("clang-analyzer-")) // TODO: Improve
txt << "^https://clang.llvm.org/extra/clang-tidy/checks/clang-analyzer/" + s + "^";
else {
int q = s.Find('-');
if(q >= 0)
txt << "^https://clang.llvm.org/extra/clang-tidy/checks/" << s.Mid(0, q) << "/" << s.Mid(q + 1) << ".html^";
}
txt << " \1" << s;
opt.text <<= txt;
}
}
void ClangTidyDlg::Group()
{
String st;
if(group.GetCursor() > 0)
st = group.GetKey();
option.Clear();
for(auto m : ~checks)
if(m.key.StartsWith(st)) {
option.Add(m.key);
option.SetCtrl(option.GetCount() - 1, 0, m.value, false);
}
}
bool ClangTidyDlg::HasClangTidy()
{
ONCELOCK {
#ifdef PLATFORM_WIN32
for(String p : Split(GetMethodVars("CLANGx64").Get("PATH", ""), ';')) {
p << "/clang-tidy.exe";
#else
String p = "clang-tidy";
#endif
String s = Sys(p + " -checks=* --list-checks");
if(s.GetCount()) {
path = p;
for(String l : Split(s, '\n')) {
l = TrimBoth(l);
if(*l.Last() != ':') // Ignore "Enabled checks:"
options.FindAdd(l);
}
for(String s : options) {
int q = s.Find('.');
if(q < 0)
q = s.Find('-');
if(q >= 0)
s.Trim(q);
groups.FindAdd(s);
}
}
#ifdef PLATFORM_WIN32
}
#endif
}
return path.GetCount() && options.GetCount();
}
bool Ide::HasClangTidy()
{
return ClangTidyDlg::HasClangTidy();
}
void Ide::ClangTidy()
{
if(!HasClangTidy()) {
Exclamation("No clang-tidy...");
return;
}
ClangTidyDlg dlg;
dlg.Execute();
}

View file

@ -1299,6 +1299,9 @@ public:
void MacroAllPackages(EscEscape& e);
void MacroTarget(EscEscape& e);
void ClangTidy();
bool HasClangTidy();
String GetAndroidSdkPath();
void TriggerIndexer0();

View file

@ -74,6 +74,7 @@ KEY(DEBUGTO, "Run to cursor (in debugger)", K_CTRL_F10)
KEY(DEBUGEXT, "Debug externally", K_ALT_F5)
KEY(DEBUGFILEEXT, "Debug file externally", K_SHIFT|K_ALT_F5)
KEY(VALGRIND, "Test in Valgrind", 0)
KEY(CLANGTIDY, "Clang Tidy", 0)
KEY(BREAKPOINT, "Toggle breakpoint", K_F9)
KEY(CONDBREAKPOINT, "Conditional breakpoint..", K_ALT_F9)
KEY(CLEARBREAKPOINTS, "Clear all breakpoints", K_CTRL_F9|K_SHIFT)

View file

@ -1028,3 +1028,10 @@ LAYOUT(SeqLayout, 764, 544)
ITEM(Upp::EditString, postfix, LeftPosZ(708, 48).TopPosZ(8, 19))
END_LAYOUT
LAYOUT(ClangTidy, 556, 588)
ITEM(Upp::ArrayCtrl, group, LeftPosZ(8, 184).TopPosZ(8, 528))
ITEM(Upp::ArrayCtrl, option, LeftPosZ(196, 348).TopPosZ(8, 528))
ITEM(Upp::Button, ok, SetLabel(t_("OK")).RightPosZ(76, 64).BottomPosZ(8, 24))
ITEM(Upp::Button, cancel, SetLabel(t_("Cancel")).RightPosZ(8, 64).BottomPosZ(8, 24))
END_LAYOUT

View file

@ -103,6 +103,7 @@ file
Build.cpp,
Debug.cpp,
Valgrind.cpp,
ClangTidy.cpp,
Export.cpp,
Repo readonly separator,
urepo.h,

View file

@ -850,6 +850,9 @@ void Ide::DebugMenu(Bar& menu)
menu.Add(b, AK_VALGRIND, THISBACK(Valgrind))
.Help("Build application & run in valgring");
#endif
if(HasClangTidy())
menu.Add(AK_CLANGTIDY, [=] { ClangTidy(); });
menu.Separator();
}

View file

@ -406,7 +406,7 @@ void AppMain___()
ide.disable_custom_caption2 = ide.disable_custom_caption;
ide.SetupBars();
#ifdef PLATFORM_COCOA
if(!ide.macos_update_icon)
Ctrl::SetAlwaysUseBundledIcon();