Skip to content
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

Output cross-language names in generated docs #130

Merged
merged 8 commits into from
Aug 6, 2018

Conversation

RomainMuller
Copy link
Contributor

Each Target implementation can contribute to this process by providing
two static functions that allow the sphinx generator to obtain:

  • The package coordinates in the "standard" registry (e.g: maven) for an
    assembly
  • The native name (or names) for a given Type. There can be multiple
    names in case the artifacts can be used across different languages,
    for example Javascript & TypeScript share names, but InterfaceTypes
    are not visible in Javascript.

The C# names are not included, because the process to come up with those
names is factored in the C# code, and the dis-ambiguation is complex to
reproduce. This omission will be corrected at a later point in time.

Fixes #74

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Each `Target` implementation can contribute to this process by providing
two static functions that allow the sphinx generator to obtain:
* The package coordinates in the "standard" registry (e.g: maven) for an
  assembly
* The native name (or names) for a given `Type`. There can be multiple
  names in case the artifacts can be used across different languages,
  for example Javascript & TypeScript share names, but `InterfaceType`s
  are not visible in Javascript.

The C# names are not included, because the process to come up with those
names is factored in the C# code, and the dis-ambiguation is complex to
reproduce. This omission will be corrected at a later point in time.

Fixes #74
@@ -16,7 +16,7 @@ import { VERSION } from '../lib/version';
const argv = yargs
.usage('Usage: jsii-pacmak [-t target,...] [-o outdir] [package-dir]')
.option('targets', {
alias: 't',
alias: ['target', 't'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -106,6 +107,21 @@ export abstract class Target {
}

export interface TargetConstructor {
/**
* Provides the coordinates of an assembly in the usual package repository for the target.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explain what "coordinates" mean in this context. Maybe provide example(s)

&& (parsedVersion.major !== 0 ? parsedVersion.inc('major')
: parsedVersion.inc('minor'));
return {
repository: 'Maven',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maven Central?

* @param assm the assembly for which coodinates are requested.
* @return the name of the repository, and the coordinates within it.
*/
toPackageCoordinates?: (assm: spec.Assembly) => { repository: string, coordinates: string };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a url?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought so. But how to we format the link? I kinda punted this for later, but if you have an idea...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the sphinx docs? Maybe something like:

<a href="link">View in ${repository}</a>

};
}

public static toNativeNames(type: spec.Type, options: any) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reuse this method in java_generator.toNativeFqn

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to, but the java generator's toNativeFqn only has a fqn(string) available, because it needs to also be able to render names for TypeRefs.

public static toPackageCoordinates(assm: spec.Assembly) {
return {
repository: 'NPM',
coordinates: JSON.stringify({ [assm.name]: `^${assm.version}` }, null, 2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can also do something like:

npm i ${assm.name}@${assm.version}

Add another field to coordinates? (usage)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea.

@@ -46,6 +47,11 @@ class SphinxDocsGenerator extends Generator {
this.code.indentation = 3;
}

public async load(packageRoot: string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we shouldn't just include set of target constructors as part of load. It is available in the outer scope.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we can couple everything to everything else. Doesn't mean it's a good idea...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep it like this for now until the 2nd case where a generator will need this info


.. group-tab:: Maven

::
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't that be .. code-block:: or something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When using code-block, the "title" of the tab must be a valid syntax highlighter... And that's to the experience I want (would have Maven Central tab require to be named XML).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the titles should actually be the language name and not the repository name.

Also, you could have full control over the tab name if you just embed a code-block in it:

.. group-tab:: MyTitle

    .. code-block:: js

        console.log('hello, world')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mind you, this will not render the same. But since we want to possibly also have a URL and "usage", this is probably something that's going to fly anyway :)

@@ -1,6 +1,30 @@
@scope/jsii-calc-lib
====================

.. tabs::

.. group-tab:: Maven
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The names of the group tabs should align with the names of the code tabs, so they will switch together

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can do, but I am not a fan of labelling the maven POM dependency blob with Java. In this case, what if we want to also provide a gradle instruction?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also provide gradle instructions (and probably also "yarn").


.. code-tab:: javascript

Value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think typescript and javascript also need the require statement:

JavaScript:

const { Value } = require('jsii-calc-lib');

TypeScript:

import { Value } from 'jsii-calc-lib'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't we say we wanted to encourage people using import lib = require('lib');? This would go against this guideline...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's true. But I can't think of a way to express this in a nicer way, and the name of the import is important here. Maybe:

import jsiiCalcLib = require('jsii-calc-lib');
jsiiCalcLib.Value

But that looks ugly.
I think import {} is fine here. The CDK examples and code should still use namespaced imports, but this is "The Right" way to express this in JS/TypeScript.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fair :)

@eladb
Copy link
Contributor

eladb commented Aug 2, 2018

Note that this will change the output directory to "js" instead of "npm", and will likely break our publishing scripts

@RomainMuller
Copy link
Contributor Author

@eladb The name change is intentional - other folders are named after the language, not the repository.

@eladb
Copy link
Contributor

eladb commented Aug 2, 2018

@RomainMuller I am aware. Just calling it out. I think we'll not include this change in the release today anyway.

@RomainMuller
Copy link
Contributor Author

The rename was "copied" under this PR, so the output directory of javascript assets shouldn't be a concern any longer.

Copy link
Contributor

@eladb eladb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.NET is missing. Let's not leave it behind anymore...

*
* @return Information about the assembly in the various package managers supported for a given language.
*/
toPackageInfos?: (assm: spec.Assembly) => { [language: string]: PackageInfo };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Provide some examples here. Specifically, it's not clear why would this return a hash instead of just PackageInfo (I understand this is for the typescript/javascript case, but maybe worth mentioning as an example)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a couple of examples.

*
* @return the native reference for the target for each supported language.
*/
toNativeReference?: (type: spec.Type, options: any) => { [language: string]: string };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

* plain string (documentation should render as a pre-formatted block of text using monospace font), or an object
* describing a language-tagged block of code.
*/
usage: { [label: string]: string | { language: string, code: string } };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Examples

*/
function formatLanguage(language: string): string {
switch (language) {
case 'csharp':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't seen the .NET target changes. Should we at least emit a C# option there?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're not publishing anything to Nuget yet, I figured it was probably best if our documentation doesn't start pointing people at places that don't exist...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#149 created to track the C# fragment.

@RomainMuller RomainMuller merged commit e9c6a06 into master Aug 6, 2018
@RomainMuller RomainMuller deleted the rmuller/74-sphinx-show-names branch August 6, 2018 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants