diff --git a/include/Protocol/Lifecycle.h b/include/Protocol/Lifecycle.h index 9c804ec3..207a6bfc 100644 --- a/include/Protocol/Lifecycle.h +++ b/include/Protocol/Lifecycle.h @@ -64,7 +64,14 @@ struct InitializeParams { /// This property is only available if the client supports workspace folders. /// It can be `null` if the client supports workspace folders but none are /// configured. - array workspaceFolders; + optional> workspaceFolders; + + /// The rootUri of the workspace. Is null if no + /// folder is open. If both `rootPath` and `rootUri` are set + /// `rootUri` wins. + /// + /// Deprecated in favour of `workspaceFolders` + optional rootUri; }; struct ServerCapabilities { diff --git a/src/Server/Lifecycle.cpp b/src/Server/Lifecycle.cpp index 8635f8f5..725ac237 100644 --- a/src/Server/Lifecycle.cpp +++ b/src/Server/Lifecycle.cpp @@ -7,13 +7,18 @@ async::Task Server::on_initialize(proto::InitializeParams params) { params.clientInfo.name, params.clientInfo.verion); - if(params.workspaceFolders.empty()) { - log::fatal("The client should provide one workspace folder at least!"); - } - /// FIXME: adjust position encoding. kind = PositionEncodingKind::UTF16; - workspace = mapping.to_path(params.workspaceFolders[0].uri); + workspace = mapping.to_path(([&] -> std::string { + if(params.workspaceFolders && !params.workspaceFolders->empty()) { + return params.workspaceFolders->front().uri; + } + if(params.rootUri) { + return *params.rootUri; + } + + log::fatal("The client should provide one workspace folder or rootUri at least!"); + })()); /// Initialize configuration. config::init(workspace);