Skip to content

Commit

Permalink
updates to display of docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Vasilevsky committed Aug 16, 2024
1 parent 15c9a8b commit 2526a01
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
30 changes: 17 additions & 13 deletions compiler/qsc_doc_gen/src/generate_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct Compilation {
/// Current package id when provided.
current_package_id: Option<PackageId>,
/// Aliases for packages.
package_aliases: FxHashMap<PackageId, Arc<str>>, // TODO: Change to dependencies.
dependencies: FxHashMap<PackageId, Arc<str>>,
}

impl Compilation {
Expand Down Expand Up @@ -77,7 +77,7 @@ impl Compilation {
Self {
package_store,
current_package_id,
package_aliases,
dependencies: package_aliases,
}
}
}
Expand Down Expand Up @@ -182,7 +182,7 @@ pub fn generate_docs(
}

_ => {
if let Some(alias) = compilation.package_aliases.get(&package_id) {
if let Some(alias) = compilation.dependencies.get(&package_id) {
// This is a direct dependency of the user code.
package_kind = PackageKind::AliasedPackage(alias.to_string());
} else {
Expand Down Expand Up @@ -297,15 +297,12 @@ fn generate_file(
let metadata = get_metadata(package_kind, ns.clone(), item, display)?;

let doc = increase_header_level(&item.doc);
let title = &metadata.title;
let full_name = metadata.fully_qualified_name();
let title = format!("{} {}", metadata.fully_qualified_name(), metadata.kind);
let sig = &metadata.signature;

let content = format!(
"# {title}
**Fully qualified name:** {full_name}
```qsharp
{sig}
```
Expand Down Expand Up @@ -387,6 +384,18 @@ enum MetadataKind {
Export,
}

impl Display for MetadataKind {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
let s = match &self {
MetadataKind::Function => "function",
MetadataKind::Operation => "operation",
MetadataKind::Udt => "user defined type",
MetadataKind::Export => "exported item",
};
write!(f, "{s}")
}
}

fn get_metadata(
package_kind: PackageKind,
ns: Rc<str>,
Expand Down Expand Up @@ -422,12 +431,7 @@ fn get_metadata(

Some(Metadata {
uid: format!("Qdk.{ns}.{name}"),
title: match &kind {
MetadataKind::Function => format!("{name} function"),
MetadataKind::Operation => format!("{name} operation"),
MetadataKind::Udt => format!("{name} user defined type"),
MetadataKind::Export => format!("{name} exported item"),
},
title: format!("{name} {kind}"),
topic: "managed-reference".to_string(),
kind,
package: package_kind,
Expand Down
7 changes: 1 addition & 6 deletions vscode/src/documentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,14 @@ export async function showDocumentationCommand(extensionUri: Uri) {
const worker = getCompilerWorker(compilerWorkerScriptPath);
const docFiles = await worker.getDocumentation(program.programConfig);

// const packageNameRegex = new RegExp("^qsharp.package: (.+)$", "m");
// let currentPackage = "";
// const namespaceRegex = new RegExp("^qsharp.namespace: (.+)$", "m");
// let currentNamespace = "";

const documentation: string[] = [];
for (const file of docFiles) {
// Some files may contain information other than documentation
// For example, table of content is a separate file in a special format
// We check presence of qsharp.name in metadata to make sure we take
// only files that contain documentation from some qsharp object.
if (file.metadata.indexOf("qsharp.name:") >= 0) {
documentation.push(file.contents);
documentation.push(file.contents);
}
}

Expand Down

0 comments on commit 2526a01

Please sign in to comment.