1+ /*---------------------------------------------------------------------------------------------
2+ * Copyright (c) Microsoft Corporation. All rights reserved.
3+ * Licensed under the MIT License. See License.txt in the project root for license information.
4+ *--------------------------------------------------------------------------------------------*/
5+
6+ import * as vscode from 'vscode' ;
7+ import * as path from 'path' ;
8+
9+ import poll from './poll' ;
10+ import { should , expect } from 'chai' ;
11+ import testAssetWorkspace from './testAssets/testAssetWorkspace' ;
12+ import { omnisharp } from '../../src/omnisharp/extension' ;
13+
14+ const chai = require ( 'chai' ) ;
15+ chai . use ( require ( 'chai-arrays' ) ) ;
16+ chai . use ( require ( 'chai-fs' ) ) ;
17+
18+ suite ( `SignatureHelp: ${ testAssetWorkspace . description } ` , function ( ) {
19+ let fileUri : vscode . Uri ;
20+ suiteSetup ( async function ( ) {
21+ should ( ) ;
22+
23+ let csharpExtension = vscode . extensions . getExtension ( "ms-vscode.csharp" ) ;
24+ if ( ! csharpExtension . isActive ) {
25+ await csharpExtension . activate ( ) ;
26+ }
27+
28+ await csharpExtension . exports . initializationFinished ;
29+
30+ let fileName = 'sigHelp.cs' ;
31+ let dir = path . dirname ( testAssetWorkspace . projects [ 0 ] . projectDirectoryPath ) ;
32+ let loc = path . join ( dir , fileName ) ;
33+ fileUri = vscode . Uri . file ( loc ) ;
34+ await omnisharp . waitForEmptyEventQueue ( ) ;
35+ await vscode . commands . executeCommand ( "vscode.open" , fileUri ) ;
36+ } ) ;
37+
38+
39+ test ( "Returns response with documentation as undefined when method does not have documentation" , async function ( ) {
40+ let c = < vscode . SignatureHelp > await vscode . commands . executeCommand ( "vscode.executeSignatureHelpProvider" , fileUri , new vscode . Position ( 19 , 23 ) ) ;
41+ expect ( c . signatures [ 0 ] . documentation ) . to . be . undefined ;
42+ } ) ;
43+
44+ test ( "Returns label when method does not have documentation" , async function ( ) {
45+ let c = < vscode . SignatureHelp > await vscode . commands . executeCommand ( "vscode.executeSignatureHelpProvider" , fileUri , new vscode . Position ( 19 , 23 ) ) ;
46+ let answer = `void sigHelp.noDocMethod()` ;
47+ expect ( c . signatures [ 0 ] . label ) . to . equal ( answer ) ;
48+ } ) ;
49+
50+ test ( "Returns summary as documentation for the method" , async function ( ) {
51+ let c = < vscode . SignatureHelp > await vscode . commands . executeCommand ( "vscode.executeSignatureHelpProvider" , fileUri , new vscode . Position ( 18 , 18 ) ) ;
52+ let answer = `DoWork is some method.` ;
53+ expect ( c . signatures [ 0 ] . documentation ) . to . equal ( answer ) ;
54+ } ) ;
55+
56+ test ( "Returns label for the method" , async function ( ) {
57+ let c = < vscode . SignatureHelp > await vscode . commands . executeCommand ( "vscode.executeSignatureHelpProvider" , fileUri , new vscode . Position ( 18 , 18 ) ) ;
58+ let answer = `void sigHelp.DoWork(int Int1, float Float1)` ;
59+ expect ( c . signatures [ 0 ] . label ) . to . equal ( answer ) ;
60+ } ) ;
61+
62+ test ( "Returns label for the parameters" , async function ( ) {
63+ let c = < vscode . SignatureHelp > await vscode . commands . executeCommand ( "vscode.executeSignatureHelpProvider" , fileUri , new vscode . Position ( 18 , 18 ) ) ;
64+ let param1 = `int Int1` ;
65+ let param2 = `float Float1` ;
66+ expect ( c . signatures [ 0 ] . parameters [ 0 ] . label ) . to . equal ( param1 ) ;
67+ expect ( c . signatures [ 0 ] . parameters [ 1 ] . label ) . to . equal ( param2 ) ;
68+ } ) ;
69+
70+ test ( "Returns documentation for the parameters" , async function ( ) {
71+ let c = < vscode . SignatureHelp > await vscode . commands . executeCommand ( "vscode.executeSignatureHelpProvider" , fileUri , new vscode . Position ( 18 , 18 ) ) ;
72+ let param1 = `**Int1**: Used to indicate status.` ;
73+ let param2 = `**Float1**: Used to specify context.` ;
74+ expect ( ( < vscode . MarkdownString > c . signatures [ 0 ] . parameters [ 0 ] . documentation ) . value ) . to . equal ( param1 ) ;
75+ expect ( ( < vscode . MarkdownString > c . signatures [ 0 ] . parameters [ 1 ] . documentation ) . value ) . to . equal ( param2 ) ;
76+ } ) ;
77+
78+ test ( "Signature Help identifies active parameter if there is no comma" , async function ( ) {
79+ let c = < vscode . SignatureHelp > await vscode . commands . executeCommand ( "vscode.executeSignatureHelpProvider" , fileUri , new vscode . Position ( 18 , 18 ) ) ;
80+ let answer = `int Int1` ;
81+ expect ( c . signatures [ 0 ] . parameters [ c . activeParameter ] . label ) . to . equal ( answer ) ;
82+ } ) ;
83+
84+ test ( "Signature Help identifies active parameter based on comma" , async function ( ) {
85+ let c = < vscode . SignatureHelp > await vscode . commands . executeCommand ( "vscode.executeSignatureHelpProvider" , fileUri , new vscode . Position ( 18 , 20 ) ) ;
86+ let answer = `float Float1` ;
87+ expect ( c . signatures [ 0 ] . parameters [ c . activeParameter ] . label ) . to . equal ( answer ) ;
88+ } ) ;
89+
90+ suiteTeardown ( async ( ) => {
91+ await testAssetWorkspace . cleanupWorkspace ( ) ;
92+ } ) ;
93+ } ) ;
0 commit comments