| 44 | } |
| 45 | |
| 46 | void CodeLensTree::setData(const lsp::References &refs) |
| 47 | { |
| 48 | onceReadFlag = false; |
| 49 | auto model = qobject_cast<QStandardItemModel *>(CodeLensTree::model()); |
| 50 | model->clear(); |
| 51 | QHash<QString, QStandardItem *> cache {}; |
| 52 | for (auto ref : refs) { |
| 53 | lsp::Range range = ref.range; |
| 54 | if (range.start.line != range.end.line) |
| 55 | continue; |
| 56 | |
| 57 | QString filePath = ref.fileUrl.toLocalFile(); |
| 58 | QStandardItem *fileItem = nullptr; |
| 59 | if (cache.contains(filePath)) { |
| 60 | fileItem = cache[filePath]; |
| 61 | } else { |
| 62 | fileItem = new QStandardItem(filePath); |
| 63 | cache[filePath] = fileItem; |
| 64 | model->appendRow(fileItem); |
| 65 | } |
| 66 | |
| 67 | QString text = readLine(filePath, range.start.line); |
| 68 | if (text.isEmpty()) |
| 69 | continue; |
| 70 | |
| 71 | QStandardItem *item = new QStandardItem(text); |
| 72 | item->setData(range.start.line, CodeLensItemRole::LineRole); |
| 73 | item->setData(range.start.character, CodeLensItemRole::TermStartRole); |
| 74 | item->setData(range.end.character, CodeLensItemRole::TermEndRole); |
| 75 | item->setTextAlignment(Qt::AlignVCenter); |
| 76 | fileItem->appendRow(item); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | QString CodeLensTree::readLine(const QString &filePath, int line) |
| 81 | { |
no test coverage detected