Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a config variable to store configuration changes #55

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
module Contextive.LanguageServer.Configuration

open System.Threading.Tasks
open OmniSharp.Extensions.LanguageServer.Protocol.Models

let resolvedPathGetter configGetter pathResolver () =
async {
let! path = configGetter ()
return pathResolver path
}

let handler (definitionsLoader: Definitions.Reloader) _ =
type Config = { mutable Path: string option }

let handler (config: Config) (definitionsLoader: Definitions.Reloader) (configParams: DidChangeConfigurationParams) =
let path = configParams.Settings.Item("contextive").Item("path")
config.Path <- Some(path.ToString())
definitionsLoader ()
Task.CompletedTask
4 changes: 1 addition & 3 deletions src/language-server/Contextive.LanguageServer/Definitions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,7 @@ module private Handle =
let matchOpenFileUri = matchGlobs findMsg.OpenFileUri

let foundContexts =
state.Definitions.Contexts
|> Seq.filter matchOpenFileUri
|> findMsg.Filter
state.Definitions.Contexts |> Seq.filter matchOpenFileUri |> findMsg.Filter

findMsg.ReplyChannel.Reply foundContexts
state
Expand Down
19 changes: 11 additions & 8 deletions src/language-server/Contextive.LanguageServer/Server.fs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ let version =
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()
.InformationalVersion

let private getConfig (s: ILanguageServer) section key =
let private getConfig (s: ILanguageServer) (contextiveConfig: Configuration.Config) section key =
async {
Log.Logger.Information $"Getting {section} {key} config..."

Expand All @@ -38,7 +38,7 @@ let private getConfig (s: ILanguageServer) section key =
let value =
if System.String.IsNullOrEmpty configValue then
match key with
| key when key = pathKey -> Some defaultContextiveDefinitionsPath
| key when key = pathKey -> contextiveConfig.Path
| _ -> None
else
Some configValue
Expand Down Expand Up @@ -89,11 +89,13 @@ let private showSurveyPrompt (s: ILanguageServer) =
let private onStartupShowSurveyPrompt =
OnLanguageServerStartedDelegate(fun (s: ILanguageServer) _cancellationToken -> showSurveyPrompt (s))

let private onStartupConfigureServer definitions =
let private onStartupConfigureServer definitions config =
OnLanguageServerStartedDelegate(fun (s: ILanguageServer) _cancellationToken ->
async {
s.Window.LogInfo $"Starting {name} v{version}..."
let configGetter () = getConfig s configSection pathKey

let configGetter () =
getConfig s config configSection pathKey
// Not sure if this is needed to ensure configuration is loaded, or allow a task/context switch
// Either way, if it's not here, then getWorkspaceFolder returns null
let! _ = configGetter ()
Expand Down Expand Up @@ -122,15 +124,16 @@ let private onStartupConfigureServer definitions =
|> Async.StartAsTask
:> Task)


let private configureServer (input: Stream) (output: Stream) (opts: LanguageServerOptions) =
let definitions = Definitions.create ()

let contextiveConfig: Configuration.Config =
{ Path = Some defaultContextiveDefinitionsPath }

opts
.WithInput(input)
.WithOutput(output)

.OnStarted(onStartupConfigureServer definitions)
.OnStarted(onStartupConfigureServer definitions contextiveConfig)
.OnStarted(onStartupShowSurveyPrompt)
.WithConfigurationSection(configSection) // Add back in when implementing didConfigurationChanged handling
.ConfigureLogging(fun z ->
Expand All @@ -141,7 +144,7 @@ let private configureServer (input: Stream) (output: Stream) (opts: LanguageServ
|> ignore)
.WithServerInfo(ServerInfo(Name = name, Version = version))

.OnDidChangeConfiguration(Configuration.handler <| Definitions.loader definitions)
.OnDidChangeConfiguration((Configuration.handler (contextiveConfig)) <| Definitions.loader definitions)
.OnCompletion(
Completion.handler <| Definitions.find definitions <| TextDocument.findToken,
Completion.registrationOptions
Expand Down