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

Include code snippets in sources Jars #19

Closed
pniederw opened this issue Jan 27, 2016 · 14 comments
Closed

Include code snippets in sources Jars #19

pniederw opened this issue Jan 27, 2016 · 14 comments

Comments

@pniederw
Copy link

A very common way to read Javadoc is through the sources (Jars) attached to the IDE project. (It's much more convenient to search/browse sources in an IDE than Javadoc on a web page, and seeing both documentation and source code at the same time is very useful.) However, seeing Javadoc such as Usage example: {@codesnippet BranchProfileSample} isn't helpful - instead I'd like to see the code snippet itself. Therefore, please embed code snippets in sources before creating sources Jars. (And please make sure line numbers in class files remain intact.)

@smarr
Copy link
Contributor

smarr commented Jan 27, 2016

Hm, I kind of share the sentiment.
Not sure about the technical solution though. Seems problematic.

@jtulach, you got an idea?
Generally, I like that the code examples are checked by the compiler. With the changes we have this is absolutely necessary.

@pniederw, the relevant project is codesnippet4javadoc, pull requests are probably welcome.

@jtulach jtulach self-assigned this Jan 28, 2016
@chumer
Copy link
Member

chumer commented Jan 28, 2016

I agree. Its also my favorite way of browse external libraries and code in general. While I understand the advantages of codesnippets its lack of IDE support kills it.

@pniederw
Copy link
Author

To be fair, after attaching Javadoc Jars to the IDE project (which at least Gradle doesn't do by default), documentation popup/window does reveal the sample code (in IntelliJ). But it's not the same experience as having it in the source code.

I do understand the need to manage code snippets externally, and it has a clear benefit for users (code is more likely to be correct). Personally I prefer to use Asciidoclet for this, but it suffers from the same problem.

There are two technical solutions I can think of:

  1. Embed snippets in source code before compiling (perhaps only for published builds).
  2. Improve IDEs to display Javadoc (e.g. taken from attached Javadoc Jar) in-place.

@jtulach
Copy link
Contributor

jtulach commented Jan 30, 2016

I was hoping attaching Javadoc will solve the most critical problem.

@chumer
Copy link
Member

chumer commented Feb 1, 2016

In the current situation for me the disadvantages outweigh the advantages. I'd rather live with the redundancy of having the test case defined in a TestClass as well.

@mlvdv
Copy link
Contributor

mlvdv commented Feb 11, 2016

I don't have a strong opinion about the tradeoff here, but I disagree with the choice of keywords "BEGIN" and "END". They appears completely mysterious to the uninformed (human) reader, and we've seen examples in recent code reviews. Keywords that are more self-explanatory would help.

@woess
Copy link
Member

woess commented Feb 11, 2016

@mlvdv +1

@jtulach
Copy link
Contributor

jtulach commented Feb 12, 2016

I don't understand what is wrong on sentences like "begin of sample xyz" and "end of sample xyz", but you are of course allowed to propose alternatives. Contribute to development of the codesnippets plugin by forking https://github.com/jtulach/codesnippet4javadoc ...

@jtulach
Copy link
Contributor

jtulach commented Feb 12, 2016

In order to proceed with this inquiry, we need a representative project to demonstrate the issues on. I suggest to use simplelanguage with truffle@0.11 as that is the project users of Truffle API are supposed to start with and (unlike internal projects) it uses Java de-facto standard build system.

After opening it in my IDE and downloading Javadoc for its libraries (one click on node representing project dependencies) I can confirm the code snippet is properly included and displayed when reading documentation in IDE's code completion:
codesnippet-in-the-ide
We should verify the same behavior is achievable in the other two supported IDEs when working with the simplelanguage project.

@mlvdv
Copy link
Contributor

mlvdv commented Feb 18, 2016

@jtulach My comment about keywords "BEGIN" and "END" comes from finding the declarations of those snippets (in code), not in their use (in JavaDoc). A reader who doesn't know about this mechanism will have no clue about how to figure out why they are there.

@jtulach
Copy link
Contributor

jtulach commented Feb 26, 2016

@chrisseaton inspired me in #40 to investigate what it would take to embed the code snippets directly in the API itself. If we do what Chris did and use @link instead of @codesnippet we'll get the same Javadoc and our IDEs will properly navigate from the Javadoc to the actual code snippet. Implemented as jtulach/codesnippet4javadoc@515fdd1

@jtulach
Copy link
Contributor

jtulach commented Feb 26, 2016

Here is Truffle code base rewritten to use the new embedded style. As far as I can tell the navigation is now OK. For majority of the cases the "go to definition" jumps to proper place. For the more complex cases (TruffleLanguage referencing PolyglotEngine) "Go to type" dialog works in my IDE.

@jtulach
Copy link
Contributor

jtulach commented Mar 4, 2016

Pull request for mx created: graalvm/mx#65

@jtulach
Copy link
Contributor

jtulach commented Mar 15, 2016

#95 is merged. Closing. Enjoy navigable snippets!

@jtulach jtulach closed this as completed Mar 15, 2016
dougxc pushed a commit that referenced this issue Apr 19, 2016
…truffle:pr/update-format-to-eclipse-45 to master

The Travis gate already uses already the new formatter and fails because of that.
The new formatter changes comment formatting slightly, as well as whitespace handling in some corner cases.
This patch is the result of running mx gate with ECLIPSE_EXE pointing to an Eclipse 4.5.2
Signed-off-by: Stefan Marr git@stefan-marr.de

* commit '3ae44b7d5fb30c7c7b7bd3668f335b982292a2b5':
  Use 4.5.2 instead of 4.5.1.
  Update hocon file to use 4.5.1 as Eclipse version.
  Update Truffle formatter to Eclipse 4.5.2
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

No branches or pull requests

6 participants