Skip to content

Commit

Permalink
Merge pull request #14 from aws/breedloj/lspClientInfo
Browse files Browse the repository at this point in the history
Pass client information to LSPs for user agent
  • Loading branch information
breedloj authored Sep 17, 2024
2 parents c2c1d69 + 28144cd commit 8e6b762
Show file tree
Hide file tree
Showing 27 changed files with 389 additions and 337 deletions.
4 changes: 2 additions & 2 deletions feature/feature.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<feature
id="aws-plugin-q-feature"
id="amazon-q-eclipse-feature"
label="AWS Q Plugin"
version="1.0.0.qualifier">

Expand All @@ -13,7 +13,7 @@
</license>

<plugin
id="aws-plugin-q"
id="amazon-q-eclipse"

download-size="0"
install-size="0"
Expand Down
6 changes: 3 additions & 3 deletions feature/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

<parent>
<groupId>software.aws.toolkits.eclipse</groupId>
<artifactId>aws-plugin-q-group</artifactId>
<artifactId>amazon-q-eclipse-group</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>

<groupId>software.aws.toolkits.eclipse</groupId>
<artifactId>aws-plugin-q-feature</artifactId>
<artifactId>amazon-q-eclipse-feature</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-feature</packaging>

</project>
</project>
7 changes: 7 additions & 0 deletions plugin/.checkstyle
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>

<fileset-config file-format-version="1.2.0" simple-config="true" sync-formatter="false">
<fileset name="all" enabled="true" check-config-name="Copy of Sun Checks" local="false">
<file-match-pattern match-pattern="." include-pattern="true"/>
</fileset>
</fileset-config>
8 changes: 3 additions & 5 deletions plugin/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: aws-plugin-q
Bundle-Name: amazon-q-eclipse
Bundle-RequiredExecutionEnvironment: JavaSE-17
Bundle-SymbolicName: aws-plugin-q;singleton:=true
Bundle-SymbolicName: amazon-q-eclipse;singleton:=true
Bundle-Version: 1.0.0.qualifier
Automatic-Module-Name: aws.plugin.q
Automatic-Module-Name: amazon.q.eclipse
Bundle-ActivationPolicy: lazy
Require-Bundle: org.eclipse.core.runtime;bundle-version="3.31.0",
org.eclipse.ui;bundle-version="3.205.100",
Expand Down Expand Up @@ -42,9 +42,7 @@ Bundle-Classpath: .,
target/dependency/j2objc-annotations-3.0.0.jar,
target/dependency/jackson-annotations-2.17.1.jar,
target/dependency/jackson-core-2.17.1.jar,
target/dependency/jackson-core-2.17.2.jar,
target/dependency/jackson-databind-2.17.1.jar,
target/dependency/jackson-databind-2.17.2.jar,
target/dependency/jakarta.annotation-api-2.1.1.jar,
target/dependency/jakarta.inject-api-2.0.1.jar,
target/dependency/jna-5.14.0.jar,
Expand Down
4 changes: 2 additions & 2 deletions plugin/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@
<extension
point="org.eclipse.lsp4e.languageServer">
<server
class="software.aws.toolkits.eclipse.amazonq.lsp.LspConnectionProvider"
class="software.aws.toolkits.eclipse.amazonq.lsp.connection.QLspConnectionProvider"
clientImpl="software.aws.toolkits.eclipse.amazonq.lsp.AmazonQLspClientImpl"
id="software.aws.toolkits.eclipse.amazonq.qlanguageserver"
label="Amazon Q Language Server"
launcherBuilder="software.aws.toolkits.eclipse.amazonq.lsp.AmazonQLspServerBuilder"
singleton="true">
</server>
<server
class="software.aws.toolkits.eclipse.amazonq.lsp.AuthLspConnectionProvider"
class="software.aws.toolkits.eclipse.amazonq.lsp.connection.AuthLspConnectionProvider"
clientImpl="software.aws.toolkits.eclipse.amazonq.lsp.AuthLspClientImpl"
id="software.aws.toolkits.eclipse.amazonq.authServer"
label="Auth LSP Server"
Expand Down
4 changes: 2 additions & 2 deletions plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>software.aws.toolkits.eclipse</groupId>
<artifactId>aws-plugin-q-group</artifactId>
<artifactId>amazon-q-eclipse-group</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>

<groupId>software.aws.toolkits.eclipse</groupId>
<artifactId>aws-plugin-q</artifactId>
<artifactId>amazon-q-eclipse</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@

package software.aws.toolkits.eclipse.amazonq.lsp;

import org.eclipse.lsp4j.ClientInfo;
import org.eclipse.lsp4j.InitializeParams;
import org.eclipse.lsp4j.jsonrpc.Launcher;
import org.eclipse.lsp4j.jsonrpc.Launcher.Builder;
import org.eclipse.lsp4j.jsonrpc.MessageConsumer;
import org.eclipse.lsp4j.jsonrpc.messages.Message;
import org.eclipse.lsp4j.jsonrpc.messages.RequestMessage;

