Skip to content

Commit

Permalink
feat: add shouldCorrectlyConfigureExtraClasspath test
Browse files Browse the repository at this point in the history
Expose two environment variables to configure the frege compiler:
- FREGE_LSP_SOURCE_DIR
- FREGE_LSP_EXTRA_CLASSPATH
  • Loading branch information
tricktron committed Jul 22, 2022
1 parent 5d6083c commit 10a1f06
Show file tree
Hide file tree
Showing 18 changed files with 972 additions and 799 deletions.
4 changes: 1 addition & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ plugins {

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

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'
}

application {
Expand All @@ -33,6 +30,7 @@ frege
mainSourceDir = layout.projectDirectory.dir('src/main/frege')
testModules =
[
'ch.fhnw.thga.fregelanguageserver.compiler.CompilerHelper',
'ch.fhnw.thga.fregelanguageserver.diagnostic.Diagnostic',
'ch.fhnw.thga.fregelanguageserver.hover.Hover'
]
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 = 3.1.0-alpha
version = 3.2.0-alpha
gradleVersion = 7.4.2
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Compiler.types.Global (
liftIO, liftStG,getSTT, getST, forsome, stio, changeST
)
import Compiler.common.CompilerOptions (standardGlobal, theClassLoader)
import Control.monad.State (StateT)
import Control.monad.State (StateT, execStateT)
import Compiler.passes.Fix()
import Compiler.passes.Imp()
import Compiler.passes.Enter()
Expand All @@ -28,6 +28,7 @@ import Compiler.common.Desugar
import Compiler.types.Tokens
import Compiler.enums.TokenID
import Compiler.types.Packs
import Test.QuickCheck (Property, once, morallyDubiousIOProperty)

instance Show Message where
show msg = substr (show msg.level) 0 1 ++ " " ++ show msg.pos.first.tokid ++ show msg.pos.end ++ ": " ++ msg.text
Expand All @@ -52,7 +53,8 @@ standardLSPOptions = Options
HINTS,
VERBOSE,
IDEMODE,
IDETOKENS
IDETOKENS,
MAKE
]
}

Expand Down Expand Up @@ -86,7 +88,15 @@ createLSPGlobal opts = do
}

standardLSPGlobal :: IO Global
standardLSPGlobal = createLSPGlobal standardLSPOptions
standardLSPGlobal =
let
fregeSourceDir = maybe "." id $ System.getenv "FREGE_LSP_SOURCE_DIR"
extraClasspath = maybe "" id $ System.getenv "FREGE_LSP_EXTRA_CLASSPATH"
in
createLSPGlobal standardLSPOptions.{
sourcePath = [ fregeSourceDir ],
path = [ extraClasspath ]
}

switchState :: Global -> StG Global
switchState new = do
Expand Down Expand Up @@ -142,9 +152,26 @@ compileFregeFile fregeCode = do
g <- getSTT
return g

compile :: String -> IO Global -> IO Global
compile fregeCode global = do
startGlobal <- global
execStateT (compileFregeFile fregeCode) startGlobal

runpass :: (StIO (String, Int), String) -> StIO ()
runpass (pass, description) = do
state <- getSTT
when (state.errors == 0) do
(itemnm, items) <- pass
return ()

shouldCorrectlyConfigureExtraClasspath :: Property
shouldCorrectlyConfigureExtraClasspath = once $ morallyDubiousIOProperty do
fregeCodeWithDependency =
"module FregeFxDep where\n\n"++
"import fregefx.JavaFxType\n\n" ++
"main = println \"Hello FregeFX\""
fregefxGlobal = createLSPGlobal standardLSPOptions. {
path = [ "./src/main/resources/fregefx-0.8.2-SNAPSHOT.jar" ]
}
actual <- compile fregeCodeWithDependency fregefxGlobal
pure $ actual.errors == 0
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module ch.fhnw.thga.fregelanguageserver.diagnostic.Diagnostic where

import ch.fhnw.thga.fregelanguageserver.compiler.CompilerHelper (compileFregeFile, standardLSPGlobal)
import ch.fhnw.thga.fregelanguageserver.compiler.CompilerHelper (compileFregeFile, standardLSPGlobal, compile)
import ch.fhnw.thga.fregelanguageserver.types.Position (Position)
import ch.fhnw.thga.fregelanguageserver.types.Range (Range, tokenToRange)
import Compiler.types.Global (StG, StIO, Message, Global, Severity(), tokens, getST, liftStG, liftIO)
Expand Down Expand Up @@ -68,8 +68,7 @@ extractDiagnostics = do

compileAndGetDiagnostics :: String -> IO [ Diagnostic ]
compileAndGetDiagnostics fregeCode = do
startGlobal <- standardLSPGlobal
gl <- execStateT (compileFregeFile fregeCode) startGlobal
gl <- compile fregeCode standardLSPGlobal
pure $ evalState (extractDiagnostics) gl

fregeLSPServerShouldMapNoCompilerMessagesToEmptyArray :: Property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import ch.fhnw.thga.fregelanguageserver.types.Position (Position)
import ch.fhnw.thga.fregelanguageserver.types.Range (Range)
import ch.fhnw.thga.fregelanguageserver.diagnostic.Diagnostic (
DiagnosticSeverity, Diagnostic, compileAndGetDiagnostics)
import ch.fhnw.thga.fregelanguageserver.compiler.CompilerHelper(standardLSPGlobal)

import ch.fhnw.thga.fregelanguageserver.lsp4j.PositionLSP4J (PositionLSP)
import ch.fhnw.thga.fregelanguageserver.lsp4j.RangeLSP4J (RangeLSP)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,20 @@

public class FregeLanguageServer implements LanguageServer, LanguageClientAware
{
private TextDocumentService textService;
private WorkspaceService workspaceService;
LanguageClient client;

private final TextDocumentService textService;
private final WorkspaceService workspaceService;
private LanguageClient client;
public FregeLanguageServer()
{
textService = new FregeTextDocumentService(this);
workspaceService = new FregeWorkspaceService();
}

public LanguageClient getClient()
{
return client;
}

@Override
public CompletableFuture<InitializeResult> initialize(InitializeParams params)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void didOpen(DidOpenTextDocumentParams params)
.collect(Collectors.toList());

DiagnosticService.publishCompilerDiagnostics(
simpleLanguageServer.client,
simpleLanguageServer.getClient(),
currentOpenFileContents,
params.getTextDocument().getUri()
);
Expand Down Expand Up @@ -74,7 +74,7 @@ public void didClose(DidCloseTextDocumentParams params)
public void didSave(DidSaveTextDocumentParams params)
{
DiagnosticService.publishCompilerDiagnostics(
simpleLanguageServer.client,
simpleLanguageServer.getClient(),
currentOpenFileContents,
params.getTextDocument().getUri()
);
Expand Down
Loading

0 comments on commit 10a1f06

Please sign in to comment.