Skip to content

Commit a968db7

Browse files
authored
fix: Allow TURBO_EXTENDS in LSP diagnostics (#12770)
## Summary - Prevent the VS Code/LSP deprecated env-var diagnostic from flagging the valid `$TURBO_EXTENDS$` package-configuration sentinel. - Keeps other deprecated `$` syntax covered by the existing diagnostic. ## Tests - `cargo fmt --check` - `cargo test -p turborepo-lsp` - pre-push hook: `pnpm exec lint-staged`, `turbo run format check:toml`, `cargo fmt --check`, `cargo lint`, `cargo check --workspace` Closes #12769
1 parent 87d468b commit a968db7

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

  • crates/turborepo-lsp/src

crates/turborepo-lsp/src/lib.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ use turborepo_repository::{
4242
package_json::PackageJson,
4343
};
4444

45+
const TURBO_EXTENDS: &str = "$TURBO_EXTENDS$";
46+
4547
pub struct Backend {
4648
client: Client,
4749
repo_root: Arc<Mutex<Option<AbsoluteSystemPathBuf>>>,
@@ -879,6 +881,10 @@ impl Backend {
879881
{
880882
for depends_on in &array.elements {
881883
if let Some(string) = depends_on.as_string_lit().cloned() {
884+
if is_turbo_extends_sentinel(&string) {
885+
continue;
886+
}
887+
882888
let suffix = if let Some(suffix) = strip_lit_prefix(&string, "^") {
883889
diagnostics.push(Diagnostic {
884890
message: format!(
@@ -997,6 +1003,10 @@ fn strip_lit_prefix<'a>(s: &'a StringLit<'a>, prefix: &str) -> Option<StringLit<
9971003
})
9981004
}
9991005

1006+
fn is_turbo_extends_sentinel(string: &StringLit<'_>) -> bool {
1007+
string.value == TURBO_EXTENDS
1008+
}
1009+
10001010
/// remove quotes from a string range
10011011
fn collapse_string_range(range: jsonc_parser::common::Range) -> jsonc_parser::common::Range {
10021012
jsonc_parser::common::Range {
@@ -1078,3 +1088,33 @@ fn report_invalid_packages_and_tasks(
10781088
(Some(_), None) => {}
10791089
}
10801090
}
1091+
1092+
#[cfg(test)]
1093+
mod tests {
1094+
use std::borrow::Cow;
1095+
1096+
use jsonc_parser::{ast::StringLit, common::Range};
1097+
1098+
use super::is_turbo_extends_sentinel;
1099+
1100+
fn string_lit(value: &'static str) -> StringLit<'static> {
1101+
StringLit {
1102+
value: Cow::Borrowed(value),
1103+
range: Range {
1104+
start: 0,
1105+
end: value.len() + 2,
1106+
},
1107+
}
1108+
}
1109+
1110+
#[test]
1111+
fn detects_turbo_extends_sentinel() {
1112+
assert!(is_turbo_extends_sentinel(&string_lit("$TURBO_EXTENDS$")));
1113+
}
1114+
1115+
#[test]
1116+
fn does_not_treat_other_dollar_syntax_as_turbo_extends_sentinel() {
1117+
assert!(!is_turbo_extends_sentinel(&string_lit("$FOO")));
1118+
assert!(!is_turbo_extends_sentinel(&string_lit("^$TURBO_EXTENDS$")));
1119+
}
1120+
}

0 commit comments

Comments
 (0)