Skip to content

Commit

Permalink
(wip): handle language clients that don't support showMessageRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
chrissimon-au committed Nov 19, 2023
1 parent 9c7e8a5 commit 81a206a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
31 changes: 29 additions & 2 deletions src/language-server/Contextive.LanguageServer.Tests/SurveyTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ let tests =
test <@ msg.IsNone @>
}

testAsync "Server creates latch file if user doesn't ignore the prompt" {
ftestAsync "Server creates latch file if user doesn't ignore the prompt" {

let messageAwaiter = ConditionAwaiter.create ()

Expand Down Expand Up @@ -138,4 +138,31 @@ let tests =
test <@ receivedDoc.External.Value = true @>
test <@ receivedDoc.Uri.ToString().Contains("forms.gle") @>

} ]
}

ftestAsync "Server does nothing if client doesn't support showMessageRequest" {

File.Delete(latchFile)

let pathValue = Guid.NewGuid().ToString()

let methodNotFoundHandler =
fun (_: ShowMessageRequestParams) ->
raise (
new OmniSharp.Extensions.JsonRpc.Server.MethodNotSupportedException(
0,
"window/showMessageRequest"
)
)

let config =
[ showMessageRequestHandlerBuilder <| methodNotFoundHandler
Workspace.optionsBuilder ""
ConfigurationSection.contextivePathBuilder pathValue ]

let! _ = TestClient(config) |> initAndWaitForReply

test <@ not <| File.Exists(latchFile) @>
}

]
3 changes: 0 additions & 3 deletions src/language-server/Contextive.LanguageServer/Server.fs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ let private onStartupConfigureServer definitions =

let definitionsFileLoader = pathGetter |> FileLoader.loader

Serilog.Log.Logger.Information
$"ShowDocumentIsSupported: {s.ClientSettings.Capabilities.Window.ShowDocument.IsSupported}"

let showDocument =
match s.ClientSettings.Capabilities.Window.ShowDocument.IsSupported with
| true -> s.Window.ShowDocument
Expand Down
6 changes: 5 additions & 1 deletion src/language-server/Contextive.LanguageServer/Survey.fs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ let private showSurveyPrompt (s: ILanguageServer) (cancellationToken: Cancellati
)
)

//try

let! response = s.Window.ShowMessageRequest(surveyPrompt, cancellationToken)

if response <> null then
Expand All @@ -38,10 +40,12 @@ let private showSurveyPrompt (s: ILanguageServer) (cancellationToken: Cancellati
s.Window.ShowDocument(ShowDocumentParams(Uri = surveyUri, External = true), cancellationToken)

()
// with e ->
// Serilog.Log.Logger.Debug("Unable to show survey message {e}", e)
}
:> Task

let private nonBlockingShowSurveyPrompt s c = Task.Run(fun _ -> showSurveyPrompt s c)

let public onStartupShowSurveyPrompt =
OnLanguageServerStartedDelegate(nonBlockingShowSurveyPrompt)
OnLanguageServerStartedDelegate(showSurveyPrompt)

0 comments on commit 81a206a

Please sign in to comment.