-
Notifications
You must be signed in to change notification settings - Fork 678
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
Support auto doc comment generation #4261
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
159de98
Support auto doc comment generation
333fred 2e54c8f
Merge branch 'master' into doc-comment-formatting
333fred 4a6ad52
Merge branch 'master' into doc-comment-formatting
JoeRobich ba53289
Fix formatting and lint issues.
333fred b69cf12
Merge branch 'master' into doc-comment-formatting
JoeRobich File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
65 changes: 65 additions & 0 deletions
65
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,65 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { expect, should } from 'chai'; | ||
import * as vscode from 'vscode'; | ||
import * as path from 'path'; | ||
import { isRazorWorkspace } from './integrationHelpers'; | ||
import testAssetWorkspace from './testAssets/testAssetWorkspace'; | ||
|
||
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() {} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
node.js does not have
replaceAll
, unfortunately...