Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9f9193a

Browse files
committedSep 11, 2024·
refactor: Use std::source_location for the LOG (#109)
1 parent 05fd9fd commit 9f9193a

40 files changed

+438
-401
lines changed
 

‎src/core/astnode.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ bool AstNode::isValid() const
5050
std::optional<treesitter::Node> AstNode::node() const
5151
{
5252
if (!isValid()) {
53-
spdlog::warn("AstNode is invalid");
53+
spdlog::warn("{}: AstNode is invalid", FUNCTION_NAME);
5454
return std::nullopt;
5555
}
5656

‎src/core/classsymbol.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ QList<Symbol *> ClassSymbol::findMembers() const
4040
}
4141
return members;
4242
}
43-
spdlog::warn("Parent of CppClass {} is not an CodeDocument!", m_name);
43+
spdlog::warn("{}: Parent of CppClass {} is not an CodeDocument!", FUNCTION_NAME, m_name);
4444
return {};
4545
}
4646

‎src/core/codedocument.cpp

+35-33
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ void CodeDocument::deleteSymbol(const Symbol &symbol)
132132
*/
133133
Core::SymbolList CodeDocument::symbols() const
134134
{
135-
LOG("CodeDocument::symbols");
135+
LOG();
136136
return m_treeSitterHelper->symbols();
137137
}
138138

