use ide::{
Annotation, AnnotationKind, Assist, AssistKind, CallInfo, CompletionItem, CompletionItemKind,
CompletionRelevance, Documentation, FileId, FileRange, FileSystemEdit, Fold, FoldKind,
- Highlight, HlMod, HlPunct, HlRange, HlTag, Indel, InlayHint, InlayKind, InsertTextFormat,
- Markup, NavigationTarget, ReferenceAccess, RenameError, Runnable, Severity, SourceChange,
- StructureNodeKind, SymbolKind, TextEdit, TextRange, TextSize,
+ Highlight, HlMod, HlOperator, HlPunct, HlRange, HlTag, Indel, InlayHint, InlayKind,
+ InsertTextFormat, Markup, NavigationTarget, ReferenceAccess, RenameError, Runnable, Severity,
+ SourceChange, StructureNodeKind, SymbolKind, TextEdit, TextRange, TextSize,
};
use itertools::Itertools;
use serde_json::to_value;
HlTag::FormatSpecifier => semantic_tokens::FORMAT_SPECIFIER,
HlTag::Keyword => lsp_types::SemanticTokenType::KEYWORD,
HlTag::None => semantic_tokens::GENERIC,
- HlTag::Operator => lsp_types::SemanticTokenType::OPERATOR,
+ HlTag::Operator(op) => match op {
+ HlOperator::Bitwise => semantic_tokens::BITWISE,
+ HlOperator::Arithmetic => semantic_tokens::ARITHMETIC,
+ HlOperator::Logical => semantic_tokens::LOGICAL,
+ HlOperator::Comparision => semantic_tokens::COMPARISION,
+ HlOperator::Other => semantic_tokens::OPERATOR,
+ },
HlTag::StringLiteral => lsp_types::SemanticTokenType::STRING,
HlTag::UnresolvedReference => semantic_tokens::UNRESOLVED_REFERENCE,
HlTag::Punctuation(punct) => match punct {
}
}
-pub(crate) fn unresolved_code_action(
+pub(crate) fn code_action(
snap: &GlobalStateSnapshot,
- code_action_params: lsp_types::CodeActionParams,
assist: Assist,
- index: usize,
+ resolve_data: Option<(usize, lsp_types::CodeActionParams)>,
) -> Result<lsp_ext::CodeAction> {
- assert!(assist.source_change.is_none());
- let res = lsp_ext::CodeAction {
+ let mut res = lsp_ext::CodeAction {
title: assist.label.to_string(),
group: assist.group.filter(|_| snap.config.code_action_group()).map(|gr| gr.0),
kind: Some(code_action_kind(assist.id.1)),
edit: None,
is_preferred: None,
- data: Some(lsp_ext::CodeActionData {
- id: format!("{}:{}", assist.id.0, index.to_string()),
- code_action_params,
- }),
- };
- Ok(res)
-}
-
-pub(crate) fn resolved_code_action(
- snap: &GlobalStateSnapshot,
- assist: Assist,
-) -> Result<lsp_ext::CodeAction> {
- let change = assist.source_change.unwrap();
- let res = lsp_ext::CodeAction {
- edit: Some(snippet_workspace_edit(snap, change)?),
- title: assist.label.to_string(),
- group: assist.group.filter(|_| snap.config.code_action_group()).map(|gr| gr.0),
- kind: Some(code_action_kind(assist.id.1)),
- is_preferred: None,
data: None,
};
+ match (assist.source_change, resolve_data) {
+ (Some(it), _) => res.edit = Some(snippet_workspace_edit(snap, it)?),
+ (None, Some((index, code_action_params))) => {
+ res.data = Some(lsp_ext::CodeActionData {
+ id: format!("{}:{}", assist.id.0, index.to_string()),
+ code_action_params,
+ });
+ }
+ (None, None) => {
+ stdx::never!("assist should always be resolved if client can't do lazy resolving")
+ }
+ };
Ok(res)
}