mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
refactored isInComment, isInString
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user