Skip to content

Commit

Permalink
feat: WIP compile on didChangedWatchedFilesNotification
Browse files Browse the repository at this point in the history
  • Loading branch information
tricktron committed Aug 26, 2022
1 parent ede5a72 commit e76096e
Show file tree
Hide file tree
Showing 19 changed files with 102 additions and 35 deletions.
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.3-alpha
version = 4.2.0-alpha
gradleVersion = 7.4.2
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Compiler.enums.Flags
getEnvDefault :: String -> String -> String
getEnvDefault defaultValue envName = maybe defaultValue id $ System.getenv envName

-- TODO: rename to standardOutputDir
rootOutputDir :: String
rootOutputDir = ".frege"

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=1661005255125L, jmajor=11, jminor=-1,
time=1661518381557L, 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=1661005252131L, jmajor=11, jminor=-1,
time=1661518378611L, 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=1661005254194L, jmajor=11, jminor=-1,
time=1661518380555L, 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=1661005252772L, jmajor=11, jminor=-1,
time=1661518379235L, 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=1661005251303L, jmajor=11, jminor=-1,
time=1661518377674L, 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 All @@ -91,12 +91,12 @@
symas={}, symcs={}, symis={}, symts={},
symvs={
@Meta.SymV(
offset=370,
offset=407,
name=@Meta.QName(pack="ch.fhnw.thga.fregelanguageserver.compile.CompileOptions", base="standardCompileOptions"),
stri="u", sig=0, depth=0, rkind=8
),
@Meta.SymV(
offset=320,
offset=357,
name=@Meta.QName(pack="ch.fhnw.thga.fregelanguageserver.compile.CompileOptions", base="rootOutputDir"), stri="s",
sig=1, depth=0, rkind=13
),
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/diagnostic/Diagnostic.fr",
time=1661005253637L, jmajor=11, jminor=-1,
time=1661518379977L, 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=1661005254117L, jmajor=11, jminor=-1,
time=1661518380476L, 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=1661005253684L, jmajor=11, jminor=-1,
time=1661518380008L, 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=1661005254181L, jmajor=11, jminor=-1,
time=1661518380536L, 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
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
package ch.fhnw.thga.fregelanguageserver.lsp;

import static java.util.Collections.singletonList;

import java.net.URI;
import java.nio.file.Path;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;

import org.eclipse.lsp4j.DidChangeWatchedFilesRegistrationOptions;
import org.eclipse.lsp4j.FileSystemWatcher;
import org.eclipse.lsp4j.InitializeParams;
import org.eclipse.lsp4j.InitializeResult;
import org.eclipse.lsp4j.InitializedParams;
import org.eclipse.lsp4j.Registration;
import org.eclipse.lsp4j.RegistrationParams;
import org.eclipse.lsp4j.ServerCapabilities;
import org.eclipse.lsp4j.TextDocumentSyncKind;
import org.eclipse.lsp4j.WatchKind;
import org.eclipse.lsp4j.services.LanguageClient;
import org.eclipse.lsp4j.services.LanguageClientAware;
import org.eclipse.lsp4j.services.LanguageServer;
Expand All @@ -22,13 +31,15 @@ class FregeLanguageServer implements LanguageServer, LanguageClientAware
{
private final FregeTextDocumentService textService;
private final WorkspaceService workspaceService;
private final CompileService compileService;
private LanguageClient client;
private ProjectService projectService;

public FregeLanguageServer()
{
textService = new FregeTextDocumentService(this);
workspaceService = new FregeWorkspaceService();
compileService = new CompileService();
textService = new FregeTextDocumentService(this, compileService);
workspaceService = new FregeWorkspaceService(this, compileService);
}

public LanguageClient getClient()
Expand All @@ -54,6 +65,26 @@ public CompletableFuture<InitializeResult> initialize(InitializeParams params)
return CompletableFuture.supplyAsync(() -> res);
}

@Override
public void initialized(InitializedParams params)
{
FileSystemWatcher fregeWatcher = new FileSystemWatcher
(
"/**/*.fr",
WatchKind.Create + WatchKind.Change + WatchKind.Delete
);
// TODO: use TextDocumentRegistrationOptions when going forward with this change
DidChangeWatchedFilesRegistrationOptions options =
new DidChangeWatchedFilesRegistrationOptions(singletonList(fregeWatcher));
Registration registration = new Registration
(
UUID.randomUUID().toString(),
"workspace/didChangeWatchedFiles",
options
);
client.registerCapability(new RegistrationParams(singletonList(registration)));
}

@Override
public CompletableFuture<Object> shutdown()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@
class FregeTextDocumentService implements TextDocumentService
{
public static final String FREGE_LANGUAGE_ID = "frege";
// TODO rename simpleLangaugeServer -> fregeServer
private final FregeLanguageServer simpleLanguageServer;
private final CompileService compileService;

public FregeTextDocumentService(FregeLanguageServer server)
public FregeTextDocumentService(FregeLanguageServer server, CompileService compileService)
{
simpleLanguageServer = server;
compileService = new CompileService();
this.compileService = compileService;
}

@Override
Expand Down Expand Up @@ -72,17 +73,17 @@ public void didClose(DidCloseTextDocumentParams params)
@Override
public void didSave(DidSaveTextDocumentParams params)
{
URI uri = URI.create(params.getTextDocument().getUri());
compileService.compileAndUpdateGlobals
(
uri,
simpleLanguageServer.getProjectService().getProjectGlobal()
);
DiagnosticService.publishCompilerDiagnostics
(
simpleLanguageServer.getClient(),
compileService.getGlobal(uri),
uri.toString()
);
//URI uri = URI.create(params.getTextDocument().getUri());
//compileService.compileAndUpdateGlobals
//(
// uri,
// simpleLanguageServer.getProjectService().getProjectGlobal()
//);
//DiagnosticService.publishCompilerDiagnostics
//(
// simpleLanguageServer.getClient(),
// compileService.getGlobal(uri),
// uri.toString()
//);
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,50 @@
package ch.fhnw.thga.fregelanguageserver.lsp;

import java.net.URI;

import org.eclipse.lsp4j.DidChangeConfigurationParams;
import org.eclipse.lsp4j.DidChangeWatchedFilesParams;
import org.eclipse.lsp4j.services.WorkspaceService;

class FregeWorkspaceService implements WorkspaceService {
import ch.fhnw.thga.fregelanguageserver.compile.CompileService;
import ch.fhnw.thga.fregelanguageserver.diagnostic.DiagnosticService;

class FregeWorkspaceService implements WorkspaceService
{
private final FregeLanguageServer fregeServer;
private final CompileService compileService;

public FregeWorkspaceService(FregeLanguageServer fregeServer, CompileService compileService)
{
this.fregeServer = fregeServer;
this.compileService = compileService;
}

@Override
public void didChangeConfiguration(DidChangeConfigurationParams params) {
}

@Override
public void didChangeWatchedFiles(DidChangeWatchedFilesParams params) {
public void didChangeWatchedFiles(DidChangeWatchedFilesParams params)
{
// TODO: extract function to functional consumer, give it good name and call it in forEach
params.getChanges().forEach
(
change ->
{
URI uri = URI.create(change.getUri());
compileService.compileAndUpdateGlobals
(
uri,
fregeServer.getProjectService().getProjectGlobal()
);
DiagnosticService.publishCompilerDiagnostics
(
fregeServer.getClient(),
compileService.getGlobal(uri),
uri.toString()
);
}
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
@SuppressWarnings("unused")
@Meta.FregePackage(
source="/Users/tricktron/github/master/frege-lsp-server/src/main/frege/ch/fhnw/thga/fregelanguageserver/types/Generics.fr",
time=1661005251303L, jmajor=11, jminor=-1,
time=1661518377675L, jmajor=11, jminor=-1,
imps={
"frege.Prelude", "frege.prelude.PreludeArrays", "frege.prelude.PreludeBase", "frege.prelude.PreludeDecimal",
"frege.prelude.PreludeIO", "frege.prelude.PreludeList", "frege.prelude.PreludeMonad", "frege.prelude.PreludeText",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
@SuppressWarnings("unused")
@Meta.FregePackage(
source="/Users/tricktron/github/master/frege-lsp-server/src/main/frege/ch/fhnw/thga/fregelanguageserver/types/Position.fr",
time=1661005251305L, jmajor=11, jminor=-1,
time=1661518377677L, jmajor=11, jminor=-1,
imps={
"frege.Prelude", "frege.prelude.PreludeArrays", "frege.prelude.PreludeBase", "frege.prelude.PreludeDecimal",
"frege.prelude.PreludeIO", "frege.prelude.PreludeList", "frege.prelude.PreludeMonad", "frege.prelude.PreludeText",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
@SuppressWarnings("unused")
@Meta.FregePackage(
source="/Users/tricktron/github/master/frege-lsp-server/src/main/frege/ch/fhnw/thga/fregelanguageserver/types/Range.fr",
time=1661005252147L, jmajor=11, jminor=-1,
time=1661518378625L, jmajor=11, jminor=-1,
imps={
"ch.fhnw.thga.fregelanguageserver.types.Position", "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 @@ -36,7 +36,7 @@
@SuppressWarnings("unused")
@Meta.FregePackage(
source="/Users/tricktron/github/master/frege-lsp-server/src/main/frege/ch/fhnw/thga/fregelanguageserver/types/lsp/PositionLSP.fr",
time=1661005252123L, jmajor=11, jminor=-1,
time=1661518378603L, jmajor=11, jminor=-1,
imps={
"ch.fhnw.thga.fregelanguageserver.types.Position", "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 @@ -40,7 +40,7 @@
@SuppressWarnings("unused")
@Meta.FregePackage(
source="/Users/tricktron/github/master/frege-lsp-server/src/main/frege/ch/fhnw/thga/fregelanguageserver/types/lsp/RangeLSP.fr",
time=1661005252478L, jmajor=11, jminor=-1,
time=1661518378882L, jmajor=11, jminor=-1,
imps={
"ch.fhnw.thga.fregelanguageserver.types.lsp.PositionLSP", "frege.Prelude", "frege.prelude.PreludeArrays",
"frege.prelude.PreludeBase", "frege.prelude.PreludeDecimal", "frege.prelude.PreludeIO", "frege.prelude.PreludeList",
Expand Down

0 comments on commit e76096e

Please sign in to comment.