Skip to content

Commit 40759df

Browse files
committed
[SourceKit] Include operation kind in compile notifications
- Compile will start / did finish now includes the operation kind (perform sema or code complete). - See also https://forums.swift.org/t/sourcekit-lsp-file-status-ux/35947
1 parent 4e7569e commit 40759df

File tree

6 files changed

+35
-1
lines changed

6 files changed

+35
-1
lines changed

test/SourceKit/CompileNotifications/arg-parsing.swift

Lines changed: 4 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.compileoperation: 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.compileoperation: 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
@@ -25,6 +27,7 @@
2527
// ARG_PARSE_1: key.notification: source.notification.compile-will-start
2628
// ARG_PARSE_1: key.compileid: [[CID1:".*"]]
2729
// ARG_PARSE_1: key.compilerargs-string: "{{.*}}.swift -no-such-arg"
30+
// ARG_PARSE_1: key.compileoperation: source.compile.operation.perform-sema
2831
// ARG_PARSE_1: }
2932
// ARG_PARSE_1: {
3033
// ARG_PARSE_1: key.notification: source.notification.compile-did-finish
@@ -36,6 +39,7 @@
3639
// ARG_PARSE_1: }
3740
// ARG_PARSE_1: ]
3841
// ARG_PARSE_1: key.compileid: [[CID1]]
42+
// ARG_PARSE_1: key.compileoperation: source.compile.operation.perform-sema
3943
// ARG_PARSE_1: }
4044
// ARG_PARSE_1-NOT: compile-will-start
4145
// ARG_PARSE_1-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.compileoperation: 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.compileoperation: source.compile.operation.code-completion
1012
// COMPILE_1: }
1113
// COMPILE_1-NOT: compile-will-start
1214
// COMPILE_1-NOT: compile-did-finish

test/SourceKit/CompileNotifications/cursor-info.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{{.*}}cursor-info.swift",
55
// COMPILE_1: key.compileid: [[CID1:".*"]]
6+
// COMPILE_1: key.compileoperation: source.compile.operation.perform-sema
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.compileoperation: source.compile.operation.perform-sema
1012
// COMPILE_1: }
1113
// COMPILE_1: <empty cursor info; internal diagnostic: "Unable to resolve cursor info.">
1214
// COMPILE_1-NOT: compile-will-start

test/SourceKit/CompileNotifications/edits.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
// COMPILE_1: {
55
// COMPILE_1: key.notification: source.notification.compile-will-start,
66
// COMPILE_1: key.compileid: [[CID1:".*"]]
7+
// COMPILE_1: key.compileoperation: source.compile.operation.perform-sema
78
// COMPILE_1: }
89
// COMPILE_1: {
910
// COMPILE_1: key.notification: source.notification.compile-did-finish,
1011
// COMPILE_1: key.compileid: [[CID1]]
12+
// COMPILE_1: key.compileoperation: source.compile.operation.perform-sema
1113
// COMPILE_1: }
1214
// COMPILE_1-NOT: compile-will-start
1315
// COMPILE_1-NOT: compile-did-finish
@@ -19,26 +21,32 @@
1921
// COMPILE_3: {
2022
// COMPILE_3: key.notification: source.notification.compile-will-start,
2123
// COMPILE_3: key.compileid: [[CID1:".*"]]
24+
// COMPILE_3: key.compileoperation: source.compile.operation.perform-sema
2225
// COMPILE_3: }
2326
// COMPILE_3: {
2427
// COMPILE_3: key.notification: source.notification.compile-did-finish,
2528
// COMPILE_3: key.compileid: [[CID1]]
29+
// COMPILE_3: key.compileoperation: source.compile.operation.perform-sema
2630
// COMPILE_3: }
2731
// COMPILE_3: {
2832
// COMPILE_3: key.notification: source.notification.compile-will-start,
2933
// COMPILE_3: key.compileid: [[CID2:".*"]]
34+
// COMPILE_3: key.compileoperation: source.compile.operation.perform-sema
3035
// COMPILE_3: }
3136
// COMPILE_3: {
3237
// COMPILE_3: key.notification: source.notification.compile-did-finish,
3338
// COMPILE_3: key.compileid: [[CID2]]
39+
// COMPILE_3: key.compileoperation: source.compile.operation.perform-sema
3440
// COMPILE_3: }
3541
// COMPILE_3: {
3642
// COMPILE_3: key.notification: source.notification.compile-will-start,
3743
// COMPILE_3: key.compileid: [[CID3:".*"]]
44+
// COMPILE_3: key.compileoperation: source.compile.operation.perform-sema
3845
// COMPILE_3: }
3946
// COMPILE_3: {
4047
// COMPILE_3: key.notification: source.notification.compile-did-finish,
4148
// COMPILE_3: key.compileid: [[CID3]]
49+
// COMPILE_3: key.compileoperation: source.compile.operation.perform-sema
4250
// COMPILE_3: }
4351
// COMPILE_3-NOT: compile-will-start
4452
// COMPILE_3-NOT: compile-did-finish

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

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

3184+
static UIdent getUIDForOperationKind(trace::OperationKind OpKind) {
3185+
static UIdent CompileOperationPerformSema("source.compile.operation.perform-sema");
3186+
static UIdent CompileOperationIndexSource("source.compile.operation.index-source");
3187+
static UIdent CompileOperationCodeCompletion("source.compile.operation.code-completion");
3188+
switch (OpKind) {
3189+
case trace::OperationKind::PerformSema:
3190+
return CompileOperationPerformSema;
3191+
case trace::OperationKind::IndexSource:
3192+
return CompileOperationIndexSource;
3193+
case trace::OperationKind::CodeCompletion:
3194+
return CompileOperationCodeCompletion;
3195+
case trace::OperationKind::All:
3196+
return CompileOperationPerformSema;
3197+
}
3198+
}
3199+
31843200
void CompileTrackingConsumer::operationStarted(
31853201
uint64_t OpId, trace::OperationKind OpKind,
31863202
const trace::SwiftInvocation &Inv, const trace::StringPairs &OpArgs) {
@@ -3193,7 +3209,7 @@ void CompileTrackingConsumer::operationStarted(
31933209
Dict.set(KeyNotification, CompileWillStartUID);
31943210
Dict.set(KeyCompileID, std::to_string(OpId));
31953211
Dict.set(KeyFilePath, Inv.Args.PrimaryFile);
3196-
// FIXME: OperationKind
3212+
Dict.set(KeyCompileOperation, getUIDForOperationKind(OpKind));
31973213
Dict.set(KeyCompilerArgsString, Inv.Args.Arguments);
31983214
sourcekitd::postNotification(RespBuilder.createResponse());
31993215
}
@@ -3209,6 +3225,7 @@ void CompileTrackingConsumer::operationFinished(
32093225
auto Dict = RespBuilder.getDictionary();
32103226
Dict.set(KeyNotification, CompileDidFinishUID);
32113227
Dict.set(KeyCompileID, std::to_string(OpId));
3228+
Dict.set(KeyCompileOperation, getUIDForOperationKind(OpKind));
32123229
auto DiagArray = Dict.setArray(KeyDiagnostics);
32133230
for (const auto &DiagInfo : Diagnostics) {
32143231
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.compileoperation'),
185186
]
186187

187188

0 commit comments

Comments
 (0)