forked from dotnet/vscode-csharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds '\n' and '/' to the on-type format list, enabling vscode support for the newly-added omnisharp feature of auto-generating documentation comments. Closes dotnet#8.
- Loading branch information
Showing
4 changed files
with
88 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
test/integrationTests/documentationCommentAutoFormatting.integration.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { expect, should } from 'chai'; | ||
import * as vscode from 'vscode'; | ||
import * as path from 'path'; | ||
import { isRazorWorkspace } from './integrationHelpers'; | ||
import testAssetWorkspace from './testAssets/testAssetWorkspace'; | ||
import { skip } from 'rxjs/operators'; | ||
|
||
const onTypeFormatProviderCommand = 'vscode.executeFormatOnTypeProvider'; | ||
|
||
function normalizeNewlines(original: string): string { | ||
while (original.indexOf('\r\n') != -1) { | ||
original = original.replace('\r\n', '\n'); | ||
} | ||
|
||
return original; | ||
} | ||
|
||
suite(`Documentation Comment Auto Formatting: ${testAssetWorkspace.description}`, function () { | ||
let fileUri: vscode.Uri; | ||
|
||
suiteSetup(async function () { | ||
should(); | ||
|
||
if (isRazorWorkspace(vscode.workspace)) { | ||
// The format-on-type provider does not run for razor files. | ||
this.skip(); | ||
} | ||
|
||
const projectDirectory = testAssetWorkspace.projects[0].projectDirectoryPath; | ||
const filePath = path.join(projectDirectory, 'DocComments.cs'); | ||
fileUri = vscode.Uri.file(filePath); | ||
|
||
await vscode.commands.executeCommand('vscode.open', fileUri); | ||
}); | ||
|
||
suiteTeardown(async () => { | ||
await testAssetWorkspace.cleanupWorkspace(); | ||
}); | ||
|
||
test('Triple slash inserts doc comment snippet', async () => { | ||
const commentPosition = new vscode.Position(2, 7); | ||
const formatEdits = <vscode.TextEdit[]>(await vscode.commands.executeCommand(onTypeFormatProviderCommand, fileUri, commentPosition, '/')); | ||
expect(formatEdits).ofSize(1); | ||
expect(normalizeNewlines(formatEdits[0].newText)).eq(" <summary>\n /// \n /// </summary>\n /// <param name=\"param1\"></param>\n /// <param name=\"param2\"></param>\n /// <returns></returns>"); | ||
expect(formatEdits[0].range.start.line).eq(commentPosition.line); | ||
expect(formatEdits[0].range.start.character).eq(commentPosition.character); | ||
expect(formatEdits[0].range.end.line).eq(commentPosition.line); | ||
expect(formatEdits[0].range.end.character).eq(commentPosition.character); | ||
}); | ||
|
||
test('Enter in comment inserts triple-slashes preceding', async () => { | ||
const commentPosition = new vscode.Position(9, 0); | ||
const formatEdits = <vscode.TextEdit[]>(await vscode.commands.executeCommand(onTypeFormatProviderCommand, fileUri, commentPosition, '\n')); | ||
expect(formatEdits).ofSize(1); | ||
expect(formatEdits[0].newText).eq(" /// "); | ||
expect(formatEdits[0].range.start.line).eq(commentPosition.line); | ||
expect(formatEdits[0].range.start.character).eq(commentPosition.character); | ||
expect(formatEdits[0].range.end.line).eq(commentPosition.line); | ||
expect(formatEdits[0].range.end.character).eq(commentPosition.character); | ||
}); | ||
}); |
13 changes: 13 additions & 0 deletions
13
test/integrationTests/testAssets/singleCsproj/DocComments.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class DocComments | ||
{ | ||
/// | ||
string M(int param1, string param2) | ||
{ | ||
return null; | ||
} | ||
|
||
/// <summary> | ||
|
||
/// </summary> | ||
void M2() {} | ||
} |
13 changes: 13 additions & 0 deletions
13
test/integrationTests/testAssets/slnWithCsproj/src/app/DocComments.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class DocComments | ||
{ | ||
/// | ||
string M(int param1, string param2) | ||
{ | ||
return null; | ||
} | ||
|
||
/// <summary> | ||
|
||
/// </summary> | ||
void M2() {} | ||
} |