mirror of
https://github.com/siemens-mobile-hacks/llvm-c166.git
synced 2026-11-25 21:45:57 +00:00
This patch improves `scripting extension list` in three ways.
First, it groups the output by `ScriptedExtension`: instead of one row
per registered plugin instance, one entry per extension is printed with
a combined `Language` field.
Second, it colorizes and visually separates the output. Each entry is
preceded by a dimmed dashed separator; field labels are printed in bold
green, the extension name value in bold cyan as a mini-heading, and
`None` usage values are dimmed, all via the same
`ansi::FormatAnsiTerminalCodes(..., use_color)` idiom
`Breakpoint::GetDescription` uses elsewhere, gracefully no-op when color
is disabled or unsupported. `ScriptedInterfaceUsages::Dump` takes an
optional `use_color` parameter so its own `API Usages:` / `Command
Interpreter Usages:` labels can match.
Third, it adds `-j`/`--json` to emit a JSON array of `{name,
description, languages, api_usages, command_interpreter_usages}` per
extension, mirroring `plugin list`'s existing `-j`. `DoExecute` now
computes the extension grouping once and branches into
`OutputJsonFormat` or `OutputTextFormat`, sharing a
`GetLanguagesForExtension` helper. It also accepts optional positional
`<extension-name>` arguments to filter the listing to specific
extensions (matched via the same case-insensitive
`ScriptInterpreter::StringToExtension` used by `scripting extension
generate`), with completion wired up via `eScriptedExtensionCompletion`.
Also fix a latent lifetime bug in the shared language-collection helper
so it owns its `std::string` values instead of holding `StringRef`s to
temporaries; the JSON path made it observable.
Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
47 lines
1.6 KiB
C++
47 lines
1.6 KiB
C++
//===-- ScriptedInterfaceUsages.cpp --------------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "lldb/Interpreter/Interfaces/ScriptedInterfaceUsages.h"
|
|
|
|
#include "lldb/Utility/AnsiTerminal.h"
|
|
|
|
using namespace lldb;
|
|
using namespace lldb_private;
|
|
|
|
void ScriptedInterfaceUsages::Dump(Stream &s, UsageKind kind,
|
|
bool use_color) const {
|
|
const std::string label =
|
|
ansi::FormatAnsiTerminalCodes("${ansi.fg.green}${ansi.bold}", use_color);
|
|
const std::string dim =
|
|
ansi::FormatAnsiTerminalCodes("${ansi.faint}", use_color);
|
|
const std::string reset =
|
|
ansi::FormatAnsiTerminalCodes("${ansi.normal}", use_color);
|
|
|
|
s.IndentMore();
|
|
s.Indent();
|
|
llvm::StringRef usage_kind =
|
|
(kind == UsageKind::CommandInterpreter) ? "Command Interpreter" : "API";
|
|
s << label << usage_kind << " Usages:" << reset;
|
|
const std::vector<llvm::StringRef> &usages =
|
|
(kind == UsageKind::CommandInterpreter) ? GetCommandInterpreterUsages()
|
|
: GetSBAPIUsages();
|
|
if (usages.empty())
|
|
s << ' ' << dim << "None" << reset << '\n';
|
|
else if (usages.size() == 1)
|
|
s << " " << usages.front() << '\n';
|
|
else {
|
|
s << '\n';
|
|
for (llvm::StringRef usage : usages) {
|
|
s.IndentMore();
|
|
s.Indent();
|
|
s << usage << '\n';
|
|
s.IndentLess();
|
|
}
|
|
}
|
|
s.IndentLess();
|
|
}
|