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
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/features/hoverProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.

let contents = [extractSummaryText(addLine), { language: 'csharp', value: value.Type }];
return new Hover(contents);
}
});
Expand Down
63 changes: 63 additions & 0 deletions test/integrationTests/hoverProvider.integration.test.ts
Original file line number Diff line number Diff line change
@@ -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.

import * as fs from 'async-file';
import * as vscode from 'vscode';
import * as path from 'path';

import poll from './poll';
import { should, expect } from 'chai';
import testAssetWorkspace from './testAssets/testAssetWorkspace';

const chai = require('chai');
chai.use(require('chai-arrays'));
chai.use(require('chai-fs'));

suite(`Test Hover Behavior ${testAssetWorkspace.description}`, function() {
suiteSetup(async function() {
should();

let csharpExtension = vscode.extensions.getExtension("ms-vscode.csharp");
if (!csharpExtension.isActive) {
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?


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 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?


});


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.


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

\nnamespace hoverXmlDoc \
\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.

\n /// <param name=\"gameObject\">The game object.</param> \
\n /// <param name=\"tagName\">Name of the tag </param>\
\n /// <returns>Returns <c> true</c>if object is tagged with tag.</returns>\
\n\
\n public static bool Compare(int gameObject,string tagName)\
\n {\
\n return gameObject.TagifyCompareTag(tagName);\
\n }\
\n }\
}";
let fileUri = await testAssetWorkspace.projects[0].addFileWithContents("test.cs", program);
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.

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.


});

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

});
6 changes: 6 additions & 0 deletions test/integrationTests/testAssets/testAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ export class TestAssetProject {
await fs.rimraf(this.binDirectoryPath);
await fs.rimraf(this.objDirectoryPath);
}

async addFileWithContents(fileName: string, contents: string) : Promise<vscode.Uri> {
let loc = path.join(vscode.workspace.workspaceFolders[0].uri.fsPath, fileName);
await fs.writeTextFile(loc, contents);
return vscode.Uri.file(loc);
}
}

export class TestAssetWorkspace {
Expand Down