Skip to content

Commit

Permalink
feat: show filetype and filetype icon and lsp name in statusline
Browse files Browse the repository at this point in the history
  • Loading branch information
ttys3 committed Apr 21, 2022
1 parent 4144c9d commit 1fc35ca
Show file tree
Hide file tree
Showing 4 changed files with 258 additions and 1 deletion.
206 changes: 206 additions & 0 deletions ft_icons.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
"glb"=""
"lua"=""
"cmake"=""
"hh"=""
"dockerfile"=""
"py"=""
".bashrc"=""
"gulpfile"=""
"cp"=""
"Brewfile"=""
"makefile"=""
"vim"=""
"Vagrantfile$"=""
"COPYING.LESSER"=""
"mdx"=""
"ex"=""
"opus"=""
"Rmd"=""
"pp"=""
"fsscript"=""
"sqlite3"=""
"jsx"=""
"fsx"=""
"_gvimrc"=""
"jpeg"=""
"sh"=""
"go"=""
"html"=""
"lhs"=""
"cljc"=""
"cljs"=""
"elm"=""
"R"=""
".npmrc"=""
".gitconfig"=""
"rs"=""
"sublime"=""
"Gemfile$"=""
"json"=""
"edn"=""
"zsh"=""
"cr"=""
"awk"=""
"fsi"=""
"mli"="λ"
"node_modules"=""
"LICENSE"=""
"CMakeLists.txt"=""
"terminal"=""
".gitmodules"=""
"hbs"=""
"sol"=""
"zig"=""
"mint"=""
"package-lock.json"=""
".ds_store"=""
"pyd"=""
"conf"=""
"xul"=""
"license"=""
"ai"=""
"leex"=""
"mjs"=""
"ppt"=""
"eex"=""
"xml"="謹"
"xls"=""
"exs"=""
"rb"=""
"cson"=""
"ejs"=""
"h"=""
"xcplayground"=""
"rakefile"=""
"c"=""
"d"=""
"webp"=""
"pl"=""
"clj"=""
"vue"=""
"cpp"=""
"hrl"=""
"coffee"=""
"hpp"=""
"txt"=""
"godot"=""
"twig"=""
"erl"=""
"tscn"=""
"ts"=""
"rake"=""
"tres"=""
"COMMIT_EDITMSG"=""
"toml"=""
"cfg"=""
"tex"=""
"t"=""
"desktop"=""
"fish"=""
"swift"=""
"bash"=""
"svg"=""
".gitattributes"=""
".vimrc"=""
"cbl"=""
"hxx"=""
"nix"=""
"jl"=""
"psd"=""
"suo"=""
"styl"=""
"c++"=""
"cobol"=""
"pyo"=""
"sql"=""
"cc"=""
"git"=""
"COPYING"=""
"sml"="λ"
".zprofile"=""
"_vimrc"=""
"sln"=""
"kt"="𝙆"
"gif"=""
"gruntfile"=""
".bash_profile"=""
"sig"="λ"
"bat"=""
"js"=""
"pyc"=""
"dart"=""
"scss"=""
"fs"=""
".gitlab-ci.yml"=""
"ini"=""
"cs"=""
"md"=""
"otf"=""
"rss"=""
"psb"=""
"rproj"=""
"less"=""
"pck"=""
"rmd"=""
"haml"=""
"rlib"=""
"webpack"=""
"r"=""
".zshenv"=""
"erb"=""
"svelte"=""
"slim"=""
"ico"=""
"procfile"=""
"cob"=""
"png"=""
"pm"=""
"webmanifest"=""
"php"=""
"pdf"=""
".settings.json"=""
"yaml"=""
"package.json"=""
"sass"=""
".zshrc"=""
"diff"=""
"nim"="👑"
"mustache"=""
"ml"="λ"
"mix.lock"=""
"yml"=""
"cpy"=""
".npmignore"=""
"tsx"=""
"markdown"=""
"ps1"=""
"ksh"=""
"jpg"=""
"java"=""
"config.ru"=""
"scala"=""
"import"=""
"Dockerfile"=""
"htm"=""
"hs"=""
"heex"=""
"gemspec"=""
".babelrc"=""
"gd"=""
"css"=""
"favicon.ico"=""
"material"=""
"f#"=""
"epp"=""
"csv"=""
"dump"=""
"pro"=""
".gitignore"=""
"doc"=""
"db"=""
"cxx"=""
"csh"=""
".gvimrc"=""
"dropbox"=""
"sqlite"=""
"bmp"=""
19 changes: 18 additions & 1 deletion helix-term/src/ui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -740,13 +740,30 @@ impl EditorView {
//-------------------------------
// Middle / File path / Title
//-------------------------------
let lang = doc.language_id().unwrap_or_default();
let dft_lsp_name = &"".to_owned();
let lsp_name = if doc.language_server().is_some() {
let cmd = if let Some(c) = doc.language_config() {
match &c.language_server {
None => dft_lsp_name,
Some(config) => {
&config.command
}
}
} else {
dft_lsp_name
};
cmd
} else {
dft_lsp_name
};
let title = {
let rel_path = doc.relative_path();
let path = rel_path
.as_ref()
.map(|p| p.to_string_lossy())
.unwrap_or_else(|| SCRATCH_BUFFER_NAME.into());
format!("{}{}", path, if doc.is_modified() { "[+]" } else { "" })
format!("{}{} ft:{} {} lsp: {}", path, if doc.is_modified() { "[+]" } else { "" }, lang, theme.get_ft_icon(&doc.extension()), lsp_name)
};

surface.set_string_truncated(
Expand Down
10 changes: 10 additions & 0 deletions helix-view/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ pub struct Document {
}

use std::{fmt, mem};

impl fmt::Debug for Document {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Document")
Expand Down Expand Up @@ -931,6 +932,15 @@ impl Document {
.map(helix_core::path::get_relative_path)
}

pub fn extension(&self) -> String {
let dft = &PathBuf::default();
let path = self.path.as_ref().unwrap_or(dft).as_path();
match path.extension() {
None => "".into(),
Some(ext) => ext.to_string_lossy().to_string(),
}
}

// transact(Fn) ?

// -- LSP methods
Expand Down
24 changes: 24 additions & 0 deletions helix-view/src/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,22 @@ pub static BASE16_DEFAULT_THEME: Lazy<Theme> = Lazy::new(|| {
.expect("Failed to parse base 16 default theme")
});

pub static DEFAULT_FT_ICON: Lazy<String> = Lazy::new(|| {
"".to_owned()
});

// #[derive(Clone, Debug)]
// pub struct FiletypeIcon {
// // HashMap<String, Style>
// icon: String,
// }

// HashMap<String, FiletypeIcon>

pub static DEFAULT_FT_ICONS: Lazy<HashMap<String, String>> = Lazy::new(|| {
toml::from_slice(include_bytes!("../../ft_icons.toml")).expect("Failed to parse default file type icons")
});

#[derive(Clone, Debug)]
pub struct Loader {
user_dir: PathBuf,
Expand Down Expand Up @@ -95,6 +111,7 @@ pub struct Theme {
// tree-sitter highlight styles are stored in a Vec to optimize lookups
scopes: Vec<String>,
highlights: Vec<Style>,
icons: HashMap<String, String>,
}

impl<'de> Deserialize<'de> for Theme {
Expand Down Expand Up @@ -135,10 +152,13 @@ impl<'de> Deserialize<'de> for Theme {
}
}

let icons = DEFAULT_FT_ICONS.clone();

Ok(Self {
scopes,
styles,
highlights,
icons,
})
}
}
Expand Down Expand Up @@ -177,6 +197,10 @@ impl Theme {
.all(|color| !matches!(color, Some(Color::Rgb(..))))
})
}

pub fn get_ft_icon(&self, ft: &str) -> &str {
self.icons.get(ft).unwrap_or_else(||{&DEFAULT_FT_ICON})
}
}

struct ThemePalette {
Expand Down

0 comments on commit 1fc35ca

Please sign in to comment.