MCPcopy Create free account
hub / github.com/KDE/kdevelop / computeIndentationFromSample

Method computeIndentationFromSample

plugins/customscript/customscript_plugin.cpp:427–464  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

425}
426
427QStringList CustomScriptPlugin::computeIndentationFromSample(const SourceFormatterStyle& style, const QUrl& url,
428 const QMimeType& mime) const
429{
430 QStringList ret;
431
432 const auto languages = ICore::self()->languageController()->languagesForUrl(url);
433 if (languages.isEmpty()) {
434 return ret;
435 }
436 const auto& language = *languages.constFirst();
437 const auto sample = language.indentationSample();
438 if (sample.isEmpty()) {
439 qCWarning(CUSTOMSCRIPT) << "Cannot compute indentation because of missing indentation sample in language plugin"
440 << language.name();
441 return ret;
442 }
443 const QString formattedSample = formatSourceWithStyle(style, sample, url, mime, QString(), QString());
444
445 const QStringList lines = formattedSample.split(QLatin1Char('\n'));
446 for (const QString& line : lines) {
447 if (!line.isEmpty() && line[0].isSpace()) {
448 QString indent;
449 for (const QChar c : line) {
450 if (c.isSpace()) {
451 indent.push_back(c);
452 } else {
453 break;
454 }
455 }
456
457 if (!indent.isEmpty() && !ret.contains(indent)) {
458 ret.push_back(indent);
459 }
460 }
461 }
462
463 return ret;
464}
465
466CustomScriptPlugin::Indentation CustomScriptPlugin::indentation(const SourceFormatterStyle& style, const QUrl& url,
467 const QMimeType& mime) const

Callers

nothing calls this directly

Calls 9

languagesForUrlMethod · 0.80
languageControllerMethod · 0.80
QStringClass · 0.50
isEmptyMethod · 0.45
indentationSampleMethod · 0.45
nameMethod · 0.45
splitMethod · 0.45
push_backMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected