diff options
author | Roland Kovacs | 2022-04-05 00:56:14 +0000 |
---|---|---|
committer | GitHub | 2022-04-05 00:56:14 +0000 |
commit | d962e06e91b997813092cc5e49a800cc9d4f0ee1 (patch) | |
tree | 9ccbee392cbee6d0dc5e9c30bd73e44d5c47a444 /helix-term/src/ui | |
parent | 6fc6f87260a2f11a892f09678fc6c10b01e88e3f (diff) |
Add runtime language configuration (#1794) (#1866)
* Add runtime language configuration (#1794)
* Add set-language typable command to change the language of current buffer.
* Add completer for available language options.
* Update set-language to refresh language server as well
* Add language id based config lookup on `syntax::Loader`.
* Add `Document::set_language3` to set programming language based on language
id.
* Update `Editor::refresh_language_server` to try language detection only if
language is not already set.
* Remove language detection from Editor::refresh_language_server
* Move document language detection to where the scratch buffer is saved.
* Rename Document::set_language3 to Document::set_language_by_language_id.
* Remove unnecessary clone in completers::language
Diffstat (limited to 'helix-term/src/ui')
-rw-r--r-- | helix-term/src/ui/mod.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs index a90debdb..2dca870b 100644 --- a/helix-term/src/ui/mod.rs +++ b/helix-term/src/ui/mod.rs @@ -298,6 +298,27 @@ pub mod completers { }) } + pub fn language(editor: &Editor, input: &str) -> Vec<Completion> { + let matcher = Matcher::default(); + + let mut matches: Vec<_> = editor + .syn_loader + .language_configs() + .filter_map(|config| { + matcher + .fuzzy_match(&config.language_id, input) + .map(|score| (&config.language_id, score)) + }) + .collect(); + + matches.sort_unstable_by_key(|(_language, score)| Reverse(*score)); + + matches + .into_iter() + .map(|(language, _score)| ((0..), language.clone().into())) + .collect() + } + pub fn directory(_editor: &Editor, input: &str) -> Vec<Completion> { filename_impl(input, |entry| { let is_dir = entry.file_type().map_or(false, |entry| entry.is_dir()); |