| 425 | } |
| 426 | |
| 427 | QStringList 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 | |
| 466 | CustomScriptPlugin::Indentation CustomScriptPlugin::indentation(const SourceFormatterStyle& style, const QUrl& url, |
| 467 | const QMimeType& mime) const |
nothing calls this directly
no test coverage detected