From 2d541fde22842fee0104c6755ef736c8562167f1 Mon Sep 17 00:00:00 2001 From: Chris Simon Date: Sun, 19 Nov 2023 10:25:39 +0000 Subject: [PATCH] chore: remove survey prompt --- .../Contextive.LanguageServer.Tests.fsproj | 1 - .../SurveyTests.fs | 161 ------------------ .../Contextive.LanguageServer.fsproj | 1 - .../Contextive.LanguageServer/Server.fs | 1 - .../Contextive.LanguageServer/Survey.fs | 56 ------ 5 files changed, 220 deletions(-) delete mode 100644 src/language-server/Contextive.LanguageServer.Tests/SurveyTests.fs delete mode 100644 src/language-server/Contextive.LanguageServer/Survey.fs diff --git a/src/language-server/Contextive.LanguageServer.Tests/Contextive.LanguageServer.Tests.fsproj b/src/language-server/Contextive.LanguageServer.Tests/Contextive.LanguageServer.Tests.fsproj index 7781130d..f9035c83 100644 --- a/src/language-server/Contextive.LanguageServer.Tests/Contextive.LanguageServer.Tests.fsproj +++ b/src/language-server/Contextive.LanguageServer.Tests/Contextive.LanguageServer.Tests.fsproj @@ -27,7 +27,6 @@ - diff --git a/src/language-server/Contextive.LanguageServer.Tests/SurveyTests.fs b/src/language-server/Contextive.LanguageServer.Tests/SurveyTests.fs deleted file mode 100644 index 86e23c72..00000000 --- a/src/language-server/Contextive.LanguageServer.Tests/SurveyTests.fs +++ /dev/null @@ -1,161 +0,0 @@ -module Contextive.LanguageServer.Tests.SurveyTests - -open System -open Expecto -open Swensen.Unquote -open Contextive.LanguageServer.Tests.Helpers -open Contextive.LanguageServer.Tests.Helpers.Window -open Helpers.TestClient -open OmniSharp.Extensions.LanguageServer.Protocol.Models -open System.IO -open System.Linq - -let latchFile = Path.Combine(System.AppContext.BaseDirectory, "survey-prompted.txt") - -let okActionTitle = "OK, I'll help!" - -[] -let tests = - testSequencedGroup "Survey Prompt Tests" - <| testList - "LanguageServer.Survey Prompt Tests" - [ testAsync "Server shows survey prompt if latch-file doesn't exist" { - let messageAwaiter = ConditionAwaiter.create () - - File.Delete(latchFile) - - let pathValue = Guid.NewGuid().ToString() - - let config = - [ showMessageRequestHandlerBuilder <| handler messageAwaiter null - Workspace.optionsBuilder "" - ConfigurationSection.contextivePathBuilder pathValue ] - - let! (client, reply) = TestClient(config) |> initAndWaitForReply - - let! msg = ConditionAwaiter.waitForAny messageAwaiter 1500 - - let receivedMsg = msg.Value - - File.Delete(latchFile) - - test <@ receivedMsg.Message.Contains("survey") @> - test <@ receivedMsg.Type = MessageType.Info @> - test <@ receivedMsg.Actions.Count() = 2 @> - test <@ receivedMsg.Actions.First().Title = okActionTitle @> - test <@ receivedMsg.Actions.Skip(1).First().Title = "No (and don't bother me again)" @> - - } - - testAsync "Server does not show prompt if latch-file already exists" { - let messageAwaiter = ConditionAwaiter.create () - - File.Create(latchFile).Close() - - let pathValue = Guid.NewGuid().ToString() - - let config = - [ showMessageRequestHandlerBuilder <| handler messageAwaiter null - Workspace.optionsBuilder "" - ConfigurationSection.contextivePathBuilder pathValue ] - - let! (client, reply) = TestClient(config) |> initAndWaitForReply - - let! msg = ConditionAwaiter.waitForAny messageAwaiter 1500 - - File.Delete(latchFile) - - test <@ msg.IsNone @> - } - - testAsync "Server creates latch file if user doesn't ignore the prompt" { - - let messageAwaiter = ConditionAwaiter.create () - - File.Delete(latchFile) - - let pathValue = Guid.NewGuid().ToString() - - let response = MessageActionItem(Title = okActionTitle) - - let config = - [ showMessageRequestHandlerBuilder <| handler messageAwaiter response - Workspace.optionsBuilder "" - ConfigurationSection.contextivePathBuilder pathValue ] - - let! _ = TestClient(config) |> initAndWaitForReply - - let fileExists = File.Exists(latchFile) - File.Delete(latchFile) - - test <@ fileExists @> - } - - testAsync "Server DOESN'T create latch file if user ignores the prompt" { - - let messageAwaiter = ConditionAwaiter.create () - - File.Delete(latchFile) - - let pathValue = Guid.NewGuid().ToString() - - let config = - [ showMessageRequestHandlerBuilder <| handler messageAwaiter null - Workspace.optionsBuilder "" - ConfigurationSection.contextivePathBuilder pathValue ] - - let! _ = TestClient(config) |> initAndWaitForReply - - test <@ not <| File.Exists(latchFile) @> - } - - testAsync "Server opens form when user says they'll help" { - - let messageAwaiter = ConditionAwaiter.create () - let showDocAwaiter = ConditionAwaiter.create () - - File.Delete(latchFile) - - let pathValue = Guid.NewGuid().ToString() - - let response = MessageActionItem(Title = okActionTitle) - let showDocResponse = ShowDocumentResult(Success = true) - - let config = - [ showMessageRequestHandlerBuilder <| handler messageAwaiter response - showDocumentRequestHandlerBuilder <| handler showDocAwaiter showDocResponse - Workspace.optionsBuilder "" - ConfigurationSection.contextivePathBuilder pathValue ] - - let! (client, reply) = TestClient(config) |> initAndWaitForReply - - let! showDocMsg = ConditionAwaiter.waitForAny showDocAwaiter 1500 - - File.Delete(latchFile) - - let receivedDoc = showDocMsg.Value - - test <@ receivedDoc.External.Value = true @> - test <@ receivedDoc.Uri.ToString().Contains("forms.gle") @> - - } - - testAsync "Server does nothing if client doesn't support showMessageRequest" { - - File.Delete(latchFile) - - let pathValue = Guid.NewGuid().ToString() - - let config = - [ Workspace.optionsBuilder "" - ConfigurationSection.contextivePathBuilder pathValue ] - - let expectedLogMessage = Some "Unable to send survey message" - - let! (_, reply) = TestClientWithCustomInitWait(config, expectedLogMessage) |> initAndWaitForReply - - test <@ not <| File.Exists(latchFile) @> - test <@ reply.IsSome @> - } - - ] diff --git a/src/language-server/Contextive.LanguageServer/Contextive.LanguageServer.fsproj b/src/language-server/Contextive.LanguageServer/Contextive.LanguageServer.fsproj index c1a9fb44..c98b530c 100644 --- a/src/language-server/Contextive.LanguageServer/Contextive.LanguageServer.fsproj +++ b/src/language-server/Contextive.LanguageServer/Contextive.LanguageServer.fsproj @@ -29,7 +29,6 @@ - diff --git a/src/language-server/Contextive.LanguageServer/Server.fs b/src/language-server/Contextive.LanguageServer/Server.fs index 34685cee..fac12d3d 100644 --- a/src/language-server/Contextive.LanguageServer/Server.fs +++ b/src/language-server/Contextive.LanguageServer/Server.fs @@ -110,7 +110,6 @@ let private configureServer (input: Stream) (output: Stream) (opts: LanguageServ .WithOutput(output) .OnStarted(onStartupConfigureServer definitions) - .OnStarted(Survey.onStartupShowSurveyPrompt) .WithConfigurationSection(configSection) // Add back in when implementing didConfigurationChanged handling .ConfigureLogging(fun z -> z diff --git a/src/language-server/Contextive.LanguageServer/Survey.fs b/src/language-server/Contextive.LanguageServer/Survey.fs deleted file mode 100644 index 66b234e0..00000000 --- a/src/language-server/Contextive.LanguageServer/Survey.fs +++ /dev/null @@ -1,56 +0,0 @@ -module Contextive.LanguageServer.Survey - -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) (cancellationToken: CancellationToken) = - task { - let latchFile = Path.Combine(System.AppContext.BaseDirectory, "survey-prompted.txt") - - if not <| File.Exists(latchFile) then - - let goToSurveyAction = "OK, I'll help!" - let surveyUri = "https://forms.gle/3pJSUYmLHv5RQ1m1A" - - let surveyPrompt = - ShowMessageRequestParams( - Message = - "👋 Please help Contextive by doing a brief survey! Click \"OK, I'll help!\" to be taken to a Google Forms survey. 🙏 to everyone who has responded to the survey so far - your thoughts are invaluable 🧠!", - Type = MessageType.Info, - Actions = - Container( - [ MessageActionItem(Title = goToSurveyAction) - MessageActionItem(Title = "No (and don't bother me again)") ] - ) - ) - - // Switch from `try` to capability check once https://github.com/OmniSharp/csharp-language-server-protocol/issues/1117 is resolved - // if s.ClientSettings.Capabilities.Window.ShowMessage.IsSupported then - try - - 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), - cancellationToken - ) - - () - with e -> - s.Window.Log($"Unable to send survey message: {e.ToString()}") - } - :> Task - -let private nonBlockingShowSurveyPrompt s c = Task.Run(fun _ -> showSurveyPrompt s c) - -let public onStartupShowSurveyPrompt = - OnLanguageServerStartedDelegate(nonBlockingShowSurveyPrompt)