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

Handling Newlines in XML Documentation #1869

Closed
wants to merge 3 commits into from

Conversation

akshita31
Copy link
Contributor

Issue : #1057

The XML Documentation being returned by omnisharp-roslyn contained newlines properly, however vscode is displaying a single newline when there are two consecutive new lines are provided. Hence a change has been made to the hoverProvider to replace a single newline with two new lines. An integration test has been added for the same. However on adding this test, the "Launch singleCsproj Workspace Tests" and "Launch slnWithCsproj Workspace Tests" are failing.

Please review @DustinCampbell @TheRealPiotrP @rchande

await csharpExtension.activate();
}

testAssetWorkspace.deleteBuildArtifacts();

Choose a reason for hiding this comment

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

do we need this?


testAssetWorkspace.deleteBuildArtifacts();

await fs.rimraf(testAssetWorkspace.vsCodeDirectoryPath);

Choose a reason for hiding this comment

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

or this?


await csharpExtension.exports.initializationFinished;

await vscode.commands.executeCommand("dotnet.generateAssets");

Choose a reason for hiding this comment

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

or this?


await vscode.commands.executeCommand("dotnet.generateAssets");

await poll(async () => await fs.exists(testAssetWorkspace.launchJsonPath), 10000, 100);

Choose a reason for hiding this comment

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

or this?

await vscode.commands.executeCommand("vscode.open", fileUri);

let c = await vscode.commands.executeCommand("vscode.executeHoverProvider", fileUri,new vscode.Position(10,30));
let answer:string = "Checks if object is tagged with the tag.\n\ngameObject: The game object.\n\ntagName: Name of the tag \n\nReturns: Returns trueif object is tagged with tag.";

Choose a reason for hiding this comment

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

the :string type specifier should not be necessary here.


let c = await vscode.commands.executeCommand("vscode.executeHoverProvider", fileUri,new vscode.Position(10,30));
let answer:string = "Checks if object is tagged with the tag.\n\ngameObject: The game object.\n\ntagName: Name of the tag \n\nReturns: Returns trueif object is tagged with tag.";
expect(c[0].contents[0].value).to.equal(answer);

Choose a reason for hiding this comment

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

for my own education, why might contents have multiple values?

Copy link

Choose a reason for hiding this comment

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

There are 2 parts to the hover: the type info, and the documentation.


test("Hover returns the correct XML", async () => {

let program : string = "using System;\

Choose a reason for hiding this comment

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

Can we use a multi-line string instead? it should be much easier to maintain since we won't be in the business of moving around \n's and \'s.

Copy link

Choose a reason for hiding this comment

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

+1

expect(c[0].contents[0].value).to.equal(answer);

});

Copy link
Member

Choose a reason for hiding this comment

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

extra blank line

@@ -0,0 +1,63 @@

Copy link
Member

Choose a reason for hiding this comment

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

Missing copyright header

Choose a reason for hiding this comment

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

@akshita31 if you install the tslint extension for vs code you will get notification for this and similar issues.

@@ -21,7 +21,8 @@ export default class OmniSharpHoverProvider extends AbstractSupport implements H

