From e74d203806efea612ef2ab33da1e561c077d6c16 Mon Sep 17 00:00:00 2001 From: Simon Van Casteren Date: Fri, 13 Dec 2019 14:44:20 +0100 Subject: Added initializationOption to specify project if multiple urp files --- src/lsp.sml | 11 ++++++++--- src/lspspec.sml | 4 +++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/lsp.sml b/src/lsp.sml index d902fed4..34137a4f 100644 --- a/src/lsp.sml +++ b/src/lsp.sml @@ -47,12 +47,17 @@ fun initState (initParams: LspSpec.initializeParams): state = val rootPath = case #rootUri initParams of NONE => raise Fail "No rootdir found" | SOME a => #path a + val optsUrpFile = + (SOME (FromJson.asString (FromJson.get "urpfile" (FromJson.get "project" (FromJson.get "urweb" (#initializationOptions initParams)))))) + handle ex => NONE val foundUrps = scanDir (fn fname => OS.Path.ext fname = SOME "urp") rootPath in { urpPath = case foundUrps of [] => raise Fail ("No .urp files found in path " ^ rootPath) | one :: [] => OS.Path.base (OS.Path.file one) - | many => raise Fail ("Found multiple .urp files in path " ^ rootPath) + | many => case List.find (fn m => SOME (OS.Path.base (OS.Path.file m)) = optsUrpFile) many of + NONE => raise Fail ("Found multiple .urp files in path " ^ rootPath) + | SOME f => OS.Path.base (OS.Path.file f) , fileStates = SM.empty } end @@ -531,8 +536,8 @@ fun serverLoop () = LspSpec.RequestMessage m => LspSpec.handleMessage m - { initialize = fn _ => - (let val st = initState (LspSpec.parseInitializeParams (#params m)) + { initialize = fn p => + (let val st = initState p in stateRef := SOME st; LspSpec.Success diff --git a/src/lspspec.sml b/src/lspspec.sml index 7993038e..fe1711f0 100644 --- a/src/lspspec.sml +++ b/src/lspspec.sml @@ -195,12 +195,14 @@ structure LspSpec = struct { textDocument = parseTextDocumentIdentifier (FromJson.get "textDocument" params) } type initializeParams = - { rootUri: documentUri option } + { rootUri: documentUri option + , initializationOptions: Json.json } fun parseInitializeParams (j: Json.json) = { rootUri = Option.map parseDocumentUri (FromJson.asOptionalString (FromJson.get "rootUri" j)) + , initializationOptions = FromJson.get "initializationOptions" j } type diagnostic = { range: range (* code?: number | string *) -- cgit v1.2.3