mod completion;
pub use completion::*;

mod notifications;
pub use notifications::*;

mod diagnostics;
pub use diagnostics::*;

use super::Request;
use super::{BasicFunctions, Response};
use crate::{LspContext, Notification};

/// Trait to handle text document functions
pub trait TextDocumentFunctions: BasicFunctions {
    /// Occurs when a document is opened.
    /// This is a notification, it has no response.
    fn did_open(
        &mut self,
        _ctx: &mut dyn LspContext,
        _notification: Notification,
        _params: DidOpenTextDocumentParams,
    ) {
    }

    /// Occurs when a document is changed.
    /// This is a notification, it has no response.
    fn did_change(
        &mut self,
        _ctx: &mut dyn LspContext,
        _notification: Notification,
        _params: DidChangeTextDocumentParams,
    ) {
    }

    /// Occurs when a document is closed.
    /// This is a notification, it has no response.
    fn did_close(
        &mut self,
        _ctx: &mut dyn LspContext,
        _notification: Notification,
        _params: DidCloseTextDocumentParams,
    ) {
    }

    /// A request for diagnostics.
    ///
    /// This is triggered in a document (for workspaces there is another
    /// variant method).
    ///
    /// # Errors
    ///
    /// See [`BasicFunctions::initialize`] for result variants.
    fn diagnostic(
        &mut self,
        _ctx: &mut dyn LspContext,
        request: Request,
        _params: DocumentDiagnosticParams,
    ) -> Result<DocumentDiagnosticReport, Response> {
        Err(request.not_found())
    }

    /// A request for completion.
    ///
    /// Completion normally checks in the `params`: [`CompletionParams`],
    /// especially the `context`: [`CompletionContext`] for information on how
    /// to produce a response.
    ///
    /// The response is a [`CompletionList`] in case of success.
    ///
    /// # Errors
    ///
    /// See [`BasicFunctions::initialize`] for result variants.
    fn completion(
        &mut self,
        _ctx: &mut dyn LspContext,
        request: Request,
        _params: CompletionParams,
    ) -> Result<CompletionList, Response> {
        Err(request.not_found())
    }
}
