@@ -23,6 +23,7 @@ import scala.language.postfixOps
2323
2424trait StandardReceiver {
2525 val coordinator : ClientCoordinator
26+
2627 implicit def executor : VerificationExecutionContext
2728}
2829
@@ -41,11 +42,11 @@ trait LanguageReceiver extends StandardReceiver with LanguageServer {
4142 // Find References:
4243 capabilities.setReferencesProvider(true )
4344 // Prepare Call Hierarchy: [N/A]
44- // Incoming Calls: [N/A]
45- // Outgoing Calls: [N/A]
45+ // Incoming Calls: [N/A]
46+ // Outgoing Calls: [N/A]
4647 // Prepare Type Hierarchy: [N/A]
47- // Super Types: [N/A]
48- // Sub Types: [N/A]
48+ // Super Types: [N/A]
49+ // Sub Types: [N/A]
4950 // Document Highlight:
5051 capabilities.setDocumentHighlightProvider(true )
5152 // Document Link (disabled Resolve):
@@ -57,21 +58,21 @@ trait LanguageReceiver extends StandardReceiver with LanguageServer {
5758 // Folding Range:
5859 capabilities.setFoldingRangeProvider(true )
5960 // Selection Range: [N/A]
60- // could try extracting from document symbols,
61- // but this req doesn't seem to ever be sent
61+ // could try extracting from document symbols,
62+ // but this req doesn't seem to ever be sent
6263 // Document Symbols:
6364 capabilities.setDocumentSymbolProvider(true )
6465 // Semantic Tokens:
6566 val legend = new SemanticTokensLegend (
6667 Seq (SemanticTokenTypes .Namespace , SemanticTokenTypes .Type , SemanticTokenTypes .Class , SemanticTokenTypes .Enum ,
67- SemanticTokenTypes .Interface , SemanticTokenTypes .Struct , SemanticTokenTypes .TypeParameter , SemanticTokenTypes .Parameter ,
68- SemanticTokenTypes .Variable , SemanticTokenTypes .Property , SemanticTokenTypes .EnumMember , SemanticTokenTypes .Event ,
69- SemanticTokenTypes .Function , SemanticTokenTypes .Method , SemanticTokenTypes .Macro , SemanticTokenTypes .Keyword ,
70- SemanticTokenTypes .Modifier , SemanticTokenTypes .Comment , SemanticTokenTypes .String , SemanticTokenTypes .Number ,
71- SemanticTokenTypes .Regexp , SemanticTokenTypes .Operator , SemanticTokenTypes .Decorator , " constant" ).asJava,
68+ SemanticTokenTypes .Interface , SemanticTokenTypes .Struct , SemanticTokenTypes .TypeParameter , SemanticTokenTypes .Parameter ,
69+ SemanticTokenTypes .Variable , SemanticTokenTypes .Property , SemanticTokenTypes .EnumMember , SemanticTokenTypes .Event ,
70+ SemanticTokenTypes .Function , SemanticTokenTypes .Method , SemanticTokenTypes .Macro , SemanticTokenTypes .Keyword ,
71+ SemanticTokenTypes .Modifier , SemanticTokenTypes .Comment , SemanticTokenTypes .String , SemanticTokenTypes .Number ,
72+ SemanticTokenTypes .Regexp , SemanticTokenTypes .Operator , SemanticTokenTypes .Decorator , " constant" ).asJava,
7273 Seq (SemanticTokenModifiers .Declaration , SemanticTokenModifiers .Definition , SemanticTokenModifiers .Readonly , SemanticTokenModifiers .Static ,
73- SemanticTokenModifiers .Deprecated , SemanticTokenModifiers .Abstract , SemanticTokenModifiers .Async , SemanticTokenModifiers .Modification ,
74- SemanticTokenModifiers .Documentation , SemanticTokenModifiers .DefaultLibrary , " controlFlow" ).asJava
74+ SemanticTokenModifiers .Deprecated , SemanticTokenModifiers .Abstract , SemanticTokenModifiers .Async , SemanticTokenModifiers .Modification ,
75+ SemanticTokenModifiers .Documentation , SemanticTokenModifiers .DefaultLibrary , " controlFlow" ).asJava
7576 )
7677 capabilities.setSemanticTokensProvider(new SemanticTokensWithRegistrationOptions (legend, true ))
7778 // Inline Value: [N/A]
@@ -83,7 +84,7 @@ trait LanguageReceiver extends StandardReceiver with LanguageServer {
8384 // Pull Diagnostics: DISABLED (we use `publishDiagnostics` instead)
8485 // capabilities.setDiagnosticProvider(new DiagnosticRegistrationOptions(true, false))
8586 // Signature Help:
86- // Allow a `,` to try and restart the signature help even after it has ended
87+ // Allow a `,` to try and restart the signature help even after it has ended
8788 capabilities.setSignatureHelpProvider(new SignatureHelpOptions (Seq (" (" , " ," ).asJava, Seq ().asJava))
8889 // Code Action:
8990 capabilities.setCodeActionProvider(true )
@@ -102,6 +103,8 @@ trait LanguageReceiver extends StandardReceiver with LanguageServer {
102103 // automatically cause all references to be renamed. This would probably be too annoying.
103104 capabilities.setLinkedEditingRangeProvider(false )
104105
106+ capabilities.setDocumentFormattingProvider(true )
107+
105108 CompletableFuture .completedFuture(new InitializeResult (capabilities))
106109 }
107110
@@ -191,7 +194,7 @@ trait TextDocumentReceiver extends StandardReceiver with TextDocumentService {
191194 val uri = params.getTextDocument.getUri
192195 val pos = params.getPosition
193196 coordinator.getRoot(uri).getGotoDefinitions(uri, pos).map(defns => {
194- Either .forRight[java.util.List [_ <: Location ], java.util.List [_ <: LocationLink ]](defns.asJava)
197+ Either .forRight[java.util.List [_ <: Location ], java.util.List [_ <: LocationLink ]](defns.asJava)
195198 }).asJava.toCompletableFuture
196199 }
197200
@@ -315,6 +318,18 @@ trait TextDocumentReceiver extends StandardReceiver with TextDocumentService {
315318 CompletableFuture .completedFuture(Nil .asJava)
316319 }
317320
321+ override def formatting (params : DocumentFormattingParams ) = {
322+ coordinator.logger.trace(s " [Req: textDocument/formatting] ${params.toString}" )
323+ val uri = params.getTextDocument.getUri
324+ val result = coordinator.getRoot(uri).reformatFile() match {
325+ case None => Seq ()
326+ case Some (e) =>
327+ val range = new Range (new Position (0 , 0 ), new Position (Int .MaxValue , Int .MaxValue ))
328+ Seq (new TextEdit (range, e))
329+ }
330+ CompletableFuture .completedFuture(result.asJava)
331+ }
332+
318333 // --- DISABLED, see comment in `initialize` ---
319334 override def diagnostic (params : DocumentDiagnosticParams ) = {
320335 coordinator.logger.trace(s " [Req: textDocument/diagnostic] ${params.toString()}" )
@@ -351,9 +366,10 @@ trait WorkspaceReceiver extends StandardReceiver with WorkspaceService {
351366}
352367
353368class CustomReceiver (config : ViperConfig , server : ViperServerService , serverUrl : String )(implicit _executor : VerificationExecutionContext )
354- extends LanguageClientAware with LanguageReceiver with WorkspaceReceiver with TextDocumentReceiver {
369+ extends LanguageClientAware with LanguageReceiver with WorkspaceReceiver with TextDocumentReceiver {
355370
356371 override val coordinator = new ClientCoordinator (server)
372+
357373 override def executor : VerificationExecutionContext = _executor
358374
359375 override def getTextDocumentService (): TextDocumentService = this
@@ -405,16 +421,22 @@ class CustomReceiver(config: ViperConfig, server: ViperServerService, serverUrl:
405421 if (verificationStarted) {
406422 coordinator.logger.info(" Verification Started" )
407423 } else {
408- coordinator.client.map{_.notifyVerificationNotStarted(VerificationNotStartedParams (data.uri))}
424+ coordinator.client.map {
425+ _.notifyVerificationNotStarted(VerificationNotStartedParams (data.uri))
426+ }
409427 }
410428 })
411429 }).recover(e => {
412430 coordinator.logger.debug(s " Error handling verify request: $e" )
413- coordinator.client.map{_.notifyVerificationNotStarted(VerificationNotStartedParams (data.uri))}
431+ coordinator.client.map {
432+ _.notifyVerificationNotStarted(VerificationNotStartedParams (data.uri))
433+ }
414434 })
415435 } else {
416436 coordinator.logger.info(" The verification cannot be started." )
417- coordinator.client.map{_.notifyVerificationNotStarted(VerificationNotStartedParams (data.uri))}
437+ coordinator.client.map {
438+ _.notifyVerificationNotStarted(VerificationNotStartedParams (data.uri))
439+ }
418440 }
419441 }
420442
0 commit comments