Exemplo n.º 1
0
ClangCodeCompleteResults CodeCompleter::completeSmartPointerCreation(uint line,
                                                                     uint column,
                                                                     int funcNameStartLine,
                                                                     int funcNameStartColumn)
{
    if (column <= 1 || funcNameStartLine == -1)
        return ClangCodeCompleteResults();

    UnsavedFile &file = unsavedFiles.unsavedFile(translationUnit.filePath());
    if (!file.hasCharacterAt(line, column - 1, '('))
        return ClangCodeCompleteResults();

    bool ok;
    const uint startPos = file.toUtf8Position(funcNameStartLine, funcNameStartColumn, &ok);
    const uint endPos = file.toUtf8Position(line, column - 1, &ok);

    Utf8String content = file.fileContent();
    const QString oldName = content.mid(startPos, endPos - startPos);
    const QString updatedName = tweakName(oldName);
    if (updatedName.isEmpty())
        return ClangCodeCompleteResults();

    column += updatedName.length();
    file.replaceAt(endPos + 1, 0, updatedName);

    ClangCodeCompleteResults results = completeHelper(line, column);
    if (results.isEmpty()) {
        column -= updatedName.length();
        file.replaceAt(endPos + 1, updatedName.length(), QString());
    }
    return results;
}
Exemplo n.º 2
0
CodeCompletions CodeCompleter::complete(uint line, uint column,
                                        int funcNameStartLine,
                                        int funcNameStartColumn)
{
    neededCorrection_ = CompletionCorrection::NoCorrection;

    // Check if we have a smart pointer completion and get proper constructor signatures in results.
    // Results are empty when it's not a smart pointer or this completion failed.
    ClangCodeCompleteResults results = completeSmartPointerCreation(line,
                                                                    column,
                                                                    funcNameStartLine,
                                                                    funcNameStartColumn);

    if (results.isNull() || results.isEmpty())
        results = completeHelper(line, column);

    filterUnknownContextResults(results, unsavedFile(), line, column);
    tryDotArrowCorrectionIfNoResults(results, line, column);

    return toCodeCompletions(results);
}