aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--helix-term/src/commands/lsp.rs5
-rw-r--r--helix-term/src/ui/completion.rs5
-rw-r--r--helix-term/src/ui/statusline.rs2
-rw-r--r--helix-view/src/document.rs16
4 files changed, 16 insertions, 12 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);
}
diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs
index c96f222d..0668e99d 100644
--- a/helix-view/src/document.rs
+++ b/helix-view/src/document.rs
@@ -926,22 +926,32 @@ impl Document {
}
/// Corresponding language scope name. Usually `source.<lang>`.
- pub fn language(&self) -> Option<&str> {
+ pub fn language_scope(&self) -> Option<&str> {
self.language
.as_ref()
.map(|language| language.scope.as_str())
}
+ /// Language name for the document. Corresponds to the `name` key in
+ /// `languages.toml` configuration.
+ pub fn language_name(&self) -> Option<&str> {
+ self.language
+ .as_ref()
+ .map(|language| language.language_id.as_str())
+ }
+
/// Language ID for the document. Either the `language-id` from the
/// `language-server` configuration, or the document language if no
/// `language-id` has been specified.
pub fn language_id(&self) -> Option<&str> {
- self.language_config()?
+ let language_config = self.language.as_deref()?;
+
+ language_config
.language_server
.as_ref()?
.language_id
.as_deref()
- .or_else(|| Some(self.language()?.rsplit_once('.')?.1))
+ .or(Some(language_config.language_id.as_str()))
}
/// Corresponding [`LanguageConfiguration`].