Skip to content

[SourceKit][IDE] New SourceKit request to retrieve context type information #21377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jan 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -2412,6 +2412,10 @@ class ValueDecl : public Decl {

bool isUsableFromInline() const;

/// Returns \c true if this declaration is *not* intended to be used directly
/// by application developers despite of the visibility.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"despite of" -> "despite", or "in spite of"

bool shouldHideFromEditor() const;

bool hasAccess() const {
return TypeAndAccess.getInt().hasValue();
}
Expand Down
60 changes: 60 additions & 0 deletions include/swift/IDE/TypeContextInfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//===--- TypeContextInfo.h --------------------------------------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2019 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

#ifndef SWIFT_IDE_TYPECONTEXTINFO_H
#define SWIFT_IDE_TYPECONTEXTINFO_H

#include "swift/AST/Type.h"
#include "swift/Basic/LLVM.h"

namespace swift {
class CodeCompletionCallbacksFactory;

namespace ide {

/// A result item for context info query.
class TypeContextInfoItem {
public:
/// Possible expected type.
Type ExpectedTy;
/// Members of \c ExpectedTy which can be referenced by "Implicit Member
/// Expression".
SmallVector<ValueDecl *, 0> ImplicitMembers;

TypeContextInfoItem(Type ExpectedTy) : ExpectedTy(ExpectedTy) {}
};

/// An abstract base class for consumers of context info results.
class TypeContextInfoConsumer {
public:
virtual ~TypeContextInfoConsumer() {}
virtual void handleResults(ArrayRef<TypeContextInfoItem>) = 0;
};

/// Printing consumer
class PrintingTypeContextInfoConsumer : public TypeContextInfoConsumer {
llvm::raw_ostream &OS;

public:
PrintingTypeContextInfoConsumer(llvm::raw_ostream &OS) : OS(OS) {}

void handleResults(ArrayRef<TypeContextInfoItem>) override;
};

/// Create a factory for code completion callbacks.
CodeCompletionCallbacksFactory *
makeTypeContextInfoCallbacksFactory(TypeContextInfoConsumer &Consumer);

} // namespace ide
} // namespace swift

#endif // SWIFT_IDE_TYPECONTEXTINFO_H
28 changes: 28 additions & 0 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2550,6 +2550,34 @@ bool ValueDecl::isUsableFromInline() const {
return false;
}

/// Returns \c true if this declaration is *not* intended to be used directly
/// by application developers despite of the visibility.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't usually copy doc comments to the definition since then we have two places to keep up to date separately.

bool ValueDecl::shouldHideFromEditor() const {
// Hide private stdlib declarations.
if (isPrivateStdlibDecl(/*treatNonBuiltinProtocolsAsPublic*/ false) ||
// ShowInInterfaceAttr is for decls to show in interface as exception but
// they are not intended to be used directly.
getAttrs().hasAttribute<ShowInInterfaceAttr>())
return true;

if (AvailableAttr::isUnavailable(this))
return true;

if (auto *ClangD = getClangDecl()) {
if (ClangD->hasAttr<clang::SwiftPrivateAttr>())
return true;
}

if (!isUserAccessible())
return true;

// Hide editor placeholders.
if (getBaseName().isEditorPlaceholder())
return true;

return false;
}

/// Return the access level of an internal or public declaration
/// that's been testably imported.
static AccessLevel getTestableOrPrivateImportsAccess(const ValueDecl *decl) {
Expand Down
3 changes: 3 additions & 0 deletions lib/IDE/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ add_swift_host_library(swiftIDE STATIC
CodeCompletion.cpp
CodeCompletionCache.cpp
CommentConversion.cpp
ExprContextAnalysis.cpp
Formatting.cpp
Refactoring.cpp
ModuleInterfacePrinting.cpp
Expand All @@ -13,7 +14,9 @@ add_swift_host_library(swiftIDE STATIC
IDETypeChecking.cpp
APIDigesterData.cpp
SourceEntityWalker.cpp
TypeContextInfo.cpp
LINK_LIBRARIES
swiftAST
swiftFrontend
swiftClangImporter
swiftDWARFImporter
Expand Down
Loading