aboutsummaryrefslogtreecommitdiff
path: root/helix-view/src
diff options
context:
space:
mode:
authorKevin Sjöberg2022-01-15 06:23:06 +0000
committerGitHub2022-01-15 06:23:06 +0000
commit3a34036310d502fe99887c7f15f02784475d6dc5 (patch)
treef5b7ab4383e631bc9563ee9dc467dac89e65e70a /helix-view/src
parent97e6f2a38f28bf0051b96fa6f0f5786746b83e74 (diff)
Use the correct language ID for JavaScript & TypeScript (#1466)
* Use correct language ID for JavaScript/TypeScript * Add missing slash * Only calculate fallback when needed
Diffstat (limited to 'helix-view/src')
-rw-r--r--helix-view/src/document.rs18
-rw-r--r--helix-view/src/editor.rs7
2 files changed, 20 insertions, 5 deletions
diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs
index 9652d7b3..579349ee 100644
--- a/helix-view/src/document.rs
+++ b/helix-view/src/document.rs
@@ -844,6 +844,24 @@ impl Document {
.map(|language| language.scope.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
+ .as_ref()
+ .and_then(|config| config.language_server.as_ref())
+ .and_then(|lsp_config| lsp_config.language_id.as_ref())
+ .map_or_else(
+ || {
+ self.language()
+ .and_then(|s| s.rsplit_once('.'))
+ .map(|(_, language_id)| language_id)
+ },
+ |language_id| Some(language_id.as_str()),
+ )
+ }
+
/// Corresponding [`LanguageConfiguration`].
pub fn language_config(&self) -> Option<&LanguageConfiguration> {
self.language.as_deref()
diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs
index f4b0f73e..7406b475 100644
--- a/helix-view/src/editor.rs
+++ b/helix-view/src/editor.rs
@@ -307,11 +307,8 @@ impl Editor {
if let Some(language_server) = doc.language_server() {
tokio::spawn(language_server.text_document_did_close(doc.identifier()));
}
- let language_id = doc
- .language()
- .and_then(|s| s.split('.').last()) // source.rust
- .map(ToOwned::to_owned)
- .unwrap_or_default();
+
+ let language_id = doc.language_id().map(ToOwned::to_owned).unwrap_or_default();
// TODO: this now races with on_init code if the init happens too quickly
tokio::spawn(language_server.text_document_did_open(