Skip to content

Commit 6d3a3db

Browse files
authored
Merge pull request swiftlang#31830 from DavidGoldman/compileopkind
[SourceKit] Include operation kind in compile notifications
2 parents 522a9fe + b6a79b5 commit 6d3a3db

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

test/SourceKit/CompileNotifications/arg-parsing.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// ARG_PARSE_0: key.notification: source.notification.compile-will-start
55
// ARG_PARSE_0: key.compileid: [[CID1:".*"]]
66
// ARG_PARSE_0: key.compilerargs-string: "{{.*}}.swift -no-such-arg"
7+
// ARG_PARSE_0: key.compile_operation: source.compile.operation.code-completion
78
// ARG_PARSE_0: }
89
// ARG_PARSE_0: {
910
// ARG_PARSE_0: key.notification: source.notification.compile-did-finish
@@ -15,6 +16,7 @@
1516
// ARG_PARSE_0: }
1617
// ARG_PARSE_0: ]
1718
// ARG_PARSE_0: key.compileid: [[CID1]]
19+
// ARG_PARSE_0: key.compile_operation: source.compile.operation.code-completion
1820
// ARG_PARSE_0: }
1921
// ARG_PARSE_0-NOT: compile-will-start
2022
// ARG_PARSE_0-NOT: compile-did-finish

test/SourceKit/CompileNotifications/code-completion.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
// COMPILE_1: key.notification: source.notification.compile-will-start,
44
// COMPILE_1: key.filepath: "{{.*}}SOURCE_DIR{{.*}}code-completion.swift",
55
// COMPILE_1: key.compileid: [[CID1:".*"]]
6+
// COMPILE_1: key.compile_operation: source.compile.operation.code-completion
67
// COMPILE_1: }
78
// COMPILE_1: {
89
// COMPILE_1: key.notification: source.notification.compile-did-finish,
910
// COMPILE_1: key.compileid: [[CID1]]
11+
// COMPILE_1: key.compile_operation: source.compile.operation.code-completion
1012
// COMPILE_1: }
1113
// COMPILE_1-NOT: compile-will-start
1214
// COMPILE_1-NOT: compile-did-finish

tools/SourceKit/tools/sourcekitd/lib/API/Requests.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3181,6 +3181,21 @@ class CompileTrackingConsumer final : public trace::TraceConsumer {
31813181
};
31823182
} // end anonymous namespace
31833183

3184+
static Optional<UIdent> getUIDForOperationKind(trace::OperationKind OpKind) {
3185+
static UIdent CompileOperationIndexSource("source.compile.operation.index-source");
3186+
static UIdent CompileOperationCodeCompletion("source.compile.operation.code-completion");
3187+
switch (OpKind) {
3188+
case trace::OperationKind::PerformSema:
3189+
return None;
3190+
case trace::OperationKind::IndexSource:
3191+
return CompileOperationIndexSource;
3192+
case trace::OperationKind::CodeCompletion:
3193+
return CompileOperationCodeCompletion;
3194+
default:
3195+
llvm_unreachable("Unknown operation kind");
3196+
}
3197+
}
3198+
31843199
void CompileTrackingConsumer::operationStarted(
31853200
uint64_t OpId, trace::OperationKind OpKind,
31863201
const trace::SwiftInvocation &Inv, const trace::StringPairs &OpArgs) {
@@ -3193,7 +3208,9 @@ void CompileTrackingConsumer::operationStarted(
31933208
Dict.set(KeyNotification, CompileWillStartUID);
31943209
Dict.set(KeyCompileID, std::to_string(OpId));
31953210
Dict.set(KeyFilePath, Inv.Args.PrimaryFile);
3196-
// FIXME: OperationKind
3211+
if (auto OperationUID = getUIDForOperationKind(OpKind)) {
3212+
Dict.set(KeyCompileOperation, OperationUID.getValue());
3213+
}
31973214
Dict.set(KeyCompilerArgsString, Inv.Args.Arguments);
31983215
sourcekitd::postNotification(RespBuilder.createResponse());
31993216
}
@@ -3209,6 +3226,9 @@ void CompileTrackingConsumer::operationFinished(
32093226
auto Dict = RespBuilder.getDictionary();
32103227
Dict.set(KeyNotification, CompileDidFinishUID);
32113228
Dict.set(KeyCompileID, std::to_string(OpId));
3229+
if (auto OperationUID = getUIDForOperationKind(OpKind)) {
3230+
Dict.set(KeyCompileOperation, OperationUID.getValue());
3231+
}
32123232
auto DiagArray = Dict.setArray(KeyDiagnostics);
32133233
for (const auto &DiagInfo : Diagnostics) {
32143234
fillDictionaryForDiagnosticInfo(DiagArray.appendDictionary(), DiagInfo);

utils/gyb_sourcekit_support/UIDs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ def __init__(self, internal_name, external_name):
182182
KEY('CompletionCheckDependencyInterval',
183183
'key.completion_check_dependency_interval'),
184184
KEY('AnnotatedTypename', 'key.annotated.typename'),
185+
KEY('CompileOperation', 'key.compile_operation'),
185186
]
186187

187188

0 commit comments

Comments
 (0)