Skip to content

Commit 16d97b2

Browse files
authored
Merge pull request #22055 from rintaro/ide-contextinfo-suppliment
[SourceKit][IDE] Update for feedback
2 parents 159b4ef + 37bb049 commit 16d97b2

File tree

5 files changed

+40
-12
lines changed

5 files changed

+40
-12
lines changed

include/swift/AST/Decl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2416,7 +2416,7 @@ class ValueDecl : public Decl {
24162416
bool isUsableFromInline() const;
24172417

24182418
/// Returns \c true if this declaration is *not* intended to be used directly
2419-
/// by application developers despite of the visibility.
2419+
/// by application developers despite the visibility.
24202420
bool shouldHideFromEditor() const;
24212421

24222422
bool hasAccess() const {

lib/AST/Decl.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2550,8 +2550,6 @@ bool ValueDecl::isUsableFromInline() const {
25502550
return false;
25512551
}
25522552

2553-
/// Returns \c true if this declaration is *not* intended to be used directly
2554-
/// by application developers despite of the visibility.
25552553
bool ValueDecl::shouldHideFromEditor() const {
25562554
// Hide private stdlib declarations.
25572555
if (isPrivateStdlibDecl(/*treatNonBuiltinProtocolsAsPublic*/ false) ||

lib/IDE/TypeContextInfo.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,16 @@ class ContextInfoCallbacks : public CodeCompletionCallbacks {
3939

4040
// Ignore callbacks for suffix completions
4141
// {
42-
void completeDotExpr(Expr *E, SourceLoc DotLoc) override{};
43-
void completePostfixExpr(Expr *E, bool hasSpace) override{};
44-
void completeExprSuper(SuperRefExpr *SRE) override{};
45-
void completeExprSuperDot(SuperRefExpr *SRE) override{};
42+
void completeDotExpr(Expr *E, SourceLoc DotLoc) override {};
43+
void completePostfixExpr(Expr *E, bool hasSpace) override {};
44+
void completeExprSuper(SuperRefExpr *SRE) override {};
45+
void completeExprSuperDot(SuperRefExpr *SRE) override {};
4646
// }
4747

4848
// Ignore non-expression callbacks.
4949
// {
50-
void completeInPrecedenceGroup(SyntaxKind SK) override{};
51-
void completePoundAvailablePlatform() override{};
50+
void completeInPrecedenceGroup(SyntaxKind SK) override {};
51+
void completePoundAvailablePlatform() override {};
5252
void completeExprKeyPath(KeyPathExpr *KPE, SourceLoc DotLoc) override {}
5353
void completeTypeSimpleBeginning() override {}
5454
void completeTypeIdentifierWithDot(IdentTypeRepr *ITR) override {}
@@ -65,15 +65,15 @@ class ContextInfoCallbacks : public CodeCompletionCallbacks {
6565
void completePlatformCondition() override {}
6666
void completeGenericParams(TypeLoc TL) override {}
6767
void completeAfterIfStmt(bool hasElse) override {}
68-
void completeAccessorBeginning() override{};
68+
void completeAccessorBeginning() override {};
6969
// }
7070

71-
void completeStmtOrExpr() override{};
71+
void completeStmtOrExpr() override {};
7272
void completePostfixExprBeginning(CodeCompletionExpr *E) override;
7373
void completeForEachSequenceBeginning(CodeCompletionExpr *E) override;
7474
void completeCaseStmtBeginning() override;
7575

76-
void completeAssignmentRHS(AssignExpr *E) override{};
76+
void completeAssignmentRHS(AssignExpr *E) override {};
7777
void completeCallArg(CodeCompletionExpr *E) override;
7878
void completeReturnStmt(CodeCompletionExpr *E) override;
7979
void completeYieldStmt(CodeCompletionExpr *E,
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %sourcekitd-test -req=track-compiles == -req=typecontextinfo %s -offset=0 -- %s | %FileCheck %s -check-prefix=COMPILE_1
2+
// COMPILE_1: {
3+
// COMPILE_1: key.notification: source.notification.compile-will-start,
4+
// COMPILE_1: key.filepath: "SOURCE_DIR{{.*}}type-context-info.swift",
5+
// COMPILE_1: key.compileid: [[CID1:".*"]]
6+
// COMPILE_1: }
7+
// COMPILE_1: {
8+
// COMPILE_1: key.notification: source.notification.compile-did-finish,
9+
// COMPILE_1: key.compileid: [[CID1]]
10+
// COMPILE_1: }
11+
// COMPILE_1-NOT: compile-will-start
12+
// COMPILE_1-NOT: compile-did-finish

tools/SourceKit/lib/SwiftLang/SwiftTypeContextInfo.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "SwiftASTManager.h"
1414
#include "SwiftLangSupport.h"
15+
#include "SwiftEditorDiagConsumer.h"
1516
#include "swift/Frontend/Frontend.h"
1617
#include "swift/Frontend/PrintingDiagnosticConsumer.h"
1718
#include "swift/IDE/TypeContextInfo.h"
@@ -54,13 +55,30 @@ static bool swiftTypeContextInfoImpl(SwiftLangSupport &Lang,
5455
auto bufferIdentifier =
5556
Lang.resolvePathSymlinks(UnresolvedInputFile->getBufferIdentifier());
5657

58+
auto origOffset = Offset;
5759
auto newBuffer = makeCodeCompletionMemoryBuffer(UnresolvedInputFile, Offset,
5860
bufferIdentifier);
5961

6062
CompilerInstance CI;
6163
PrintingDiagnosticConsumer PrintDiags;
6264
CI.addDiagnosticConsumer(&PrintDiags);
6365

66+
EditorDiagConsumer TraceDiags;
67+
trace::TracedOperation TracedOp(trace::OperationKind::CodeCompletion);
68+
if (TracedOp.enabled()) {
69+
CI.addDiagnosticConsumer(&TraceDiags);
70+
trace::SwiftInvocation SwiftArgs;
71+
trace::initTraceInfo(SwiftArgs, bufferIdentifier, Args);
72+
TracedOp.setDiagnosticProvider(
73+
[&TraceDiags](SmallVectorImpl<DiagnosticEntryInfo> &diags) {
74+
TraceDiags.getAllDiagnostics(diags);
75+
});
76+
TracedOp.start(
77+
SwiftArgs,
78+
{std::make_pair("OriginalOffset", std::to_string(origOffset)),
79+
std::make_pair("Offset", std::to_string(Offset))});
80+
}
81+
6482
CompilerInvocation Invocation;
6583
bool Failed = Lang.getASTManager()->initCompilerInvocation(
6684
Invocation, Args, CI.getDiags(), bufferIdentifier, Error);

0 commit comments

Comments
 (0)