public static bool IsPositionInComment(this IREditorDocument document, int position) {
bool inComment = false;
var editorTree = document?.EditorTree;
if(editorTree != null) {
var ast = editorTree.AstRoot;
inComment = ast.Comments.GetItemsContainingInclusiveEnd(position).Count > 0;
if(!inComment) {
var line = document.TextBuffer.CurrentSnapshot.GetLineFromPosition(position);
position -= line.Start.Position;
var tokens = (new RTokenizer()).Tokenize(line.GetText());
var token = tokens.FirstOrDefault(t => t.Contains(position) || t.End == position);
inComment = token != null && token.TokenType == RTokenType.Comment;
}
}
return inComment;
}
}