Skip to content

Commit

Permalink
fix: dup inlay hint and padding for hints (#1474)
Browse files Browse the repository at this point in the history
* fix: dup inlay hint and padding for hints

Signed-off-by: peefy <[email protected]>

* docs: add dotnet sdk in readme

Signed-off-by: peefy <[email protected]>

---------

Signed-off-by: peefy <[email protected]>
  • Loading branch information
Peefy authored Jul 4, 2024
1 parent 0c18572 commit 34d0e46
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 76 deletions.
2 changes: 1 addition & 1 deletion README-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ KCL 是一个开源的基于约束的记录及函数语言并通过成熟的编
+ **API 亲和**:原生支持 [OpenAPI](https://github.com/kcl-lang/kcl-openapi)、 Kubernetes CRD, Kubernetes Resource Model (KRM) 等 API 生态规范
+ **开发友好**[语言工具](https://kcl-lang.io/docs/tools/cli/kcl/) (Format,Lint,Test,Vet,Doc, 包管理工具等) 和 [IDE 插件](https://kcl-lang.io/docs/tools/Ide/) 构建良好的研发体验
+ **安全可控**:面向领域,不原生提供线程、IO 等系统级功能,低噪音,低安全风险,易维护,易治理
+ **多语言 SDK**:Rust, Go, Python, Java 和 Node.js 等 SDK 满足不同场景和应用使用需求
+ **多语言 SDK**:Rust, Go, Python, .NET, Java 和 Node.js 等 SDK 满足不同场景和应用使用需求
+ **生态集成**:通过 [Kubectl KCL 插件](https://github.com/kcl-lang/kubectl-kcl)[Kustomize KCL 插件](https://github.com/kcl-lang/kustomize-kcl)[Helm KCL 插件](https://github.com/kcl-lang/helm-kcl)[KPT KCL SDK](https://github.com/kcl-lang/kpt-kcl) 或者 [Crossplane KCL 函数](https://github.com/kcl-lang/crossplane-kcl) 直接编辑、校验或者抽象资源

+ **生产可用**:广泛应用在蚂蚁集团平台工程及自动化的生产环境实践中
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ You can use KCL to
+ **API affinity**: Native support for ecological API specifications such as [OpenAPI](https://github.com/kcl-lang/kcl-openapi), Kubernetes CRD, Kubernetes Resource Model (KRM) spec.
+ **Developer-friendly**: Friendly development experiences with rich [language tools](https://kcl-lang.io/docs/tools/cli/kcl/) (Format, Lint, Test, Vet, Doc, package management tools etc.), and multiple [IDE extensions](https://kcl-lang.io/docs/tools/Ide/).
+ **Safety & maintainable**: Domain-oriented, no system-level functions such as native threads and IO, low noise and security risk, easy maintenance and governance.
+ **Rich multi-language SDK**: Rust, Go, Python, Java and Node.js SDKs meet different scenarios and application use prelude.
+ **Rich multi-language SDK**: Rust, Go, Python, .NET, Java and Node.js SDKs meet different scenarios and application use prelude.
+ **Integrations**: Abstract, mutate and validate manifests through [Kubectl KCL Plugin](https://github.com/kcl-lang/kubectl-kcl), [Kustomize KCL Plugin](https://github.com/kcl-lang/kustomize-kcl), [Helm KCL Plugin](https://github.com/kcl-lang/helm-kcl), [KPT KCL SDK](https://github.com/kcl-lang/kpt-kcl) or [Crossplane KCL Function](https://github.com/kcl-lang/crossplane-kcl).
+ **Production-ready**: Widely used in production practices of platform engineering and automation at Ant Group.

Expand Down
54 changes: 46 additions & 8 deletions kclvm/tools/src/LSP/src/inlay_hints.rs
Original file line number Diff line number Diff line change
@@ -1,35 +1,73 @@
use indexmap::IndexSet;
use kclvm_sema::core::symbol::SymbolHint;
use kclvm_sema::core::{global_state::GlobalState, symbol::KCLSymbol};
use lsp_types::{InlayHint, InlayHintLabelPart, Position as LspPosition};
use std::convert::TryInto;
use std::hash::Hash;

#[derive(Clone, Debug)]
struct KCLInlayHint {
/// The position of this hint.
pub position: LspPosition,

/// An inlay hint label part allows for interactive and composite labels
/// of inlay hints.
pub part: InlayHintLabelPart,
}

impl Hash for KCLInlayHint {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.position.line.hash(state);
self.position.character.hash(state);
self.part.value.hash(state);
}
}

impl PartialEq for KCLInlayHint {
fn eq(&self, other: &Self) -> bool {
self.position == other.position && self.part.value == other.part.value
}
}

impl Eq for KCLInlayHint {}

pub fn inlay_hints(file: &str, gs: &GlobalState) -> Option<Vec<InlayHint>> {
let mut inlay_hints: Vec<InlayHint> = vec![];
let mut inlay_hints: IndexSet<KCLInlayHint> = Default::default();
let sema_db = gs.get_sema_db();
if let Some(file_sema) = sema_db.get_file_sema(file) {
let symbols = file_sema.get_symbols();
for symbol_ref in symbols {
if let Some(symbol) = gs.get_symbols().get_symbol(*symbol_ref) {
if let Some(hint) = symbol.get_hint() {
inlay_hints.push(generate_inlay_hint(symbol, hint));
inlay_hints.insert(generate_inlay_hint(symbol, hint));
}
}
}
}
Some(inlay_hints)
Some(
inlay_hints
.into_iter()
.map(|h| into_lsp_inlay_hint(&h))
.collect(),
)
}

#[inline]
fn generate_inlay_hint(symbol: &KCLSymbol, hint: &SymbolHint) -> InlayHint {
fn generate_inlay_hint(symbol: &KCLSymbol, hint: &SymbolHint) -> KCLInlayHint {
let (part, position) = get_hint_label(symbol, &hint);
KCLInlayHint { position, part }
}

#[inline]
fn into_lsp_inlay_hint(hint: &KCLInlayHint) -> InlayHint {
InlayHint {
position,
label: lsp_types::InlayHintLabel::LabelParts(vec![part]),
position: hint.position.clone(),
label: lsp_types::InlayHintLabel::LabelParts(vec![hint.part.clone()]),
kind: None,
text_edits: None,
tooltip: None,
padding_left: Some(true),
padding_right: Some(true),
padding_left: None,
padding_right: None,
data: None,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,8 @@ Some(
kind: None,
text_edits: None,
tooltip: None,
padding_left: Some(
true,
),
padding_right: Some(
true,
),
padding_left: None,
padding_right: None,
data: None,
},
InlayHint {
Expand All @@ -48,12 +44,8 @@ Some(
kind: None,
text_edits: None,
tooltip: None,
padding_left: Some(
true,
),
padding_right: Some(
true,
),
padding_left: None,
padding_right: None,
data: None,
},
InlayHint {
Expand All @@ -74,12 +66,8 @@ Some(
kind: None,
text_edits: None,
tooltip: None,
padding_left: Some(
true,
),
padding_right: Some(
true,
),
padding_left: None,
padding_right: None,
data: None,
},
InlayHint {
Expand All @@ -100,12 +88,8 @@ Some(
kind: None,
text_edits: None,
tooltip: None,
padding_left: Some(
true,
),
padding_right: Some(
true,
),
padding_left: None,
padding_right: None,
data: None,
},
InlayHint {
Expand All @@ -126,12 +110,8 @@ Some(
kind: None,
text_edits: None,
tooltip: None,
padding_left: Some(
true,
),
padding_right: Some(
true,
),
padding_left: None,
padding_right: None,
data: None,
},
InlayHint {
Expand All @@ -152,12 +132,8 @@ Some(
kind: None,
text_edits: None,
tooltip: None,
padding_left: Some(
true,
),
padding_right: Some(
true,
),
padding_left: None,
padding_right: None,
data: None,
},
InlayHint {
Expand All @@ -178,12 +154,8 @@ Some(
kind: None,
text_edits: None,
tooltip: None,
padding_left: Some(
true,
),
padding_right: Some(
true,
),
padding_left: None,
padding_right: None,
data: None,
},
InlayHint {
Expand All @@ -204,12 +176,8 @@ Some(
kind: None,
text_edits: None,
tooltip: None,
padding_left: Some(
true,
),
padding_right: Some(
true,
),
padding_left: None,
padding_right: None,
data: None,
},
InlayHint {
Expand All @@ -230,12 +198,8 @@ Some(
kind: None,
text_edits: None,
tooltip: None,
padding_left: Some(
true,
),
padding_right: Some(
true,
),
padding_left: None,
padding_right: None,
data: None,
},
InlayHint {
Expand All @@ -256,12 +220,8 @@ Some(
kind: None,
text_edits: None,
tooltip: None,
padding_left: Some(
true,
),
padding_right: Some(
true,
),
padding_left: None,
padding_right: None,
data: None,
},
InlayHint {
Expand All @@ -282,12 +242,8 @@ Some(
kind: None,
text_edits: None,
tooltip: None,
padding_left: Some(
true,
),
padding_right: Some(
true,
),
padding_left: None,
padding_right: None,
data: None,
},
],
Expand Down

0 comments on commit 34d0e46

Please sign in to comment.