Skip to content

Static hover #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 9, 2025
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
19 changes: 11 additions & 8 deletions Cargo.lock

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

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace.package]
version = "2.3.3"
version = "2.3.4"
edition = "2021"

[workspace]
Expand Down Expand Up @@ -39,6 +39,7 @@ info-provider = { path = "./crates/info-provider" }
crate_info = { path = "./crates/crate_info" }
async-recursion = { version = "1" }
byteorder = "1.5.0"

indexmap = "2.9.0"
regex = "1.11.1"
[patch.crates-io]
html2md = { git = "https://gitlab.com/o0Frederik0o/html2md" }
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
- [x] available versions
- [x] available features
- [x] crate description(README)
- [ ] Static
- [x] Static

### Code completion
- [ ] static manifest suggestions
Expand Down
56 changes: 47 additions & 9 deletions crates/lsp/src/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ use tower_lsp::lsp_types::{
CodeActionProviderCapability, CodeActionResponse, Command, CompletionItem, CompletionItemKind,
CompletionOptions, CompletionParams, CompletionResponse, CompletionTextEdit,
DidChangeTextDocumentParams, DidChangeWorkspaceFoldersParams, DidOpenTextDocumentParams,
DocumentFormattingParams, ExecuteCommandParams, Hover, HoverParams, HoverProviderCapability,
InlayHint, InlayHintKind, InlayHintParams, MessageType, OneOf, Position, Range,
ServerCapabilities, ServerInfo, SignatureHelpOptions, TextDocumentSyncCapability,
TextDocumentSyncKind, TextDocumentSyncOptions, TextEdit, Url, WorkspaceEdit,
WorkspaceFoldersServerCapabilities, WorkspaceServerCapabilities,
DocumentFormattingParams, ExecuteCommandParams, Hover, HoverContents, HoverParams,
HoverProviderCapability, InlayHint, InlayHintKind, InlayHintParams, MarkupKind, MessageType,
OneOf, Position, Range, ServerCapabilities, ServerInfo, SignatureHelpOptions,
TextDocumentSyncCapability, TextDocumentSyncKind, TextDocumentSyncOptions, TextEdit, Url,
WorkspaceEdit, WorkspaceFoldersServerCapabilities, WorkspaceServerCapabilities,
};
use tower_lsp::{
async_trait,
Expand Down Expand Up @@ -587,6 +587,40 @@ impl LanguageServer for Context {
return Ok(Some(h));
}

let path = lock
.get_path(
&uri,
params.text_document_position_params.position.line,
params.text_document_position_params.position.character,
)
.await;
if let (Some(last), Some(path)) = (path.as_ref().and_then(|v| v.last()), &path) {
let p = path
.iter()
.map(|v| v.tyoe.to_string())
.collect::<Vec<String>>();
let detail = try_option!(lock.static_data.get_detail(&p, 0, last.is_value()));
let start = try_option!(lock.get_offset(&uri, last.range.start as usize));
let end = try_option!(lock.get_offset(&uri, last.range.end as usize));

return Ok(Some(Hover {
contents: HoverContents::Markup(tower_lsp::lsp_types::MarkupContent {
kind: MarkupKind::PlainText,
value: detail,
}),
range: Some(Range::new(
Position {
line: start.0 as u32,
character: start.1 as u32,
},
Position {
line: end.0 as u32,
character: end.1 as u32,
},
)),
}));
}

Ok(None)
}

Expand Down Expand Up @@ -615,14 +649,14 @@ impl LanguageServer for Context {
let start = try_option!(lock.get_offset(&uri, dep.start as usize));
let end = try_option!(lock.get_offset(&uri, dep.end as usize));

return Ok(Some(CompletionResponse::Array(
let out = Ok(Some(CompletionResponse::Array(
info.into_iter()
.enumerate()
.map(|(i, v)| CompletionItem {
label: v.name.clone(),
kind: Some(CompletionItemKind::MODULE),
label: format!("{i}. {}", v.name.clone()),
// kind: Some(CompletionItemKind::MODULE),
detail: v.description,
preselect: Some(v.exact_match),
// preselect: Some(v.exact_match),
sort_text: Some(format!("{:06}", i)),
text_edit: Some(CompletionTextEdit::Edit(TextEdit {
range: Range {
Expand Down Expand Up @@ -666,6 +700,10 @@ impl LanguageServer for Context {
})
.collect(),
)));
self.client
.log_message(MessageType::INFO, format!("{:#?}", out))
.await;
return out;
}
if let DepSource::Version { value, registry } = &dep.data.source {
if value.value.contains(pos) {
Expand Down
188 changes: 0 additions & 188 deletions crates/old/parser/cargo.json

This file was deleted.

2 changes: 1 addition & 1 deletion crates/old/parser/src/raw_to_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl From<&Table> for Tree {
let value = Value::from(value);
TreeValue {
value: match value.range() == Some(key.range) {
true => Value::NoContent,
true => value,
false => value,
},
key,
Expand Down
5 changes: 5 additions & 0 deletions crates/parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,8 @@ info-provider = { workspace = true }
rust-version.workspace = true
tokio = { workspace = true, features = ["sync"] }
async-recursion.workspace = true
indexmap = { workspace = true, features = ["serde"] }
regex.workspace = true

[dev-dependencies]
tokio = { workspace = true, features = ["full"] }
Loading