{"id":18352885,"url":"https://github.com/erg-lang/molc","last_synced_at":"2025-04-06T11:33:10.824Z","repository":{"id":193320266,"uuid":"688601739","full_name":"erg-lang/molc","owner":"erg-lang","description":"A mock language client for testing language servers","archived":false,"fork":false,"pushed_at":"2024-02-18T02:17:33.000Z","size":27,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-05-01T11:15:51.744Z","etag":null,"topics":["language-server","lsp","lsp-client","rust","testing"],"latest_commit_sha":null,"homepage":"https://docs.rs/molc/","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/erg-lang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-09-07T17:34:01.000Z","updated_at":"2024-01-16T10:45:25.000Z","dependencies_parsed_at":null,"dependency_job_id":"7246eed8-c83c-45de-b80d-9d3f265860b2","html_url":"https://github.com/erg-lang/molc","commit_stats":{"total_commits":20,"total_committers":1,"mean_commits":20.0,"dds":0.0,"last_synced_commit":"a4ba1c75eb16b6aeefd28a12e295571d25481410"},"previous_names":["erg-lang/molc"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erg-lang%2Fmolc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erg-lang%2Fmolc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erg-lang%2Fmolc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erg-lang%2Fmolc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/erg-lang","download_url":"https://codeload.github.com/erg-lang/molc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247478152,"owners_count":20945258,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["language-server","lsp","lsp-client","rust","testing"],"created_at":"2024-11-05T21:37:48.625Z","updated_at":"2025-04-06T11:33:10.076Z","avatar_url":"https://github.com/erg-lang.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `molc`\n\n`molc` provides a mock (fake) language client for testing language servers.\n\n## Usage\n\nYou can see specific examples of molc use in [ELS](https://github.com/erg-lang/erg/blob/main/crates/els/tests/test.rs).\n\n```rust\nuse lsp_types::{Url, Value};\n\nuse molc::{FakeClient, LangServer, RedirectableStdout};\nuse molc::oneline_range;\n\npub struct Server {\n    stdout_redirect: Option\u003cstd::sync::mpsc::Sender\u003cValue\u003e\u003e,\n    ...\n}\n\nimpl LangServer for Server {\n    fn dispatch(\u0026mut self, msg: impl Into\u003cValue\u003e) -\u003e Result\u003c(), Box\u003cdyn std::error::Error\u003e\u003e {\n        self.dispatch(msg)\n    }\n}\n\nimpl RedirectableStdout for Server {\n    fn sender(\u0026self) -\u003e Option\u003c\u0026std::sync::mpsc::Sender\u003cValue\u003e\u003e {\n        self.stdout_redirect.as_ref()\n    }\n}\n\nimpl Server {\n    fn bind_fake_client() -\u003e FakeClient\u003cSelf\u003e {\n        // The server should send responses to this channel at least during testing.\n        let (sender, receiver) = std::sync::mpsc::channel();\n        DummyClient::new(\n            Server::new(Some(sender)),\n            receiver,\n        )\n    }\n\n    fn init(\u0026mut self, msg: \u0026Value, id: i64) -\u003e ELSResult\u003c()\u003e {\n        self.send_log(\"initializing the language server\")?;\n        let result = InitializeResult {\n            ...\n        };\n        self.init_services();\n        self.send_stdout(\u0026json!({\n            \"jsonrpc\": \"2.0\",\n            \"id\": id,\n            \"result\": result,\n        }))\n    }\n\n    ...\n}\n\n#[test]\nfn test_references() -\u003e Result\u003c(), Box\u003cdyn std::error::Error\u003e\u003e {\n    let mut client = Server::bind_fake_client();\n    client.request_initialize()?;\n    let uri = Url::from_file_path(Path::new(FILE_A).canonicalize()?).unwrap();\n    client.notify_open(FILE_A)?;\n    let locations = client.request_references(uri, 1, 4)?.unwrap();\n    assert_eq!(locations.len(), 1);\n    assert_eq!(\u0026locations[0].range, \u0026oneline_range(1, 4, 5));\n    Ok(())\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferg-lang%2Fmolc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ferg-lang%2Fmolc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferg-lang%2Fmolc/lists"}