Skip to content

Commit e6809c3

Browse files
author
Arthur Ozga
committed
Simplfied Return Values
1 parent 355db23 commit e6809c3

2 files changed

Lines changed: 20 additions & 6 deletions

File tree

src/harness/typeWriter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,4 @@ class TypeWriterWalker {
7171
symbol: symbolString
7272
});
7373
}
74-
}
74+
}

src/services/services.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6764,14 +6764,23 @@ namespace ts {
67646764

67656765
/**
67666766
* Checks if position points to a valid position to add JSDoc comments, and if so,
6767-
* returns the appropriate scaffolding. Otherwise returns a default string.
6768-
* @param fileName The file in which to perofrm the check
6767+
* returns the appropriate scaffolding. Otherwise returns an empty string.
6768+
* Valid positions are
6769+
* * outside of comments, statements, and expressions, and
6770+
* * preceding a function declaration.
6771+
*
6772+
* In VS, we additionally check that:
6773+
* * The line is all whitespace up to 'position' before performing the insertion.
6774+
* * If the keystroke sequence "/\*\*" induced the call, we also check that the next
6775+
* non-whitespace character is '*', which (approximately) indicates whether we added
6776+
* the second '*' to complete an existing (JSDoc) comment.
6777+
* @param fileName The file in which to perform the check.
67696778
* @param position The (character-indexed) position in the file where the check should
67706779
* be performed.
67716780
*/
67726781
function getDocCommentScaffoldingAtPosition(fileName: string, position: number): TextInsertion {
6773-
const nullResult = { newText: "/**", cursorOffset: 3 };
6774-
const emptyCompletion = { newText: "/** */", cursorOffset: 3 };
6782+
// Indicates the position is not appropriate to insert a comment (eg: a string or a regex).
6783+
const nullResult: TextInsertion = { newText: "", cursorOffset: 0 };
67756784
let start = new Date().getTime();
67766785
let sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName);
67776786
log("getDocCommentScaffoldingAtPosition: getCurrentSourceFile: " + (new Date().getTime() - start));
@@ -6782,10 +6791,15 @@ namespace ts {
67826791
}
67836792

67846793
let nodeAtPos = getTokenAtPosition(sourceFile, position);
6794+
6795+
if (!nodeAtPos || nodeAtPos.getStart() < position) {
6796+
return nullResult;
6797+
}
6798+
67856799
let containingFunction = <FunctionDeclaration>getAncestor(nodeAtPos, SyntaxKind.FunctionDeclaration);
67866800

67876801
if (hasDocComment(sourceFile, position) || !containingFunction || containingFunction.getStart() < position) {
6788-
return emptyCompletion;
6802+
return nullResult;
67896803
}
67906804

67916805
let parameters = containingFunction.parameters;

0 commit comments

Comments
 (0)