From aa45967b795387a3e24e89ffafad2097e12e18db Mon Sep 17 00:00:00 2001 From: Arthur Ozga Date: Fri, 17 Jul 2015 09:12:59 -0700 Subject: [PATCH] refactored isInComment, isInString --- src/compiler/binder.ts | 4 ++++ src/services/services.ts | 10 ++++++---- src/services/utilities.ts | 13 ++++++++++++- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 336be9d1eda..66b5a0b894d 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -9,7 +9,11 @@ namespace ts { Instantiated = 1, ConstEnumOnly = 2 } + + "/**" + /* /** */ + // /** getDocCommentScaffoldingAtPosition -- TS side! */ export function getModuleInstanceState(node: Node): ModuleInstanceState { // A module is uninstantiated if it contains only // 1. interface declarations, type alias declarations diff --git a/src/services/services.ts b/src/services/services.ts index d7bcb6c0629..876d5646a13 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -6756,19 +6756,21 @@ namespace ts { * be performed. */ function getDocCommentScaffoldingAtPosition(fileName: string, position: number): string { - const nullResult = "/** */"; + const nullResult = "/**"; + const emptyCompletion = "/** */"; let start = new Date().getTime(); let sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName); log("getDocCommentScaffoldingAtPosition: getCurrentSourceFile: " + (new Date().getTime() - start)); // Check if in comment context - var nodeAtPos = getTokenAtPosition(sourceFile, position); - - return "/** token is : daniel cant copy/paste " + tokenToString(nodeAtPos.kind) + " */"; + if(isInString(sourceFile, position) || isInComment(sourceFile,position)) { return nullResult; } // Get the next non-comment token + var nodeAtPos = getTokenAtPosition(sourceFile, position); + var containingFunction = getAncestor(nodeAtPos, SyntaxKind.FunctionDeclaration); // check if token is a function keyword + if(!containingFunction) { return emptyCompletion; } // Get the parsed object corresponding to the token diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 98d5c2efec4..4c0ce77c522 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -438,7 +438,18 @@ namespace ts { // Then we want to make sure that it wasn't in a "///<" directive comment // We don't want to unintentionally update a file name. - return forEach(commentRanges, c => c.pos < position && position < c.end && extraCheck(c)); + return forEach(commentRanges, c => c.pos < position && + // The end marker of a single-line comment does not include the newline character. + // In the following case, we are inside a comment (^ denotes the cursor position): + // + // // 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. + (c.kind == SyntaxKind.SingleLineCommentTrivia ? position <= c.end : position < c.end) && + extraCheck(c)); } return false;