Skip to content

Commit

Permalink
Add ClientInfo to MetalsLspContext
Browse files Browse the repository at this point in the history
  • Loading branch information
WojciechMazur committed Jan 17, 2024
1 parent 2124a9c commit 8f0a4c9
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(_)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package scala.meta.internal.telemetry

import java.util.Optional

import scala.collection.JavaConverters._
import scala.jdk.OptionConverters._

Expand All @@ -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
Expand Down Expand Up @@ -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()),
)

}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package scala.meta.internal.telemetry;

import java.util.Optional;

public class MetalsClientInfo {
final private Optional<String> name;
final private Optional<String> version;

public MetalsClientInfo(Optional<String> name, Optional<String> version) {
this.name = name;
this.version = version;
}

public Optional<String> getName() {
return name;
}

public Optional<String> 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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<BuildServerConnection> buildServerConnections;

public MetalsLspContext(String metalsVersion, MetalsUserConfiguration userConfig,
MetalsServerConfiguration serverConfig, List<BuildServerConnection> buildServerConnections) {
MetalsServerConfiguration serverConfig, MetalsClientInfo clientInfo,
List<BuildServerConnection> buildServerConnections) {
this.metalsVersion = metalsVersion;
this.userConfig = userConfig;
this.serverConfig = serverConfig;
this.clientInfo = clientInfo;
this.buildServerConnections = buildServerConnections;
}

Expand All @@ -28,6 +31,10 @@ public MetalsServerConfiguration getServerConfig() {
return serverConfig;
}

public MetalsClientInfo getClientInfo() {
return clientInfo;
}

public List<BuildServerConnection> getBuildServerConnections() {
return buildServerConnections;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/src/test/scala/tests/telemetry/SampleReports.scala
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ object SampleReports {
nextBoolean(),
presentationCompilerConfig,
),
new telemetry.MetalsClientInfo(
optional("name"),
optional("version"),
),
maybeEmptyList(
new telemetry.BuildServerConnection(
"connection.name",
Expand Down

0 comments on commit 8f0a4c9

Please sign in to comment.