From 2f9c7845a4c15ced50da8b91794423892c611a87 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Wed, 6 Dec 2017 11:29:05 -0800 Subject: [PATCH 01/23] Added the changes for structured documentation --- src/features/hoverProvider.ts | 33 ++++++++++- src/omnisharp/protocol.ts | 12 ++++ .../hoverProvider.integration.test.ts | 56 +++++++++++++++++++ .../testAssets/singleCsproj/test1.cs | 16 ++++++ .../integrationTests/testAssets/testAssets.ts | 14 +++-- 5 files changed, 125 insertions(+), 6 deletions(-) create mode 100644 test/integrationTests/hoverProvider.integration.test.ts create mode 100644 test/integrationTests/testAssets/singleCsproj/test1.cs diff --git a/src/features/hoverProvider.ts b/src/features/hoverProvider.ts index 2285b1c00..31fd0a5f4 100644 --- a/src/features/hoverProvider.ts +++ b/src/features/hoverProvider.ts @@ -21,9 +21,38 @@ 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 structuredDocumentation = value.StructuredDocumentation ; + let newline = "\n\n"; + let ParamText = structuredDocumentation.ParamElements.join(newline); + if(ParamText.length>0) + { + ParamText = "Parameters:\n\n"+ ParamText; + } + + let TypeParamText = structuredDocumentation.TypeParamElements.join(newline); + if(TypeParamText.length>0) + { + TypeParamText = "TypeParameters:\n\n"+TypeParamText; + } + + let ExceptionText = structuredDocumentation.Exception.join(newline); + if(ExceptionText.length>0) + { + ExceptionText = "Exceptions:\n\n"+ ExceptionText; + } + + let documentation = + structuredDocumentation.SummaryText + newline + + ParamText + newline + + TypeParamText + newline + + structuredDocumentation.ValueText + newline + + structuredDocumentation.ExampleText + newline + + structuredDocumentation.RemarksText + newline + + structuredDocumentation.ReturnsText + newline + + ExceptionText; + let contents = [documentation, { language: 'csharp', value: value.Type }]; return new Hover(contents); } }); } -} +} \ No newline at end of file diff --git a/src/omnisharp/protocol.ts b/src/omnisharp/protocol.ts index 0532112bc..415fba0ad 100644 --- a/src/omnisharp/protocol.ts +++ b/src/omnisharp/protocol.ts @@ -214,6 +214,17 @@ export interface FindSymbolsResponse { QuickFixes: SymbolLocation[]; } +export interface DocumentationComment { + RemarksText : string; + ExampleText : string; + ReturnsText : string ; + SummaryText: string ; + ValueText: string; + Exception : string[]; + ParamElements : string[]; + TypeParamElements :string[]; +} + export interface TypeLookupRequest extends Request { IncludeDocumentation: boolean; } @@ -221,6 +232,7 @@ export interface TypeLookupRequest extends Request { export interface TypeLookupResponse { Type: string; Documentation: string; + StructuredDocumentation : DocumentationComment; } export interface RunCodeActionResponse { diff --git a/test/integrationTests/hoverProvider.integration.test.ts b/test/integrationTests/hoverProvider.integration.test.ts new file mode 100644 index 000000000..42262d287 --- /dev/null +++ b/test/integrationTests/hoverProvider.integration.test.ts @@ -0,0 +1,56 @@ +/*--------------------------------------------------------------------------------------------- +* Copyright (c) Microsoft Corporation. All rights reserved. +* Licensed under the MIT License. See License.txt in the project root for license information. +*--------------------------------------------------------------------------------------------*/ + +import * as fs from 'async-file'; +import * as vscode from 'vscode'; + +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(); + } + + await csharpExtension.exports.initializationFinished; + }); + + + test("Hover returns the correct XML", async () => { + + var program = +`using System; +namespace hoverXmlDoc +{ + class testissue + { + ///Checks if object is tagged with the tag. + /// The game object. + /// Name of the tag + /// Returns trueif object is tagged with tag. + + public static bool Compare(int gameObject,string tagName) + { + return gameObject.TagifyCompareTag(tagName); + } + } +}`; + let fileUri = await testAssetWorkspace.projects[0].addFileWithContents("test1.cs", program); + await vscode.commands.executeCommand("vscode.open", fileUri); + + let c = await vscode.commands.executeCommand("vscode.executeHoverProvider", fileUri,new vscode.Position(10,29)); + 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); + }); +}); \ No newline at end of file diff --git a/test/integrationTests/testAssets/singleCsproj/test1.cs b/test/integrationTests/testAssets/singleCsproj/test1.cs new file mode 100644 index 000000000..04c62e082 --- /dev/null +++ b/test/integrationTests/testAssets/singleCsproj/test1.cs @@ -0,0 +1,16 @@ +using System; +namespace hoverXmlDoc +{ + class testissue + { + ///Checks if object is tagged with the tag. + /// The game object. + /// Name of the tag + /// Returns trueif object is tagged with tag. + + public static bool Compare(int gameObject,string tagName) + { + return gameObject.TagifyCompareTag(tagName); + } + } +} \ No newline at end of file diff --git a/test/integrationTests/testAssets/testAssets.ts b/test/integrationTests/testAssets/testAssets.ts index 5451abe57..114cad04f 100644 --- a/test/integrationTests/testAssets/testAssets.ts +++ b/test/integrationTests/testAssets/testAssets.ts @@ -16,7 +16,7 @@ export class TestAssetProject { get projectDirectoryPath(): string { return path.join(vscode.workspace.workspaceFolders[0].uri.fsPath, - this.relativePath); + this.relativePath); } get binDirectoryPath(): string { @@ -31,6 +31,12 @@ export class TestAssetProject { await fs.rimraf(this.binDirectoryPath); await fs.rimraf(this.objDirectoryPath); } + + async addFileWithContents(fileName: string, contents: string): Promise { + let loc = path.join(vscode.workspace.workspaceFolders[0].uri.fsPath, fileName); + await fs.writeTextFile(loc, contents); + return vscode.Uri.file(loc); + } } export class TestAssetWorkspace { @@ -45,7 +51,7 @@ export class TestAssetWorkspace { async deleteBuildArtifacts(): Promise { this.projects.forEach(async p => await p.deleteBuildArtifacts()); } - + get vsCodeDirectoryPath(): string { return path.join(vscode.workspace.rootPath, ".vscode"); } @@ -53,14 +59,14 @@ export class TestAssetWorkspace { get launchJsonPath(): string { return path.join(this.vsCodeDirectoryPath, "launch.json"); } - + get tasksJsonPath(): string { return path.join(this.vsCodeDirectoryPath, "tasks.json"); } description: string; - projects: TestAssetProject []; + projects: TestAssetProject[]; } export interface ITestAssetProject { From 0df87fa2728fce7749a26183d1b96088dfb70809 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Wed, 6 Dec 2017 13:40:35 -0800 Subject: [PATCH 02/23] Test --- .../testAssets/singleCsproj/test1.cs | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 test/integrationTests/testAssets/singleCsproj/test1.cs diff --git a/test/integrationTests/testAssets/singleCsproj/test1.cs b/test/integrationTests/testAssets/singleCsproj/test1.cs deleted file mode 100644 index 04c62e082..000000000 --- a/test/integrationTests/testAssets/singleCsproj/test1.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -namespace hoverXmlDoc -{ - class testissue - { - ///Checks if object is tagged with the tag. - /// The game object. - /// Name of the tag - /// Returns trueif object is tagged with tag. - - public static bool Compare(int gameObject,string tagName) - { - return gameObject.TagifyCompareTag(tagName); - } - } -} \ No newline at end of file From 27f5dde305d4f75ee80e17c48c379b1427886201 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Wed, 6 Dec 2017 14:38:26 -0800 Subject: [PATCH 03/23] First Test Running Properly --- .../hoverProvider.integration.test.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/test/integrationTests/hoverProvider.integration.test.ts b/test/integrationTests/hoverProvider.integration.test.ts index 42262d287..31bbe375a 100644 --- a/test/integrationTests/hoverProvider.integration.test.ts +++ b/test/integrationTests/hoverProvider.integration.test.ts @@ -27,7 +27,7 @@ suite(`Test Hover Behavior ${testAssetWorkspace.description}`, function() { }); - test("Hover returns the correct XML", async () => { + test("Hover returns the correct XML", async function () { var program = `using System; @@ -42,7 +42,7 @@ namespace hoverXmlDoc public static bool Compare(int gameObject,string tagName) { - return gameObject.TagifyCompareTag(tagName); + return true; } } }`; @@ -52,5 +52,10 @@ namespace hoverXmlDoc let c = await vscode.commands.executeCommand("vscode.executeHoverProvider", fileUri,new vscode.Position(10,29)); 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); - }); + }); + + teardown(async() => + { + await testAssetWorkspace.cleanupWorkspace(); + }) }); \ No newline at end of file From 50aa8e85a3e9bf4988c697d9bc0084e743992ce7 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Thu, 7 Dec 2017 20:04:50 -0800 Subject: [PATCH 04/23] Integration Test Running --- src/features/hoverProvider.ts | 48 ++++++++----------- src/omnisharp/protocol.ts | 8 ++-- .../hoverProvider.integration.test.ts | 15 ++++-- 3 files changed, 36 insertions(+), 35 deletions(-) diff --git a/src/features/hoverProvider.ts b/src/features/hoverProvider.ts index 31fd0a5f4..dc03958e5 100644 --- a/src/features/hoverProvider.ts +++ b/src/features/hoverProvider.ts @@ -21,35 +21,27 @@ export default class OmniSharpHoverProvider extends AbstractSupport implements H return serverUtils.typeLookup(this._server, req, token).then(value => { if (value && value.Type) { - let structuredDocumentation = value.StructuredDocumentation ; + let structDoc = value.StructuredDocumentation ; let newline = "\n\n"; - let ParamText = structuredDocumentation.ParamElements.join(newline); - if(ParamText.length>0) - { - ParamText = "Parameters:\n\n"+ ParamText; - } - - let TypeParamText = structuredDocumentation.TypeParamElements.join(newline); - if(TypeParamText.length>0) - { - TypeParamText = "TypeParameters:\n\n"+TypeParamText; - } - - let ExceptionText = structuredDocumentation.Exception.join(newline); - if(ExceptionText.length>0) - { - ExceptionText = "Exceptions:\n\n"+ ExceptionText; - } - - let documentation = - structuredDocumentation.SummaryText + newline + - ParamText + newline + - TypeParamText + newline + - structuredDocumentation.ValueText + newline + - structuredDocumentation.ExampleText + newline + - structuredDocumentation.RemarksText + newline + - structuredDocumentation.ReturnsText + newline + - ExceptionText; + let documentation = ""; + Object.getOwnPropertyNames(structDoc).forEach( + function (val, idx, array) { + if(Array.isArray(structDoc[val])){ + if(structDoc[val].length>0){ + if(val=="ParamElements") + documentation += "Parameters:" ; + else if(val=="TypeParamElements") + documentation += "TypeParameters:"; + else + documentation += "Exceptions:"; + documentation += newline + structDoc[val].join(newline) + newline; + } + } + else if(structDoc[val]) + documentation += structDoc[val] + newline; + } + ); + documentation = documentation.trim(); let contents = [documentation, { language: 'csharp', value: value.Type }]; return new Hover(contents); } diff --git a/src/omnisharp/protocol.ts b/src/omnisharp/protocol.ts index 415fba0ad..edaebd936 100644 --- a/src/omnisharp/protocol.ts +++ b/src/omnisharp/protocol.ts @@ -215,14 +215,14 @@ export interface FindSymbolsResponse { } export interface DocumentationComment { + SummaryText: string ; + TypeParamElements :string[]; + ParamElements : string[]; + ReturnsText : string ; RemarksText : string; ExampleText : string; - ReturnsText : string ; - SummaryText: string ; ValueText: string; Exception : string[]; - ParamElements : string[]; - TypeParamElements :string[]; } export interface TypeLookupRequest extends Request { diff --git a/test/integrationTests/hoverProvider.integration.test.ts b/test/integrationTests/hoverProvider.integration.test.ts index 31bbe375a..ebce9c337 100644 --- a/test/integrationTests/hoverProvider.integration.test.ts +++ b/test/integrationTests/hoverProvider.integration.test.ts @@ -37,8 +37,8 @@ namespace hoverXmlDoc { ///Checks if object is tagged with the tag. /// The game object. - /// Name of the tag - /// Returns trueif object is tagged with tag. + /// Name of the tag. + /// Returns true if object is tagged with tag. public static bool Compare(int gameObject,string tagName) { @@ -50,7 +50,16 @@ namespace hoverXmlDoc await vscode.commands.executeCommand("vscode.open", fileUri); let c = await vscode.commands.executeCommand("vscode.executeHoverProvider", fileUri,new vscode.Position(10,29)); - 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."; + let answer:string = +`Summary: Checks if object is tagged with the tag. + +Parameters: + +gameObject: The game object. + +tagName: Name of the tag. + +Returns: Returns trueif object is tagged with tag.`; expect(c[0].contents[0].value).to.equal(answer); }); From 007dba8a04397aaafb599cddabbd253ad26140f3 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Fri, 8 Dec 2017 15:25:42 -0800 Subject: [PATCH 05/23] Test Commit --- src/features/hoverProvider.ts | 4 +- .../hoverProvider.integration.test.ts | 41 +++++++++++++------ .../launchConfiguration.integration.test.ts | 9 +++- .../integrationTests/testAssets/testAssets.ts | 3 ++ 4 files changed, 40 insertions(+), 17 deletions(-) diff --git a/src/features/hoverProvider.ts b/src/features/hoverProvider.ts index dc03958e5..98d31bad6 100644 --- a/src/features/hoverProvider.ts +++ b/src/features/hoverProvider.ts @@ -5,11 +5,11 @@ 'use strict'; -import {extractSummaryText} from './documentation'; import AbstractSupport from './abstractProvider'; import * as protocol from '../omnisharp/protocol'; import * as serverUtils from '../omnisharp/utils'; import {createRequest} from '../omnisharp/typeConvertion'; + import {HoverProvider, Hover, TextDocument, CancellationToken, Position} from 'vscode'; export default class OmniSharpHoverProvider extends AbstractSupport implements HoverProvider { @@ -25,7 +25,7 @@ export default class OmniSharpHoverProvider extends AbstractSupport implements H let newline = "\n\n"; let documentation = ""; Object.getOwnPropertyNames(structDoc).forEach( - function (val, idx, array) { + function (val) { if(Array.isArray(structDoc[val])){ if(structDoc[val].length>0){ if(val=="ParamElements") diff --git a/test/integrationTests/hoverProvider.integration.test.ts b/test/integrationTests/hoverProvider.integration.test.ts index ebce9c337..25b022238 100644 --- a/test/integrationTests/hoverProvider.integration.test.ts +++ b/test/integrationTests/hoverProvider.integration.test.ts @@ -14,21 +14,31 @@ 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(); +suite(`Tasks generation: ${testAssetWorkspace.description}`, function() { + suiteSetup(async function() { + should(); + console.log("Suite start"); + let csharpExtension = vscode.extensions.getExtension("ms-vscode.csharp"); + if (!csharpExtension.isActive) { + await csharpExtension.activate(); + } - let csharpExtension = vscode.extensions.getExtension("ms-vscode.csharp"); - if (!csharpExtension.isActive) { - await csharpExtension.activate(); - } - - await csharpExtension.exports.initializationFinished; - }); + await testAssetWorkspace.cleanupWorkspace(); + + await csharpExtension.exports.initializationFinished; + + await vscode.commands.executeCommand("dotnet.generateAssets"); + await poll(async () => await fs.exists(testAssetWorkspace.launchJsonPath), 10000, 100); + + console.log("Suite end"); + }); - test("Hover returns the correct XML", async function () { + test("Hover returns structured documentation with proper newlines", async function () { + + console.log("Test start"); + await vscode.commands.executeCommand('workbench.action.tasks.runTask','build'); var program = `using System; namespace hoverXmlDoc @@ -48,8 +58,10 @@ namespace hoverXmlDoc }`; let fileUri = await testAssetWorkspace.projects[0].addFileWithContents("test1.cs", program); await vscode.commands.executeCommand("vscode.open", fileUri); - + /*var d = await fs.exists(fileUri.fsPath); + console.log("File exists",d);*/ let c = await vscode.commands.executeCommand("vscode.executeHoverProvider", fileUri,new vscode.Position(10,29)); + let answer:string = `Summary: Checks if object is tagged with the tag. @@ -60,11 +72,14 @@ gameObject: The game object. tagName: Name of the tag. Returns: Returns trueif object is tagged with tag.`; - expect(c[0].contents[0].value).to.equal(answer); + expect(c[0].contents[0].value).to.equal(answer); + console.log("Test end "); }); teardown(async() => { + console.log("Teardown start"); await testAssetWorkspace.cleanupWorkspace(); + console.log("Teardown end"); }) }); \ No newline at end of file diff --git a/test/integrationTests/launchConfiguration.integration.test.ts b/test/integrationTests/launchConfiguration.integration.test.ts index fd7cbe269..8cb25f4e9 100644 --- a/test/integrationTests/launchConfiguration.integration.test.ts +++ b/test/integrationTests/launchConfiguration.integration.test.ts @@ -17,7 +17,7 @@ chai.use(require('chai-fs')); suite(`Tasks generation: ${testAssetWorkspace.description}`, function() { suiteSetup(async function() { should(); - + let csharpExtension = vscode.extensions.getExtension("ms-vscode.csharp"); if (!csharpExtension.isActive) { await csharpExtension.activate(); @@ -30,9 +30,11 @@ suite(`Tasks generation: ${testAssetWorkspace.description}`, function() { await vscode.commands.executeCommand("dotnet.generateAssets"); await poll(async () => await fs.exists(testAssetWorkspace.launchJsonPath), 10000, 100); + console.log("suite launch finished"); }); test("Starting .NET Core Launch (console) from the workspace root should create an Active Debug Session", async () => { + console.log("Launch Test Started"); await vscode.debug.startDebugging(vscode.workspace.workspaceFolders[0], ".NET Core Launch (console)"); let debugSessionTerminated = new Promise(resolve => { @@ -42,10 +44,13 @@ suite(`Tasks generation: ${testAssetWorkspace.description}`, function() { vscode.debug.activeDebugSession.type.should.equal("coreclr"); await debugSessionTerminated; + console.log("Launch Test Ended"); }); teardown(async() => { + console.log("Teardown started Launch Test"); await testAssetWorkspace.cleanupWorkspace(); + console.log("Teardown finished Launch Test"); }) -}); \ No newline at end of file +}); \ No newline at end of file diff --git a/test/integrationTests/testAssets/testAssets.ts b/test/integrationTests/testAssets/testAssets.ts index cae8cda68..34c777c68 100644 --- a/test/integrationTests/testAssets/testAssets.ts +++ b/test/integrationTests/testAssets/testAssets.ts @@ -67,12 +67,15 @@ export class TestAssetWorkspace { async cleanupWorkspace() : Promise { + console.log("Clean started"); for (let project of this.projects) { let wd = path.dirname(project.projectDirectoryPath); await this.invokeGit("clean -xdf . ", wd); await this.invokeGit("checkout -- .", wd); + console.log("Cleaning"); } + console.log("Clean ended"); } invokeGit(args: string, workingDirectory: string) : Promise<{stdout: string, stderr: string}> { From b66e5f1f9fd66a0007b13617f2aa8b528623dc2e Mon Sep 17 00:00:00 2001 From: Ravi Chande Date: Mon, 11 Dec 2017 10:17:54 -0800 Subject: [PATCH 06/23] Add new test files next to the csproj, not in the root of the workspace --- test/integrationTests/testAssets/testAssets.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/test/integrationTests/testAssets/testAssets.ts b/test/integrationTests/testAssets/testAssets.ts index 34c777c68..eb9fa4ffa 100644 --- a/test/integrationTests/testAssets/testAssets.ts +++ b/test/integrationTests/testAssets/testAssets.ts @@ -34,7 +34,8 @@ export class TestAssetProject { } async addFileWithContents(fileName: string, contents: string): Promise { - let loc = path.join(vscode.workspace.workspaceFolders[0].uri.fsPath, fileName); + let dir = path.dirname(this.projectDirectoryPath) + let loc = path.join(dir, fileName); await fs.writeTextFile(loc, contents); return vscode.Uri.file(loc); } @@ -67,15 +68,12 @@ export class TestAssetWorkspace { async cleanupWorkspace() : Promise { - console.log("Clean started"); for (let project of this.projects) { let wd = path.dirname(project.projectDirectoryPath); await this.invokeGit("clean -xdf . ", wd); - await this.invokeGit("checkout -- .", wd); - console.log("Cleaning"); + await this.invokeGit("checkout -- .", wd); } - console.log("Clean ended"); } invokeGit(args: string, workingDirectory: string) : Promise<{stdout: string, stderr: string}> { From 6873f90e55668899a68608a98deaf638aaa36239 Mon Sep 17 00:00:00 2001 From: Ravi Chande Date: Mon, 11 Dec 2017 10:18:20 -0800 Subject: [PATCH 07/23] Make it possible for tests to await restore --- src/features/commands.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/features/commands.ts b/src/features/commands.ts index 146a27c91..c83312612 100644 --- a/src/features/commands.ts +++ b/src/features/commands.ts @@ -105,7 +105,7 @@ function projectsToCommands(projects: protocol.ProjectDescriptor[]): Promise { if (!server.isRunning()) { return Promise.reject('OmniSharp server is not running.'); From 882d13bc8f6a786b07bf8a55779db0f3fe8b37b8 Mon Sep 17 00:00:00 2001 From: Ravi Chande Date: Mon, 11 Dec 2017 10:18:50 -0800 Subject: [PATCH 08/23] Enable tests to wait for the omnisharp request queue to be empty --- src/omnisharp/extension.ts | 3 +++ src/omnisharp/requestQueue.ts | 7 +++++++ src/omnisharp/server.ts | 8 ++++++++ 3 files changed, 18 insertions(+) diff --git a/src/omnisharp/extension.ts b/src/omnisharp/extension.ts index 41a3a75ff..61f5982dc 100644 --- a/src/omnisharp/extension.ts +++ b/src/omnisharp/extension.ts @@ -33,6 +33,8 @@ import forwardChanges from '../features/changeForwarding'; import registerCommands from '../features/commands'; import reportStatus from '../features/status'; +export let omnisharp: OmniSharpServer; + export function activate(context: vscode.ExtensionContext, reporter: TelemetryReporter, channel: vscode.OutputChannel) { const documentSelector: vscode.DocumentSelector = { language: 'csharp', @@ -42,6 +44,7 @@ export function activate(context: vscode.ExtensionContext, reporter: TelemetryRe const options = Options.Read(); const server = new OmniSharpServer(reporter); + omnisharp = server; const advisor = new Advisor(server); // create before server is started const disposables: vscode.Disposable[] = []; const localDisposables: vscode.Disposable[] = []; diff --git a/src/omnisharp/requestQueue.ts b/src/omnisharp/requestQueue.ts index 26fe65070..644afba7f 100644 --- a/src/omnisharp/requestQueue.ts +++ b/src/omnisharp/requestQueue.ts @@ -135,6 +135,13 @@ export class RequestQueueCollection { } } + public isEmpty() + { + return !this._deferredQueue.hasPending() + && !this._normalQueue.hasPending() + && !this._priorityQueue.hasPending(); + } + public enqueue(request: Request) { const queue = this.getQueue(request.command); queue.enqueue(request); diff --git a/src/omnisharp/server.ts b/src/omnisharp/server.ts index b2dc6086e..40130accf 100644 --- a/src/omnisharp/server.ts +++ b/src/omnisharp/server.ts @@ -18,6 +18,7 @@ import * as path from 'path'; import * as protocol from './protocol'; import * as utils from '../common'; import * as vscode from 'vscode'; +import { setTimeout } from 'timers'; enum ServerState { Starting, @@ -98,6 +99,13 @@ export class OmniSharpServer { return this._state === ServerState.Started; } + public async waitForEmptyEventQueue() : Promise { + while (!this._requestQueue.isEmpty()) { + var p = new Promise((resolve) => setTimeout(resolve, 100)); + await p; + } + } + private _getState(): ServerState { return this._state; } From ccc21a60b62e505267432e201dd8c2eceb3d6592 Mon Sep 17 00:00:00 2001 From: Ravi Chande Date: Mon, 11 Dec 2017 10:19:32 -0800 Subject: [PATCH 09/23] Wait for queue empty in hover test --- test/integrationTests/hoverProvider.integration.test.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/integrationTests/hoverProvider.integration.test.ts b/test/integrationTests/hoverProvider.integration.test.ts index 25b022238..1d0376583 100644 --- a/test/integrationTests/hoverProvider.integration.test.ts +++ b/test/integrationTests/hoverProvider.integration.test.ts @@ -9,6 +9,9 @@ import * as vscode from 'vscode'; import poll from './poll'; import { should, expect } from 'chai'; import testAssetWorkspace from './testAssets/testAssetWorkspace'; +import { RequestQueueCollection } from '../../src/omnisharp/requestQueue'; +import { OmniSharpServer } from '../../src/omnisharp/server'; +import { omnisharp } from '../../src/omnisharp/extension'; const chai = require('chai'); chai.use(require('chai-arrays')); @@ -38,7 +41,7 @@ suite(`Tasks generation: ${testAssetWorkspace.description}`, function() { test("Hover returns structured documentation with proper newlines", async function () { console.log("Test start"); - await vscode.commands.executeCommand('workbench.action.tasks.runTask','build'); + //await vscode.commands.executeCommand("dotnet.restore"); var program = `using System; namespace hoverXmlDoc @@ -57,6 +60,9 @@ namespace hoverXmlDoc } }`; let fileUri = await testAssetWorkspace.projects[0].addFileWithContents("test1.cs", program); + + await omnisharp.waitForEmptyEventQueue(); + await vscode.commands.executeCommand("vscode.open", fileUri); /*var d = await fs.exists(fileUri.fsPath); console.log("File exists",d);*/ From d0acf84e3be0ffe4d96fc918a8a8da9dbb7daa30 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Mon, 11 Dec 2017 10:49:38 -0800 Subject: [PATCH 10/23] Removed debug statements --- .../hoverProvider.integration.test.ts | 15 ++++----------- .../launchConfiguration.integration.test.ts | 10 +++------- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/test/integrationTests/hoverProvider.integration.test.ts b/test/integrationTests/hoverProvider.integration.test.ts index 1d0376583..2a2039a25 100644 --- a/test/integrationTests/hoverProvider.integration.test.ts +++ b/test/integrationTests/hoverProvider.integration.test.ts @@ -20,7 +20,7 @@ chai.use(require('chai-fs')); suite(`Tasks generation: ${testAssetWorkspace.description}`, function() { suiteSetup(async function() { should(); - console.log("Suite start"); + let csharpExtension = vscode.extensions.getExtension("ms-vscode.csharp"); if (!csharpExtension.isActive) { await csharpExtension.activate(); @@ -34,17 +34,14 @@ suite(`Tasks generation: ${testAssetWorkspace.description}`, function() { await poll(async () => await fs.exists(testAssetWorkspace.launchJsonPath), 10000, 100); - console.log("Suite end"); }); test("Hover returns structured documentation with proper newlines", async function () { - console.log("Test start"); - //await vscode.commands.executeCommand("dotnet.restore"); var program = `using System; -namespace hoverXmlDoc +namespace Test { class testissue { @@ -64,8 +61,7 @@ namespace hoverXmlDoc await omnisharp.waitForEmptyEventQueue(); await vscode.commands.executeCommand("vscode.open", fileUri); - /*var d = await fs.exists(fileUri.fsPath); - console.log("File exists",d);*/ + let c = await vscode.commands.executeCommand("vscode.executeHoverProvider", fileUri,new vscode.Position(10,29)); let answer:string = @@ -79,13 +75,10 @@ tagName: Name of the tag. Returns: Returns trueif object is tagged with tag.`; expect(c[0].contents[0].value).to.equal(answer); - console.log("Test end "); }); teardown(async() => { - console.log("Teardown start"); - await testAssetWorkspace.cleanupWorkspace(); - console.log("Teardown end"); + await testAssetWorkspace.cleanupWorkspace(); }) }); \ No newline at end of file diff --git a/test/integrationTests/launchConfiguration.integration.test.ts b/test/integrationTests/launchConfiguration.integration.test.ts index 8cb25f4e9..1d609fbce 100644 --- a/test/integrationTests/launchConfiguration.integration.test.ts +++ b/test/integrationTests/launchConfiguration.integration.test.ts @@ -30,11 +30,10 @@ suite(`Tasks generation: ${testAssetWorkspace.description}`, function() { await vscode.commands.executeCommand("dotnet.generateAssets"); await poll(async () => await fs.exists(testAssetWorkspace.launchJsonPath), 10000, 100); - console.log("suite launch finished"); + }); - test("Starting .NET Core Launch (console) from the workspace root should create an Active Debug Session", async () => { - console.log("Launch Test Started"); + test("Starting .NET Core Launch (console) from the workspace root should create an Active Debug Session", async () => { await vscode.debug.startDebugging(vscode.workspace.workspaceFolders[0], ".NET Core Launch (console)"); let debugSessionTerminated = new Promise(resolve => { @@ -44,13 +43,10 @@ suite(`Tasks generation: ${testAssetWorkspace.description}`, function() { vscode.debug.activeDebugSession.type.should.equal("coreclr"); await debugSessionTerminated; - console.log("Launch Test Ended"); }); teardown(async() => - { - console.log("Teardown started Launch Test"); + { await testAssetWorkspace.cleanupWorkspace(); - console.log("Teardown finished Launch Test"); }) }); \ No newline at end of file From eebb979e08cbbbb8ea051c570785e163a59a8102 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Mon, 11 Dec 2017 10:56:58 -0800 Subject: [PATCH 11/23] Removed Unnecessary space --- test/integrationTests/launchConfiguration.integration.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integrationTests/launchConfiguration.integration.test.ts b/test/integrationTests/launchConfiguration.integration.test.ts index 1d609fbce..17b6151a6 100644 --- a/test/integrationTests/launchConfiguration.integration.test.ts +++ b/test/integrationTests/launchConfiguration.integration.test.ts @@ -33,7 +33,7 @@ suite(`Tasks generation: ${testAssetWorkspace.description}`, function() { }); - test("Starting .NET Core Launch (console) from the workspace root should create an Active Debug Session", async () => { + test("Starting .NET Core Launch (console) from the workspace root should create an Active Debug Session", async () => { await vscode.debug.startDebugging(vscode.workspace.workspaceFolders[0], ".NET Core Launch (console)"); let debugSessionTerminated = new Promise(resolve => { From 020722232ab15463c2aab4c5c7baa6d034e227e0 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Mon, 11 Dec 2017 11:13:41 -0800 Subject: [PATCH 12/23] Added braces for if-else --- src/features/hoverProvider.ts | 14 +++++++++----- src/omnisharp/server.ts | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/features/hoverProvider.ts b/src/features/hoverProvider.ts index 98d31bad6..7009442d9 100644 --- a/src/features/hoverProvider.ts +++ b/src/features/hoverProvider.ts @@ -28,17 +28,21 @@ export default class OmniSharpHoverProvider extends AbstractSupport implements H function (val) { if(Array.isArray(structDoc[val])){ if(structDoc[val].length>0){ - if(val=="ParamElements") + if(val=="ParamElements"){ documentation += "Parameters:" ; - else if(val=="TypeParamElements") + } + else if(val=="TypeParamElements"){ documentation += "TypeParameters:"; - else + } + else{ documentation += "Exceptions:"; + } documentation += newline + structDoc[val].join(newline) + newline; } } - else if(structDoc[val]) - documentation += structDoc[val] + newline; + else if(structDoc[val]){ + documentation += structDoc[val] + newline; + } } ); documentation = documentation.trim(); diff --git a/src/omnisharp/server.ts b/src/omnisharp/server.ts index 40130accf..61c002c05 100644 --- a/src/omnisharp/server.ts +++ b/src/omnisharp/server.ts @@ -101,7 +101,7 @@ export class OmniSharpServer { public async waitForEmptyEventQueue() : Promise { while (!this._requestQueue.isEmpty()) { - var p = new Promise((resolve) => setTimeout(resolve, 100)); + let p = new Promise((resolve) => setTimeout(resolve, 100)); await p; } } From 66f5b7efa61efb7e32f6b28793b010e6ea628fcd Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Mon, 11 Dec 2017 13:24:18 -0800 Subject: [PATCH 13/23] Added conditions for each field individually --- src/features/hoverProvider.ts | 51 ++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/src/features/hoverProvider.ts b/src/features/hoverProvider.ts index 7009442d9..b9d6196fd 100644 --- a/src/features/hoverProvider.ts +++ b/src/features/hoverProvider.ts @@ -22,29 +22,36 @@ export default class OmniSharpHoverProvider extends AbstractSupport implements H return serverUtils.typeLookup(this._server, req, token).then(value => { if (value && value.Type) { let structDoc = value.StructuredDocumentation ; - let newline = "\n\n"; + let newLine = "\n\n"; let documentation = ""; - Object.getOwnPropertyNames(structDoc).forEach( - function (val) { - if(Array.isArray(structDoc[val])){ - if(structDoc[val].length>0){ - if(val=="ParamElements"){ - documentation += "Parameters:" ; - } - else if(val=="TypeParamElements"){ - documentation += "TypeParameters:"; - } - else{ - documentation += "Exceptions:"; - } - documentation += newline + structDoc[val].join(newline) + newline; - } - } - else if(structDoc[val]){ - documentation += structDoc[val] + newline; - } - } - ); + if (structDoc.SummaryText) { + documentation += structDoc.SummaryText + newLine; + } + if (structDoc.TypeParamElements && structDoc.TypeParamElements.length > 0) { + documentation += "Type Parameters:" + newLine; + documentation += structDoc.TypeParamElements.join(newLine) + newLine; + } + if (structDoc.ParamElements && structDoc.ParamElements.length > 0) { + documentation += "Parameters:" + newLine; + documentation += structDoc.ParamElements.join(newLine) + newLine; + } + if (structDoc.ReturnsText) { + documentation += structDoc.ReturnsText + newLine; + } + if (structDoc.RemarksText) { + documentation += structDoc.RemarksText + newLine; + } + if (structDoc.ExampleText) { + documentation += structDoc.ExampleText + newLine; + } + if (structDoc.ValueText) { + documentation += structDoc.ValueText + newLine; + } + if (structDoc.Exception && structDoc.Exception.length > 0) { + documentation += "Exceptions:" + newLine; + documentation += structDoc.Exception.join(newLine) + newLine; + } + documentation = documentation.trim(); let contents = [documentation, { language: 'csharp', value: value.Type }]; return new Hover(contents); From c07a4ca94daed5f1b8f73b92debe74a8e3da5a27 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Tue, 12 Dec 2017 14:12:17 -0800 Subject: [PATCH 14/23] Aligned parameters --- src/features/hoverProvider.ts | 14 +++++++++++--- .../hoverProvider.integration.test.ts | 7 +++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/features/hoverProvider.ts b/src/features/hoverProvider.ts index b9d6196fd..d2750fe52 100644 --- a/src/features/hoverProvider.ts +++ b/src/features/hoverProvider.ts @@ -23,33 +23,41 @@ export default class OmniSharpHoverProvider extends AbstractSupport implements H if (value && value.Type) { let structDoc = value.StructuredDocumentation ; let newLine = "\n\n"; + let indentSpaces = "\t\t"; let documentation = ""; if (structDoc.SummaryText) { documentation += structDoc.SummaryText + newLine; } + if (structDoc.TypeParamElements && structDoc.TypeParamElements.length > 0) { documentation += "Type Parameters:" + newLine; - documentation += structDoc.TypeParamElements.join(newLine) + newLine; + documentation += indentSpaces + structDoc.TypeParamElements.join("\n" + indentSpaces) + newLine; } + if (structDoc.ParamElements && structDoc.ParamElements.length > 0) { documentation += "Parameters:" + newLine; - documentation += structDoc.ParamElements.join(newLine) + newLine; + documentation += indentSpaces + structDoc.ParamElements.join("\n" + indentSpaces) + newLine; } + if (structDoc.ReturnsText) { documentation += structDoc.ReturnsText + newLine; } + if (structDoc.RemarksText) { documentation += structDoc.RemarksText + newLine; } + if (structDoc.ExampleText) { documentation += structDoc.ExampleText + newLine; } + if (structDoc.ValueText) { documentation += structDoc.ValueText + newLine; } + if (structDoc.Exception && structDoc.Exception.length > 0) { documentation += "Exceptions:" + newLine; - documentation += structDoc.Exception.join(newLine) + newLine; + documentation += indentSpaces + structDoc.Exception.join("\n" + indentSpaces) + newLine; } documentation = documentation.trim(); diff --git a/test/integrationTests/hoverProvider.integration.test.ts b/test/integrationTests/hoverProvider.integration.test.ts index 2a2039a25..b8a511d56 100644 --- a/test/integrationTests/hoverProvider.integration.test.ts +++ b/test/integrationTests/hoverProvider.integration.test.ts @@ -39,7 +39,7 @@ suite(`Tasks generation: ${testAssetWorkspace.description}`, function() { test("Hover returns structured documentation with proper newlines", async function () { - var program = + let program = `using System; namespace Test { @@ -69,9 +69,8 @@ namespace Test Parameters: -gameObject: The game object. - -tagName: Name of the tag. +\t\tgameObject: The game object. +\t\ttagName: Name of the tag. Returns: Returns trueif object is tagged with tag.`; expect(c[0].contents[0].value).to.equal(answer); From 05ed4bdfd43ca308000a3cabf87e2bd6b66fd77f Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Tue, 12 Dec 2017 19:03:47 -0800 Subject: [PATCH 15/23] Changes for parameter as an object --- src/features/hoverProvider.ts | 10 +++++++--- src/omnisharp/protocol.ts | 10 +++++++--- .../integrationTests/hoverProvider.integration.test.ts | 4 ++-- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/features/hoverProvider.ts b/src/features/hoverProvider.ts index d2750fe52..78596f9e9 100644 --- a/src/features/hoverProvider.ts +++ b/src/features/hoverProvider.ts @@ -31,12 +31,12 @@ export default class OmniSharpHoverProvider extends AbstractSupport implements H if (structDoc.TypeParamElements && structDoc.TypeParamElements.length > 0) { documentation += "Type Parameters:" + newLine; - documentation += indentSpaces + structDoc.TypeParamElements.join("\n" + indentSpaces) + newLine; + documentation += indentSpaces + structDoc.TypeParamElements.map(OmniSharpHoverProvider.displayDocumentationObject).join("\n" + indentSpaces) + newLine; } if (structDoc.ParamElements && structDoc.ParamElements.length > 0) { documentation += "Parameters:" + newLine; - documentation += indentSpaces + structDoc.ParamElements.join("\n" + indentSpaces) + newLine; + documentation += indentSpaces + structDoc.ParamElements.map(OmniSharpHoverProvider.displayDocumentationObject).join("\n" + indentSpaces) + newLine; } if (structDoc.ReturnsText) { @@ -57,7 +57,7 @@ export default class OmniSharpHoverProvider extends AbstractSupport implements H if (structDoc.Exception && structDoc.Exception.length > 0) { documentation += "Exceptions:" + newLine; - documentation += indentSpaces + structDoc.Exception.join("\n" + indentSpaces) + newLine; + documentation += indentSpaces + structDoc.Exception.map(OmniSharpHoverProvider.displayDocumentationObject).join("\n" + indentSpaces) + newLine; } documentation = documentation.trim(); @@ -66,4 +66,8 @@ export default class OmniSharpHoverProvider extends AbstractSupport implements H } }); } + + private static displayDocumentationObject(obj: protocol.DocumentedObject): string{ + return obj.Name + ": " + obj.Documentation; + } } \ No newline at end of file diff --git a/src/omnisharp/protocol.ts b/src/omnisharp/protocol.ts index edaebd936..b05cf1c31 100644 --- a/src/omnisharp/protocol.ts +++ b/src/omnisharp/protocol.ts @@ -214,15 +214,19 @@ export interface FindSymbolsResponse { QuickFixes: SymbolLocation[]; } +export interface DocumentedObject { + Name: string; + Documentation: string; +} export interface DocumentationComment { SummaryText: string ; - TypeParamElements :string[]; - ParamElements : string[]; + TypeParamElements :DocumentedObject[]; + ParamElements : DocumentedObject[]; ReturnsText : string ; RemarksText : string; ExampleText : string; ValueText: string; - Exception : string[]; + Exception : DocumentedObject[]; } export interface TypeLookupRequest extends Request { diff --git a/test/integrationTests/hoverProvider.integration.test.ts b/test/integrationTests/hoverProvider.integration.test.ts index b8a511d56..abd66d2ff 100644 --- a/test/integrationTests/hoverProvider.integration.test.ts +++ b/test/integrationTests/hoverProvider.integration.test.ts @@ -65,14 +65,14 @@ namespace Test let c = await vscode.commands.executeCommand("vscode.executeHoverProvider", fileUri,new vscode.Position(10,29)); let answer:string = -`Summary: Checks if object is tagged with the tag. +`Checks if object is tagged with the tag. Parameters: \t\tgameObject: The game object. \t\ttagName: Name of the tag. -Returns: Returns trueif object is tagged with tag.`; +Returns trueif object is tagged with tag.`; expect(c[0].contents[0].value).to.equal(answer); }); From 47129b78ed8a43a1a268b3469e0e386ffaf2269f Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Tue, 12 Dec 2017 19:16:34 -0800 Subject: [PATCH 16/23] Add missing line --- src/omnisharp/protocol.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/omnisharp/protocol.ts b/src/omnisharp/protocol.ts index b05cf1c31..a59d08232 100644 --- a/src/omnisharp/protocol.ts +++ b/src/omnisharp/protocol.ts @@ -218,6 +218,7 @@ export interface DocumentedObject { Name: string; Documentation: string; } + export interface DocumentationComment { SummaryText: string ; TypeParamElements :DocumentedObject[]; From e289fb1036bc95c24bdd56c71df72bb5a8b6ca62 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Wed, 13 Dec 2017 10:49:20 -0800 Subject: [PATCH 17/23] Changed to DocumentationItem --- src/features/hoverProvider.ts | 2 +- src/omnisharp/protocol.ts | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/features/hoverProvider.ts b/src/features/hoverProvider.ts index 78596f9e9..1ae9ad634 100644 --- a/src/features/hoverProvider.ts +++ b/src/features/hoverProvider.ts @@ -67,7 +67,7 @@ export default class OmniSharpHoverProvider extends AbstractSupport implements H }); } - private static displayDocumentationObject(obj: protocol.DocumentedObject): string{ + private static displayDocumentationObject(obj: protocol.DocumentationItem): string{ return obj.Name + ": " + obj.Documentation; } } \ No newline at end of file diff --git a/src/omnisharp/protocol.ts b/src/omnisharp/protocol.ts index a59d08232..31999b0a8 100644 --- a/src/omnisharp/protocol.ts +++ b/src/omnisharp/protocol.ts @@ -214,20 +214,20 @@ export interface FindSymbolsResponse { QuickFixes: SymbolLocation[]; } -export interface DocumentedObject { +export interface DocumentationItem { Name: string; Documentation: string; } export interface DocumentationComment { SummaryText: string ; - TypeParamElements :DocumentedObject[]; - ParamElements : DocumentedObject[]; + TypeParamElements :DocumentationItem[]; + ParamElements : DocumentationItem[]; ReturnsText : string ; RemarksText : string; ExampleText : string; ValueText: string; - Exception : DocumentedObject[]; + Exception : DocumentationItem[]; } export interface TypeLookupRequest extends Request { From c2a32f751b6a4489228f52397be03c917fdcc7d2 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Wed, 10 Jan 2018 16:38:10 -0800 Subject: [PATCH 18/23] Extracted Documentation helper as a function in a separate file --- src/features/documentation.ts | 57 ++++++++++++++++++++++++++++++++--- src/features/hoverProvider.ts | 47 ++--------------------------- 2 files changed, 55 insertions(+), 49 deletions(-) diff --git a/src/features/documentation.ts b/src/features/documentation.ts index c7f191c52..8f5c614fc 100644 --- a/src/features/documentation.ts +++ b/src/features/documentation.ts @@ -1,9 +1,6 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - 'use strict'; +import * as protocol from '../omnisharp/protocol'; +import { MarkdownString } from 'vscode'; const summaryStartTag = //i; const summaryEndTag = /<\/summary>/i; @@ -29,3 +26,53 @@ export function extractSummaryText(xmlDocComment: string): string { return summary.slice(0, endIndex); } + +export function GetDocumentationString(structDoc: protocol.DocumentationComment) { + let newLine = "\n\n"; + let indentSpaces = "\t\t"; + let documentation = ""; + if (structDoc == null) { + return documentation; + } + if (structDoc.SummaryText) { + documentation += structDoc.SummaryText + newLine; + } + + if (structDoc.TypeParamElements && structDoc.TypeParamElements.length > 0) { + documentation += "Type Parameters:" + newLine; + documentation += indentSpaces + structDoc.TypeParamElements.map(displayDocumentationObject).join("\n" + indentSpaces) + newLine; + } + + if (structDoc.ParamElements && structDoc.ParamElements.length > 0) { + documentation += "Parameters:" + newLine; + documentation += indentSpaces + structDoc.ParamElements.map(displayDocumentationObject).join("\n" + indentSpaces) + newLine; + } + + if (structDoc.ReturnsText) { + documentation += structDoc.ReturnsText + newLine; + } + + if (structDoc.RemarksText) { + documentation += structDoc.RemarksText + newLine; + } + + if (structDoc.ExampleText) { + documentation += structDoc.ExampleText + newLine; + } + + if (structDoc.ValueText) { + documentation += structDoc.ValueText + newLine; + } + + if (structDoc.Exception && structDoc.Exception.length > 0) { + documentation += "Exceptions:" + newLine; + documentation += indentSpaces + structDoc.Exception.map(displayDocumentationObject).join("\n" + indentSpaces) + newLine; + } + + documentation = documentation.trim(); + return documentation; +} + +export function displayDocumentationObject(obj: protocol.DocumentationItem): string { + return obj.Name + ": " + obj.Documentation; +} diff --git a/src/features/hoverProvider.ts b/src/features/hoverProvider.ts index 1ae9ad634..b63cea4c3 100644 --- a/src/features/hoverProvider.ts +++ b/src/features/hoverProvider.ts @@ -11,6 +11,7 @@ import * as serverUtils from '../omnisharp/utils'; import {createRequest} from '../omnisharp/typeConvertion'; import {HoverProvider, Hover, TextDocument, CancellationToken, Position} from 'vscode'; +import { GetDocumentationString } from './documentation'; export default class OmniSharpHoverProvider extends AbstractSupport implements HoverProvider { @@ -21,53 +22,11 @@ export default class OmniSharpHoverProvider extends AbstractSupport implements H return serverUtils.typeLookup(this._server, req, token).then(value => { if (value && value.Type) { - let structDoc = value.StructuredDocumentation ; - let newLine = "\n\n"; - let indentSpaces = "\t\t"; - let documentation = ""; - if (structDoc.SummaryText) { - documentation += structDoc.SummaryText + newLine; - } - - if (structDoc.TypeParamElements && structDoc.TypeParamElements.length > 0) { - documentation += "Type Parameters:" + newLine; - documentation += indentSpaces + structDoc.TypeParamElements.map(OmniSharpHoverProvider.displayDocumentationObject).join("\n" + indentSpaces) + newLine; - } - - if (structDoc.ParamElements && structDoc.ParamElements.length > 0) { - documentation += "Parameters:" + newLine; - documentation += indentSpaces + structDoc.ParamElements.map(OmniSharpHoverProvider.displayDocumentationObject).join("\n" + indentSpaces) + newLine; - } - - if (structDoc.ReturnsText) { - documentation += structDoc.ReturnsText + newLine; - } - - if (structDoc.RemarksText) { - documentation += structDoc.RemarksText + newLine; - } - - if (structDoc.ExampleText) { - documentation += structDoc.ExampleText + newLine; - } - - if (structDoc.ValueText) { - documentation += structDoc.ValueText + newLine; - } - - if (structDoc.Exception && structDoc.Exception.length > 0) { - documentation += "Exceptions:" + newLine; - documentation += indentSpaces + structDoc.Exception.map(OmniSharpHoverProvider.displayDocumentationObject).join("\n" + indentSpaces) + newLine; - } - - documentation = documentation.trim(); + let structDoc = value.StructuredDocumentation; + let documentation = GetDocumentationString(value.StructuredDocumentation); let contents = [documentation, { language: 'csharp', value: value.Type }]; return new Hover(contents); } }); } - - private static displayDocumentationObject(obj: protocol.DocumentationItem): string{ - return obj.Name + ": " + obj.Documentation; - } } \ No newline at end of file From 9e61bc9e9c50845cd228d85f80a646d89eeee334 Mon Sep 17 00:00:00 2001 From: akshita31 Date: Wed, 10 Jan 2018 19:55:30 -0800 Subject: [PATCH 19/23] Removed unnecessary using --- src/features/documentation.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/features/documentation.ts b/src/features/documentation.ts index 8f5c614fc..145b314ee 100644 --- a/src/features/documentation.ts +++ b/src/features/documentation.ts @@ -1,6 +1,5 @@ 'use strict'; import * as protocol from '../omnisharp/protocol'; -import { MarkdownString } from 'vscode'; const summaryStartTag = //i; const summaryEndTag = /<\/summary>/i; From ecec82cbc31bf7e0aec4a89a27dceeef6edca20d Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Thu, 11 Jan 2018 10:30:11 -0800 Subject: [PATCH 20/23] Code Clean up --- src/features/documentation.ts | 7 +++- src/features/hoverProvider.ts | 5 ++- .../launchConfiguration.integration.test.ts | 33 +++++++++---------- .../integrationTests/testAssets/testAssets.ts | 24 +++++++------- 4 files changed, 35 insertions(+), 34 deletions(-) diff --git a/src/features/documentation.ts b/src/features/documentation.ts index 145b314ee..e306650d6 100644 --- a/src/features/documentation.ts +++ b/src/features/documentation.ts @@ -1,3 +1,8 @@ +/*--------------------------------------------------------------------------------------------- + - * Copyright (c) Microsoft Corporation. All rights reserved. + - * Licensed under the MIT License. See License.txt in the project root for license information. + - *--------------------------------------------------------------------------------------------*/ + 'use strict'; import * as protocol from '../omnisharp/protocol'; @@ -73,5 +78,5 @@ export function GetDocumentationString(structDoc: protocol.DocumentationComment) } export function displayDocumentationObject(obj: protocol.DocumentationItem): string { - return obj.Name + ": " + obj.Documentation; + return obj.Name + ": " + obj.Documentation; } diff --git a/src/features/hoverProvider.ts b/src/features/hoverProvider.ts index b63cea4c3..7d9b23a57 100644 --- a/src/features/hoverProvider.ts +++ b/src/features/hoverProvider.ts @@ -8,9 +8,8 @@ import AbstractSupport from './abstractProvider'; import * as protocol from '../omnisharp/protocol'; import * as serverUtils from '../omnisharp/utils'; -import {createRequest} from '../omnisharp/typeConvertion'; - -import {HoverProvider, Hover, TextDocument, CancellationToken, Position} from 'vscode'; +import { createRequest } from '../omnisharp/typeConvertion'; +import { HoverProvider, Hover, TextDocument, CancellationToken, Position } from 'vscode'; import { GetDocumentationString } from './documentation'; export default class OmniSharpHoverProvider extends AbstractSupport implements HoverProvider { diff --git a/test/integrationTests/launchConfiguration.integration.test.ts b/test/integrationTests/launchConfiguration.integration.test.ts index 17b6151a6..1b0d593f1 100644 --- a/test/integrationTests/launchConfiguration.integration.test.ts +++ b/test/integrationTests/launchConfiguration.integration.test.ts @@ -10,43 +10,42 @@ import poll from './poll'; import { should } from 'chai'; import testAssetWorkspace from './testAssets/testAssetWorkspace'; -const chai = require('chai'); -chai.use(require('chai-arrays')); -chai.use(require('chai-fs')); - -suite(`Tasks generation: ${testAssetWorkspace.description}`, function() { - suiteSetup(async function() { +const chai = require('chai'); +chai.use(require('chai-arrays')); +chai.use(require('chai-fs')); + +suite(`Tasks generation: ${testAssetWorkspace.description}`, function () { + suiteSetup(async function () { should(); - - let csharpExtension = vscode.extensions.getExtension("ms-vscode.csharp"); - if (!csharpExtension.isActive) { - await csharpExtension.activate(); + + let csharpExtension = vscode.extensions.getExtension("ms-vscode.csharp"); + if (!csharpExtension.isActive) { + await csharpExtension.activate(); } await testAssetWorkspace.cleanupWorkspace(); await csharpExtension.exports.initializationFinished; - + await vscode.commands.executeCommand("dotnet.generateAssets"); await poll(async () => await fs.exists(testAssetWorkspace.launchJsonPath), 10000, 100); - - }); - + + }); + test("Starting .NET Core Launch (console) from the workspace root should create an Active Debug Session", async () => { await vscode.debug.startDebugging(vscode.workspace.workspaceFolders[0], ".NET Core Launch (console)"); let debugSessionTerminated = new Promise(resolve => { vscode.debug.onDidTerminateDebugSession((e) => resolve()); }); - + vscode.debug.activeDebugSession.type.should.equal("coreclr"); await debugSessionTerminated; }); - teardown(async() => - { + teardown(async () => { await testAssetWorkspace.cleanupWorkspace(); }) }); \ No newline at end of file diff --git a/test/integrationTests/testAssets/testAssets.ts b/test/integrationTests/testAssets/testAssets.ts index eb9fa4ffa..6e690edb1 100644 --- a/test/integrationTests/testAssets/testAssets.ts +++ b/test/integrationTests/testAssets/testAssets.ts @@ -6,7 +6,7 @@ import * as fs from 'async-file'; import * as path from 'path'; import * as vscode from 'vscode'; -import * as cp from 'child_process' +import * as cp from 'child_process'; export class TestAssetProject { constructor(project: ITestAssetProject) { @@ -34,7 +34,7 @@ export class TestAssetProject { } async addFileWithContents(fileName: string, contents: string): Promise { - let dir = path.dirname(this.projectDirectoryPath) + let dir = path.dirname(this.projectDirectoryPath); let loc = path.join(dir, fileName); await fs.writeTextFile(loc, contents); return vscode.Uri.file(loc); @@ -66,26 +66,24 @@ export class TestAssetWorkspace { return path.join(this.vsCodeDirectoryPath, "tasks.json"); } - async cleanupWorkspace() : Promise - { - for (let project of this.projects) - { + async cleanupWorkspace(): Promise { + for (let project of this.projects) { let wd = path.dirname(project.projectDirectoryPath); await this.invokeGit("clean -xdf . ", wd); - await this.invokeGit("checkout -- .", wd); + await this.invokeGit("checkout -- .", wd); } } - invokeGit(args: string, workingDirectory: string) : Promise<{stdout: string, stderr: string}> { - return new Promise((resolve, reject) => { - let child = cp.exec('git ' + args, {cwd: path.dirname(workingDirectory) }, + invokeGit(args: string, workingDirectory: string): Promise<{ stdout: string, stderr: string }> { + return new Promise((resolve, reject) => { + let child = cp.exec('git ' + args, { cwd: path.dirname(workingDirectory) }, (err, stdout, stderr) => { return err ? reject(err) : resolve({ stdout: stdout, stderr: stderr - }) - }) - }); + }); + }); + }); } description: string; From cbfde537fe3db5208cb34f2788fae0a1a09ae7f8 Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Thu, 11 Jan 2018 10:34:35 -0800 Subject: [PATCH 21/23] Clean up --- src/features/documentation.ts | 6 +++--- .../launchConfiguration.integration.test.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/features/documentation.ts b/src/features/documentation.ts index e306650d6..eb023007c 100644 --- a/src/features/documentation.ts +++ b/src/features/documentation.ts @@ -1,7 +1,7 @@ /*--------------------------------------------------------------------------------------------- - - * Copyright (c) Microsoft Corporation. All rights reserved. - - * Licensed under the MIT License. See License.txt in the project root for license information. - - *--------------------------------------------------------------------------------------------*/ + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ 'use strict'; import * as protocol from '../omnisharp/protocol'; diff --git a/test/integrationTests/launchConfiguration.integration.test.ts b/test/integrationTests/launchConfiguration.integration.test.ts index 1b0d593f1..6331c7bcc 100644 --- a/test/integrationTests/launchConfiguration.integration.test.ts +++ b/test/integrationTests/launchConfiguration.integration.test.ts @@ -47,5 +47,5 @@ suite(`Tasks generation: ${testAssetWorkspace.description}`, function () { teardown(async () => { await testAssetWorkspace.cleanupWorkspace(); - }) + }); }); \ No newline at end of file From 62e6c2e75e230b6c766fc072b1cd8c9eabbc28bf Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Fri, 12 Jan 2018 14:01:41 -0800 Subject: [PATCH 22/23] Fixed spacing --- src/omnisharp/protocol.ts | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/omnisharp/protocol.ts b/src/omnisharp/protocol.ts index 31999b0a8..68aec029a 100644 --- a/src/omnisharp/protocol.ts +++ b/src/omnisharp/protocol.ts @@ -220,14 +220,14 @@ export interface DocumentationItem { } export interface DocumentationComment { - SummaryText: string ; - TypeParamElements :DocumentationItem[]; - ParamElements : DocumentationItem[]; - ReturnsText : string ; - RemarksText : string; - ExampleText : string; + SummaryText: string; + TypeParamElements: DocumentationItem[]; + ParamElements: DocumentationItem[]; + ReturnsText: string; + RemarksText: string; + ExampleText: string; ValueText: string; - Exception : DocumentationItem[]; + Exception: DocumentationItem[]; } export interface TypeLookupRequest extends Request { @@ -237,7 +237,7 @@ export interface TypeLookupRequest extends Request { export interface TypeLookupResponse { Type: string; Documentation: string; - StructuredDocumentation : DocumentationComment; + StructuredDocumentation: DocumentationComment; } export interface RunCodeActionResponse { @@ -435,13 +435,12 @@ export interface PackageDependency { Name: string; Version: string; } - -export interface FilesChangedRequest extends Request{ + +export interface FilesChangedRequest extends Request { ChangeType: FileChangeType; } -export enum FileChangeType -{ +export enum FileChangeType { Change = "Change", Create = "Create", Delete = "Delete" From 5e69bcba3fdd634125a330ee7b74bd37013a381d Mon Sep 17 00:00:00 2001 From: Akshita Agarwal Date: Fri, 12 Jan 2018 15:33:12 -0800 Subject: [PATCH 23/23] Removed unused variable --- src/features/documentation.ts | 4 +--- src/features/hoverProvider.ts | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/features/documentation.ts b/src/features/documentation.ts index eb023007c..b20489d7c 100644 --- a/src/features/documentation.ts +++ b/src/features/documentation.ts @@ -35,9 +35,7 @@ export function GetDocumentationString(structDoc: protocol.DocumentationComment) let newLine = "\n\n"; let indentSpaces = "\t\t"; let documentation = ""; - if (structDoc == null) { - return documentation; - } + if (structDoc.SummaryText) { documentation += structDoc.SummaryText + newLine; } diff --git a/src/features/hoverProvider.ts b/src/features/hoverProvider.ts index 7d9b23a57..03c40d051 100644 --- a/src/features/hoverProvider.ts +++ b/src/features/hoverProvider.ts @@ -21,7 +21,6 @@ export default class OmniSharpHoverProvider extends AbstractSupport implements H return serverUtils.typeLookup(this._server, req, token).then(value => { if (value && value.Type) { - let structDoc = value.StructuredDocumentation; let documentation = GetDocumentationString(value.StructuredDocumentation); let contents = [documentation, { language: 'csharp', value: value.Type }]; return new Hover(contents);