Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor for performance improvements #146

Merged
merged 15 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jobs:
runs-on: ${{ matrix.os }}
name: Java ${{ matrix.java }} ${{ matrix.os }}
strategy:
fail-fast: false
milesziemer marked this conversation as resolved.
Show resolved Hide resolved
matrix:
java: [8, 11, 17]
os: [ubuntu-latest, windows-latest, macos-latest]
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.4
0.3.0
24 changes: 17 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -156,21 +156,27 @@ publishing {


dependencies {
implementation "org.eclipse.lsp4j:org.eclipse.lsp4j:0.14.0"
implementation "org.eclipse.lsp4j:org.eclipse.lsp4j:0.20.0"
implementation "software.amazon.smithy:smithy-build:[smithyVersion, 2.0["
implementation "software.amazon.smithy:smithy-cli:[smithyVersion, 2.0["
implementation "software.amazon.smithy:smithy-model:[smithyVersion, 2.0["
implementation 'com.disneystreaming.smithy:smithytranslate-formatter-jvm-java-api:0.3.10'
implementation "software.amazon.smithy:smithy-syntax:[smithyVersion, 2.0["

// Use JUnit test framework
testImplementation "junit:junit:4.13"

testImplementation "org.junit.jupiter:junit-jupiter-api:5.10.0"
testImplementation "org.junit.jupiter:junit-jupiter-params:5.10.0"
testImplementation "org.hamcrest:hamcrest:2.1"

testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.10.0"
}

tasks.withType(Javadoc).all {
options.addStringOption('Xdoclint:none', '-quiet')
}

tasks.withType(Test) {
tasks.withType(Test).configureEach {
useJUnitPlatform()

testLogging {
events TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED, TestLogEvent.STANDARD_OUT, TestLogEvent.STANDARD_ERROR
exceptionFormat TestExceptionFormat.FULL
Expand All @@ -180,7 +186,8 @@ tasks.withType(Test) {
}
}

task createProperties(dependsOn: processResources) {
tasks.register('createProperties') {
dependsOn processResources
doLast {
new File("$buildDir/resources/main/version.properties").withWriter { w ->
Properties p = new Properties()
Expand All @@ -202,7 +209,9 @@ application {
// ==== CheckStyle ====
// https://docs.gradle.org/current/userguide/checkstyle_plugin.html
apply plugin: "checkstyle"
tasks["checkstyleTest"].enabled = false
tasks.named("checkstyleTest") {
enabled = false
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
Expand All @@ -213,6 +222,7 @@ jar {
from (configurations.compileClasspath.collect { entry -> zipTree(entry) }) {
exclude "about.html"
exclude "META-INF/LICENSE"
exclude "META-INF/LICENSE.txt"
exclude "META-INF/NOTICE"
exclude "META-INF/MANIFEST.MF"
exclude "META-INF/*.SF"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

package software.amazon.smithy.lsp;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.logging.Logger;

/**
* Tracks asynchronous lifecycle tasks and client-managed documents.
* Allows cancelling of an ongoing task if a new task needs to be started.
*/
final class DocumentLifecycleManager {
milesziemer marked this conversation as resolved.
Show resolved Hide resolved
private static final Logger LOGGER = Logger.getLogger(DocumentLifecycleManager.class.getName());
private final Map<String, CompletableFuture<Void>> tasks = new HashMap<>();
private final Set<String> managedDocumentUris = new HashSet<>();

Set<String> managedDocuments() {
return managedDocumentUris;
}

boolean isManaged(String uri) {
return managedDocuments().contains(uri);
}

CompletableFuture<Void> getTask(String uri) {
return tasks.get(uri);
}

void cancelTask(String uri) {
if (tasks.containsKey(uri)) {
milesziemer marked this conversation as resolved.
Show resolved Hide resolved
CompletableFuture<Void> task = tasks.get(uri);
if (!task.isDone()) {
task.cancel(true);
tasks.remove(uri);
}
}
}

void putTask(String uri, CompletableFuture<Void> future) {
tasks.put(uri, future);
}

void putOrComposeTask(String uri, CompletableFuture<Void> future) {
if (tasks.containsKey(uri)) {
tasks.computeIfPresent(uri, (k, v) -> v.thenCompose((unused) -> future));
} else {
tasks.put(uri, future);
}
}

void cancelAllTasks() {
for (CompletableFuture<Void> task : tasks.values()) {
task.cancel(true);
}
tasks.clear();
}

void waitForAllTasks() throws ExecutionException, InterruptedException {
for (CompletableFuture<Void> task : tasks.values()) {
if (!task.isDone()) {
task.get();
}
}
}
}
20 changes: 19 additions & 1 deletion src/main/java/software/amazon/smithy/lsp/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

package software.amazon.smithy.lsp;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
Expand All @@ -39,7 +40,11 @@ private Main() {
*/
public static Optional<Exception> launch(InputStream in, OutputStream out) {
SmithyLanguageServer server = new SmithyLanguageServer();
Launcher<LanguageClient> launcher = LSPLauncher.createServerLauncher(server, in, out);
Launcher<LanguageClient> launcher = LSPLauncher.createServerLauncher(
server,
exitOnClose(in),
out);

LanguageClient client = launcher.getRemoteProxy();

server.connect(client);
Expand All @@ -51,6 +56,19 @@ public static Optional<Exception> launch(InputStream in, OutputStream out) {
}
}

private static InputStream exitOnClose(InputStream delegate) {
return new InputStream() {
@Override
public int read() throws IOException {
int result = delegate.read();
if (result < 0) {
milesziemer marked this conversation as resolved.
Show resolved Hide resolved
System.exit(0);
}
return result;
}
};
}

/**
* @param args Arguments passed to launch server. First argument must either be
* a port number for socket connection, or 0 to use STDIN and STDOUT
Expand Down
127 changes: 0 additions & 127 deletions src/main/java/software/amazon/smithy/lsp/ProtocolAdapter.java

This file was deleted.

72 changes: 0 additions & 72 deletions src/main/java/software/amazon/smithy/lsp/SmithyInterface.java

This file was deleted.

Loading
Loading