-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
708bfc4
commit c304f94
Showing
6 changed files
with
209 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/java/software/amazon/smithy/lsp/websocket/SmithyWebSocketEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package software.amazon.smithy.lsp.websocket; | ||
|
||
import java.util.Collection; | ||
import org.eclipse.lsp4j.jsonrpc.Launcher.Builder; | ||
import org.eclipse.lsp4j.services.LanguageClient; | ||
import org.eclipse.lsp4j.services.LanguageClientAware; | ||
import org.eclipse.lsp4j.websocket.jakarta.WebSocketEndpoint; | ||
import software.amazon.smithy.lsp.SmithyLanguageServer; | ||
|
||
public class SmithyWebSocketEndpoint extends WebSocketEndpoint<LanguageClient> { | ||
|
||
@Override | ||
protected void configure(Builder<LanguageClient> builder) { | ||
builder.setLocalService(new SmithyLanguageServer()); | ||
builder.setRemoteInterface(LanguageClient.class); | ||
} | ||
|
||
@Override | ||
protected void connect(Collection<Object> localServices, LanguageClient remoteProxy) { | ||
localServices.stream() | ||
.filter(LanguageClientAware.class::isInstance) | ||
.forEach(languageClientAware -> ((LanguageClientAware) languageClientAware).connect(remoteProxy)); | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/software/amazon/smithy/lsp/websocket/SmithyWebSocketServerConfigProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package software.amazon.smithy.lsp.websocket; | ||
|
||
import jakarta.websocket.Endpoint; | ||
import jakarta.websocket.server.ServerApplicationConfig; | ||
import jakarta.websocket.server.ServerEndpointConfig; | ||
import java.util.Collections; | ||
import java.util.Set; | ||
|
||
public class SmithyWebSocketServerConfigProvider implements ServerApplicationConfig { | ||
|
||
private static final String LSP_PATH = "/"; | ||
|
||
@Override | ||
public Set<ServerEndpointConfig> getEndpointConfigs(Set<Class<? extends Endpoint>> endpointClasses) { | ||
ServerEndpointConfig conf = | ||
ServerEndpointConfig.Builder.create(SmithyWebSocketEndpoint.class, | ||
LSP_PATH).build(); | ||
return Collections.singleton(conf); | ||
} | ||
|
||
@Override | ||
public Set<Class<?>> getAnnotatedEndpointClasses(Set<Class<?>> scanned) { | ||
return scanned; | ||
} | ||
|
||
} |
55 changes: 55 additions & 0 deletions
55
src/main/java/software/amazon/smithy/lsp/websocket/WebSocketRunner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package software.amazon.smithy.lsp.websocket; | ||
|
||
import jakarta.websocket.DeploymentException; | ||
import org.glassfish.tyrus.server.Server; | ||
import software.amazon.smithy.lsp.ext.LspLog; | ||
|
||
public class WebSocketRunner { | ||
private static final String DEFAULT_HOSTNAME = "localhost"; | ||
private static final int DEFAULT_PORT = 3000; | ||
private static final String DEFAULT_CONTEXT_PATH = "/"; | ||
|
||
/** | ||
* Run the websocket server on port of given host and path. | ||
* @param hostname hostname for server | ||
* @param port port server will listen on | ||
* @param contextPath path which routes to the lsp | ||
*/ | ||
public void run(String hostname, int port, String contextPath) { | ||
Server server = new Server( | ||
hostname != null ? hostname : DEFAULT_HOSTNAME, | ||
port > 0 ? port : DEFAULT_PORT, | ||
contextPath != null ? contextPath : DEFAULT_CONTEXT_PATH, | ||
null, | ||
SmithyWebSocketServerConfigProvider.class | ||
); | ||
Runtime.getRuntime().addShutdownHook(new Thread(server::stop, "smithy-lsp-websocket-server-shutdown-hook")); | ||
|
||
try { | ||
server.start(); | ||
Thread.currentThread().join(); | ||
} catch (InterruptedException e) { | ||
LspLog.println("Smithy LSP Websocket server has been interrupted."); | ||
Thread.currentThread().interrupt(); | ||
} catch (DeploymentException e) { | ||
LspLog.println("Could not start Smithy LSP Websocket server."); | ||
} finally { | ||
server.stop(); | ||
} | ||
} | ||
} |