Skip to content

Commit

Permalink
Gradle Tooling Api Support (#39)
Browse files Browse the repository at this point in the history
* feat: read frege main source dir and dependencies from build.gradle if available

This integrates the frege-gradle-plugin with the frege-lsp server!

* refactor: use factory method to read project options

* chore: bump version

* fix: include name change from gradle plugin

* fix: include package name change from gradle plugin

* chore: update gradle plugin 4.1.0 -> 4.2.0
  • Loading branch information
tricktron committed Aug 8, 2022
1 parent cf04755 commit 6038d56
Show file tree
Hide file tree
Showing 28 changed files with 3,193 additions and 2,988 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
uses: actions/checkout@v2
with:
repository: tricktron/frege-gradle-plugin
ref: v4.1.0-alpha
ref: v4.2.0-alpha
path: frege-gradle-plugin
- name: Install Frege Gradle Plugin to MavenLocal
run: |
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ bin
.vscode
.idea
frege-native-gen*
.frege-ls
.frege
7 changes: 6 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
plugins {
id 'application'
id 'ch.fhnw.thga.frege' version '4.1.0-alpha'
id 'ch.fhnw.thga.frege' version '4.2.0-alpha'
}

repositories {
mavenCentral()
maven { url 'https://repo.gradle.org/gradle/libs-releases' }
mavenLocal()
}

dependencies {
implementation group: 'org.eclipse.lsp4j', name: 'org.eclipse.lsp4j', version: '0.12.0'
frege group: 'org.eclipse.lsp4j', name: 'org.eclipse.lsp4j', version: '0.12.0'
implementation files(compileFrege.fregeCompilerJar)
implementation "org.gradle:gradle-tooling-api:$gradleVersion"
runtimeOnly 'org.slf4j:slf4j-simple:1.7.10'
implementation group: 'ch.fhnw.thga', name: 'frege-plugin', version: '4.2.0-alpha'
}

application {
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.0.0-alpha
version = 4.1.0-alpha
gradleVersion = 7.4.2
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ module ch.fhnw.thga.fregelanguageserver.compile.CompileExecutorLSP where
import ch.fhnw.thga.fregelanguageserver.types.Generics(ArrayList)
import ch.fhnw.thga.fregelanguageserver.compile.CompileMakeMode(compileMake)
import ch.fhnw.thga.fregelanguageserver.compile.CompileGlobal(standardCompileGlobal, fromOptions)
import ch.fhnw.thga.fregelanguageserver.compile.CompileOptions(standardCompileOptions)
import ch.fhnw.thga.fregelanguageserver.compile.CompileOptions(
standardCompileOptions, getEnvDefault, rootOutputDir
)
import Compiler.types.Global(Global, Options)

compileMakeLSP :: String -> Global -> IOMutable (ArrayList Global)
Expand All @@ -18,4 +20,13 @@ standardCompileOptionsLSP :: Options
standardCompileOptionsLSP = standardCompileOptions

fromOptionsLSP :: Options -> IO Global
fromOptionsLSP = fromOptions
fromOptionsLSP = fromOptions

fromGradle :: String -> String -> Options
fromGradle srcDir extraClasspath = standardCompileOptionsLSP.{
sourcePath = [ getEnvDefault srcDir "FREGE_LS_SOURCE_DIR" ],
path = [ getEnvDefault extraClasspath "FREGE_LS_EXTRA_CLASSPATH" ]
}

rootOutputDirLSP :: String
rootOutputDirLSP = rootOutputDir
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ import Compiler.enums.Flags
getEnvDefault :: String -> String -> String
getEnvDefault defaultValue envName = maybe defaultValue id $ System.getenv envName

rootOutputDir :: String
rootOutputDir = ".frege"

standardCompileOptions :: Options
standardCompileOptions = Options
{
source = "-",
sourcePath = [ getEnvDefault "./src/main/frege" "FREGE_LS_SOURCE_DIR" ],
dir = getEnvDefault "./.frege-ls/classes/frege" "FREGE_LS_TARGET_DIR", -- this folder must already exist, otherwise we get import errors
dir = rootOutputDir ++ "/classes/frege", -- this folder must already exist before loading the classloader, otherwise we get import errors
path = [ getEnvDefault "" "FREGE_LS_EXTRA_CLASSPATH" ],
prefix = "",
encoding = Just "UTF-8",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package ch.fhnw.thga.fregelanguageserver;

import static ch.fhnw.thga.fregelanguageserver.compile.CompileService.ROOT_OUTPUT_DIR;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand All @@ -19,13 +22,15 @@
import org.eclipse.lsp4j.services.WorkspaceService;

import ch.fhnw.thga.fregelanguageserver.compile.CompileService;
import ch.fhnw.thga.fregelanguageserver.project.DefaultProject;
import ch.fhnw.thga.fregelanguageserver.project.GradleProjectOptions;
import frege.compiler.types.Global.TGlobal;
import frege.compiler.types.Global.TOptions;


public class FregeLanguageServer implements LanguageServer, LanguageClientAware
{
private static final String LOGFILE_NAME = "frege-ls.log";
private static final String LOGFILE_NAME = "frege.log";
private final FregeTextDocumentService textService;
private final WorkspaceService workspaceService;
private LanguageClient client;
Expand All @@ -47,9 +52,14 @@ public TGlobal getProjectGlobal()
return projectGlobal;
}

private TOptions createProjectOptions()
private TOptions createProjectOptions(Path projectRootPath)
{
return CompileService.STANDARD_COMPILE_OPTIONS;
if (projectRootPath.resolve("build.gradle").toFile().exists())
{
return new GradleProjectOptions()
.getCompileOptions(projectRootPath.toFile().getAbsolutePath());
}
return new DefaultProject().getCompileOptions();
}

private String couldNotCreateOutputDirMessage(String outputDirPath)
Expand All @@ -61,18 +71,36 @@ private String couldNotCreateOutputDirMessage(String outputDirPath)
);
}

private void createLogFile(Path projectRootPath)
{
try
{
Path rootOutputDir = Files
.createDirectories(projectRootPath.resolve(ROOT_OUTPUT_DIR));
System.setErr(new PrintStream(new FileOutputStream
(
rootOutputDir
.resolve(LOGFILE_NAME).toFile()
)));
} catch (IOException e)
{
e.printStackTrace();
}
}

@Override
public CompletableFuture<InitializeResult> initialize(InitializeParams params)
{
TOptions projectOptions = createProjectOptions();
Path projectRootPath = Path.of
(
URI.create(params.getWorkspaceFolders().get(0).getUri())
);
createLogFile(projectRootPath);
TOptions projectOptions = createProjectOptions(projectRootPath);
Path languageServerOutputDir = Paths.get(projectOptions.mem$dir).normalize();
try
{
Path outputDir = Files.createDirectories(languageServerOutputDir);
System.setErr(new PrintStream(new FileOutputStream
(
outputDir.resolve(LOGFILE_NAME).toFile()
)));
Files.createDirectories(languageServerOutputDir);
} catch (IOException e)
{
e.printStackTrace();
Expand Down
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=1659795939838L, jmajor=11, jminor=-1,
time=1659972660613L, jmajor=11, jminor=-1,
imps={
"ch.fhnw.thga.fregelanguageserver.compile.CompileGlobal",
"ch.fhnw.thga.fregelanguageserver.compile.CompileMakeMode",
Expand All @@ -169,28 +169,38 @@
symas={}, symcs={}, symis={}, symts={},
symvs={
@Meta.SymV(
offset=720,
offset=764,
name=@Meta.QName(
pack="ch.fhnw.thga.fregelanguageserver.compile.CompileExecutorLSP", base="standardCompileOptionsLSP"
),
stri="s", sig=0, depth=0, rkind=13
),
@Meta.SymV(
offset=631,
offset=675,
name=@Meta.QName(
pack="ch.fhnw.thga.fregelanguageserver.compile.CompileExecutorLSP", base="standardCompileGlobalLSP"
),
stri="s", sig=1, depth=0, rkind=13
),
@Meta.SymV(
offset=809,
offset=1184,
name=@Meta.QName(pack="ch.fhnw.thga.fregelanguageserver.compile.CompileExecutorLSP", base="rootOutputDirLSP"),
stri="s", sig=2, depth=0, rkind=13
),
@Meta.SymV(
offset=853,
name=@Meta.QName(pack="ch.fhnw.thga.fregelanguageserver.compile.CompileExecutorLSP", base="fromOptionsLSP"),
stri="s(s)", sig=2, depth=1, rkind=13
stri="s(s)", sig=3, depth=1, rkind=13
),
@Meta.SymV(
offset=922,
name=@Meta.QName(pack="ch.fhnw.thga.fregelanguageserver.compile.CompileExecutorLSP", base="fromGradle"),
stri="s(uu)", sig=4, depth=2, rkind=13
),
@Meta.SymV(
offset=449,
offset=493,
name=@Meta.QName(pack="ch.fhnw.thga.fregelanguageserver.compile.CompileExecutorLSP", base="compileMakeLSP"),
stri="s(uu)", sig=5, depth=2, rkind=13
stri="s(uu)", sig=6, depth=2, rkind=13
)
},
symls={},
Expand All @@ -213,13 +223,14 @@
@Meta.Tau(kind=0, suba=11, subb=4), @Meta.Tau(kind=0, suba=10, subb=12), @Meta.Tau(kind=0, suba=3, subb=13)
},
rhos={
@Meta.Rho(rhofun=false, rhotau=0), @Meta.Rho(rhofun=false, rhotau=5), @Meta.Rho(sigma=0, rhotau=1),
@Meta.Rho(rhofun=false, rhotau=8), @Meta.Rho(rhofun=false, rhotau=4), @Meta.Rho(rhofun=false, rhotau=14),
@Meta.Rho(sigma=4, rhotau=5), @Meta.Rho(sigma=3, rhotau=6)
@Meta.Rho(rhofun=false, rhotau=0), @Meta.Rho(rhofun=false, rhotau=5), @Meta.Rho(rhofun=false, rhotau=8),
@Meta.Rho(sigma=0, rhotau=1), @Meta.Rho(sigma=2, rhotau=0), @Meta.Rho(sigma=2, rhotau=4),
@Meta.Rho(rhofun=false, rhotau=4), @Meta.Rho(rhofun=false, rhotau=14), @Meta.Rho(sigma=5, rhotau=7),
@Meta.Rho(sigma=2, rhotau=8)
},
sigmas={
@Meta.Sigma(rho=0), @Meta.Sigma(rho=1), @Meta.Sigma(rho=2), @Meta.Sigma(rho=3), @Meta.Sigma(rho=4),
@Meta.Sigma(rho=7)
@Meta.Sigma(rho=0), @Meta.Sigma(rho=1), @Meta.Sigma(rho=2), @Meta.Sigma(rho=3), @Meta.Sigma(rho=5),
@Meta.Sigma(rho=6), @Meta.Sigma(rho=9)
},
exprs={@Meta.Expr()}
)
Expand All @@ -233,21 +244,47 @@ final public class CompileExecutorLSP {
.call();
final public static Func.U<RealWorld, Global.TGlobal> standardCompileGlobalLSP = CompileGlobal.standardCompileGlobal
.call();
final public static String/*<Character>*/ rootOutputDirLSP = CompileOptions.rootOutputDir;
final public static Func.U<RealWorld, Global.TGlobal> fromOptionsLSP(final Global.TOptions arg$1) {
return CompileGlobal.fromOptions(arg$1);
}
final public static Global.TOptions fromGradle(
final Lazy<String/*<Character>*/> arg$1, final Lazy<String/*<Character>*/> arg$2
) {
return Global.TOptions.upd$path(
Global.TOptions.upd$sourcePath(
CompileExecutorLSP.standardCompileOptionsLSP,
PreludeBase.TList.DCons.<String/*<Character>*/>mk(
Thunk.<String/*<Character>*/>nested(
(Lazy<Lazy<String/*<Character>*/>>)(() -> CompileOptions.getEnvDefault(
arg$1, "FREGE_LS_SOURCE_DIR"
))
),
PreludeBase.TList.DList.<String/*<Character>*/>mk()
)
),
PreludeBase.TList.DCons.<String/*<Character>*/>mk(
Thunk.<String/*<Character>*/>nested(
(Lazy<Lazy<String/*<Character>*/>>)(() -> CompileOptions.getEnvDefault(
arg$2, "FREGE_LS_EXTRA_CLASSPATH"
))
),
PreludeBase.TList.DList.<String/*<Character>*/>mk()
)
);
}
final public static Func.U<RealWorld, java.util.ArrayList<Global.TGlobal>> compileMakeLSP(
final Lazy<String/*<Character>*/> arg$1, final Lazy<Global.TGlobal> arg$2
) {
return (Func.U<RealWorld, java.util.ArrayList<Global.TGlobal>>)((final Lazy<RealWorld> arg$17733) -> {
final PreludeBase.TList<Global.TGlobal> v2056$17719 = CompileMakeMode.compileMake(
return (Func.U<RealWorld, java.util.ArrayList<Global.TGlobal>>)((final Lazy<RealWorld> arg$17766) -> {
final PreludeBase.TList<Global.TGlobal> v2056$17752 = CompileMakeMode.compileMake(
arg$1, arg$2
).apply(arg$17733).call();
final Func.U<RealWorld, java.util.ArrayList<Global.TGlobal>> v2057$17720 =
Generics.TArrayList.<Global.TGlobal, RealWorld>fromFregeList(v2056$17719);
).apply(arg$17766).call();
final Func.U<RealWorld, java.util.ArrayList<Global.TGlobal>> v2057$17753 =
Generics.TArrayList.<Global.TGlobal, RealWorld>fromFregeList(v2056$17752);
return Thunk.<java.util.ArrayList<Global.TGlobal>>nested(
(Lazy<Lazy<java.util.ArrayList<Global.TGlobal>>>)(() -> v2057$17720
.apply(arg$17733))
(Lazy<Lazy<java.util.ArrayList<Global.TGlobal>>>)(() -> v2057$17753
.apply(arg$17766))
);
});
}
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=1659795936730L, jmajor=11, jminor=-1,
time=1659972657615L, 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 Expand Up @@ -124,41 +124,41 @@ final public class CompileGlobal {


final public static Func.U<RealWorld, Global.TGlobal> fromOptions(final Global.TOptions arg$1) {
return (Func.U<RealWorld, Global.TGlobal>)((final Lazy<RealWorld> arg$13593) -> {
final java.net.URLClassLoader v2056$13557 = CompilerOptions.theClassLoader(
return (Func.U<RealWorld, Global.TGlobal>)((final Lazy<RealWorld> arg$13594) -> {
final java.net.URLClassLoader v2056$13558 = CompilerOptions.theClassLoader(
arg$1
).apply(arg$13593).call();
final Func.U<RealWorld, Global.TGlobal> v2053$13576 = CompilerOptions.standardGlobal
).apply(arg$13594).call();
final Func.U<RealWorld, Global.TGlobal> v2053$13577 = CompilerOptions.standardGlobal
.call();
final Global.TGlobal v2056$13579 = v2053$13576.apply(arg$13593).call();
final Func.U<RealWorld, Global.TGlobal> v2057$13580 = PreludeMonad.IMonad_ST.<
final Global.TGlobal v2056$13580 = v2053$13577.apply(arg$13594).call();
final Func.U<RealWorld, Global.TGlobal> v2057$13581 = PreludeMonad.IMonad_ST.<
RealWorld, Global.TGlobal
>pure(
Thunk.<Global.TGlobal>shared(
(Lazy<Global.TGlobal>)(() -> Global.TGlobal.chg$sub(
Global.TGlobal.upd$options(v2056$13579, arg$1),
(Func.U<Global.TSubSt, Global.TSubSt>)((final Lazy<Global.TSubSt> η$13597) -> Thunk.<
Global.TGlobal.upd$options(v2056$13580, arg$1),
(Func.U<Global.TSubSt, Global.TSubSt>)((final Lazy<Global.TSubSt> η$13598) -> Thunk.<
Global.TSubSt
>nested(
(Lazy<Lazy<Global.TSubSt>>)(() -> PreludeBase.<
Global.TSubSt, Global.TSubSt, java.net.URLClassLoader
>flip(
(Func.U<Global.TSubSt, Func.U<java.net.URLClassLoader, Global.TSubSt>>)((
final Lazy<Global.TSubSt> η$13598
final Lazy<Global.TSubSt> η$13599
) -> (Func.U<java.net.URLClassLoader, Global.TSubSt>)((
final Lazy<java.net.URLClassLoader> η$13599
final Lazy<java.net.URLClassLoader> η$13600
) -> Thunk.<Global.TSubSt>shared(
(Lazy<Global.TSubSt>)(() -> Global.TSubSt.upd$loader(
η$13598.call(), η$13599.call()
η$13599.call(), η$13600.call()
))
))),
Thunk.<java.net.URLClassLoader>lazy(v2056$13557), η$13597
Thunk.<java.net.URLClassLoader>lazy(v2056$13558), η$13598
))
))
))
)
);
return Thunk.<Global.TGlobal>nested((Lazy<Lazy<Global.TGlobal>>)(() -> v2057$13580.apply(arg$13593)));
return Thunk.<Global.TGlobal>nested((Lazy<Lazy<Global.TGlobal>>)(() -> v2057$13581.apply(arg$13594)));
});
}
final public static Lazy<Func.U<RealWorld, Global.TGlobal>> standardCompileGlobal = Thunk.<
Expand Down
Loading

0 comments on commit 6038d56

Please sign in to comment.