diff --git a/metals/src/main/scala/scala/meta/internal/metals/MetalsLspService.scala b/metals/src/main/scala/scala/meta/internal/metals/MetalsLspService.scala index 5ac3cd3db5c..07cfd365ae2 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/MetalsLspService.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/MetalsLspService.scala @@ -2855,6 +2855,9 @@ class MetalsLspService( /* serverConfig = */ telemetry.conversion.MetalsServerConfig( serverInputs.initialServerConfig ), + /* clientInfo =*/ telemetry.conversion.MetalsClientInfo( + initializeParams.getClientInfo() + ), /* buildServerConnections = */ bspSession.toList .flatMap( telemetry.conversion.BuildServerConnections(_) diff --git a/metals/src/main/scala/scala/meta/internal/telemetry/conversion/package.scala b/metals/src/main/scala/scala/meta/internal/telemetry/conversion/package.scala index e3a6654d163..88f8140c5bc 100644 --- a/metals/src/main/scala/scala/meta/internal/telemetry/conversion/package.scala +++ b/metals/src/main/scala/scala/meta/internal/telemetry/conversion/package.scala @@ -1,5 +1,7 @@ package scala.meta.internal.telemetry +import java.util.Optional + import scala.collection.JavaConverters._ import scala.jdk.OptionConverters._ @@ -8,6 +10,8 @@ import scala.meta.internal.metals import scala.meta.internal.pc.telemetry.conversion.PresentationCompilerConfig import scala.meta.internal.telemetry +import org.eclipse.lsp4j + package object conversion { def UserConfiguration( config: metals.UserConfiguration @@ -65,4 +69,10 @@ package object conversion { /* compilers = */ PresentationCompilerConfig(config.compilers), ) + def MetalsClientInfo(info: lsp4j.ClientInfo): telemetry.MetalsClientInfo = + new telemetry.MetalsClientInfo( + /* name = */ Optional.of(info.getName()), + /* version = */ Optional.of(info.getVersion()), + ) + } diff --git a/mtags/src/main/scala/scala/meta/internal/metals/ScalametaSourceCodeTransformer.scala b/mtags/src/main/scala/scala/meta/internal/metals/ScalametaSourceCodeTransformer.scala index a667c884278..c0d1f5679a0 100644 --- a/mtags/src/main/scala/scala/meta/internal/metals/ScalametaSourceCodeTransformer.scala +++ b/mtags/src/main/scala/scala/meta/internal/metals/ScalametaSourceCodeTransformer.scala @@ -64,8 +64,10 @@ object ScalametaSourceCodeTransformer override def apply(tree: Tree): Tree = { tree match { case name: Name if isCommonScalaName(name) => name - case node: Term.Select if isWellKnownPackageSelector(node.toString()) => node - case node: Type.Select if isWellKnownPackageSelector(node.toString()) => node + case node: Term.Select if isWellKnownPackageSelector(node.toString()) => + node + case node: Type.Select if isWellKnownPackageSelector(node.toString()) => + node case node: Type.Name => sanitizeTypeName(node) case node: Term.Name => sanitizeTermName(node) case node: Name.Indeterminate => sanitizeUnclasifiedName(node) diff --git a/telemetry-interfaces/src/main/java/scala/meta/internal/telemetry/MetalsClientInfo.java b/telemetry-interfaces/src/main/java/scala/meta/internal/telemetry/MetalsClientInfo.java new file mode 100644 index 00000000000..df6f5cd6e1d --- /dev/null +++ b/telemetry-interfaces/src/main/java/scala/meta/internal/telemetry/MetalsClientInfo.java @@ -0,0 +1,53 @@ +package scala.meta.internal.telemetry; + +import java.util.Optional; + +public class MetalsClientInfo { + final private Optional name; + final private Optional version; + + public MetalsClientInfo(Optional name, Optional version) { + this.name = name; + this.version = version; + } + + public Optional getName() { + return name; + } + + public Optional getVersion() { + return version; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((version == null) ? 0 : version.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + MetalsClientInfo other = (MetalsClientInfo) obj; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (version == null) { + if (other.version != null) + return false; + } else if (!version.equals(other.version)) + return false; + return true; + } + +} \ No newline at end of file diff --git a/telemetry-interfaces/src/main/java/scala/meta/internal/telemetry/MetalsLspContext.java b/telemetry-interfaces/src/main/java/scala/meta/internal/telemetry/MetalsLspContext.java index ae05d673df5..7b3f6e4ebe2 100644 --- a/telemetry-interfaces/src/main/java/scala/meta/internal/telemetry/MetalsLspContext.java +++ b/telemetry-interfaces/src/main/java/scala/meta/internal/telemetry/MetalsLspContext.java @@ -6,13 +6,16 @@ public class MetalsLspContext implements ReporterContext { final private String metalsVersion; final private MetalsUserConfiguration userConfig; final private MetalsServerConfiguration serverConfig; + final private MetalsClientInfo clientInfo; final private List buildServerConnections; public MetalsLspContext(String metalsVersion, MetalsUserConfiguration userConfig, - MetalsServerConfiguration serverConfig, List buildServerConnections) { + MetalsServerConfiguration serverConfig, MetalsClientInfo clientInfo, + List buildServerConnections) { this.metalsVersion = metalsVersion; this.userConfig = userConfig; this.serverConfig = serverConfig; + this.clientInfo = clientInfo; this.buildServerConnections = buildServerConnections; } @@ -28,6 +31,10 @@ public MetalsServerConfiguration getServerConfig() { return serverConfig; } + public MetalsClientInfo getClientInfo() { + return clientInfo; + } + public List getBuildServerConnections() { return buildServerConnections; } @@ -39,6 +46,7 @@ public int hashCode() { result = prime * result + ((metalsVersion == null) ? 0 : metalsVersion.hashCode()); result = prime * result + ((userConfig == null) ? 0 : userConfig.hashCode()); result = prime * result + ((serverConfig == null) ? 0 : serverConfig.hashCode()); + result = prime * result + ((clientInfo == null) ? 0 : clientInfo.hashCode()); result = prime * result + ((buildServerConnections == null) ? 0 : buildServerConnections.hashCode()); return result; } @@ -67,6 +75,11 @@ public boolean equals(Object obj) { return false; } else if (!serverConfig.equals(other.serverConfig)) return false; + if (clientInfo == null) { + if (other.clientInfo != null) + return false; + } else if (!clientInfo.equals(other.clientInfo)) + return false; if (buildServerConnections == null) { if (other.buildServerConnections != null) return false; diff --git a/tests/unit/src/test/scala/tests/telemetry/SampleReports.scala b/tests/unit/src/test/scala/tests/telemetry/SampleReports.scala index dff782fb7d6..d556799f9ca 100644 --- a/tests/unit/src/test/scala/tests/telemetry/SampleReports.scala +++ b/tests/unit/src/test/scala/tests/telemetry/SampleReports.scala @@ -105,6 +105,10 @@ object SampleReports { nextBoolean(), presentationCompilerConfig, ), + new telemetry.MetalsClientInfo( + optional("name"), + optional("version"), + ), maybeEmptyList( new telemetry.BuildServerConnection( "connection.name",