Skip to content

Commit

Permalink
render child docs
Browse files Browse the repository at this point in the history
  • Loading branch information
tsuf239 committed Sep 26, 2024
1 parent 9176564 commit be6d1da
Show file tree
Hide file tree
Showing 13 changed files with 200 additions and 13 deletions.
91 changes: 91 additions & 0 deletions packages/@winglang/wingc/src/lsp/hover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,97 @@ Json.stringify({});
"#,
);

test_hover_list!(
parent_class_docs_are_inherited_on_declaration,
r#"
/// Some parent docs
class Parent {
/// Some method docs
pub method() {}
}
class Child extends Parent {
//^
pub method() {}
}
new Child().method();
"#,
);

test_hover_list!(
parent_class_docs_are_inherited_on_method_declaration,
r#"
/// Some parent docs
class Parent {
/// Some method docs
pub method() {}
}
class Child extends Parent {
pub method() {}
//^
}
new Child().method();
"#,
);

test_hover_list!(
parent_class_docs_are_inherited_on_call,
r#"
/// Some parent docs
class Parent {
/// Some method docs
pub method() {}
}
class Child extends Parent {
pub method() {}
}
new Child().method();
//^
"#,
);

test_hover_list!(
parent_class_docs_are_inherited_on_method_call,
r#"
/// Some parent docs
class Parent {
/// Some method docs
pub method() {}
}
class Child extends Parent {
pub method() {}
//^
}
new Child().method();
//^
"#,
);

test_hover_list!(
parent_class_docs_are_overridden,
r#"
/// Some parent docs
class Parent {
/// Some method docs
pub method() {}
}
/// Some child docs
class Child extends Parent {
}
new Child().method();
//^
"#,
);

test_hover_list!(
ignoe_empty_lines_in_doc,
r#"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
source: packages/@winglang/wingc/src/lsp/hover.rs
---
contents:
kind: markdown
value: "```wing\nnew(): Child\n```\n---\nSome parent docs"
range:
start:
line: 11
character: 4
end:
line: 11
character: 9

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
source: packages/@winglang/wingc/src/lsp/hover.rs
---
contents:
kind: markdown
value: "```wing\nclass Child extends Parent {\n method(): void;\n}\n```\n---\nSome parent docs"
range:
start:
line: 7
character: 6
end:
line: 7
character: 11

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
source: packages/@winglang/wingc/src/lsp/hover.rs
---
contents:
kind: markdown
value: "```wing\npreflight method(): void\n```\n---\nSome method docs"
range:
start:
line: 8
character: 6
end:
line: 8
character: 12

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
source: packages/@winglang/wingc/src/lsp/hover.rs
---
contents:
kind: markdown
value: "```wing\npreflight method(): void\n```\n---\nSome method docs"
range:
start:
line: 8
character: 6
end:
line: 8
character: 12

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
source: packages/@winglang/wingc/src/lsp/hover.rs
---
contents:
kind: markdown
value: "```wing\nnew(): Child\n```\n---\nSome child docs"
range:
start:
line: 11
character: 4
end:
line: 11
character: 9

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
source: libs/wingc/src/lsp/hover.rs
source: packages/@winglang/wingc/src/lsp/hover.rs
---
contents:
kind: markdown
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
source: libs/wingc/src/lsp/hover.rs
source: packages/@winglang/wingc/src/lsp/hover.rs
---
contents:
kind: markdown
value: "```wing\nclass Foo {\n // No public members\n}\n```"
value: "```wing\nclass Foo {\n // No public members\n}\n```\n---\nShared behavior between all Wing SDK resources.\n\n*@noinflight*"
range:
start:
line: 2
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
source: libs/wingc/src/lsp/hover.rs
source: packages/@winglang/wingc/src/lsp/hover.rs
---
contents:
kind: markdown
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
source: libs/wingc/src/lsp/hover.rs
source: packages/@winglang/wingc/src/lsp/hover.rs
---
contents:
kind: markdown
value: "```wing\nclass Foo {\n // No public members\n}\n```"
value: "```wing\nclass Foo {\n // No public members\n}\n```\n---\nShared behavior between all Wing SDK resources.\n\n*@noinflight*"
range:
start:
line: 4
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
source: libs/wingc/src/lsp/hover.rs
source: packages/@winglang/wingc/src/lsp/hover.rs
---
contents:
kind: markdown
value: "```wing\nclass Foo {\n // No public members\n}\n```"
value: "```wing\nclass Foo {\n // No public members\n}\n```\n---\nShared behavior between all Wing SDK resources.\n\n*@noinflight*"
range:
start:
line: 1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
source: libs/wingc/src/lsp/hover.rs
source: packages/@winglang/wingc/src/lsp/hover.rs
---
contents:
kind: markdown
Expand Down
34 changes: 30 additions & 4 deletions packages/@winglang/wingc/src/type_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::ast::{
};
use crate::comp_ctx::{CompilationContext, CompilationPhase};
use crate::diagnostic::{report_diagnostic, Diagnostic, DiagnosticAnnotation, DiagnosticSeverity, TypeError, WingSpan};
use crate::docs::Docs;
use crate::docs::{Docs, Documented};
use crate::file_graph::{File, FileGraph};
use crate::parser::normalize_path;
use crate::type_check::has_type_stmt::HasStatementVisitor;
Expand Down Expand Up @@ -4157,7 +4157,7 @@ This value is set by the CLI at compile time and can be used to conditionally co
let interface_spec = Interface {
name: iface.name.clone(),
fqn: format!("{}.{}", self.base_fqn_for_current_file(), iface.name),
docs: doc.as_ref().map_or(Docs::default(), |s| Docs::with_summary(s)),
docs: doc.as_ref().map_or(Docs::default(), |s: &String| Docs::with_summary(s)),
env: dummy_env,
extends: extend_interfaces.clone(),
phase: iface.phase,
Expand Down Expand Up @@ -4748,6 +4748,14 @@ This value is set by the CLI at compile time and can be used to conditionally co
}
}

