diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 1668fcedc62..82f24279a87 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -1945,7 +1945,7 @@ module FourSlash { let actual = this.languageService.getDocCommentScaffoldingAtPosition(this.activeFile.fileName, this.currentCaretPosition); if (actual.newText !== expected.newText) { - this.raiseError('verifyDocCommentScaffolding failed - expected insertion:\n' + expected.newText + 'actual insertion:\n' + actual.newText); + this.raiseError('verifyDocCommentScaffolding failed - expected insertion:\n' + expected.newText + '\nactual insertion:\n' + actual.newText); } if (actual.cursorOffset !== expected.cursorOffset) { diff --git a/src/services/services.ts b/src/services/services.ts index 23621f133b8..2a0516b2d34 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -6778,7 +6778,7 @@ namespace ts { let nodeAtPos = getTokenAtPosition(sourceFile, position); let containingFunction = getAncestor(nodeAtPos, SyntaxKind.FunctionDeclaration); - if (hasDocComment(sourceFile, position) || !containingFunction) { + if (hasDocComment(sourceFile, position) || !containingFunction || containingFunction.getStart() < position) { return emptyCompletion; } diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 999b3d30427..6007fcdbaf4 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -432,7 +432,7 @@ namespace ts { extraCheck: (c: CommentRange) => boolean): boolean { let token = getTokenAtPosition(sourceFile, position); - if (token && position < token.getStart()) { + if (token && position <= token.getStart()) { let commentRanges = getLeadingCommentRanges(sourceFile.text, token.pos); return forEach(commentRanges, c => c.pos < position && @@ -442,6 +442,7 @@ namespace ts { // // asdf ^\n // // But for multi-line comments, we don't want to be inside the comment in the following case: + // // /* asdf */^ // // Internally, we represent the end of the comment at the newline and closing '/', respectively. diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index d673acba671..c5446ef4148 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -379,7 +379,7 @@ module FourSlashInterface { } // Will fix in fourslash-referencing - public DocCommentScaffolding(position: number, expectedText: string, expectedOffset: number) { + public DocCommentScaffolding(expectedText: string, expectedOffset: number) { FourSlash.currentTestState.verifyDocCommentScaffolding({ newText: expectedText, cursorOffset: expectedOffset }); }