Skip to content

Commit

Permalink
Refactor & Fixes (#45)
Browse files Browse the repository at this point in the history
* fix: shutdown threadpool executor on language server shutdown

* refactor: create new lsp package and move classes

* refactor: manage compiler global state in compileService class instead
of in fregeTextDocumentService class

* refactor: extract createLanguageServerOutputDir to its own function

* refactor: extract project setup logic to new projectService class from
FregeLanguageServer class
  • Loading branch information
tricktron authored Aug 20, 2022
1 parent 6038d56 commit ede5a72
Show file tree
Hide file tree
Showing 30 changed files with 321 additions and 276 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ dependencies {
}

application {
mainClass = 'ch.fhnw.thga.fregelanguageserver.App'
mainClass = 'ch.fhnw.thga.fregelanguageserver.lsp.App'
}

java {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version = 4.1.0-alpha
version = 4.1.3-alpha
gradleVersion = 7.4.2

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
@SuppressWarnings("unused")
@Meta.FregePackage(
source="/Users/tricktron/github/master/frege-lsp-server/src/main/frege/ch/fhnw/thga/fregelanguageserver/compile/CompileExecutorLSP.fr",
time=1659972660613L, jmajor=11, jminor=-1,
time=1661005255125L, jmajor=11, jminor=-1,
imps={
"ch.fhnw.thga.fregelanguageserver.compile.CompileGlobal",
"ch.fhnw.thga.fregelanguageserver.compile.CompileMakeMode",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
@SuppressWarnings("unused")
@Meta.FregePackage(
source="/Users/tricktron/github/master/frege-lsp-server/src/main/frege/ch/fhnw/thga/fregelanguageserver/compile/CompileGlobal.fr",
time=1659972657615L, jmajor=11, jminor=-1,
time=1661005252131L, jmajor=11, jminor=-1,
imps={
"ch.fhnw.thga.fregelanguageserver.compile.CompileOptions", "frege.compiler.common.CompilerOptions",
"frege.compiler.types.Global", "frege.Prelude", "frege.prelude.PreludeArrays", "frege.prelude.PreludeBase",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
@SuppressWarnings("unused")
@Meta.FregePackage(
source="/Users/tricktron/github/master/frege-lsp-server/src/main/frege/ch/fhnw/thga/fregelanguageserver/compile/CompileMakeMode.fr",
time=1659972659671L, jmajor=11, jminor=-1,
time=1661005254194L, jmajor=11, jminor=-1,
imps={
"frege.control.Concurrent", "ch.fhnw.thga.fregelanguageserver.compile.CompileGlobal",
"ch.fhnw.thga.fregelanguageserver.compile.CompileNormalMode",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
@SuppressWarnings("unused")
@Meta.FregePackage(
source="/Users/tricktron/github/master/frege-lsp-server/src/main/frege/ch/fhnw/thga/fregelanguageserver/compile/CompileNormalMode.fr",
time=1659972658261L, jmajor=11, jminor=-1,
time=1661005252772L, jmajor=11, jminor=-1,
imps={
"frege.compiler.Classes", "ch.fhnw.thga.fregelanguageserver.compile.CompileGlobal",
"ch.fhnw.thga.fregelanguageserver.compile.CompileOptions", "frege.compiler.common.Desugar",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
@SuppressWarnings("unused")
@Meta.FregePackage(
source="/Users/tricktron/github/master/frege-lsp-server/src/main/frege/ch/fhnw/thga/fregelanguageserver/compile/CompileOptions.fr",
time=1659972656810L, jmajor=11, jminor=-1,
time=1661005251303L, jmajor=11, jminor=-1,
imps={
"frege.compiler.enums.Flags", "frege.compiler.types.Global", "frege.Prelude", "frege.prelude.PreludeArrays",
"frege.prelude.PreludeBase", "frege.prelude.PreludeDecimal", "frege.prelude.PreludeIO", "frege.prelude.PreludeList",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

import static frege.prelude.PreludeBase.TST.performUnsafe;

import java.net.URI;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.List;
import java.util.function.Consumer;

import frege.compiler.types.Global.TGlobal;
import frege.compiler.types.Global.TOptions;
Expand All @@ -14,6 +18,17 @@ public class CompileService
CompileExecutorLSP.standardCompileOptionsLSP.call();

public static final String ROOT_OUTPUT_DIR = CompileExecutorLSP.rootOutputDirLSP;
private HashMap<URI, TGlobal> uriGlobals;

final Consumer<TGlobal> updateUriGlobals = new Consumer<TGlobal>()
{
@Override
public final void accept(TGlobal global)
{
URI uri = Path.of(global.mem$options.mem$source).normalize().toUri();
uriGlobals.put(uri, global);
}
};

public static TGlobal createCompileGlobal(TOptions options)
{
Expand Down Expand Up @@ -45,5 +60,24 @@ public static List<TGlobal> compileWithMakeMode(String filePath, TGlobal global)
).call();
}


public CompileService()
{
uriGlobals = new HashMap<>();
}

public TGlobal getGlobal(URI uri)
{
return uriGlobals.get(uri);
}

public void compileAndUpdateGlobals(URI uri, TGlobal projectGlobal)
{
List<TGlobal> newGlobals = compileWithMakeMode(uri.getPath(), projectGlobal);
newGlobals.forEach(updateUriGlobals);
}

public static void shutdownCompilerExecutorService()
{
performUnsafe(frege.control.Concurrent.shutdown.call());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
@SuppressWarnings("unused")
@Meta.FregePackage(
source="/Users/tricktron/github/master/frege-lsp-server/src/main/frege/ch/fhnw/thga/fregelanguageserver/diagnostic/Diagnostic.fr",
time=1659972659081L, jmajor=11, jminor=-1,
time=1661005253637L, jmajor=11, jminor=-1,
imps={
"ch.fhnw.thga.fregelanguageserver.compile.CompileGlobal",
"ch.fhnw.thga.fregelanguageserver.compile.CompileNormalMode", "frege.compiler.types.Global",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
@SuppressWarnings("unused")
@Meta.FregePackage(
source="/Users/tricktron/github/master/frege-lsp-server/src/main/frege/ch/fhnw/thga/fregelanguageserver/diagnostic/DiagnosticLSP.fr",
time=1659972659590L, jmajor=11, jminor=-1,
time=1661005254117L, jmajor=11, jminor=-1,
imps={
"ch.fhnw.thga.fregelanguageserver.diagnostic.Diagnostic", "ch.fhnw.thga.fregelanguageserver.types.Generics",
"frege.compiler.types.Global", "frege.Prelude", "frege.prelude.PreludeArrays", "frege.prelude.PreludeBase",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
@SuppressWarnings("unused")
@Meta.FregePackage(
source="/Users/tricktron/github/master/frege-lsp-server/src/main/frege/ch/fhnw/thga/fregelanguageserver/hover/Hover.fr",
time=1659972659116L, jmajor=11, jminor=-1,
time=1661005253684L, jmajor=11, jminor=-1,
imps={
"ch.fhnw.thga.fregelanguageserver.compile.CompileGlobal",
"ch.fhnw.thga.fregelanguageserver.compile.CompileNormalMode", "frege.compiler.types.Global", "frege.data.List",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
@SuppressWarnings("unused")
@Meta.FregePackage(
source="/Users/tricktron/github/master/frege-lsp-server/src/main/frege/ch/fhnw/thga/fregelanguageserver/hover/HoverLSP.fr",
time=1659972659643L, jmajor=11, jminor=-1,
time=1661005254181L, jmajor=11, jminor=-1,
imps={
"frege.compiler.types.Global", "ch.fhnw.thga.fregelanguageserver.hover.Hover",
"ch.fhnw.thga.fregelanguageserver.types.lsp.PositionLSP", "frege.Prelude", "frege.prelude.PreludeArrays",
Expand Down
Loading

0 comments on commit ede5a72

Please sign in to comment.