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

Using Structured Documentation for Signature Help and improving Parameter Documentation #1958

Merged
merged 20 commits into from
Feb 21, 2018
Merged
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
93 changes: 93 additions & 0 deletions test/integrationTests/signatureHelp.integration.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as vscode from 'vscode';
import * as path from 'path';

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

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

suite(`SignatureHelp: ${testAssetWorkspace.description}`, function () {
let fileUri: vscode.Uri;
suiteSetup(async function () {
should();

let csharpExtension = vscode.extensions.getExtension("ms-vscode.csharp");
if (!csharpExtension.isActive) {
await csharpExtension.activate();
}

await csharpExtension.exports.initializationFinished;

let fileName = 'sigHelp.cs';
let dir = path.dirname(testAssetWorkspace.projects[0].projectDirectoryPath);
let loc = path.join(dir, fileName);
fileUri = vscode.Uri.file(loc);
await omnisharp.waitForEmptyEventQueue();
await vscode.commands.executeCommand("vscode.open", fileUri);
});


test("Returns response with documentation as undefined when method does not have documentation", async function () {
Copy link

Choose a reason for hiding this comment

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

There are two types of tests we should be thinking about:

  • Unit tests, which test the specifics of the C# extension's signature help implementation. These tests should theoretically be able to run outside of VS Code and shouldn't need to send VS Code commands
  • Integration tests, which verify that the C# extension's signature help is hooked up in VS Code and validate any nuances there (eg, trigger characters, etc). By definition, these tests run in VS Code.

Today, we can only test features by writing "integration" tests. At some point, we should think about what we'll need to do to write "unit" tests to test these kinds of implementation details. Not blocking your PR on this, but something to consider (cc @TheRealPiotrP ).

let c = <vscode.SignatureHelp>await vscode.commands.executeCommand("vscode.executeSignatureHelpProvider", fileUri, new vscode.Position(20, 23));
expect(c.signatures[0].documentation).to.be.undefined;
});

test("Returns label when method does not have documentation", async function () {
let c = <vscode.SignatureHelp>await vscode.commands.executeCommand("vscode.executeSignatureHelpProvider", fileUri, new vscode.Position(20, 23));
let answer = `void testissue.noDocMethod()`;
expect(c.signatures[0].label).to.equal(answer);
});

test("Returns summary as documentation for the method", async function () {
let c = <vscode.SignatureHelp>await vscode.commands.executeCommand("vscode.executeSignatureHelpProvider", fileUri, new vscode.Position(19, 19));
let answer = `Checks if object is tagged with the tag.`;
expect(c.signatures[0].documentation).to.equal(answer);
});

test("Returns label for the method", async function () {
let c = <vscode.SignatureHelp>await vscode.commands.executeCommand("vscode.executeSignatureHelpProvider", fileUri, new vscode.Position(19, 19));
let answer = `void testissue.Compare(int gameObject, string tagName)`;
expect(c.signatures[0].label).to.equal(answer);
});

test("Returns label for the parameters", async function () {
let c = <vscode.SignatureHelp>await vscode.commands.executeCommand("vscode.executeSignatureHelpProvider", fileUri, new vscode.Position(19, 19));
let param1 = `int gameObject`;
let param2 = `string tagName`;
expect(c.signatures[0].parameters[0].label).to.equal(param1);
expect(c.signatures[0].parameters[1].label).to.equal(param2);
});

test("Returns documentation for the parameters", async function () {
let c = <vscode.SignatureHelp>await vscode.commands.executeCommand("vscode.executeSignatureHelpProvider", fileUri, new vscode.Position(19, 19));
let param1 = `**gameObject**: The game object.`;
let param2 = `**tagName**: Name of the tag.`;
expect((<vscode.MarkdownString> c.signatures[0].parameters[0].documentation).value).to.equal(param1);
expect((<vscode.MarkdownString> c.signatures[0].parameters[1].documentation).value).to.equal(param2);
});

test("Signature Help identifies active parameter if there is no comma", async function () {
Copy link

Choose a reason for hiding this comment

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

Nice! BTW, where did these tests come from?

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 wrote them myself.

let c = <vscode.SignatureHelp>await vscode.commands.executeCommand("vscode.executeSignatureHelpProvider", fileUri, new vscode.Position(19, 19));
let answer = `int gameObject`;
expect(c.signatures[0].parameters[c.activeParameter].label).to.equal(answer);
});

test("Signature Help identifies active parameter based on comma", async function () {
let c = <vscode.SignatureHelp>await vscode.commands.executeCommand("vscode.executeSignatureHelpProvider", fileUri, new vscode.Position(19, 21));
let answer = `string tagName`;
expect(c.signatures[0].parameters[c.activeParameter].label).to.equal(answer);
});

suiteTeardown(async () => {
await testAssetWorkspace.cleanupWorkspace();
});
});
Original file line number Diff line number Diff line change
@@ -1 +1 @@
fe2f654e9c48e6a308b6a264aa38a2b3defe5730
a42255fc669f86623d73c2e9ad48ccb8310c65c0
24 changes: 24 additions & 0 deletions test/integrationTests/testAssets/singleCsproj/sigHelp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
namespace Test
{
class testissue
{
///<summary>Checks if object is tagged with the tag.</summary>
/// <param name="gameObject">The game object.</param>
/// <param name="tagName">Name of the tag.</param>
/// <returns>Returns <c>true</c> if object is tagged with tag.</returns>
public static void Compare(int gameObject,string tagName)
{
}

public static void noDocMethod()
{
}

public static void main()
{
Compare(4, "four");
noDocMethod();
}
}
}
24 changes: 24 additions & 0 deletions test/integrationTests/testAssets/slnWithCsproj/src/app/sigHelp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
namespace Test
{
class testissue
{
///<summary>Checks if object is tagged with the tag.</summary>
/// <param name="gameObject">The game object.</param>
/// <param name="tagName">Name of the tag.</param>
/// <returns>Returns <c>true</c> if object is tagged with tag.</returns>
public static void Compare(int gameObject,string tagName)
{
}

public static void noDocMethod()
{
}

public static void main()
{
Compare(4, "four");
noDocMethod();
}
}
}