Repository: lapce/lapce
File: lapce-data/src/document.rs (Rust)

Code before:
            code_actions: im::HashMap::new(),
            inlay_hints: None,
            diagnostics: None,
            ime_text: None,
            ime_pos: (0, 0, 0),
            find: Rc::new(RefCell::new(Find::new(0))),
            find_progress: Rc::new(RefCell::new(FindProgress::Ready)),
            event_sink,
            proxy,
            syntax_selection_range: None,
        }
    }

    fn syntax_to_option(
        proxy: &Arc<LapceProxy>,
        syntax: Result<Syntax, HighlightIssue>,
    ) -> Option<Syntax> {
        match syntax {
            Ok(x) => Some(x),
            Err(HighlightIssue::NotAvailable) => None,
            Err(HighlightIssue::Error(x)) => {
                proxy.core_rpc.show_message(
                    "Syntax Highlighting failed".to_owned(),
                    ShowMessageParams {
                        typ: MessageType::ERROR,
                        message: format!("An error occured trying to load syntax highlighting info: {x}. Please report this."),
                    },
                );
                None
            }
        }
    }

    pub fn id(&self) -> BufferId {
        self.id
    }

    pub fn loaded(&self) -> bool {
        self.loaded
    }

    pub fn set_content(&mut self, content: BufferContent) {
        self.content = content;
        self.syntax = match &self.content {
            BufferContent::File(path) => {
                Self::syntax_to_option(&self.proxy, Syntax::init(path))
            }
            BufferContent::Local(_) => None,
            BufferContent::SettingsValue(..) => None,
            BufferContent::Scratch(..) => None,
        };

Review comment (suggestion):
```suggestion
                        message: format!("An error occurred trying to load syntax highlighting info: {x}."),
```

Code after:
            code_actions: im::HashMap::new(),
            inlay_hints: None,
            diagnostics: None,
            ime_text: None,
            ime_pos: (0, 0, 0),
            find: Rc::new(RefCell::new(Find::new(0))),
            find_progress: Rc::new(RefCell::new(FindProgress::Ready)),
            event_sink,
            proxy,
            syntax_selection_range: None,
        }
    }

    fn syntax_to_option(
        proxy: &Arc<LapceProxy>,
        syntax: Result<Syntax, HighlightIssue>,
    ) -> Option<Syntax> {
        match syntax {
            Ok(x) => Some(x),
            Err(HighlightIssue::NotAvailable) => None,
            Err(HighlightIssue::Error(x)) => {
                proxy.core_rpc.show_message(
                    "Syntax Highlighting failed".to_owned(),
                    ShowMessageParams {
                        typ: MessageType::ERROR,
                        message: format!("An error occurred trying to load syntax highlighting info: {x}."),
                    },
                );
                None
            }
        }
    }

    pub fn id(&self) -> BufferId {
        self.id
    }

    pub fn loaded(&self) -> bool {
        self.loaded
    }

    pub fn set_content(&mut self, content: BufferContent) {
        self.content = content;
        self.syntax = match &self.content {
            BufferContent::File(path) => {
                Self::syntax_to_option(&self.proxy, Syntax::init(path))
            }
            BufferContent::Local(_) => None,
            BufferContent::SettingsValue(..) => None,
            BufferContent::Scratch(..) => None,
        };