1// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#include "symbolkeeper.h"
6
7#include "common/common.h"
8#include "services/builder/builderservice.h"
9
10#include <QStandardItem>
11
12namespace {
13static SymbolTreeView *tree{nullptr};
14static SymbolParser *parser{nullptr};
15static SymbolParseArgs parserArgs;
16}
17
18SymbolKeeper::SymbolKeeper()
19{
20
21}
22
23SymbolKeeper *SymbolKeeper::instance()
24{
25 static SymbolKeeper ins;
26 return &ins;
27}
28
29SymbolTreeView *SymbolKeeper::treeView()
30{
31 if (!tree) {
32 tree = new SymbolTreeView();
33 QObject::connect(tree, &SymbolTreeView::jumpToLine,
34 this, &SymbolKeeper::jumpToLine);
35 }
36 return tree;
37}
38
39void SymbolKeeper::doParse(const SymbolParseArgs &args)
40{
41 parserArgs = args;
42 if (parser) {
43 QObject::disconnect(parser, &SymbolParser::parseDone,
44 this, &SymbolKeeper::doParseDone);
45 parser->kill();
46 parser->waitForFinished();
47 delete parser;
48 parser = nullptr;
49 }
50 parser = new SymbolParser();
51 parser->setArgs(args);
52 parser->SymbolParser::start();
53 QObject::connect(parser, &SymbolParser::parseDone,
54 this, &SymbolKeeper::doParseDone);
55}
56
57void SymbolKeeper::jumpToLine(const QString &filePath, const QString &fileLine)
58{
59 editor.jumpToLine(filePath, fileLine.toInt());
60}
61
62void SymbolKeeper::doParseDone(bool result)
63{
64 SymbolParseArgs args = parser->args();
65 symbol.parseDone(args.workspace, args.language, args.storage, result);
66 this->treeView()->expandAll();
67 parser->kill();
68 delete parser;
69 parser = nullptr;
70}
71