import software.aws.toolkits.eclipse.amazonq.providers.LspProvider;
import software.aws.toolkits.eclipse.amazonq.util.ClientMetadata;

public class AmazonQLspServerBuilder extends Builder<AmazonQLspServer> {

Expand All @@ -18,4 +24,15 @@ public final Launcher<AmazonQLspServer> create() {
return launcher;
}

@Override
protected final MessageConsumer wrapMessageConsumer(final MessageConsumer consumer) {
return super.wrapMessageConsumer((Message message) -> {
if (message instanceof RequestMessage && ((RequestMessage) message).getMethod().equals("initialize")) {
InitializeParams initParams = (InitializeParams) ((RequestMessage) message).getParams();
initParams.setClientInfo(new ClientInfo(ClientMetadata.getPluginName(), ClientMetadata.getPluginVersion()));
}
consumer.consume(message);
});
}

}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package software.aws.toolkits.eclipse.amazonq.lsp.connection;

import java.io.File;
import java.io.IOException;
import java.util.Map;

import org.eclipse.lsp4e.server.ProcessStreamConnectionProvider;
import org.eclipse.lsp4e.server.StreamConnectionProvider;

public abstract class AbstractLspConnectionProvider extends ProcessStreamConnectionProvider implements StreamConnectionProvider {

protected AbstractLspConnectionProvider() throws IOException {
setWorkingDirectory(System.getProperty("user.dir"));
}

@Override
protected final ProcessBuilder createProcessBuilder() {
final var builder = new ProcessBuilder(getCommands());
if (getWorkingDirectory() != null) {
builder.directory(new File(getWorkingDirectory()));
}
builder.redirectError(ProcessBuilder.Redirect.INHERIT);
addEnvironmentVariables(builder.environment());
return builder;
}

protected abstract void addEnvironmentVariables(Map<String, String> env);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package software.aws.toolkits.eclipse.amazonq.lsp.connection;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import software.aws.toolkits.eclipse.amazonq.providers.LspManagerProvider;
import software.aws.toolkits.eclipse.amazonq.util.PluginUtils;

public class AuthLspConnectionProvider extends AbstractLspConnectionProvider {

public AuthLspConnectionProvider() throws IOException {
super();
var authJs = PluginUtils.getResource("auth/packages/server/dist/index.js");
var lspManager = LspManagerProvider.getInstance();

List<String> commands = new ArrayList<>();
commands.add(lspManager.getLspInstallation().nodeExecutable().toString());
commands.add(authJs.getPath());
commands.add("--nolazy");
commands.add("--inspect=5599");
commands.add("--stdio");
setCommands(commands);
}

@Override
protected void addEnvironmentVariables(final Map<String, String> env) { }

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package software.aws.toolkits.eclipse.amazonq.lsp.connection;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import software.aws.toolkits.eclipse.amazonq.lsp.manager.LspManager;
import software.aws.toolkits.eclipse.amazonq.providers.LspManagerProvider;

public class QLspConnectionProvider extends AbstractLspConnectionProvider {

public QLspConnectionProvider() throws IOException {
super();
LspManager lspManager = LspManagerProvider.getInstance();
List<String> commands = new ArrayList<>();
commands.add(lspManager.getLspInstallation().nodeExecutable().toString());
commands.add(lspManager.getLspInstallation().lspJs().toString());
commands.add("--nolazy");
commands.add("--inspect=5599");
commands.add("--stdio");
setCommands(commands);
}

@Override
protected final void addEnvironmentVariables(final Map<String, String> env) {
env.put("ENABLE_INLINE_COMPLETION", "true");
env.put("ENABLE_TOKEN_PROVIDER", "true");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package software.aws.toolkits.eclipse.amazonq.providers;

import software.aws.toolkits.eclipse.amazonq.lsp.manager.DefaultLspManager;
import software.aws.toolkits.eclipse.amazonq.lsp.manager.LspConstants;
import software.aws.toolkits.eclipse.amazonq.lsp.manager.LspManager;
import software.aws.toolkits.eclipse.amazonq.lsp.manager.fetcher.RemoteManifestLspFetcher;

public final class LspManagerProvider {

private LspManagerProvider() {
// prevent instantiation
}

private static LspManager instance;

public static LspManager getInstance() {
if (instance == null) {
synchronized (LspManagerProvider.class) {
if (instance == null) {
instance = createLspManager();
}
}
}
return instance;
}

private static LspManager createLspManager() {
return DefaultLspManager.builder()
.withLspExecutablePrefix(LspConstants.CW_LSP_FILENAME)
.withFetcher(RemoteManifestLspFetcher.builder()
.withManifestUrl(LspConstants.CW_MANIFEST_URL)
.build())
.build();
}

}
Loading

0 comments on commit 8e6b762

Please sign in to comment.