on master help sign in
Use the correct language ID for JavaScript & TypeScript (#1466)
3a34036Kevin Sjöberg
helix-core/src/syntax.rs+1
@@ -95,6 +95,7 @@ pub struct LanguageServerConfiguration {
95 #[serde(default)]
95 #[serde(default)]
96 #[serde(skip_serializing_if = "Vec::is_empty")]
96 #[serde(skip_serializing_if = "Vec::is_empty")]
97 pub args: Vec<String>,
97 pub args: Vec<String>,
98+ pub language_id: Option<String>,
98}
99}
99
100
100#[derive(Debug, Serialize, Deserialize)]
101#[derive(Debug, Serialize, Deserialize)]
helix-term/src/application.rs+2−6
@@ -358,12 +358,8 @@ impl Application {
358
358
359 // trigger textDocument/didOpen for docs that are already open
359 // trigger textDocument/didOpen for docs that are already open
360 for doc in docs {
360 for doc in docs {
361− // TODO: extract and share with editor.open
362− let language_id = doc
361+ let language_id =
363− .language()
364− .and_then(|s| s.split('.').last()) // source.rust
365− .map(ToOwned::to_owned)
362+ doc.language_id().map(ToOwned::to_owned).unwrap_or_default();
366− .unwrap_or_default();
367
363
368 tokio::spawn(language_server.text_document_did_open(
364 tokio::spawn(language_server.text_document_did_open(
369 doc.url().unwrap(),
365 doc.url().unwrap(),
helix-view/src/document.rs+18
@@ -844,6 +844,24 @@ impl Document {
844 .map(|language| language.scope.as_str())
844 .map(|language| language.scope.as_str())
845 }
845 }
846
846
847+ /// Language ID for the document. Either the `language-id` from the
848+ /// `language-server` configuration, or the document language if no
849+ /// `language-id` has been specified.
850+ pub fn language_id(&self) -> Option<&str> {
851+ self.language
852+ .as_ref()
853+ .and_then(|config| config.language_server.as_ref())
854+ .and_then(|lsp_config| lsp_config.language_id.as_ref())
855+ .map_or_else(
856+ || {
857+ self.language()
858+ .and_then(|s| s.rsplit_once('.'))
859+ .map(|(_, language_id)| language_id)
860+ },
861+ |language_id| Some(language_id.as_str()),
862+ )
863+ }
864+
847 /// Corresponding [`LanguageConfiguration`].
865 /// Corresponding [`LanguageConfiguration`].
848 pub fn language_config(&self) -> Option<&LanguageConfiguration> {
866 pub fn language_config(&self) -> Option<&LanguageConfiguration> {
849 self.language.as_deref()
867 self.language.as_deref()
helix-view/src/editor.rs+2−5
@@ -307,11 +307,8 @@ impl Editor {
307 if let Some(language_server) = doc.language_server() {
307 if let Some(language_server) = doc.language_server() {
308 tokio::spawn(language_server.text_document_did_close(doc.identifier()));
308 tokio::spawn(language_server.text_document_did_close(doc.identifier()));
309 }
309 }
310− let language_id = doc
310+
311− .language()
312− .and_then(|s| s.split('.').last()) // source.rust
313− .map(ToOwned::to_owned)
311+ let language_id = doc.language_id().map(ToOwned::to_owned).unwrap_or_default();
314− .unwrap_or_default();
315
312
316 // TODO: this now races with on_init code if the init happens too quickly
313 // TODO: this now races with on_init code if the init happens too quickly
317 tokio::spawn(language_server.text_document_did_open(
314 tokio::spawn(language_server.text_document_did_open(
languages.toml+3−3
@@ -128,7 +128,7 @@ roots = []
128comment-token = "//"
128comment-token = "//"
129# TODO: highlights-jsx, highlights-params
129# TODO: highlights-jsx, highlights-params
130
130
131−language-server = { command = "typescript-language-server", args = ["--stdio"] }
131+language-server = { command = "typescript-language-server", args = ["--stdio"], language-id = "javascript" }
132indent = { tab-width = 2, unit = " " }
132indent = { tab-width = 2, unit = " " }
133
133
134[[language]]
134[[language]]
@@ -140,7 +140,7 @@ shebangs = []
140roots = []
140roots = []
141# TODO: highlights-jsx, highlights-params
141# TODO: highlights-jsx, highlights-params
142
142
143−language-server = { command = "typescript-language-server", args = ["--stdio"] }
143+language-server = { command = "typescript-language-server", args = ["--stdio"], language-id = "typescript"}
144indent = { tab-width = 2, unit = " " }
144indent = { tab-width = 2, unit = " " }
145
145
146[[language]]
146[[language]]
@@ -151,7 +151,7 @@ file-types = ["tsx"]
151roots = []
151roots = []
152# TODO: highlights-jsx, highlights-params
152# TODO: highlights-jsx, highlights-params
153
153
154−language-server = { command = "typescript-language-server", args = ["--stdio"] }
154+language-server = { command = "typescript-language-server", args = ["--stdio"], language-id = "typescriptreact" }
155indent = { tab-width = 2, unit = " " }
155indent = { tab-width = 2, unit = " " }
156
156
157[[language]]
157[[language]]