diff options
author | Michael Davis | 2022-08-30 01:59:45 +0000 |
---|---|---|
committer | GitHub | 2022-08-30 01:59:45 +0000 |
commit | 5f043dde56c20e694078ceb46aac5f053327196c (patch) | |
tree | 37892f2c929a8c3bf6a78fbd9173b78e3b50c356 /helix-term | |
parent | ae81fbdbf6e44cc6b2aa35876afab65055e40df5 (diff) |
Derive Document language name from languages.toml name key (#3338)
* Derive Document language name from `languages.toml` `name` key
This changes switches from deriving the language name from the
`languages.toml` `scope` key to `name` (`language_id` in the
`LanguageConfiguration` type). For the most part it works to derive the
language name from scope by chopping off `source.` or `rsplit_once` on
`.` but for some languages we have now like html (`text.html.basic`),
it doesn't. This also should be a more accurate fallback for the
`language_id` method which is used in LSP and currently uses the
`rsplit_once` strategy.
Here we expose the language's name as `language_name` on `Document` and
replace ad-hoc calculations of the language name with the new method.
This is most impactful for the `file-type` statusline element which is
using `language_id`.
* Use `Document::language_name` for the `file-type` statusline element
The `file-type` indicator element in the statusline was using
`Document::language_id` which is meant to be used to for telling
Language Servers what language we're using. That works for languages
with `language-server` configurations in `languages.toml` but shows
text otherwise. The new `Document::language_name` method from the
parent commit is a more accurate way to determine the language.
Diffstat (limited to 'helix-term')
-rw-r--r-- | helix-term/src/commands/lsp.rs | 5 | ||||
-rw-r--r-- | helix-term/src/ui/completion.rs | 5 | ||||
-rw-r--r-- | helix-term/src/ui/statusline.rs | 2 |
3 files changed, 3 insertions, 9 deletions
diff --git a/helix-term/src/commands/lsp.rs b/helix-term/src/commands/lsp.rs index 38507e4d..61eed638 100644 --- a/helix-term/src/commands/lsp.rs +++ b/helix-term/src/commands/lsp.rs @@ -863,10 +863,7 @@ pub fn signature_help_impl(cx: &mut Context, invoked: SignatureHelpInvoked) { } }; let doc = doc!(editor); - let language = doc - .language() - .and_then(|scope| scope.strip_prefix("source.")) - .unwrap_or(""); + let language = doc.language_name().unwrap_or(""); let signature = match response .signatures diff --git a/helix-term/src/ui/completion.rs b/helix-term/src/ui/completion.rs index 87913a8c..2d7d4f92 100644 --- a/helix-term/src/ui/completion.rs +++ b/helix-term/src/ui/completion.rs @@ -324,10 +324,7 @@ impl Component for Completion { // option.documentation let (view, doc) = current!(cx.editor); - let language = doc - .language() - .and_then(|scope| scope.strip_prefix("source.")) - .unwrap_or(""); + let language = doc.language_name().unwrap_or(""); let text = doc.text().slice(..); let cursor_pos = doc.selection(view.id).primary().cursor(text); let coords = helix_core::visual_coords_at_pos(text, cursor_pos, doc.tab_width()); diff --git a/helix-term/src/ui/statusline.rs b/helix-term/src/ui/statusline.rs index 75e5dbd7..b2836f50 100644 --- a/helix-term/src/ui/statusline.rs +++ b/helix-term/src/ui/statusline.rs @@ -329,7 +329,7 @@ fn render_file_type<F>(context: &mut RenderContext, write: F) where F: Fn(&mut RenderContext, String, Option<Style>) + Copy, { - let file_type = context.doc.language_id().unwrap_or("text"); + let file_type = context.doc.language_name().unwrap_or("text"); write(context, format!(" {} ", file_type), None); } |