mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-25 23:36:16 +02:00
Refactor: extract DocComment::getInnerText(PosTable)
This commit is contained in:
parent
e68234c4f9
commit
491b9cf415
3 changed files with 21 additions and 14 deletions
|
@ -572,20 +572,7 @@ std::optional<EvalState::Doc> EvalState::getDoc(Value & v)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (exprLambda->docComment) {
|
if (exprLambda->docComment) {
|
||||||
auto begin = positions[exprLambda->docComment.begin];
|
docStr = exprLambda->docComment.getInnerText(positions);
|
||||||
auto end = positions[exprLambda->docComment.end];
|
|
||||||
auto docCommentStr = begin.getSnippetUpTo(end);
|
|
||||||
|
|
||||||
// Strip "/**" and "*/"
|
|
||||||
constexpr size_t prefixLen = 3;
|
|
||||||
constexpr size_t suffixLen = 2;
|
|
||||||
docStr = docCommentStr.substr(prefixLen, docCommentStr.size() - prefixLen - suffixLen);
|
|
||||||
if (docStr.empty())
|
|
||||||
return {};
|
|
||||||
// Turn the now missing "/**" into indentation
|
|
||||||
docStr = " " + docStr;
|
|
||||||
// Strip indentation (for the whole, potentially multi-line string)
|
|
||||||
docStr = stripIndentation(docStr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name.empty()) {
|
if (name.empty()) {
|
||||||
|
|
|
@ -641,4 +641,22 @@ size_t SymbolTable::totalSize() const
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string DocComment::getInnerText(const PosTable & positions) const {
|
||||||
|
auto beginPos = positions[begin];
|
||||||
|
auto endPos = positions[end];
|
||||||
|
auto docCommentStr = beginPos.getSnippetUpTo(endPos);
|
||||||
|
|
||||||
|
// Strip "/**" and "*/"
|
||||||
|
constexpr size_t prefixLen = 3;
|
||||||
|
constexpr size_t suffixLen = 2;
|
||||||
|
std::string docStr = docCommentStr.substr(prefixLen, docCommentStr.size() - prefixLen - suffixLen);
|
||||||
|
if (docStr.empty())
|
||||||
|
return {};
|
||||||
|
// Turn the now missing "/**" into indentation
|
||||||
|
docStr = " " + docStr;
|
||||||
|
// Strip indentation (for the whole, potentially multi-line string)
|
||||||
|
docStr = stripIndentation(docStr);
|
||||||
|
return docStr;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,6 +60,8 @@ struct DocComment {
|
||||||
*/
|
*/
|
||||||
operator bool() const { return static_cast<bool>(begin); }
|
operator bool() const { return static_cast<bool>(begin); }
|
||||||
|
|
||||||
|
std::string getInnerText(const PosTable & positions) const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue