Repository: helix-editor/helix
File: helix-term/src/application.rs (Rust)

Code before:
                            }
                        }

                        Ok(serde_json::Value::Null)
                    }
                    Ok(MethodCall::UnregisterCapability(params)) => {
                        for unreg in params.unregisterations {
                            match unreg.method.as_str() {
                                lsp::notification::DidChangeWatchedFiles::METHOD => {
                                    self.editor
                                        .language_servers
                                        .file_event_handler
                                        .unregister(server_id, unreg.id);
                                }
                                _ => {
                                    log::warn!("Received unregistration request for unsupported method: {}", unreg.method);
                                }
                            }
                        }
                        Ok(serde_json::Value::Null)
                    }
                    Ok(MethodCall::ShowDocument(params)) => {
                        let language_server = language_server!();
                        let offset_encoding = language_server.offset_encoding();

                        let success = match params {
                            lsp::ShowDocumentParams {
                                external: Some(true),
                                uri,
                                ..
                            } => {
                                self.jobs.callback(crate::open_external_url_callback(uri));
                                true
                            }
                            lsp::ShowDocumentParams {
                                uri,
                                selection,
                                take_focus,
                                ..
                            } => {
                                match uri.to_file_path() {
                                    Ok(path) => {
                                        let action = match take_focus {
                                            Some(true) => helix_view::editor::Action::Replace,
                                            _ => helix_view::editor::Action::VerticalSplit,
                                        };

                                        match self.editor.open(&path, action) {
                                            Ok(id) => {
                                                let doc = doc_mut!(self.editor, &id);
                                                if let Some(range) = selection {

Review comment (suggestion):
Using a match is pretty verbose here. I would just use early return liberally  (`return Ok(json!(lsp::ShowDocumentResult { success: true/false }))` is simple enough to repeat a few times).

You could also use a mutable variable like `let mut success = false` here. Either way I am not a fan of the direct assignment here it creates too much nesting

Code after:
        }
    }

    fn handle_show_document(
        &mut self,
        params: lsp::ShowDocumentParams,
        offset_encoding: helix_lsp::OffsetEncoding,
    ) -> lsp::ShowDocumentResult {
        if let lsp::ShowDocumentParams {
            external: Some(true),
            uri,
            ..
        } = params
        {
            self.jobs.callback(crate::open_external_url_callback(uri));
            return lsp::ShowDocumentResult { success: true };
        };

        let lsp::ShowDocumentParams {
            uri,
            selection,
            take_focus,
            ..
        } = params;

        let path = match uri.to_file_path() {
            Ok(path) => path,
            Err(err) => {
                log::error!("unsupported file URI: {}: {:?}", uri, err);
                return lsp::ShowDocumentResult { success: false };
            }
        };

        let action = match take_focus {
            Some(true) => helix_view::editor::Action::Replace,
            _ => helix_view::editor::Action::VerticalSplit,
        };

        let doc_id = match self.editor.open(&path, action) {
            Ok(id) => id,
            Err(err) => {
                log::error!("failed to open path: {:?}: {:?}", uri, err);
                return lsp::ShowDocumentResult { success: false };
            }
        };

        let doc = doc_mut!(self.editor, &doc_id);
        if let Some(range) = selection {
            // TODO: convert inside server
            if let Some(new_range) = lsp_range_to_range(doc.text(), range, offset_encoding) {
                let view = view_mut!(self.editor);