use crate::{server::LspServer, utils::{get_definition_token, get_language_id_by_uri}};
use tower_lsp::lsp_types::*;

mod sv;
mod vhdl;

impl LspServer {
    pub fn document_highlight(
        &self,
        params: DocumentHighlightParams,
    ) -> Option<Vec<DocumentHighlight>> {
        let uri = &params.text_document_position_params.text_document.uri;
        let pos = params.text_document_position_params.position;
        let file_id = self.srcs.get_id(&uri).to_owned();
        self.srcs.wait_parse_ready(file_id, false);
        let file = self.srcs.get_file(file_id)?;
        let file = file.read().ok()?;
        let line_text = file.text.line(pos.line as usize);
        let token = get_definition_token(&line_text, pos);

        let language_id = get_language_id_by_uri(&uri);
        
        match language_id.as_str() {
            // "vhdl" => vhdl::document_highlight(
            //     self,
            //     &token,
            //     &file,
            //     pos,
            //     &uri
            // ),
            
            "verilog" | "systemverilog" => sv::document_highlight(
                self,
                &token,
                &file,
                pos,
                &uri
            ),
            _ => None
        }
    }
}