1use anyhow::{Context, Result};
2use libloading::{Library, Symbol};
3use tree_sitter::Language;
5fn replace_dashes_with_underscores(name: &str) -> String {
9const DYLIB_EXTENSION: &str = "so";
12const DYLIB_EXTENSION: &str = "dll";
14pub fn get_language(runtime_path: &std::path::Path, name: &str) -> Result<Language> {
15 let name = name.to_ascii_lowercase();
16 let mut library_path = runtime_path.join("grammars").join(&name);
17 // TODO: duplicated under build
18 library_path.set_extension(DYLIB_EXTENSION);
20 let library = unsafe { Library::new(&library_path) }
21 .with_context(|| format!("Error opening dynamic library {:?}", &library_path))?;
22 let language_fn_name = format!("tree_sitter_{}", replace_dashes_with_underscores(&name));
23 let language = unsafe {
24 let language_fn: Symbol<unsafe extern "C" fn() -> Language> = library
25 .get(language_fn_name.as_bytes())
26 .with_context(|| format!("Failed to load symbol {}", language_fn_name))?;
29 std::mem::forget(library);
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list