Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 12 additions & 9 deletions packages/core/src/analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1562,10 +1562,10 @@ fn add_default_export_name(
component_names.insert("default".to_string());
}
}
ExportDefaultDeclarationKind::Identifier(identifier) => {
if local_component_names.contains(identifier.name.as_str()) {
component_names.insert("default".to_string());
}
ExportDefaultDeclarationKind::Identifier(identifier)
if local_component_names.contains(identifier.name.as_str()) =>
{
component_names.insert("default".to_string());
}
ExportDefaultDeclarationKind::ArrowFunctionExpression(_)
| ExportDefaultDeclarationKind::FunctionExpression(_)
Expand Down Expand Up @@ -2478,8 +2478,8 @@ mod tests {
&mut ranges,
&mut locals,
);
assert!(ranges.is_empty());
assert!(locals.is_empty());
assert_eq!(ranges.len(), 0);
assert_eq!(locals.len(), 0);
}

#[rstest]
Expand Down Expand Up @@ -2652,8 +2652,8 @@ mod tests {
);
}
}
assert!(local_component_names.is_empty());
assert!(pattern_component_names.is_empty());
assert_eq!(local_component_names.len(), 0);
assert_eq!(pattern_component_names.len(), 0);
}

#[test]
Expand Down Expand Up @@ -2734,6 +2734,9 @@ mod tests {
};

collector.track_function_declaration(function);
assert!(collector.per_component_funcs.expect("func map")["Component"].is_empty());
assert_eq!(
collector.per_component_funcs.expect("func map")["Component"].len(),
0
);
}
}
10 changes: 4 additions & 6 deletions packages/core/tests/conformance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,7 @@ fn conformance_corpus_matches_oracle_goldens() {

let mut goldens = Vec::new();
collect_goldens(&goldens_root, &mut goldens);
assert!(
!goldens.is_empty(),
"no goldens found under {goldens_root:?}"
);
assert_ne!(goldens.len(), 0, "no goldens found under {goldens_root:?}");

let mut passed = 0usize;
let mut failures: Vec<String> = Vec::new();
Expand Down Expand Up @@ -142,8 +139,9 @@ fn conformance_corpus_matches_oracle_goldens() {

let total = goldens.len();
eprintln!("conformance: {passed}/{total} passing");
assert!(
failures.is_empty(),
assert_eq!(
failures.len(),
0,
"{}/{} fixtures failed:\n{}",
failures.len(),
total,
Expand Down
8 changes: 4 additions & 4 deletions packages/lsp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@
.iter()
.filter(|(line, character, _, _)| *line == 1 && *character >= 20)
.collect::<Vec<_>>();
assert!(!client_jsx_tuples.is_empty());
assert_ne!(client_jsx_tuples.len(), 0);

Check failure on line 411 in packages/lsp/src/main.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

used `assert!` to check that a value is not empty

Check failure on line 411 in packages/lsp/src/main.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

used `assert!` to check that a value is not empty
assert!(
client_jsx_tuples
.iter()
Expand Down Expand Up @@ -484,7 +484,7 @@
assert_eq!(legend.token_types.len(), 2);
assert_eq!(legend.token_types[0].as_str(), "rscClientComponent");
assert_eq!(legend.token_types[1].as_str(), "rscServerComponent");
assert!(legend.token_modifiers.is_empty());
assert_eq!(legend.token_modifiers.len(), 0);

Check failure on line 487 in packages/lsp/src/main.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

used `assert!` to check that a value is empty

Check failure on line 487 in packages/lsp/src/main.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

used `assert!` to check that a value is empty
}

#[test]
Expand All @@ -502,7 +502,7 @@
fn path_from_uri_returns_document_tsx_for_non_file_url_with_empty_path() {
let url = Url::parse("untitled:").expect("parse empty untitled URL");
assert!(url.to_file_path().is_err());
assert!(url.path().is_empty());
assert_eq!(url.path(), "");

Check failure on line 505 in packages/lsp/src/main.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

used `assert!` to check that a value is empty

Check failure on line 505 in packages/lsp/src/main.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

used `assert!` to check that a value is empty

let result = path_from_uri(&url);

Expand Down Expand Up @@ -624,7 +624,7 @@
let tuples = semantic_token_tuples_for_source(&entry_path, &entry_source);

// The imported Star is a client component, so its JSX usage in entry.tsx is colored as client (token_type 0).
assert!(!tuples.is_empty());
assert_ne!(tuples.len(), 0);

Check failure on line 627 in packages/lsp/src/main.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

used `assert!` to check that a value is not empty

Check failure on line 627 in packages/lsp/src/main.rs

View workflow job for this annotation

GitHub Actions / test (windows-latest)

used `assert!` to check that a value is not empty
let star_jsx = tuples
.iter()
.find(|(line, character, _, _)| *line == 1 && *character >= 20);
Expand Down
44 changes: 39 additions & 5 deletions packages/zed/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ use zed_extension_api::{self as zed, Result};
const BINARY_NAME: &str = "rcl-lsp";
const REPOSITORY: &str = "dev-five-git/react-component-lens";

/// The version number inside a release tag.
///
/// This repository's releases are tagged by package, e.g.
/// `react-component-lens(packages/vscode/package.json)@1.0.5`, while the
/// `rcl-lsp` archives attached to them are named with the bare version
/// (`rcl-lsp-1.0.5-x86_64-pc-windows-msvc.zip`). A tag without an `@` is
/// returned as it is, minus a leading `v`.
fn release_version(tag: &str) -> &str {
let version = tag.rsplit('@').next().unwrap_or(tag);
version.strip_prefix('v').unwrap_or(version)
}

struct ReactComponentLensExtension {
cached_binary_path: Option<String>,
}
Expand Down Expand Up @@ -69,18 +81,17 @@ impl ReactComponentLensExtension {
zed::Os::Windows => "zip",
};

let asset_name = format!(
"{BINARY_NAME}-{version}-{arch_str}-{os_str}.{archive_ext}",
version = release.version,
);
// `release.version` is the whole tag, not a version number.
let version = release_version(&release.version);
let asset_name = format!("{BINARY_NAME}-{version}-{arch_str}-{os_str}.{archive_ext}");

let asset = release
.assets
.iter()
.find(|asset| asset.name == asset_name)
.ok_or_else(|| format!("no release asset found matching {asset_name:?}"))?;

let install_dir = format!("{BINARY_NAME}-{}", release.version);
let install_dir = format!("{BINARY_NAME}-{version}");
let binary_suffix = if matches!(platform, zed::Os::Windows) {
".exe"
} else {
Expand Down Expand Up @@ -141,3 +152,26 @@ impl zed::Extension for ReactComponentLensExtension {
}

zed::register_extension!(ReactComponentLensExtension);

#[cfg(test)]
mod tests {
use super::release_version;

#[test]
fn version_is_taken_from_a_package_scoped_tag() {
assert_eq!(
release_version("react-component-lens(packages/vscode/package.json)@1.0.5"),
"1.0.5"
);
assert_eq!(
release_version("rcl-zed(packages/zed/Cargo.toml)@1.0.5"),
"1.0.5"
);
}

#[test]
fn plain_tags_are_left_alone() {
assert_eq!(release_version("1.0.5"), "1.0.5");
assert_eq!(release_version("v1.0.5"), "1.0.5");
}
}
Loading
Loading