@@ -1090,7 +1090,8 @@ namespace ts {
10901090
10911091 export interface TextInsertion {
10921092 newText : string ;
1093- offsetInNewText : number ;
1093+ /** The position in newText the caret should point to after the insertion. */
1094+ caretOffset : number ;
10941095 }
10951096
10961097 export interface RenameLocation {
@@ -6758,7 +6759,6 @@ namespace ts {
67586759 function getIndentationAtPosition ( fileName : string , position : number , editorOptions : EditorOptions ) {
67596760 let start = new Date ( ) . getTime ( ) ;
67606761 let sourceFile = syntaxTreeCache . getCurrentSourceFile ( fileName ) ;
6761- log ( "getIndentationAtPosition: getCurrentSourceFile: " + ( new Date ( ) . getTime ( ) - start ) ) ;
67626762
67636763 start = new Date ( ) . getTime ( ) ;
67646764
@@ -6800,11 +6800,11 @@ namespace ts {
68006800 * Valid positions are
68016801 * * outside of comments, statements, and expressions, and
68026802 * * preceding a function declaration.
6803- *
6803+ *
68046804 * Hosts should ideally check that:
68056805 * * The line is all whitespace up to 'position' before performing the insertion.
68066806 * * If the keystroke sequence "/\*\*" induced the call, we also check that the next
6807- * non-whitespace character is '*', which (approximately) indicates whether we added
6807+ * non-whitespace character is '*', which (approximately) indicates whether we added
68086808 * the second '*' to complete an existing (JSDoc) comment.
68096809 * @param fileName The file in which to perform the check.
68106810 * @param position The (character-indexed) position in the file where the check should
@@ -6843,16 +6843,24 @@ namespace ts {
68436843 let docParams = parameters . map ( ( p , index ) =>
68446844 indentationStr + " * @param " + ( p . name . kind === SyntaxKind . Identifier ? ( < Identifier > p . name ) . text : "param" + index . toString ( ) ) + newLine ) ;
68456845
6846- let result =
6847- /* opening comment */ "/**" + newLine +
6848- /* first line for function info */ indentationStr + " * " + newLine +
6849- /* paramters */ docParams . reduce ( ( prev , cur ) => prev + cur , "" ) +
6850- /* closing comment */ indentationStr + " */" +
6851- /* newline if at decl start */ ( tokenStart === position ? newLine + indentationStr : "" ) ;
6852-
6853- let cursorOffset = /* "/**" */ 3 + /* newLine */ newLine . length + indentationStr . length + /* " * " */ 3 ;
68546846
6855- return { newText : result , offsetInNewText : cursorOffset } ;
6847+ // A doc comment consists of the following
6848+ // * The opening comment line
6849+ // * the first line (without a param) for the object's untagged info (this is also where the caret ends up)
6850+ // * the '@param'-tagged lines
6851+ // * TODO: other tags.
6852+ // * the closing comment line
6853+ // * if the caret was directly in front of the object, then we add an extra line and indentation.
6854+ let result =
6855+ "/**" + newLine +
6856+ indentationStr + " * " + newLine +
6857+ docParams . reduce ( ( prev , cur ) => prev + cur , "" ) +
6858+ indentationStr + " */" +
6859+ ( tokenStart === position ? newLine + indentationStr : "" ) ;
6860+
6861+ let cursorOffset = "/**" . length + newLine . length + indentationStr . length + " * " . length ;
6862+
6863+ return { newText : result , caretOffset : cursorOffset } ;
68566864 }
68576865
68586866 function getTodoComments ( fileName : string , descriptors : TodoCommentDescriptor [ ] ) : TodoComment [ ] {
0 commit comments