Skip to content

Commit

Permalink
0.0.2: Bugfixes
Browse files Browse the repository at this point in the history
Fix a bug where hovering over invalid region returned dependency info for the last available dependency in a file
  • Loading branch information
osiewicz committed Jul 3, 2024
1 parent 810cdc8 commit 6231588
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "package-version-server"
version = "0.1.0"
version = "0.0.2"
edition = "2021"
authors = ["Zed Team <[email protected]>"]
license = "MIT"
Expand Down
14 changes: 9 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ impl LanguageServer for Backend {
return Ok(None);
};

let package_name_pair =
parser::extract_package_name(document, params.text_document_position_params.position);

let Some(package_name) = package_name_pair else {
let Some(package_name) =
parser::extract_package_name(document, params.text_document_position_params.position)
else {
return Ok(None);
};

let meta = fetch_latest_version(&package_name)
.await
.ok_or_else(tower_lsp::jsonrpc::Error::internal_error)?;
Expand Down Expand Up @@ -131,7 +131,11 @@ async fn fetch_latest_version(package_name: &str) -> Option<MetadataFromRegistry

#[tokio::main]
async fn main() {
if let Some(_) = std::env::args().nth(1).filter(|arg| arg == "--version") {
if std::env::args()
.nth(1)
.filter(|arg| arg == "--version")
.is_some()
{
println!("package-version-server {}", env!("CARGO_PKG_VERSION"));
return;
}
Expand Down
10 changes: 4 additions & 6 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ pub fn extract_package_name(text: Arc<str>, position: Position) -> Option<String
(pair
key: (string (string_content) @name)
value: (string)
)
)
) @_dep_specifier
)+
(#any-of? @root_name "dependencies" "devDependencies" "peerDependencies" "optionalDependencies" "bundledDependencies" "bundleDependencies")
)+
"#;
Expand All @@ -33,10 +33,9 @@ pub fn extract_package_name(text: Arc<str>, position: Position) -> Option<String

let root_node = tree.root_node();
let matches = cursor.matches(&query, root_node, text.as_bytes());
let mut package_name = None;
let capture_names = query.capture_names();
for m in matches {
package_name.take();
let mut package_name = None;
let mut matched = false;
for capture in m.captures {
let capture_name = capture_names[capture.index as usize];
Expand All @@ -52,8 +51,7 @@ pub fn extract_package_name(text: Arc<str>, position: Position) -> Option<String
return package_name;
}
}

package_name
None
}

#[cfg(test)]
Expand Down

0 comments on commit 6231588

Please sign in to comment.