Skip to content

Commit c659916

Browse files
committed
Fixes
1 parent f5e2501 commit c659916

8 files changed

Lines changed: 40 additions & 38 deletions

File tree

src/main/scala/viper/server/frontends/lsp/ClientCoordinator.scala

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@ class ClientCoordinator(val server: ViperServerService)(implicit executor: Verif
2525
private var _client: Option[IdeLanguageClient] = None
2626
private val _files: ConcurrentMap[String, FileManager] = new ConcurrentHashMap() // each file is managed individually.
2727
private var _vprFileEndings: Option[Array[String]] = None
28-
private var _exited: Boolean = false
2928

30-
def client: IdeLanguageClient = {
31-
_client.getOrElse({assert(false, "getting client failed - client has not been set yet"); ???})
29+
def client: Option[IdeLanguageClient] = {
30+
_client
3231
}
3332

3433
def setClient(c: IdeLanguageClient): Unit = {
@@ -38,15 +37,10 @@ class ClientCoordinator(val server: ViperServerService)(implicit executor: Verif
3837

3938
/** called when client disconnects; the server should however remain running */
4039
def exit(): Unit = {
41-
_exited = true
4240
_client = None
4341
_files.clear()
4442
}
4543

46-
def isAlive: Boolean = {
47-
!_exited
48-
}
49-
5044
def closeFile(uri: String): Unit = {
5145
val toRemove = Option(_files.get(uri)).map(fm => {
5246
fm.isOpen = false
@@ -167,17 +161,17 @@ class ClientCoordinator(val server: ViperServerService)(implicit executor: Verif
167161
// update file manager's state:
168162
task.foreach(vm => vm.state = VerificationState(params.newState))
169163
try {
170-
client.notifyStateChanged(params)
164+
client.get.notifyStateChanged(params)
171165
} catch {
172166
case e: Throwable => logger.debug(s"Error while changing state: $e")
173167
}
174168
}
175169

176170
def refreshEndings(): Future[Array[String]] = {
177-
client.requestVprFileEndings().asScala.map(response => {
171+
client.map{_.requestVprFileEndings().asScala.map(response => {
178172
_vprFileEndings = Some(response.fileEndings)
179173
response.fileEndings
180-
})
174+
})}.getOrElse(Future(Array()))
181175
}
182176

183177
def isViperSourceFile(uri: String): Future[Boolean] = {
@@ -191,8 +185,7 @@ class ClientCoordinator(val server: ViperServerService)(implicit executor: Verif
191185
}
192186

193187
def hint(message: String, showSettingsButton: Boolean = false, showViperToolsUpdateButton: Boolean = false): Unit = {
194-
if (!isAlive) return
195-
client.notifyHint(HintMessage(message, showSettingsButton, showViperToolsUpdateButton ))
188+
client.map{_.notifyHint(HintMessage(message, showSettingsButton, showViperToolsUpdateButton ))}
196189
}
197190

198191
private def getFileManager(uri: String, content: Option[String] = None): FileManager = {

src/main/scala/viper/server/frontends/lsp/ClientLogger.scala

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,16 @@ class ClientAppender(coordinator: ClientCoordinator) extends UnsynchronizedAppen
4141
def getParams(logLevel: LogLevel): LogParams =
4242
LogParams(event.getMessage, logLevel.id)
4343

44-
if (!coordinator.isAlive) return
44+
if (coordinator.client.isEmpty) return
45+
val client = coordinator.client.get
4546
event.getLevel match {
4647
case Level.OFF =>
47-
case Level.ERROR => coordinator.client.notifyLog(getParams(LogLevel.Info))
48-
case Level.WARN => coordinator.client.notifyLog(getParams(LogLevel.Info))
49-
case Level.INFO => coordinator.client.notifyLog(getParams(LogLevel.Info))
50-
case Level.DEBUG => coordinator.client.notifyLog(getParams(LogLevel.Debug))
51-
case Level.TRACE => coordinator.client.notifyLog(getParams(LogLevel.LowLevelDebug))
52-
case Level.ALL => coordinator.client.notifyLog(getParams(LogLevel.LowLevelDebug))
48+
case Level.ERROR => client.notifyLog(getParams(LogLevel.Info))
49+
case Level.WARN => client.notifyLog(getParams(LogLevel.Info))
50+
case Level.INFO => client.notifyLog(getParams(LogLevel.Info))
51+
case Level.DEBUG => client.notifyLog(getParams(LogLevel.Debug))
52+
case Level.TRACE => client.notifyLog(getParams(LogLevel.LowLevelDebug))
53+
case Level.ALL => client.notifyLog(getParams(LogLevel.LowLevelDebug))
5354
}
5455
}
5556
}

src/main/scala/viper/server/frontends/lsp/Receiver.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,16 +405,16 @@ class CustomReceiver(config: ViperConfig, server: ViperServerService, serverUrl:
405405
if (verificationStarted) {
406406
coordinator.logger.info("Verification Started")
407407
} else {
408-
coordinator.client.notifyVerificationNotStarted(VerificationNotStartedParams(data.uri))
408+
coordinator.client.map{_.notifyVerificationNotStarted(VerificationNotStartedParams(data.uri))}
409409
}
410410
})
411411
}).recover(e => {
412412
coordinator.logger.debug(s"Error handling verify request: $e")
413-
coordinator.client.notifyVerificationNotStarted(VerificationNotStartedParams(data.uri))
413+
coordinator.client.map{_.notifyVerificationNotStarted(VerificationNotStartedParams(data.uri))}
414414
})
415415
} else {
416416
coordinator.logger.info("The verification cannot be started.")
417-
coordinator.client.notifyVerificationNotStarted(VerificationNotStartedParams(data.uri))
417+
coordinator.client.map{_.notifyVerificationNotStarted(VerificationNotStartedParams(data.uri))}
418418
}
419419
}
420420

src/main/scala/viper/server/frontends/lsp/ViperServerService.scala

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,19 @@ class ViperServerService(config: ViperConfig)(override implicit val executor: Ve
115115
}
116116

117117
private def stopOnlyVerification(handle: VerHandle, combinedLogger: Logger): Future[Boolean] = {
118-
implicit val askTimeout: Timeout = Timeout(config.actorCommunicationTimeout() milliseconds)
119-
val interrupt: Future[String] = (handle.job_actor ? StopVerification).mapTo[String]
120-
handle.job_actor ! PoisonPill // the actor played its part.
121-
interrupt.map(msg => {
122-
combinedLogger.info(msg)
123-
true
124-
})
118+
handle match {
119+
// If AST construction failed, a verification handle will be returned where the actor field is null.
120+
case VerHandle(null, _, _, _) => Future.successful(false)
121+
case _ => {
122+
implicit val askTimeout: Timeout = Timeout(config.actorCommunicationTimeout() milliseconds)
123+
val interrupt: Future[String] = (handle.job_actor ? StopVerification).mapTo[String]
124+
handle.job_actor ! PoisonPill // the actor played its part.
125+
interrupt.map(msg => {
126+
combinedLogger.info(msg)
127+
true
128+
})
129+
}
130+
}
125131
}
126132

127133
def stopAstConstruction(jid: AstJobId, localLogger: Option[Logger] = None): Future[Boolean] = {

src/main/scala/viper/server/frontends/lsp/file/Manager.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,10 @@ trait StandardManager extends Manager {
9090
c.onUpdate()
9191
}
9292

93+
9394
// CodeLens
9495
type CodeLensContainer = utility.StageArrayContainer.ArrayContainer[lsp.CodeLens, lsp4j.CodeLens]
95-
val codeLensContainer: CodeLensContainer = utility.LspContainer(utility.CodeLensTranslator, coordinator.client.refreshCodeLenses)
96+
val codeLensContainer: CodeLensContainer = utility.LspContainer(utility.CodeLensTranslator, if (coordinator.client.isDefined) coordinator.client.get.refreshCodeLenses else () => {})
9697
containers.addOne(codeLensContainer)
9798
def getCodeLens() = codeLensContainer.get(())
9899
def addCodeLens(first: Boolean)(vs: Seq[lsp.CodeLens]): Unit = add(codeLensContainer, first, vs)
@@ -102,7 +103,7 @@ trait StandardManager extends Manager {
102103
val diagnosticContainer: DiagnosticContainer = utility.LspContainer(utility.DiagnosticTranslator, publishDiags)
103104
private def publishDiags(): Unit = {
104105
val diagnosticParams = new PublishDiagnosticsParams(file.file_uri, getDiagnostic().asJava)
105-
coordinator.client.publishDiagnostics(diagnosticParams)
106+
coordinator.client.map{_.publishDiagnostics(diagnosticParams)}
106107
}
107108
// containers.addOne(diagnosticContainer)
108109
def getDiagnostic() = diagnosticContainer.get(())
@@ -145,14 +146,14 @@ trait StandardManager extends Manager {
145146

146147
// InlayHint
147148
type InlayHintContainer = utility.StageArrayContainer.ArrayContainer[lsp.InlayHint, lsp4j.InlayHint]
148-
val inlayHintContainer: InlayHintContainer = utility.LspContainer(utility.InlayHintTranslator, coordinator.client.refreshInlayHints)
149+
val inlayHintContainer: InlayHintContainer = utility.LspContainer(utility.InlayHintTranslator, if(coordinator.client.isDefined) coordinator.client.get.refreshInlayHints else () => {})
149150
containers.addOne(inlayHintContainer)
150151
def getInlayHint() = inlayHintContainer.get(())
151152
def addInlayHint(first: Boolean)(vs: Seq[lsp.InlayHint]): Unit = add(inlayHintContainer, first, vs)
152153

153154
// SemanticHighlight
154155
type SemanticHighlightContainer = utility.StageArrayContainer.ArrayContainer[lsp.SemanticHighlight, Lsp4jSemanticHighlight]
155-
val semanticHighlightContainer: SemanticHighlightContainer = utility.LspContainer(utility.SemanticHighlightTranslator, coordinator.client.refreshSemanticTokens)
156+
val semanticHighlightContainer: SemanticHighlightContainer = utility.LspContainer(utility.SemanticHighlightTranslator, if(coordinator.client.isDefined) coordinator.client.get.refreshSemanticTokens else () => {})
156157
containers.addOne(semanticHighlightContainer)
157158
def getSemanticHighlight() = semanticHighlightContainer.get(())
158159
def addSemanticHighlight(first: Boolean)(vs: Seq[lsp.SemanticHighlight]): Unit = add(semanticHighlightContainer, first, vs)

src/main/scala/viper/server/frontends/lsp/file/ProjectManager.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ trait ProjectManager extends FullManager with ProjectAware {
172172
this.project = Left(newProject.map(uri => uri -> getLeafManager(uri)).toMap)
173173

174174
val setupProject = SetupProjectParams(file.file_uri, newProject.toArray)
175-
coordinator.client.requestSetupProject(setupProject)
175+
coordinator.client.map{_.requestSetupProject(setupProject)}
176176
}
177177

178178
def handleChangeInLeaf(leaf: String, range: Range, text: String): Unit = {

src/main/scala/viper/server/frontends/lsp/file/RelayActor.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ trait MessageHandler extends ProjectManager with VerificationManager with Quanti
7979
timeMs = 0
8080
} catch {
8181
case e: Throwable =>
82-
coordinator.client.notifyVerificationNotStarted(lsp.VerificationNotStartedParams(file_uri))
82+
coordinator.client.map{_.notifyVerificationNotStarted(lsp.VerificationNotStartedParams(file_uri))}
8383
coordinator.logger.debug(s"Error handling verification completion: $e")
8484
}
8585
}
@@ -207,7 +207,7 @@ class RelayActor(task: MessageHandler, backendClassName: Option[String]) extends
207207
task.handleQuantifierInstantiations(quantifier, instantiations, magGen, maxCost)
208208
case m: Message =>
209209
coordinator.logger.debug(s"[receive@${task.filename}/${backendClassName.isDefined}] Message")
210-
coordinator.client.notifyUnhandledViperServerMessage(lsp.UnhandledViperServerMessageTypeParams(m.name, m.toString, lsp.LogLevel.Info.id))
210+
coordinator.client.map{_.notifyUnhandledViperServerMessage(lsp.UnhandledViperServerMessageTypeParams(m.name, m.toString, lsp.LogLevel.Info.id))}
211211
case Status.Success =>
212212
coordinator.logger.debug(s"[receive@${task.filename}/${backendClassName.isDefined}] Status.Success")
213213
// Success is sent when the stream is completed

src/main/scala/viper/server/vsi/VerificationServer.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ trait VerificationServer extends Post {
168168
protected def discardAstOnCompletion(jid: AstJobId, jobActor: ActorRef) = {
169169
ast_jobs.lookupJob(jid).map(_.map(_.queue.watchCompletion().onComplete(_ => {
170170
ast_jobs.discardJob(jid)
171-
jobActor ! PoisonPill
171+
// Killing the jobActor here is too early, messages still arrive.
172+
//jobActor ! PoisonPill
172173
})))
173174
}
174175

0 commit comments

Comments
 (0)