public void Test_Nested_Multi_Line_Block_Comment() { //arrange var sqlStatementRaw = $@"SELECT 1; SELECT 2; GO /* another line comment /*this is a multi-line block comment*/ another line comment */ SELECT 3; GO "; //act var sut = new CommentAnalyzer(); var results = sut.Run(sqlStatementRaw); //assert results.Count.ShouldBe(1); results[0].Text.ShouldBe( $@"/* another line comment /*this is a multi-line block comment*/ another line comment */"); results[0].Start = 28; results[0].End = 120; }
private void CheckMember( IClassMemberDeclaration declaration, IHighlightingConsumer highlightingConsumer, CommentAnalyzer commentAnalyzer, IdentifierSpellCheckAnalyzer identifierAnalyzer) { if (declaration is IConstructorDeclaration && declaration.IsStatic) { // TODO: probably need to put this somewhere in settings. //Static constructors have no visibility so not clear how to check them. return; } // Documentation doesn't work properly on multiple declarations (as of R# 6.1) so see if we can get it from the parent XmlNode docNode = null; IDocCommentBlockNode commentBlock; var multipleDeclarationMember = declaration as IMultipleDeclarationMember; if (multipleDeclarationMember != null) { // get the parent IMultipleDeclaration multipleDeclaration = multipleDeclarationMember.MultipleDeclaration; // Now ask for the actual comment block commentBlock = SharedImplUtil.GetDocCommentBlockNode(multipleDeclaration); if (commentBlock != null) { docNode = commentBlock.GetXML(null); } } else { commentBlock = SharedImplUtil.GetDocCommentBlockNode(declaration); docNode = declaration.GetXMLDoc(false); } commentAnalyzer.CheckMemberHasComment(declaration, docNode, highlightingConsumer); commentAnalyzer.CheckCommentSpelling(declaration, commentBlock, highlightingConsumer, true); identifierAnalyzer.CheckMemberSpelling(declaration, highlightingConsumer, true); }
/// <summary> /// Execute this stage of the process. /// </summary> /// <param name="commiter">The function to call when we've finished the stage to report the results.</param> public void Execute(Action <DaemonStageResult> commiter) { IFile file = _daemonProcess.SourceFile.GetTheOnlyPsiFile(CSharpLanguage.Instance); if (file == null) { return; } StringSettings stringSettings = _settingsStore.GetKey <StringSettings>(SettingsOptimization.OptimizeDefault); if (!_daemonProcess.FullRehighlightingRequired) { return; } CommentAnalyzer commentAnalyzer = new CommentAnalyzer(_solution, _settingsStore); IdentifierSpellCheckAnalyzer identifierAnalyzer = new IdentifierSpellCheckAnalyzer(_solution, _settingsStore, _daemonProcess.SourceFile); #if RESHARPER20173 var consumer = new DefaultHighlightingConsumer(_daemonProcess.SourceFile); #else var consumer = new DefaultHighlightingConsumer(this, _settingsStore); #endif foreach (var classMemberDeclaration in file.Descendants <IClassMemberDeclaration>()) { CheckMember(classMemberDeclaration, consumer, commentAnalyzer, identifierAnalyzer); } if (_daemonProcess.InterruptFlag) { return; } try { commiter(new DaemonStageResult(consumer.Highlightings)); } catch { // Do nothing if it doesn't work. } }
public void Test_Dash_Dash_Inline_Comment_Inside_Middle_Valid_Sql_Statement() { //arrange var sqlStatementRaw = $@"SELECT 1; SELECT 2; GO SELECT 'This is normal statement with --this is an inline comment'; GO "; //act var sut = new CommentAnalyzer(); var results = sut.Run(sqlStatementRaw); //assert results.Count.ShouldBe(0); }
public void Test_Dash_Dash_Inline_Comment_After_Sql_Statement() { //arrange var sqlStatementRaw = $@"SELECT 1; SELECT 2; GO SELECT 3; --this is an inline comment GO "; //act var sut = new CommentAnalyzer(); var results = sut.Run(sqlStatementRaw); //assert results.Count.ShouldBe(1); results[0].Text.ShouldBe($@"--this is an inline comment" + Environment.NewLine); results[0].Start = 40; results[0].End = 69; }
public void Test_Single_Line_Block_Comment() { //arrange var sqlStatementRaw = $@"SELECT 1; SELECT 2; GO /*this is a single line block comment*/ SELECT 3; GO "; //act var sut = new CommentAnalyzer(); var results = sut.Run(sqlStatementRaw); //assert results.Count.ShouldBe(1); results[0].Text.ShouldBe($@"/*this is a single line block comment*/"); results[0].Start = 28; results[0].End = 69; }
/// <summary> /// Execute this stage of the process. /// </summary> /// <param name="commiter">The function to call when we've finished the stage to report the results.</param> public void Execute(Action <DaemonStageResult> commiter) { //var highlightings = new List<HighlightingInfo>(); IHighlightingConsumer highlightingConsumer = new DefaultHighlightingConsumer( this, _settingsStore); IFile file = _daemonProcess.SourceFile.GetTheOnlyPsiFile(CSharpLanguage.Instance); if (file == null) { return; } if (!_daemonProcess.FullRehighlightingRequired) { return; } var commentAnalyzer = new CommentAnalyzer(_solution, _settingsStore); var identifierAnalyzer = new IdentifierSpellCheckAnalyzer(_solution, _settingsStore, _daemonProcess.SourceFile); file.ProcessChildren <IClassMemberDeclaration>( declaration => CheckMember( declaration, highlightingConsumer, commentAnalyzer, identifierAnalyzer)); if (_daemonProcess.InterruptFlag) { return; } try { commiter(new DaemonStageResult(highlightingConsumer.Highlightings)); } catch { // Do nothing if it doesn't work. } }