diff --git a/compiler/qsc_doc_gen/src/generate_docs.rs b/compiler/qsc_doc_gen/src/generate_docs.rs index 7622900805..183d340e0e 100644 --- a/compiler/qsc_doc_gen/src/generate_docs.rs +++ b/compiler/qsc_doc_gen/src/generate_docs.rs @@ -29,7 +29,7 @@ struct Compilation { /// Current package id when provided. current_package_id: Option, /// Aliases for packages. - package_aliases: FxHashMap>, // TODO: Change to dependencies. + dependencies: FxHashMap>, } impl Compilation { @@ -77,7 +77,7 @@ impl Compilation { Self { package_store, current_package_id, - package_aliases, + dependencies: package_aliases, } } } @@ -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 { @@ -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} ``` @@ -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, @@ -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, diff --git a/vscode/src/documentation.ts b/vscode/src/documentation.ts index 82ac932254..f9d068d11d 100644 --- a/vscode/src/documentation.ts +++ b/vscode/src/documentation.ts @@ -27,11 +27,6 @@ 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 @@ -39,7 +34,7 @@ export async function showDocumentationCommand(extensionUri: Uri) { // 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); } }