@@ -199,7 +199,7 @@ QString CodeDocument::hover(int position, std::function<void(const QString &)> a
199199
std::pair<QString, std::optional<RangeMark>> CodeDocument::hoverWithRange(
200200
int position, std::function<void(const QString &, std::optional<RangeMark>)> asyncCallback /* = {} */) const
201201
{
202-
spdlog::debug("CodeDocument::hover");
202+
spdlog::debug("{}", FUNCTION_NAME);
203203

204204
if (!checkClient())
205205
return {"", {}};
@@ -226,8 +226,10 @@ std::pair<QString, std::optional<RangeMark>> CodeDocument::hoverWithRange(
226226
if (const auto *content = std::get_if<Lsp::MarkupContent>(&hover.contents)) {
227227
return {QString::fromStdString(content->value), range};
228228
} else {
229-
spdlog::warn("LSP returned deprecated MarkedString type which is unsupported by Knut\n - Consider updating "
230-
"your LSP server");
229+
spdlog::warn(
230+
"{}: LSP returned deprecated MarkedString type which is unsupported by Knut\n - Consider updating "
231+
"your LSP server",
232+
FUNCTION_NAME);
231233
return {"", {}};
232234
}
233235
};
@@ -245,7 +247,7 @@ std::pair<QString, std::optional<RangeMark>> CodeDocument::hoverWithRange(
245247
// a Tooltip is requested.
246248
// See: TextView::eventFilter.
247249
if (!std::holds_alternative<Lsp::Hover>(result.value())) {
248-
spdlog::debug("LSP server returned no result for Hover");
250+
spdlog::debug("{}: LSP server returned no result for Hover", FUNCTION_NAME);
249251
}
250252
return convertResult(result.value());
251253
}
@@ -256,7 +258,7 @@ std::pair<QString, std::optional<RangeMark>> CodeDocument::hoverWithRange(
256258

257259
RangeMarkList CodeDocument::references(int position) const
258260
{
259-
spdlog::debug("CodeDocument::references");
261+
spdlog::debug("{}", FUNCTION_NAME);
260262

261263
if (!checkClient()) {
262264
return {};
@@ -271,10 +273,10 @@ RangeMarkList CodeDocument::references(int position) const
271273
if (const auto *locations = std::get_if<std::vector<Lsp::Location>>(&value)) {
272274
return Utils::lspToRangeMarkList(*locations);
273275
} else {
274-
spdlog::warn("CodeDocument::references: Language server returned unsupported references type!");
276+
spdlog::warn("{}: Language server returned unsupported references type!", FUNCTION_NAME);
275277
}
276278
} else {
277-
spdlog::warn("CodeDocument::references: LSP call to references returned nothing!");
279+
spdlog::warn("{}: LSP call to references returned nothing!", FUNCTION_NAME);
278280
}
279281

280282
return {};
@@ -283,7 +285,7 @@ RangeMarkList CodeDocument::references(int position) const
283285
// Follows the symbol under the cursor.
284286
Document *CodeDocument::followSymbol()
285287
{
286-
spdlog::debug("CodeDocument::followSymbol");
288+
spdlog::debug("{}", FUNCTION_NAME);
287289
if (!checkClient())
288290
return {};
289291

@@ -332,7 +334,7 @@ Document *CodeDocument::followSymbol(int pos)
332334
return nullptr;
333335

334336
if (locations.size() > 1)
335-
spdlog::warn("CodeDocument::followSymbol: Multiple locations returned!");
337+
spdlog::warn("{}: Multiple locations returned!", FUNCTION_NAME);
336338
// Heuristic: If multiple locations were found, use the last one.
337339
auto location = locations.back();
338340

@@ -347,8 +349,7 @@ Document *CodeDocument::followSymbol(int pos)
347349
if (auto *codeDocument = qobject_cast<CodeDocument *>(document)) {
348350
codeDocument->selectRange(Utils::lspToRange(*codeDocument, location.range));
349351
} else {
350-
spdlog::warn("CodeDocument::followSymbol: Opened document '{}' is not an CodeDocument",
351-
document->fileName());
352+
spdlog::warn("{}: Opened document '{}' is not an CodeDocument", FUNCTION_NAME, document->fileName());
352353
}
353354
}
354355

@@ -358,7 +359,7 @@ Document *CodeDocument::followSymbol(int pos)
358359
// Switches between the function declaration or definition.
359360
Document *CodeDocument::switchDeclarationDefinition()
360361
{
361-
spdlog::debug("CodeDocument::switchDeclarationDefinition");
362+
spdlog::debug("{}", FUNCTION_NAME);
362363
if (!checkClient())
363364
return {};
364365

@@ -371,7 +372,7 @@ Document *CodeDocument::switchDeclarationDefinition()
371372
});
372373

373374
if (!currentFunction) {
374-
spdlog::info("CodeDocument::switchDeclarationDefinition: Cursor is currently not within a function!");
375+
spdlog::info("{}: Cursor is currently not within a function!", FUNCTION_NAME);
375376
return nullptr;
376377
}
377378

@@ -390,7 +391,7 @@ Document *CodeDocument::switchDeclarationDefinition()
390391
*/
391392
void CodeDocument::selectSymbol(const QString &name, int options)
392393
{
393-
LOG("CodeDocument::selectSymbol", LOG_ARG("text", name), options);
394+
LOG(LOG_ARG("text", name), options);
394395

395396
if (auto symbol = findSymbol(name, options))
396397
selectRange(symbol->selectionRange());
@@ -405,7 +406,7 @@ void CodeDocument::selectSymbol(const QString &name, int options)
405406
*/
406407
int CodeDocument::selectLargerSyntaxNode(int count /* = 1*/)
407408
{
408-
LOG_AND_MERGE("CodeDocument::selectLargerSyntaxNode", LOG_ARG("count", count));
409+
LOG_AND_MERGE(LOG_ARG("count", count));
409410

410411
auto currentNode = m_treeSitterHelper->nodeCoveringRange(selectionStart(), selectionEnd());
411412

@@ -444,7 +445,7 @@ int CodeDocument::selectLargerSyntaxNode(int count /* = 1*/)
444445
*/
445446
int CodeDocument::selectSmallerSyntaxNode(int count /* = 1*/)
446447
{
447-
LOG_AND_MERGE("CodeDocument::selectSmallerSyntaxNode", LOG_ARG("count", count));
448+
LOG_AND_MERGE(LOG_ARG("count", count));
448449

449450
auto smallerNodes =
450451
kdalgorithms::filtered(m_treeSitterHelper->nodesInRange(createRangeMark()), [](const auto &node) {
@@ -469,8 +470,7 @@ int CodeDocument::selectSmallerSyntaxNode(int count /* = 1*/)
469470
if (node.has_value()) {
470471
selectRegion(node->startPosition(), node->endPosition());
471472
} else {
472-
spdlog::warn(
473-
"CodeDocument::selectSmallerSyntaxNode: No smaller node found! Do you currently not have a selection?");
473+
spdlog::warn("{}: No smaller node found! Do you currently not have a selection?", FUNCTION_NAME);
474474
}
475475

476476
LOG_RETURN("pos", position());
@@ -513,7 +513,7 @@ findSibling(const treesitter::Node &start, treesitter::Node (treesitter::Node::*
513513
*/
514514
int CodeDocument::selectNextSyntaxNode(int count /*= 1*/)
515515
{
516-
LOG_AND_MERGE("CodeDocument::selectNextSyntaxNode", LOG_ARG("count", count));
516+
LOG_AND_MERGE(LOG_ARG("count", count));
517517

518518
auto node = m_treeSitterHelper->nodeCoveringRange(selectionStart(), selectionEnd());
519519

@@ -540,7 +540,7 @@ int CodeDocument::selectNextSyntaxNode(int count /*= 1*/)
540540
*/
541541
int CodeDocument::selectPreviousSyntaxNode(int count /*= 1*/)
542542
{
543-
LOG_AND_MERGE("CodeDocument::selectPreviousSyntaxNode", LOG_ARG("count", count));
543+
LOG_AND_MERGE(LOG_ARG("count", count));
544544

545545
auto node = m_treeSitterHelper->nodeCoveringRange(selectionStart(), selectionEnd());
546546

@@ -566,7 +566,7 @@ int CodeDocument::selectPreviousSyntaxNode(int count /*= 1*/)
566566
*/
567567
Symbol *CodeDocument::findSymbol(const QString &name, int options) const
568568
{
569-
LOG("CodeDocument::findSymbol", LOG_ARG("text", name), options);
569+
LOG(LOG_ARG("text", name), options);
570570

571571
auto symbols = this->symbols();
572572
const auto regexp =
@@ -681,7 +681,7 @@ Core::QueryMatchList CodeDocument::query(const std::shared_ptr<treesitter::Query
681681
*/
682682
Core::QueryMatchList CodeDocument::query(const QString &query)
683683
{
684-
LOG("CodeDocument::query", LOG_ARG("query", query));
684+
LOG(LOG_ARG("query", query));
685685

686686
return this->query(m_treeSitterHelper->constructQuery(query));
687687
}
@@ -701,7 +701,7 @@ Core::QueryMatchList CodeDocument::query(const QString &query)
701701
*/
702702
Core::QueryMatch CodeDocument::queryFirst(const QString &query)
703703
{
704-
LOG("CodeDocument::queryOne", LOG_ARG("query", query));
704+
LOG(LOG_ARG("query", query));
705705

706706
return this->queryFirst(m_treeSitterHelper->constructQuery(query));
707707
}
@@ -715,20 +715,20 @@ Core::QueryMatch CodeDocument::queryFirst(const QString &query)
715715
*/
716716
Core::QueryMatchList CodeDocument::queryInRange(const Core::RangeMark &range, const QString &query)
717717
{
718-
LOG("CodeDocument::queryInRange", LOG_ARG("range", range), LOG_ARG("query", query));
718+
LOG(LOG_ARG("range", range), LOG_ARG("query", query));
719719

720720
if (!range.isValid()) {
721-
spdlog::warn("CodeDocument::queryInRange: Range is not valid");
721+
spdlog::warn("{}: Range is not valid", FUNCTION_NAME);
722722
return {};
723723
}
724724

725725
const auto nodes = m_treeSitterHelper->nodesInRange(range);
726726

727727
if (nodes.isEmpty()) {
728-
spdlog::warn("CodeDocument::queryInRange: No nodes in range");
728+
spdlog::warn("{}: No nodes in range", FUNCTION_NAME);
729729
return {};
730730
}
731-
spdlog::debug("CodeDocument::queryInRange: Found {} nodes in range", nodes.size());
731+
spdlog::debug("{}: Found {} nodes in range", FUNCTION_NAME, nodes.size());
732732

733733
auto tsQuery = m_treeSitterHelper->constructQuery(query);
734734
if (!tsQuery)
@@ -755,7 +755,7 @@ bool CodeDocument::checkClient() const
755755
{
756756
Q_ASSERT(textEdit());
757757
if (!client()) {
758-
spdlog::error("CodeDocument {} has no LSP client - API not available", fileName());
758+
spdlog::error("{}: CodeDocument {} has no LSP client - API not available", FUNCTION_NAME, fileName());
759759
return false;
760760
}
761761
return true;
@@ -770,14 +770,16 @@ void CodeDocument::changeContentLsp(int position, int charsRemoved, int charsAdd
770770
// TODO: Keep copy of previous string around, so we can find the oldEndPosition.
771771
// const auto document = textEdit()->document();
772772
// const auto startblock = document->findBlock(position);
773-
// spdlog::warn("start point: {}, {}", startblock.blockNumber(), position - startblock.position());
773+
// spdlog::warn("{} - start point: {}, {}", FUNCTION_NAME, startblock.blockNumber(), position -
774+
// startblock.position());
774775

775776
// const auto newEndPosition = position + charsAdded;
776777
// const auto newEndBlock = document->findBlock(newEndPosition);
777-
// spdlog::warn("new end point: {}, {}", newEndBlock.blockNumber(), newEndPosition - newEndBlock.position());
778+
// spdlog::warn("{} - new end point: {}, {}", FUNCTION_NAME, newEndBlock.blockNumber(), newEndPosition -
779+
// newEndBlock.position());
778780

779781
// const auto plain = document->toPlainText();
780-
// spdlog::warn("added: {}", plain.sliced(position, charsAdded));
782+
// spdlog::warn("{} - added: {}", FUNCTION_NAME, plain.sliced(position, charsAdded));
781783

782784
if (!checkClient()) {
783785
return;
@@ -811,7 +813,7 @@ void CodeDocument::changeContentLsp(int position, int charsRemoved, int charsAdd
811813

812814
client()->didChange(std::move(params));
813815
} else {
814-
spdlog::error("LSP server does not support Document changes!");
816+
spdlog::error("{}: LSP server does not support Document changes!", FUNCTION_NAME);
815817
}
816818
}
817819

‎src/core/codedocument_p.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ std::optional<treesitter::Tree> &TreeSitterHelper::syntaxTree()
5050
if (!m_tree) {
5151
auto &parser = this->parser();
5252
if (!parser.setIncludedRanges(m_document->includedRanges())) {
53-
spdlog::warn("TreeSitterHelper::syntaxTree: Unable to set the included ranges on the treesitter parser!");
53+
spdlog::warn("{}: Unable to set the included ranges on the treesitter parser!", FUNCTION_NAME);
5454
parser.setIncludedRanges({});
5555
}
5656
m_tree = parser.parseString(m_document->text());
5757
if (!m_tree) {
58-
spdlog::warn("CodeDocument::syntaxTree: Failed to parse document {}!", m_document->fileName());
58+
spdlog::warn("{}: Failed to parse document {}!", FUNCTION_NAME, m_document->fileName());
5959
}
6060
}
6161
return m_tree;
@@ -67,8 +67,8 @@ std::shared_ptr<treesitter::Query> TreeSitterHelper::constructQuery(const QStrin
6767
try {
6868
tsQuery = std::make_shared<treesitter::Query>(parser().language(), query);
6969
} catch (treesitter::Query::Error &error) {
70-
spdlog::error("CodeDocument::constructQuery: Failed to parse query `{}` error: {} at: {}", query,
71-
error.description, error.utf8_offset);
70+
spdlog::error("{}: Failed to parse query `{}` error: {} at: {}", FUNCTION_NAME, query, error.description,
71+
error.utf8_offset);
7272
return {};
7373
}
7474
return tsQuery;

0 commit comments

Comments
 (0)
Please sign in to comment.