Skip to content

Commit

Permalink
test(language-server): ensure survey prompt is non-blocking which was…
Browse files Browse the repository at this point in the history
… affecting test run
  • Loading branch information
chrissimon-au committed Nov 14, 2023
1 parent 669c9df commit a5dc4db
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ open Contextive.LanguageServer.Tests.Helpers.TestClient
module DH = Helpers.Definitions

[<Tests>]
let completionTests =
testSequenced
<| testList
let tests =
testList
"LanguageServer.Completion Tests"
[ testAsync "Given no contextive respond with empty completion list " {
use! client = SimpleTestClient |> init
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ open Helpers.TestClient
open Contextive.LanguageServer.Tests.Helpers

[<Tests>]
let definitionsTests =
let tests =
testList
"LanguageServer.Configuration Tests"
[ testAsync "Can receive configuration value" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ open Contextive.Core
open Contextive.LanguageServer.Tests.Helpers

[<Tests>]
let definitionsTests =
let tests =
testList
"LanguageServer.Definitions File Tests"
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ open Swensen.Unquote
open System.IO

[<Tests>]
let fileLoaderTests =
let tests =
testList
"LanguageServer.File Loader Tests"
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ open Contextive.LanguageServer.Tests.Helpers
module DH = Helpers.Definitions

[<Tests>]
let hoverTests =
let tests =
testList
"LanguageServer.Hover Tests"
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ open Contextive.LanguageServer.Tests.Helpers
open Helpers.TestClient

[<Tests>]
let initializationTests =
let tests =
testList
"LanguageServer.Initialization Tests"
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ open Swensen.Unquote
open System.Runtime.InteropServices

[<Tests>]
let pathLoaderTests =
let tests =
testList
"LanguageServer.Path Resolver Tests"
[ testCase "No Workspace, non-root path"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ open Contextive.LanguageServer.Tests.Helpers
module DH = Helpers.Definitions

[<Tests>]
let renderingTests =
let tests =
testList
"LanguageServer.Rendering Tests"
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ let latchFile = Path.Combine(System.AppContext.BaseDirectory, "survey-prompted.t
let okActionTitle = "OK, I'll help!"

[<Tests>]
let initializationTests =
testSequenced
let tests =
testSequencedGroup "Survey Prompt Tests"
<| testList
"LanguageServer.Survey Prompt Tests"
[ testAsync "Server shows survey prompt if latch-file doesn't exist" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ open Contextive.LanguageServer.Tests.Helpers
open Helpers.TestClient

[<Tests>]
let textDocumentTests =
let tests =
testList
"LanguageServer.TextDocument Tests"
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ let didChangeWatchedFiles (client: ILanguageClient) (uri: string) =
)

[<Tests>]
let watchedFileTests =
let tests =
testList
"LanguageServer.Watched File Tests"
[
Expand Down Expand Up @@ -125,8 +125,6 @@ let watchedFileTests =

didChangeWatchedFiles client definitionsFileUri

didChangeWatchedFiles client definitionsFileUri

let! labelsWhileEmpty = Completion.getCompletionLabels client

File.WriteAllText(
Expand Down
6 changes: 5 additions & 1 deletion src/language-server/Contextive.LanguageServer/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ let setupLogging =
LoggerConfiguration()
.MinimumLevel.Verbose()
.Enrich.FromLogContext()
.WriteTo.File("log.txt", rollingInterval = RollingInterval.Day)
.WriteTo.File(
// formatter = Formatting.Json.JsonFormatter(), // uncomment to enable detailed logging of protocol messages
path = "log.txt",
rollingInterval = RollingInterval.Day
)
.CreateLogger()
#else
()
Expand Down
15 changes: 11 additions & 4 deletions src/language-server/Contextive.LanguageServer/Survey.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ open OmniSharp.Extensions.LanguageServer.Protocol.Server
open OmniSharp.Extensions.LanguageServer.Protocol.Models
open OmniSharp.Extensions.LanguageServer.Protocol.Window
open System.IO
open System.Threading
open System.Threading.Tasks

let private showSurveyPrompt (s: ILanguageServer) =
let private showSurveyPrompt (s: ILanguageServer) (cancellationToken: CancellationToken) =
task {
let latchFile = Path.Combine(System.AppContext.BaseDirectory, "survey-prompted.txt")

Expand All @@ -26,15 +28,20 @@ let private showSurveyPrompt (s: ILanguageServer) =
)
)

let! response = s.Window.ShowMessageRequest(surveyPrompt, System.Threading.CancellationToken.None)
let! response = s.Window.ShowMessageRequest(surveyPrompt, cancellationToken)

if response <> null then
File.Create(latchFile).Close()

if response.Title = goToSurveyAction then
let! res = s.Window.ShowDocument(ShowDocumentParams(Uri = surveyUri, External = true))
let! res =
s.Window.ShowDocument(ShowDocumentParams(Uri = surveyUri, External = true), cancellationToken)

()
}
:> Task

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

let public onStartupShowSurveyPrompt =
OnLanguageServerStartedDelegate(fun (s: ILanguageServer) _cancellationToken -> showSurveyPrompt (s))
OnLanguageServerStartedDelegate(nonBlockingShowSurveyPrompt)

0 comments on commit a5dc4db

Please sign in to comment.