Example #1
0
void SwiftLangSupport::codeComplete(llvm::MemoryBuffer *UnresolvedInputFile,
                                    unsigned Offset,
                                    SourceKit::CodeCompletionConsumer &SKConsumer,
                                    ArrayRef<const char *> Args) {
  SwiftCodeCompletionConsumer SwiftConsumer([&](
      ArrayRef<CodeCompletionResult *> Results, SwiftCompletionInfo &) {
    for (auto *Result : Results) {
      if (!SwiftToSourceKitCompletionAdapter::handleResult(SKConsumer, Result))
        break;
    }
  });

  std::string Error;
  if (!swiftCodeCompleteImpl(*this, UnresolvedInputFile, Offset, SwiftConsumer,
                             Args, Error)) {
    SKConsumer.failed(Error);
  }
}
Example #2
0
void SwiftLangSupport::codeComplete(llvm::MemoryBuffer *UnresolvedInputFile,
                                    unsigned Offset,
                                    SourceKit::CodeCompletionConsumer &SKConsumer,
                                    ArrayRef<const char *> Args) {
  SwiftCodeCompletionConsumer SwiftConsumer([&](
      MutableArrayRef<CodeCompletionResult *> Results,
      SwiftCompletionInfo &info) {
    bool hasExpectedType = info.completionContext->HasExpectedTypeRelation;
    CodeCompletionContext::sortCompletionResults(Results);
    // FIXME: this adhoc filtering should be configurable like it is in the
    // codeCompleteOpen path.
    for (auto *Result : Results) {
      if (Result->getKind() == CodeCompletionResult::Literal) {
        switch (Result->getLiteralKind()) {
        case CodeCompletionLiteralKind::NilLiteral:
        case CodeCompletionLiteralKind::BooleanLiteral:
          break;
        case CodeCompletionLiteralKind::ImageLiteral:
        case CodeCompletionLiteralKind::ColorLiteral:
          if (hasExpectedType &&
              Result->getExpectedTypeRelation() <
                  CodeCompletionResult::Convertible)
            continue;
          break;
        default:
          continue;
        }
      }
      if (!SwiftToSourceKitCompletionAdapter::handleResult(SKConsumer, Result))
        break;
    }
  });

  std::string Error;
  if (!swiftCodeCompleteImpl(*this, UnresolvedInputFile, Offset, SwiftConsumer,
                             Args, Error)) {
    SKConsumer.failed(Error);
  }
}