-
Notifications
You must be signed in to change notification settings - Fork 122
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
LSP inlay hints for str, int, float, bool, any types #1431
Conversation
Signed-off-by: shruti2522 <shruti.apc01@gmail.com>
Pull Request Test Coverage Report for Build 9631229019Details
💛 - Coveralls |
KCL Inlay Hints1. Introduction
2. Design principlesTypeKind::Str|Int|Float|Bool|Any
TypeKind::Schema
TypeKind::Function
TypeKind::List
TypeKind::Dict
TypeKind::NumberMultiplier
TypeKind::Union
|
Signed-off-by: shruti2522 <shruti.apc01@gmail.com>
Good Job! 👍 I will only add one implementation point: we only need to display hint for left valued variables without explicit type annotations. |
for func definition, I think the first
for func call, y is the argument. x is not type for y, it is a param name in func definition, so the hint
I don’t recommend you to complete all the work in one PR, so you can put the design doc in the track issue instead of the PR. |
Signed-off-by: shruti2522 <shruti.apc01@gmail.com>
Pull Request Test Coverage Report for Build 9763995728Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
for symbol_ref in symbols { | ||
if let Some(symbol) = gs.get_symbols().get_symbol(*symbol_ref) { | ||
let (start, end) = symbol.get_range(); | ||
if has_type_assignment(program, &start) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this information should be obtained by extending the API of symbol, such as is_declaration/as_declaration (in the sema module), rather than recalculating it in the syntax tree, because for a large number of symbol computations, it requires a lot of computation. cc @He1pa Could you help review it and give more comments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also think that hint information should not be calculated here. Perhaps it is more appropriate to calculate it when traversing the AST in AdvancedResolver. My suggestion is to store hint-related information in the symbol's sema_info. You can abstract a struct to record this information, and use this struct toconstruct the results in lsp.
use lsp_types::{InlayHint, InlayHintLabelPart, Position as LspPosition, Range}; | ||
use std::convert::TryInto; | ||
|
||
pub fn inlay_hints(file: &str, gs: &GlobalState, program: &Program) -> Option<Vec<InlayHint>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add more comments on public functions.
match &ty.kind { | ||
TypeKind::Str | TypeKind::Bool | TypeKind::Int | TypeKind::Float | TypeKind::Any => { | ||
label_parts.push(InlayHintLabelPart { | ||
value: format!("[: {}]", ty.ty_str()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
value: format!("[: {}]", ty.ty_str()), | |
value: format!(": {}", ty.ty_str()), |
In addition to assign_stmt, other syntax including types and variables that may needs inlay hints.
pub struct LambdaExpr {
pub args: Option<NodeRef<Arguments>>,
pub body: Vec<NodeRef<Stmt>>,
pub return_ty: Option<NodeRef<Type>>,
} func = lambda x[: any] [-> any] {
x
}
values = [1, 2, 3]
data = all x [: [int]] in values {
x >= 1
} |
let mut label_parts = Vec::new(); | ||
|
||
match &ty.kind { | ||
TypeKind::Str | TypeKind::Bool | TypeKind::Int | TypeKind::Float | TypeKind::Any => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function type and schema type should also be included.
Hello @shruti2522 I've leaved some comments and You can open other PRs to deal this and I will merge this PR to test. |
okay @Peefy, I will open another PR to resolve above. |
1. Does this PR affect any open issues?(Y/N) and add issue references (e.g. "fix #123", "re #123".):
fix #1244
2. What is the scope of this PR (e.g. component or file name):
kclvm/tools/src/LSP/src/inlay_hints.rs
kclvm/tools/src/LSP/src/capabilities.rs
kclvm/tools/src/LSP/src/lib.rs
kclvm/tools/src/LSP/src/main.rs
kclvm/tools/src/LSP/src/request.rs
kclvm/tools/src/LSP/Cargo.toml
3. Provide a description of the PR(e.g. more details, effects, motivations or doc link):
4. Are there any breaking changes?(Y/N) and describe the breaking changes(e.g. more details, motivations or doc link):
5. Are there test cases for these changes?(Y/N) select and add more details, references or doc links:
cc @He1pa @Peefy