@@ -42,7 +42,7 @@ index d82646afb1..3d507b5fe3 100644
4242 import org.openide.util.Lookup;
4343
4444 /**
45- @@ -55,130 +58,164 @@ import org.openide.util.Lookup;
45+ @@ -55,130 +58,171 @@ import org.openide.util.Lookup;
4646 */
4747 public class LspServerTelemetryManager {
4848
@@ -63,7 +63,7 @@ index d82646afb1..3d507b5fe3 100644
6363- public synchronized void connect(LanguageClient client, Future<Void> future) {
6464- clients.put(client, future);
6565- lspServerIntiailizationTime = System.currentTimeMillis();
66- + private static enum ProjectType {
66+ + public static enum ProjectType {
6767+ standalone,
6868+ maven,
6969+ gradle;
@@ -188,12 +188,12 @@ index d82646afb1..3d507b5fe3 100644
188188-
189189- // In future if different JDK is used for different project then this can be updated
190190- obj.addProperty("javaVersion", System.getProperty("java.version"));
191- -
192- - if (mp.containsKey(prjPath)) {
193- - Project prj = mp.get(prjPath);
194191+ String javaVersion = getProjectJavaVersion();
195192+ obj.addProperty("javaVersion", javaVersion);
196-
193+
194+ - if (mp.containsKey(prjPath)) {
195+ - Project prj = mp.get(prjPath);
196+ -
197197- ProjectManager.Result r = ProjectManager.getDefault().isProject2(prj.getProjectDirectory());
198198- String projectType = r.getProjectType();
199199- obj.addProperty("buildTool", (projectType.contains("maven") ? "MavenProject" : "GradleProject"));
@@ -220,7 +220,7 @@ index d82646afb1..3d507b5fe3 100644
220220+ obj.addProperty("isOpenedWithProblems", ProjectProblems.isBroken(prj));
221221 }
222222+ obj.addProperty("buildTool", projectType.name());
223- + boolean isPreviewFlagEnabled = isPreviewEnabled(projectDirectory, projectType);
223+ + boolean isPreviewFlagEnabled = isPreviewEnabled(projectDirectory, projectType, client );
224224+ obj.addProperty("isPreviewEnabled", isPreviewFlagEnabled);
225225
226226 prjProps.add(obj);
@@ -236,26 +236,35 @@ index d82646afb1..3d507b5fe3 100644
236236
237237- properties.add("prjsInfo", prjProps);
238238+ properties.add("projectInfo", prjProps);
239-
240- - properties.addProperty("timeToOpenPrjs", timeToOpenPrjs);
241- - properties.addProperty("numOfPrjsOpened", workspaceClientFolders.size());
242- - properties.addProperty("lspServerInitializationTime", System.currentTimeMillis() - this.lspServerIntiailizationTime);
239+ +
243240+ properties.addProperty("projInitTimeTaken", timeToOpenProjects);
244241+ properties.addProperty("numProjects", workspaceClientFolders.size());
245242+ properties.addProperty("lspInitTimeTaken", System.currentTimeMillis() - this.lspServerIntializationTime);
246243
247- - this.sendTelemetry(client, new TelemetryEvent(MessageType.Info.toString(), this.WORKSPACE_INFO_EVT, properties));
244+ - properties.addProperty("timeToOpenPrjs", timeToOpenPrjs);
245+ - properties.addProperty("numOfPrjsOpened", workspaceClientFolders.size());
246+ - properties.addProperty("lspServerInitializationTime", System.currentTimeMillis() - this.lspServerIntiailizationTime);
248247+ this.sendTelemetry(client, new TelemetryEvent(MessageType.Info.toString(), LspServerTelemetryManager.WORKSPACE_INFO_EVT, properties));
248+ + }
249+
250+ - this.sendTelemetry(client, new TelemetryEvent(MessageType.Info.toString(), this.WORKSPACE_INFO_EVT, properties));
251+ + public boolean isPreviewEnabled(FileObject source, ProjectType prjType) {
252+ + return isPreviewEnabled(source, prjType, null);
249253 }
250254-
251255- private boolean isEnablePreivew(FileObject source, String prjType) {
252256- if (prjType.equals(this.STANDALONE_PRJ)) {
257+ - NbCodeLanguageClient client = Lookup.getDefault().lookup(NbCodeLanguageClient.class);
253258+
254- + private boolean isPreviewEnabled(FileObject source, ProjectType prjType) {
259+ + public boolean isPreviewEnabled(FileObject source, ProjectType prjType, LanguageClient languageClient ) {
255260+ if (prjType == ProjectType.standalone) {
256- NbCodeLanguageClient client = Lookup.getDefault().lookup( NbCodeLanguageClient.class) ;
261+ + NbCodeLanguageClient client = languageClient instanceof NbCodeLanguageClient ? ( NbCodeLanguageClient) languageClient : null ;
257262 if (client == null) {
258- return false;
263+ - return false;
264+ + client = Lookup.getDefault().lookup(NbCodeLanguageClient.class);
265+ + if (client == null) {
266+ + return false;
267+ + }
259268 }
260269- AtomicBoolean isEnablePreviewSet = new AtomicBoolean(false);
261270+ boolean[] isEnablePreviewSet = {false};
@@ -283,7 +292,7 @@ index d82646afb1..3d507b5fe3 100644
283292 }
284293
285294 private String getPrjId(String prjPath) throws NoSuchAlgorithmException {
286- @@ -187,15 +224 ,50 @@ public class LspServerTelemetryManager {
295+ @@ -187,15 +231 ,50 @@ public class LspServerTelemetryManager {
287296
288297 BigInteger number = new BigInteger(1, hash);
289298
@@ -331,7 +340,7 @@ index d82646afb1..3d507b5fe3 100644
331340+ return propertyLookup.apply("java.vm.name");
332341+ }
333342+
334- + private ProjectType getProjectType(Project prj) {
343+ + public ProjectType getProjectType(Project prj) {
335344+ ProjectManager.Result r = ProjectManager.getDefault().isProject2(prj.getProjectDirectory());
336345+ String projectType = r == null ? null : r.getProjectType();
337346+ return projectType != null && projectType.contains(ProjectType.maven.name()) ? ProjectType.maven : ProjectType.gradle;
@@ -358,7 +367,7 @@ index 9134992f5f..f070fec320 100644
358367 }
359368
360369+ public boolean wantsTelemetryEnabled() {
361- + return wantsTelemetryEnabled;
370+ + return wantsTelemetryEnabled == Boolean.TRUE ;
362371+ }
363372+
364373 private NbCodeClientCapabilities withCapabilities(ClientCapabilities caps) {
0 commit comments