Skip to content
Snippets Groups Projects
Commit 93b708d3 authored by sebastian's avatar sebastian
Browse files

changed file representation for test purposes

parent 36053d45
No related branches found
No related tags found
No related merge requests found
org.gradle.jvmargs=-Xmx1000m
\ No newline at end of file
...@@ -5,6 +5,7 @@ import b.language.server.proBMangement.ProBInterface ...@@ -5,6 +5,7 @@ import b.language.server.proBMangement.ProBInterface
import b.language.server.proBMangement.prob.CouldNotFindProBHomeException import b.language.server.proBMangement.prob.CouldNotFindProBHomeException
import org.eclipse.lsp4j.* import org.eclipse.lsp4j.*
import org.eclipse.lsp4j.services.TextDocumentService import org.eclipse.lsp4j.services.TextDocumentService
import java.net.URI
import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.ConcurrentHashMap
class BDocumentService(private val server: ServerInterface, class BDocumentService(private val server: ServerInterface,
...@@ -35,18 +36,19 @@ class BDocumentService(private val server: ServerInterface, ...@@ -35,18 +36,19 @@ class BDocumentService(private val server: ServerInterface,
override fun didSave(params: DidSaveTextDocumentParams?) { override fun didSave(params: DidSaveTextDocumentParams?) {
communicator.sendDebugMessage("document ${params!!.textDocument.uri} was saved", MessageType.Info) communicator.sendDebugMessage("document ${params!!.textDocument.uri} was saved", MessageType.Info)
val currentUri = params.textDocument.uri checkDocument(URI(params.textDocument.uri))
checkDocument(currentUri)
} }
/** /**
* checks a document via prob an the set options * checks a document via prob and the set options
* @param currentUri the uri to perform actions on * @param currentUri the uri to perform actions on
*/ */
fun checkDocument(currentUri : String){ fun checkDocument(currentUri : URI){
val clientSettings = server.getDocumentSettings(currentUri)
val clientSettings = server.getDocumentSettings(currentUri.path)
communicator.sendDebugMessage("waiting for document settings", MessageType.Info) communicator.sendDebugMessage("waiting for document settings", MessageType.Info)
clientSettings.thenAccept{ settings -> clientSettings.thenAccept{ settings ->
...@@ -61,10 +63,10 @@ class BDocumentService(private val server: ServerInterface, ...@@ -61,10 +63,10 @@ class BDocumentService(private val server: ServerInterface,
communicator.showMessage("Evaluation done: ${diagnostics.size} problem(s)", MessageType.Log) communicator.showMessage("Evaluation done: ${diagnostics.size} problem(s)", MessageType.Log)
val filesWithProblems = sortedDiagnostic.keys.toList() val filesWithProblems = sortedDiagnostic.keys.toList()
val invalidFiles = calculateToInvalidate(currentUri, filesWithProblems) val invalidFiles = calculateToInvalidate(currentUri.path, filesWithProblems)
invalidFiles.forEach{uri -> communicator.publishDiagnostics(uri, listOf())} invalidFiles.forEach{uri -> communicator.publishDiagnostics(uri, listOf())}
communicator.sendDebugMessage("invalidating old files $invalidFiles", MessageType.Info) communicator.sendDebugMessage("invalidating old files $invalidFiles", MessageType.Info)
issueTracker[currentUri] = filesWithProblems.toSet() issueTracker[currentUri.path] = filesWithProblems.toSet()
}catch (e : CouldNotFindProBHomeException){ }catch (e : CouldNotFindProBHomeException){
communicator.sendDebugMessage(e.message!!, MessageType.Info) communicator.sendDebugMessage(e.message!!, MessageType.Info)
...@@ -106,8 +108,7 @@ class BDocumentService(private val server: ServerInterface, ...@@ -106,8 +108,7 @@ class BDocumentService(private val server: ServerInterface,
*/ */
override fun didChange(params: DidChangeTextDocumentParams?) { override fun didChange(params: DidChangeTextDocumentParams?) {
communicator.sendDebugMessage("document ${params!!.textDocument.uri} was changed", MessageType.Info) communicator.sendDebugMessage("document ${params!!.textDocument.uri} was changed", MessageType.Info)
val currentUri = params.textDocument.uri checkDocument(URI(params.textDocument.uri))
checkDocument(currentUri)
} }
} }
\ No newline at end of file
...@@ -2,6 +2,7 @@ package b.language.server.proBMangement ...@@ -2,6 +2,7 @@ package b.language.server.proBMangement
import b.language.server.dataStorage.Settings import b.language.server.dataStorage.Settings
import org.eclipse.lsp4j.Diagnostic import org.eclipse.lsp4j.Diagnostic
import java.net.URI
interface ProBInterface { interface ProBInterface {
...@@ -11,6 +12,6 @@ interface ProBInterface { ...@@ -11,6 +12,6 @@ interface ProBInterface {
* @param settings the settings for this document * @param settings the settings for this document
* @return a list of all problems found * @return a list of all problems found
*/ */
fun checkDocument(uri : String, settings: Settings) : List<Diagnostic> fun checkDocument(uri : URI, settings: Settings) : List<Diagnostic>
} }
\ No newline at end of file
...@@ -15,6 +15,7 @@ import de.prob.statespace.AnimationSelector ...@@ -15,6 +15,7 @@ import de.prob.statespace.AnimationSelector
import org.eclipse.lsp4j.Diagnostic import org.eclipse.lsp4j.Diagnostic
import org.eclipse.lsp4j.MessageType import org.eclipse.lsp4j.MessageType
import java.io.IOException import java.io.IOException
import java.net.URI
/** /**
* Represents the interface to communicate with prob kernel * Represents the interface to communicate with prob kernel
...@@ -33,14 +34,15 @@ class ProBKernel @Inject constructor(private val injector : Injector, ...@@ -33,14 +34,15 @@ class ProBKernel @Inject constructor(private val injector : Injector,
* @param settings the settings under which the check takes place * @param settings the settings under which the check takes place
* @return a list with the problems found * @return a list with the problems found
*/ */
fun check(path : String, settings : ProBSettings) : List<Diagnostic>{ fun check(path : URI, settings : ProBSettings) : List<Diagnostic>{
communicator.sendDebugMessage("unloading old machine", MessageType.Info) communicator.sendDebugMessage("unloading old machine", MessageType.Info)
unloadMachine() unloadMachine()
val factory = injector.getInstance(FactoryProvider.factoryClassFromExtension(path.substringAfterLast(".")))
val informationListener = InformationListener(path) val factory = injector.getInstance(FactoryProvider.factoryClassFromExtension(path.path.substringAfterLast(".")))
val informationListener = InformationListener(path.path)
animator.addWarningListener(informationListener) animator.addWarningListener(informationListener)
communicator.sendDebugMessage("loading new machine", MessageType.Info) communicator.sendDebugMessage("loading new machine", MessageType.Info)
...@@ -58,7 +60,7 @@ class ProBKernel @Inject constructor(private val injector : Injector, ...@@ -58,7 +60,7 @@ class ProBKernel @Inject constructor(private val injector : Injector,
* @param path the path to the document * @param path the path to the document
* @param factory a factory * @param factory a factory
*/ */
private fun loadMachine(settings: ProBSettings, path : String, factory : ModelFactory<*>): List<Diagnostic> { private fun loadMachine(settings: ProBSettings, path : URI, factory : ModelFactory<*>): List<Diagnostic> {
communicator.sendDebugMessage("creating new state space", MessageType.Info) communicator.sendDebugMessage("creating new state space", MessageType.Info)
val newStateSpace = animator.createStateSpace() val newStateSpace = animator.createStateSpace()
...@@ -68,7 +70,7 @@ class ProBKernel @Inject constructor(private val injector : Injector, ...@@ -68,7 +70,7 @@ class ProBKernel @Inject constructor(private val injector : Injector,
val errors = mutableListOf<ErrorItem>() val errors = mutableListOf<ErrorItem>()
try { try {
factory.extract(path).loadIntoStateSpace(newStateSpace) factory.extract(path.path).loadIntoStateSpace(newStateSpace)
} catch (e: IOException) { } catch (e: IOException) {
communicator.sendDebugMessage("IOException ${e.message}", MessageType.Info) communicator.sendDebugMessage("IOException ${e.message}", MessageType.Info)
} catch (e : ProBError){ } catch (e : ProBError){
...@@ -94,7 +96,7 @@ class ProBKernel @Inject constructor(private val injector : Injector, ...@@ -94,7 +96,7 @@ class ProBKernel @Inject constructor(private val injector : Injector,
communicator.sendDebugMessage("processing errors", MessageType.Info) communicator.sendDebugMessage("processing errors", MessageType.Info)
newStateSpace.kill() newStateSpace.kill()
return convertErrorItems(errors, path) return convertErrorItems(errors, path.path)
} }
......
...@@ -77,10 +77,7 @@ class ProBKernelManager(private val communicator : CommunicatorInterface) : ProB ...@@ -77,10 +77,7 @@ class ProBKernelManager(private val communicator : CommunicatorInterface) : ProB
* *
* @throws CouldNotFindProBHomeException the given path ist not "DEFAULT" and wrong * @throws CouldNotFindProBHomeException the given path ist not "DEFAULT" and wrong
*/ */
override fun checkDocument(uri: String, settings: Settings): List<Diagnostic> { override fun checkDocument(uri: URI, settings: Settings): List<Diagnostic> {
val path = URI(uri).path
//Files.exists(Path.of(URI(uri)))
communicator.sendDebugMessage("try to use ${settings.probHome} as prob version instead of " + System.getProperty("prob.home"), MessageType.Info) communicator.sendDebugMessage("try to use ${settings.probHome} as prob version instead of " + System.getProperty("prob.home"), MessageType.Info)
val result = checkProBVersionSetting(settings.probHome) val result = checkProBVersionSetting(settings.probHome)
...@@ -91,7 +88,7 @@ class ProBKernelManager(private val communicator : CommunicatorInterface) : ProB ...@@ -91,7 +88,7 @@ class ProBKernelManager(private val communicator : CommunicatorInterface) : ProB
communicator.sendDebugMessage("success!", MessageType.Info) communicator.sendDebugMessage("success!", MessageType.Info)
communicator.sendDebugMessage("checking document", MessageType.Info) communicator.sendDebugMessage("checking document", MessageType.Info)
return kernel.check(path, ProBSettings(wdChecks = settings.wdChecks, strictChecks = settings.strictChecks, return kernel.check(uri, ProBSettings(wdChecks = settings.wdChecks, strictChecks = settings.strictChecks,
performanceHints = settings.performanceHints)) performanceHints = settings.performanceHints))
} }
} }
\ No newline at end of file
...@@ -9,6 +9,8 @@ import b.language.server.proBMangement.prob.ProBKernelManager ...@@ -9,6 +9,8 @@ import b.language.server.proBMangement.prob.ProBKernelManager
import org.eclipse.lsp4j.Diagnostic import org.eclipse.lsp4j.Diagnostic
import org.eclipse.lsp4j.MessageType import org.eclipse.lsp4j.MessageType
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import java.io.File
import java.net.URI
import java.util.concurrent.CompletableFuture import java.util.concurrent.CompletableFuture
import kotlin.test.assertEquals import kotlin.test.assertEquals
import kotlin.test.assertTrue import kotlin.test.assertTrue
...@@ -56,7 +58,6 @@ class BDocumentServiceTest { ...@@ -56,7 +58,6 @@ class BDocumentServiceTest {
* @param mode the new state of the debug mode * @param mode the new state of the debug mode
*/ */
override fun setDebugMode(mode: Boolean) { override fun setDebugMode(mode: Boolean) {
//void //void
} }
...@@ -94,7 +95,7 @@ class BDocumentServiceTest { ...@@ -94,7 +95,7 @@ class BDocumentServiceTest {
private var counter = 0 private var counter = 0
override fun checkDocument(uri: String, settings: Settings): List<Diagnostic> { override fun checkDocument(uri: URI, settings: Settings): List<Diagnostic> {
return if(counter == 0){ return if(counter == 0){
counter++ counter++
val realKernel = ProBKernelManager(communicator) val realKernel = ProBKernelManager(communicator)
...@@ -114,7 +115,9 @@ class BDocumentServiceTest { ...@@ -114,7 +115,9 @@ class BDocumentServiceTest {
val documentService = BDocumentService(DummyServer(), communicator, ProBKernelManager(communicator)) val documentService = BDocumentService(DummyServer(), communicator, ProBKernelManager(communicator))
documentService.checkDocument("src/test/resources/WD_M1.mch")
documentService.checkDocument(URI("src/test/resources/WD_M1.mch"))
val targetSet = communicator.pushedDiagnostics.entries.first().value.map { value -> value.source }.toSet() val targetSet = communicator.pushedDiagnostics.entries.first().value.map { value -> value.source }.toSet()
...@@ -133,20 +136,22 @@ class BDocumentServiceTest { ...@@ -133,20 +136,22 @@ class BDocumentServiceTest {
val documentService = BDocumentService(DummyServer(), communicator, ProBKernelManager(communicator)) val documentService = BDocumentService(DummyServer(), communicator, ProBKernelManager(communicator))
documentService.checkDocument("src/test/resources/WD_M2.mch") val documentToCheck = URI("src/test/resources/WD_M2.mch")
communicator.pushedDiagnostics.clear() val expectedDocument = "src/test/resources/WD_M1.mch"
documentService.checkDocument("src/test/resources/WD_M2.mch")
println(communicator.pushedDiagnostics.size) documentService.checkDocument(documentToCheck)
val targetSet = communicator.pushedDiagnostics.entries.first().value.map { value -> value.source }.toSet() communicator.pushedDiagnostics.clear()
documentService.checkDocument(documentToCheck)
val targetSet = communicator.pushedDiagnostics.entries.first().value.map { value -> value.source }.toSet()
assertEquals(2, communicator.pushedDiagnostics.entries.size) assertEquals(2, communicator.pushedDiagnostics.entries.size)
assertEquals(3, communicator.pushedDiagnostics.entries.first().value.size) assertEquals(3, communicator.pushedDiagnostics.entries.first().value.size)
assertTrue(targetSet.first().contains("b-language-server/src/test/resources/WD_M1.mch")) assertEquals(File(expectedDocument).absolutePath, targetSet.first())
} }
...@@ -159,12 +164,19 @@ class BDocumentServiceTest { ...@@ -159,12 +164,19 @@ class BDocumentServiceTest {
val documentService = BDocumentService(DummyServer(), communicator, DummyProBKernelManager(communicator)) val documentService = BDocumentService(DummyServer(), communicator, DummyProBKernelManager(communicator))
documentService.checkDocument("src/test/resources/WD_M2.mch") documentService.checkDocument(URI("src/test/resources/WD_M2.mch"))
documentService.checkDocument("src/test/resources/WD_M2.mch")
println(communicator.pushedDiagnostics) documentService.checkDocument(URI("src/test/resources/WD_M2.mch"))
assertEquals(emptyList(), communicator.pushedDiagnostics.entries.first().value) assertEquals(emptyList(), communicator.pushedDiagnostics.entries.first().value)
} }
/**
* Write Tests:
* Test different options you can turn on and off
* strict, WD, performance
* Included files have errors and errors are mapped properly
* Included files have no errors
* Included files have
*/
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment