Skip to content

Commit bbdb64e

Browse files
SLLS-398 Collect usage data separately for Cursor and Windsurf
1 parent 49d453b commit bbdb64e

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

src/main/java/org/sonarsource/sonarlint/ls/backend/BackendServiceFacade.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.util.EnumMap;
3030
import java.util.EnumSet;
3131
import java.util.List;
32+
import java.util.Locale;
3233
import java.util.Optional;
3334
import java.util.concurrent.ExecutionException;
3435
import java.util.concurrent.TimeUnit;
@@ -120,9 +121,11 @@ private InitializeParams toInitParams(SonarLintLanguageServerInitializationOptio
120121
sonarLintUserHome = overriddenUserHome.toString();
121122
workDir = Path.of(sonarLintUserHome);
122123
}
124+
123125
return new InitializeParams(
124126
new ClientConstantInfoDto("Visual Studio Code", userAgent),
125-
new TelemetryClientConstantAttributesDto(initializationOptions.productKey(),
127+
new TelemetryClientConstantAttributesDto(
128+
determineProductKey(appName, initializationOptions.productKey()),
126129
initializationOptions.productName(),
127130
initializationOptions.productVersion(),
128131
ideVersion,
@@ -147,6 +150,16 @@ private InitializeParams toInitParams(SonarLintLanguageServerInitializationOptio
147150
null);
148151
}
149152

153+
static String determineProductKey(String appName, String clientProductKey) {
154+
if (appName.toLowerCase(Locale.US).contains("cursor")) {
155+
return "cursor";
156+
}
157+
if (appName.toLowerCase(Locale.US).contains("windsurf")) {
158+
return "windsurf";
159+
}
160+
return clientProductKey;
161+
}
162+
150163
@NotNull
151164
EnumSet<BackendCapability> getBackendCapabilities() {
152165
var backendCapabilities = EnumSet.of(BackendCapability.SMART_NOTIFICATIONS, BackendCapability.PROJECT_SYNCHRONIZATION,

src/test/java/org/sonarsource/sonarlint/ls/backend/BackendServiceFacadeTests.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ class BackendServiceFacadeTests {
4747
public static final String SONARLINT_HTTP_CONNECTION_TIMEOUT = "sonarlint.http.connectTimeout";
4848
public static final String SONARLINT_HTTP_SOCKET_TIMEOUT = "sonarlint.http.socketTimeout";
4949
SonarLintRpcClientDelegate backend = mock(SonarLintRpcClientDelegate.class);
50-
BackendServiceFacade underTest = new BackendServiceFacade(backend, mock(LanguageClientLogger.class), mock(SonarLintExtendedLanguageClient.class), new EnabledLanguages(List.of(), null));
50+
BackendServiceFacade underTest = new BackendServiceFacade(backend, mock(LanguageClientLogger.class), mock(SonarLintExtendedLanguageClient.class),
51+
new EnabledLanguages(List.of(), null));
5152

5253
@Test
5354
void shouldReturnDurationInMinutes() {
@@ -179,4 +180,25 @@ void shouldComputeBackendCapabilities_withFlightRecorder() {
179180
.contains(BackendCapability.FLIGHT_RECORDER);
180181

181182
}
183+
184+
@Test
185+
void should_use_cursor_as_product_key_if_present_in_app_name() {
186+
var productKey = BackendServiceFacade.determineProductKey("Cursor", null);
187+
188+
assertThat(productKey).isEqualTo("cursor");
189+
}
190+
191+
@Test
192+
void should_use_windsurf_as_product_key_if_present_in_app_name() {
193+
var productKey = BackendServiceFacade.determineProductKey("Windsurf", null);
194+
195+
assertThat(productKey).isEqualTo("windsurf");
196+
}
197+
198+
@Test
199+
void should_use_client_product_key_if_unknown_app_name() {
200+
var productKey = BackendServiceFacade.determineProductKey("XXX", "vscode");
201+
202+
assertThat(productKey).isEqualTo("vscode");
203+
}
182204
}

0 commit comments

Comments
 (0)