@@ -264,11 +264,13 @@ module ts {
264
264
265
265
private processDocumentationCommentDeclaration ( lines : string [ ] , declaration : Node ) {
266
266
var commentRanges = getLeadingCommentRangesOfNode ( declaration ) ;
267
- var sourceFile = declaration . getSourceFile ( ) ;
267
+ if ( commentRanges ) {
268
+ var sourceFile = declaration . getSourceFile ( ) ;
268
269
269
- for ( var i = 0 , n = commentRanges . length ; i < n ; i ++ ) {
270
- this . processDocumentationCommentRange (
271
- lines , sourceFile , commentRanges [ 0 ] ) ;
270
+ for ( var i = 0 , n = commentRanges . length ; i < n ; i ++ ) {
271
+ this . processDocumentationCommentRange (
272
+ lines , sourceFile , commentRanges [ 0 ] ) ;
273
+ }
272
274
}
273
275
}
274
276
@@ -320,16 +322,21 @@ module ts {
320
322
// Baz
321
323
var trimLength : number = undefined ;
322
324
for ( var iLine = startLineAndChar . line + 1 ; iLine <= endLineAndChar . line ; iLine ++ ) {
323
- var lineStart = sourceFile . getPositionFromLineAndCharacter ( iLine , /*character:*/ 0 ) ;
324
- var docCommentTriviaLength = this . skipDocumentationCommentTrivia ( sourceFile . text , lineStart ) ;
325
+ var lineStart = sourceFile . getPositionFromLineAndCharacter ( iLine , /*character:*/ 1 ) ;
326
+ var lineEnd = iLine === endLineAndChar . line
327
+ ? commentRange . end - "*/" . length
328
+ : sourceFile . getPositionFromLineAndCharacter ( iLine + 1 , 1 ) ;
329
+ var docCommentTriviaLength = this . skipDocumentationCommentTrivia ( sourceFile . text , lineStart , lineEnd ) ;
325
330
326
331
if ( trimLength === undefined || ( docCommentTriviaLength && docCommentTriviaLength < trimLength ) ) {
327
332
trimLength = docCommentTriviaLength ;
328
333
}
329
334
}
330
335
331
336
// Add the first line in.
332
- var firstLine = this . trimRight ( sourceFile . text . substr ( commentRange . pos + "/**" . length ) ) ;
337
+ var firstLine = sourceFile . text . substring (
338
+ commentRange . pos + "/**" . length ,
339
+ sourceFile . getPositionFromLineAndCharacter ( startLineAndChar . line + 1 , /*character:*/ 1 ) ) . trim ( ) ;
333
340
if ( firstLine !== "" ) {
334
341
lines . push ( firstLine ) ;
335
342
}
@@ -338,16 +345,16 @@ module ts {
338
345
// of the line (with the length up to the
339
346
for ( var iLine = startLineAndChar . line + 1 ; iLine < endLineAndChar . line ; iLine ++ ) {
340
347
var line = this . trimRight ( sourceFile . text . substring (
341
- sourceFile . getPositionFromLineAndCharacter ( iLine , /*character*/ 0 ) ,
342
- sourceFile . getPositionFromLineAndCharacter ( iLine + 1 , /*character*/ 0 ) ) ) . substr ( trimLength ) ;
348
+ sourceFile . getPositionFromLineAndCharacter ( iLine , /*character*/ 1 ) ,
349
+ sourceFile . getPositionFromLineAndCharacter ( iLine + 1 , /*character*/ 1 ) ) ) . substr ( trimLength ) ;
343
350
344
351
lines . push ( line ) ;
345
352
}
346
353
347
354
// Add the last line if there is any actual text before the */
348
- var lastLine = sourceFile . text . substring (
349
- sourceFile . getPositionFromLineAndCharacter ( endLineAndChar . line , /*character:*/ 0 ) ,
350
- commentRange . end - "*/" . length ) . substr ( trimLength ) ;
355
+ var lastLine = this . trimRight ( sourceFile . text . substring (
356
+ sourceFile . getPositionFromLineAndCharacter ( endLineAndChar . line , /*character:*/ 1 ) ,
357
+ commentRange . end - "*/" . length ) ) . substr ( trimLength ) ;
351
358
352
359
if ( lastLine !== "" ) {
353
360
lines . push ( lastLine ) ;
@@ -358,13 +365,25 @@ module ts {
358
365
return val . replace ( / ( \n | \r | \s ) + $ / , '' ) ;
359
366
}
360
367
361
- private skipDocumentationCommentTrivia ( text : string , lineStart : number ) : number {
362
- for ( var i = 0 ; i < text . length ; i ++ ) {
363
- var char = text . charCodeAt ( i ) ;
364
- if ( char === CharacterCodes . asterisk ) {
365
- return i + 1 ;
368
+ private skipDocumentationCommentTrivia ( text : string , lineStart : number , lineEnd : number ) : number {
369
+ var seenAsterisk = false ;
370
+ var lineLength = lineEnd - lineStart ;
371
+ for ( var i = 0 ; i < lineLength ; i ++ ) {
372
+ var char = text . charCodeAt ( i + lineStart ) ;
373
+ if ( char === CharacterCodes . asterisk && ! seenAsterisk ) {
374
+ // Ignore the first asterisk we see. We want to trim out the line of *'s
375
+ // commonly seen at the start of a doc comment.
376
+ seenAsterisk = true ;
377
+ continue ;
378
+ }
379
+ else if ( isLineBreak ( char ) ) {
380
+ // This was a blank line. Just ignore it wrt computing the leading whitespace to
381
+ // trim.
382
+ break ;
366
383
}
367
384
else if ( ! isWhiteSpace ( char ) ) {
385
+ // Found a real doc comment character. Keep track of it so we can determine how
386
+ // much of the doc comment leading trivia to trim off.
368
387
return i ;
369
388
}
370
389
}
@@ -2362,10 +2381,9 @@ module ts {
2362
2381
return result . length > 0 ? result . join ( ',' ) : ScriptElementKindModifier . none ;
2363
2382
}
2364
2383
2365
- /// QuickInfo
2366
2384
function getQuickInfoAtPosition ( fileName : string , position : number ) : QuickInfo {
2367
2385
synchronizeHostData ( ) ;
2368
-
2386
+
2369
2387
fileName = TypeScript . switchToForwardSlashes ( fileName ) ;
2370
2388
var sourceFile = getSourceFile ( fileName ) ;
2371
2389
var node = getNodeAtPosition ( sourceFile , position ) ;
@@ -2378,6 +2396,9 @@ module ts {
2378
2396
return undefined ;
2379
2397
}
2380
2398
2399
+ var documentation = symbol . getDocumentationComment ( ) ;
2400
+ var documentationParts = documentation === "" ? [ ] : [ new SymbolDisplayPart ( documentation , SymbolDisplayPartKind . text , /*symbol:*/ null ) ] ;
2401
+
2381
2402
// Having all this logic here is pretty unclean. Consider moving to the roslyn model
2382
2403
// where all symbol display logic is encapsulated into visitors and options.
2383
2404
var totalParts : SymbolDisplayPart [ ] = [ ] ;
@@ -2465,7 +2486,7 @@ module ts {
2465
2486
getSymbolModifiers ( symbol ) ,
2466
2487
new TypeScript . TextSpan ( node . getStart ( ) , node . getWidth ( ) ) ,
2467
2488
totalParts ,
2468
- [ new SymbolDisplayPart ( symbol . getDocumentationComment ( ) , SymbolDisplayPartKind . text , /*symbol:*/ null ) ] ) ;
2489
+ documentationParts ) ;
2469
2490
}
2470
2491
2471
2492
function getTypeAtPosition ( fileName : string , position : number ) : TypeInfo {
0 commit comments