let mut default_docs = Docs::default();
// if parent docs exist we use them as the defualt
if let Some(parent_class) = parent_class {
if let Some(parent_docs) = parent_class.docs() {
default_docs = parent_docs.clone();
}
}

// Create the resource/class type and add it to the current environment (so class implementation can reference itself)
let class_spec = Class {
name: ast_class.name.clone(),
Expand All @@ -4758,7 +4766,7 @@ This value is set by the CLI at compile time and can be used to conditionally co
is_abstract: false,
phase: ast_class.phase,
defined_in_phase: env.phase,
docs: stmt.doc.as_ref().map_or(Docs::default(), |s| Docs::with_summary(s)),
docs: stmt.doc.as_ref().map_or(default_docs, |s| Docs::with_summary(s)),
std_construct_args: ast_class.phase == Phase::Preflight,
lifts: None,
uid: self.types.class_counter,
Expand Down Expand Up @@ -4821,6 +4829,7 @@ This value is set by the CLI at compile time and can be used to conditionally co
method_def.access,
&mut class_env,
method_name,
parent_class,
);
method_types.insert(&method_name, method_type);
}
Expand All @@ -4839,6 +4848,7 @@ This value is set by the CLI at compile time and can be used to conditionally co
ast_class.initializer.access,
&mut class_env,
&init_symb,
parent_class,
);
method_types.insert(&init_symb, init_func_type);

Expand All @@ -4857,6 +4867,7 @@ This value is set by the CLI at compile time and can be used to conditionally co
ast_class.inflight_initializer.access,
&mut class_env,
&inflight_init_symb,
parent_class,
);
method_types.insert(&inflight_init_symb, inflight_init_func_type);

Expand Down Expand Up @@ -5759,6 +5770,7 @@ This value is set by the CLI at compile time and can be used to conditionally co
access: AccessModifier,
class_env: &mut SymbolEnv,
method_name: &Symbol,
parent_class: Option<UnsafeRef<Type>>,
) {
// Modify the method's type based on the fact we know it's a method and not just a function
let method_sig = method_type
Expand Down Expand Up @@ -5829,6 +5841,16 @@ This value is set by the CLI at compile time and can be used to conditionally co

let method_phase = method_type.as_function_sig().unwrap().phase;

// use the parent's method docs as default, if exist.
let mut default_method_docs = None;
if let Some(parent_class) = parent_class {
if let Some(c) = parent_class.as_class() {
if let Some(parent_method) = c.methods(true).find(|m| m.1.name.eq(&method_name)) {
default_method_docs = parent_method.1.docs;
}
}
};

match class_env.define(
method_name,
SymbolKind::make_member_variable(
Expand All @@ -5838,7 +5860,11 @@ This value is set by the CLI at compile time and can be used to conditionally co
instance_type.is_none(),
method_phase,
access,
method_def.doc.as_ref().map(|s| Docs::with_summary(s)),
method_def
.doc
.as_ref()
.map(|s| Docs::with_summary(s))
.or(default_method_docs),
),
access,
StatementIdx::Top,
Expand Down

0 comments on commit be6d1da

Please sign in to comment.