fn ensure_did_open(request: &EditorRequest, mut ctx: &mut Context) {
    let buffile = &request.meta.buffile;
    if buffile.is_empty() || ctx.documents.contains_key(buffile) {
        return;
    };
    if request.method == notification::DidChangeTextDocument::METHOD {
        return text_document_did_open(request.meta.clone(), request.params.clone(), &mut ctx);
    }
    match std::fs::read_to_string(buffile) {
        Ok(draft) => {
            let mut params = toml::value::Table::default();
            params.insert("draft".to_string(), toml::Value::String(draft));
            text_document_did_open(request.meta.clone(), toml::Value::Table(params), &mut ctx);
        }
        Err(_) => error!(
            "Failed to read file {} to simulate textDocument/didOpen",
            buffile
        ),
    };
}
/// Ensure that textDocument/didOpen is sent for the given buffer before any other request, if possible.
///
/// kak-lsp tries to not bother Kakoune side of the plugin with bookkeeping status of kak-lsp server
/// itself and lsp servers run by it. It is possible that kak-lsp server or lsp server dies at some
/// point while Kakoune session is still running. That session can send a request for some already
/// open (opened before kak-lsp/lsp exit) buffer. In this case, kak-lsp/lsp server will be restarted
/// by the incoming request. `ensure_did_open` tries to sneak in `textDocument/didOpen` request for
/// this buffer then as the specification requires to send such request before other requests for
/// the file.
///
/// In a normal situation, such extra request is not required, and `ensure_did_open` short-circuits
/// most of the time in `if buffile.is_empty() || ctx.documents.contains_key(buffile)` condition.
Ensure that textDocument/didOpen is sent for the given buffer before any other request, if possible.
kak-lsp tries to not bother Kakoune side of the plugin with bookkeeping status of kak-lsp server
itself and lsp servers run by it. It is possible that kak-lsp server or lsp server dies at some
point while Kakoune session is still running. That session can send a request for some already
open (opened before kak-lsp/lsp exit) buffer. In this case, kak-lsp/lsp server will be restarted
by the incoming request. `ensure_did_open` tries to sneak in `textDocument/didOpen` request for
this buffer then as the specification requires to send such request before other requests for
the file.

In a normal situation, such extra request is not required, and `ensure_did_open` short-circuits
most of the time in `if buffile.is_empty() || ctx.documents.contains_key(buffile)` condition.
Ensure that textDocument / didOpen is sent for the given buffer before any other request if possible . kak - lsp tries to not bother Kakoune side of the plugin with bookkeeping status of kak - lsp server itself and lsp servers run by it . It is possible that kak - lsp server or lsp server dies at some point while Kakoune session is still running . That session can send a request for some already open ( opened before kak - lsp / lsp exit ) buffer . In this case kak - lsp / lsp server will be restarted by the incoming request . ` ensure_did_open ` tries to sneak in ` textDocument / didOpen ` request for this buffer then as the specification requires to send such request before other requests for the file . In a normal situation such extra request is not required and ` ensure_did_open ` short - circuits most of the time in ` if buffile . is_empty () || ctx . documents . contains_key ( buffile ) ` condition .
fn ensure_did_open(request: &EditorRequest, mut ctx: &mut Context) {
    let buffile = &request.meta.buffile;
    if buffile.is_empty() || ctx.documents.contains_key(buffile) {
        return;
    };
    if request.method == notification::DidChangeTextDocument::METHOD {
        return text_document_did_open(request.meta.clone(), request.params.clone(), &mut ctx);
    }
    match std::fs::read_to_string(buffile) {
        Ok(draft) => {
            let mut params = toml::value::Table::default();
            params.insert("draft".to_string(), toml::Value::String(draft));
            text_document_did_open(request.meta.clone(), toml::Value::Table(params), &mut ctx);
        }
        Err(_) => error!(
            "Failed to read file {} to simulate textDocument/didOpen",
            buffile
        ),
    };
}
fn ensure_did_open ( request : & EditorRequest , mut ctx : & mut Context ) { let buffile = & request . meta . buffile ; if buffile . is_empty ( ) || ctx . documents . contains_key ( buffile ) { return ; } ; if request . method == notification :: DidChangeTextDocument :: METHOD { return text_document_did_open ( request . meta . clone ( ) , request . params . clone ( ) , & mut ctx ) ; } match std :: fs :: read_to_string ( buffile ) { Ok ( draft ) => { let mut params = toml :: value :: Table :: default ( ) ; params . insert ( " " . to_string ( ) , toml :: Value :: String ( draft ) ) ; text_document_did_open ( request . meta . clone ( ) , toml :: Value :: Table ( params ) , & mut ctx ) ; } Err ( _ ) => error ! ( " " buffile ) , } ; }
Ensure that textDocument/didOpen is sent for the given buffer before any other request, if possible.
Ensure that textDocument / didOpen is sent for the given buffer before any other request if possible .
request
&EditorRequest
ctx
&mut Context
request
&EditorRequest
ctx
&mut Context