refactored isInComment, isInString

This commit is contained in:
Arthur Ozga
2015-07-17 09:12:59 -07:00
parent bf7c073e63
commit aa45967b79
3 changed files with 22 additions and 5 deletions
+4
View File
@@ -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
+6 -4
View File
@@ -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
+12 -1
View File
@@ -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;