return serverUtils.typeLookup(this._server, req, token).then(value => {
if (value && value.Type) {
let contents = [extractSummaryText(value.Documentation), { language: 'csharp', value: value.Type }];
let addLine = value.Documentation.split("\n").join("\n\n");
Copy link

Choose a reason for hiding this comment

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

I'm not convinced that this is correct. The bug wants us to have line breaks between sections (summary, parameter, etc), but this seems like it's going to add them anywhere a newline appears in the doc comment. Can you post a screenshot with your changes, with a doc comment with a multline summary section?

Copy link
Contributor Author

@akshita31 akshita31 Nov 16, 2017

Choose a reason for hiding this comment

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

1057_7

Here is the output on adding a newline in the summary text. Isn't this what we are expecting?

Copy link

Choose a reason for hiding this comment

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

I don't think there should be a visible line break between "the" and "tag".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

1057_6

An interesting observation here is that even if there are multiple newlines together in the text, vscode displays it as a single newline only. But I am not really sure whether this is ok or we need to do something about it.

Copy link

@rchande rchande Nov 16, 2017

Choose a reason for hiding this comment

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

There are multiple "kinds" of newlines at play.

  • There are single newlines that have to be in doc comments if a section spans more than one line. I contend that we should not cause a visible line break for those
  • There might be multiple consecutive newlines in a doc comment section where the user was trying to separate paragraphs. We should make those visible.
  • There are visible line breaks between sections (like between summary and parameters, or between parameters). We should always show those, even if the user wrote all their parameter documentation sections on one line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

1057_8

This is the output from the master branch(where no changes have been made). As noticeable, the problem is that vscode doesn't show a newline for a single newline.It shows a "single" newline for 2 or more newlines(irrespective of whether they were part of the text originally or added by roslyn to separate the tags). Hence a quick solution was to double the '\n' character before being passed to the Hover object.

If we have to deal with single newlines and double newlines already present in the text separately, we will have to make changes on the roslyn side.Is that what you are suggesting?

Copy link

Choose a reason for hiding this comment

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

Yes, it looks like we will need to make a change that spans both repos. I propose that we:

  • Augment Roslyn to be able to return some data structure that contains all of the "sections"
  • Consume that on the VSCode side and properly insert newlines between sections.

Choose a reason for hiding this comment

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

@rchande can we split this up into two features? @akshita31's change here makes the text much more readable than before, though it does not replicate VS's behavior. I'd start by finishing off this PR, then making it better once we have a chance to close on and implement the relevant change in omnisharp-roslyn. Thoughts?

Copy link

Choose a reason for hiding this comment

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

@TheRealPiotrP I pulled @akshita31's branch to play with the behavior. Given the doc comment in the first screenshot, this is what it looks like before and after the change, respectively. I feel that the second example is enough of a regression to the readability of longer documentation comments that we should wait until we have an appropriate change on the roslyn side. @DustinCampbell what do you think?

image
image

Copy link
Member

Choose a reason for hiding this comment

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

I agree. Let's not merge changes that regress the user experience.


test("Hover returns the correct XML", async () => {

let program : string = "using System;\
Copy link

Choose a reason for hiding this comment

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

+1

\n{\
\n class testissue\
\n {\
\n ///<summary>Checks if object is tagged with the tag.</summary>\
Copy link

Choose a reason for hiding this comment

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

Put a newline inside this tag.


let c = await vscode.commands.executeCommand("vscode.executeHoverProvider", fileUri,new vscode.Position(10,30));
let answer:string = "Checks if object is tagged with the tag.\n\ngameObject: The game object.\n\ntagName: Name of the tag \n\nReturns: Returns trueif object is tagged with tag.";
expect(c[0].contents[0].value).to.equal(answer);
Copy link

Choose a reason for hiding this comment

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

There are 2 parts to the hover: the type info, and the documentation.

});


test("Hover returns the correct XML", async () => {

Choose a reason for hiding this comment

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

Can we make this more specific? Perhaps HoverProvider replaces \n with \n\n? Hover does not return XML, and this test is validating our newline replacement strategy.

Copy link

@TheRealPiotrP TheRealPiotrP left a comment

Choose a reason for hiding this comment

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

One remaining comment about test name, and a question to @rchande. LGTM otherwise.

@DustinCampbell
Copy link
Member

One remaining comment about test name, and a question to @rchande. LGTM otherwise.

Except that, looking at the new hover tooltip, this change doesn't solve the problem. 😄

Copy link
Member

@DustinCampbell DustinCampbell left a comment

Choose a reason for hiding this comment

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

It seems that simply replacing all \n with \n\n does not produce the right user experience.

@ghost ghost removed the cla-signed label Dec 7, 2017
@ghost ghost deleted a comment from dnfclas Dec 7, 2017
@ghost ghost deleted a comment from dnfclas Dec 7, 2017
@DustinCampbell
Copy link
Member

@akshita31 : Should this be closed in favor of #1918?

@akshita31
Copy link
Contributor Author

Yes .Closing this in favor of #1918

@akshita31 akshita31 closed this Dec 12, 2017
@akshita31 akshita31 deleted the addlines branch February 23, 2018 23:14
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.

5 participants