| 59 | } |
| 60 | |
| 61 | void CMakeCodeCompletionModel::completionInvoked(View* view, const Range& range, InvocationType invocationType) |
| 62 | { |
| 63 | beginResetModel(); |
| 64 | if(s_commands.isEmpty()) { |
| 65 | ICMakeDocumentation* cmakedoc=CMake::cmakeDocumentation(); |
| 66 | |
| 67 | if(cmakedoc) |
| 68 | s_commands=cmakedoc->names(ICMakeDocumentation::Command); |
| 69 | } |
| 70 | |
| 71 | Q_UNUSED(invocationType); |
| 72 | m_declarations.clear(); |
| 73 | DUChainReadLocker lock(DUChain::lock()); |
| 74 | KTextEditor::Document* d=view->document(); |
| 75 | TopDUContext* ctx = DUChain::self()->chainForDocument( d->url() ); |
| 76 | |
| 77 | QString line=d->line(range.end().line()); |
| 78 | // m_inside=line.lastIndexOf('(', range.end().column())>=0; |
| 79 | m_inside=line.lastIndexOf(QLatin1Char('('), range.end().column()-line.size()-1)>=0; |
| 80 | |
| 81 | for(int l=range.end().line(); l>=0 && !m_inside; --l) |
| 82 | { |
| 83 | const auto lineString = d->line(l); |
| 84 | const auto line = leftOfNeedleOrEntireView(lineString, QLatin1Char{'#'}); |
| 85 | |
| 86 | int close=line.lastIndexOf(QLatin1Char(')')), open=line.indexOf(QLatin1Char('(')); |
| 87 | |
| 88 | if(close>=0 && open>=0) { |
| 89 | m_inside=open>close; |
| 90 | break; |
| 91 | } else if(open>=0) { |
| 92 | m_inside=true; |
| 93 | break; |
| 94 | } else if(close>=0) { |
| 95 | m_inside=false; |
| 96 | break; |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | int numRows = 0; |
| 101 | if(m_inside) { |
| 102 | Cursor start=range.start(); |
| 103 | for(; isPathChar(d->characterAt(start)); start-=Cursor(0,1)) |
| 104 | {} |
| 105 | start+=Cursor(0,1); |
| 106 | |
| 107 | const auto toCompleteString = d->text(Range(start, range.end() - Cursor(0, 1))); |
| 108 | const QStringView toComplete = toCompleteString; |
| 109 | |
| 110 | const auto lastdir = toComplete.lastIndexOf(QLatin1Char{'/'}); |
| 111 | QString path = KIO::upUrl(QUrl(d->url())).adjusted(QUrl::StripTrailingSlash).toLocalFile()+QLatin1Char('/'); |
| 112 | if(lastdir>=0) { |
| 113 | const auto basePath = toComplete.first(lastdir); |
| 114 | path += basePath; |
| 115 | } |
| 116 | QDir dir(path); |
| 117 | |
| 118 | const auto paths = dir.entryInfoList(QStringList(toComplete.sliced(lastdir + 1) + QLatin1Char{'*'}), |