Skip to content

Commit

Permalink
Add completion labels
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinegb committed May 7, 2024
1 parent 71681a9 commit 255a338
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/wit.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use zed_extension_api::{register_extension, Extension, LanguageServerId, Worktree};
use zed_extension_api::{
lsp::{Completion, CompletionKind},
register_extension, CodeLabel, CodeLabelSpan, Extension, LanguageServerId, Worktree,
};

struct WitExtension;

Expand All @@ -25,6 +28,27 @@ impl Extension for WitExtension {
env: Default::default(),
})
}

fn label_for_completion(
&self,
_language_server_id: &LanguageServerId,
completion: Completion,
) -> Option<CodeLabel> {
// https://github.com/Michael-F-Bryan/wit-lsp/blob/main/crates/wit-language-server/src/ops/completion.rs#L110
let highlight_name = match completion.kind? {
CompletionKind::Struct | CompletionKind::Interface | CompletionKind::Module => {
Some("type".to_string())
}
CompletionKind::Keyword => Some("keyword".to_string()),
_ => None,
};

Some(CodeLabel {
spans: vec![CodeLabelSpan::literal(&completion.label, highlight_name)],
filter_range: (0..completion.label.len()).into(),
code: completion.label,
})
}
}

register_extension!(WitExtension);

0 comments on commit 255a338

Please sign in to comment.