Skip to content

Commit e66bcb6

Browse files
committed
Now really counting lines of code.
1 parent 9d1e39b commit e66bcb6

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

LinesCountAddIn/LinesCountAddIn.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,10 @@
4242
<ItemGroup>
4343
<None Include="packages.config" />
4444
</ItemGroup>
45+
<ItemGroup>
46+
<ProjectReference Include="..\LinesCount\LinesCount.csproj">
47+
<Project>{85AD5C26-45BD-4BB8-B52F-938F8CACD11F}</Project>
48+
<Name>LinesCount</Name>
49+
</ProjectReference>
50+
</ItemGroup>
4551
</Project>

LinesCountAddIn/LinesCountWriter.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Mono.TextEditor;
1+
using LinesCount;
2+
using Mono.TextEditor;
23
using MonoDevelop.Core;
34
using MonoDevelop.Ide.Gui;
45
using MonoDevelop.Ide;
@@ -13,6 +14,8 @@ public class LinesCountWriter
1314
private TextEditorData textEditorData;
1415
private Document linesCountDocument;
1516

17+
int linesOfCode, sourceLines, effectiveLines, commentLines;
18+
1619
/// <summary>
1720
/// Initializes a new instance of the <see cref="DateInserter.LinesCountWriter"/> class.
1821
/// </summary>
@@ -23,6 +26,8 @@ public LinesCountWriter(string linesCountDocumentName)
2326
if (linesCountDocument == null)
2427
linesCountDocument = IdeApp.Workbench.NewDocument(linesCountDocumentName, "text/plain", "");
2528
textEditorData = linesCountDocument.GetContent<ITextEditorDataProvider>().GetTextEditorData();
29+
30+
linesOfCode = sourceLines = effectiveLines = commentLines = 0;
2631
}
2732

2833
/// <summary>
@@ -32,6 +37,7 @@ public LinesCountWriter(string linesCountDocumentName)
3237
public void WriteInfoOfSelectedItem(object selectedItem)
3338
{
3439
textEditorData.Document.Text = "";
40+
Write(String.Format(" {0, -80} {1, 15} {2, 15} {3, 15} {4, 15}", "File", "Lines of code", "Source lines", "Effective lines", "Comment lines"));
3541

3642
Solution selectedSolution = selectedItem as Solution;
3743
if (selectedSolution != null)
@@ -44,7 +50,7 @@ public void WriteInfoOfSelectedItem(object selectedItem)
4450
ProjectFile selectedFile = selectedItem as ProjectFile;
4551
if (selectedFile != null)
4652
ShowProjectFile(selectedFile);
47-
53+
Write(String.Format(" {0, -80} {1, 15} {2, 15} {3, 15} {4, 15}", " ", linesOfCode, sourceLines, effectiveLines, commentLines));
4854
linesCountDocument.Select();
4955
}
5056

@@ -92,8 +98,15 @@ public static bool IsCSharpFile(ProjectFile projectFile)
9298
private void WriteFileInfo(FilePath filePath)
9399
{
94100
string[] lines = File.ReadAllLines(filePath.ToString());
101+
SourceFile s = new SourceFile(filePath.ToString(), lines, new CSharpSourceLineAnalyzer());
95102
string fittingPath = filePath.ToString().Length > 80 ? filePath.ToString().Substring(0, 79) : filePath.ToString();
96-
string info = String.Format("{0, -80} {1, 3}", fittingPath, lines.Length);
103+
104+
linesOfCode += s.LinesOfCode;
105+
sourceLines += s.SourceLinesOfCode;
106+
effectiveLines += s.EffectiveLinesOfCode;
107+
commentLines += s.CommentLines;
108+
109+
string info = String.Format("{0, -80} {1, 15} {2, 15} {3, 15} {4, 15}", fittingPath, s.LinesOfCode, s.SourceLinesOfCode, s.EffectiveLinesOfCode, s.CommentLines);
97110
Write(" " + info);
98111
}
99112

0 commit comments

Comments
 (0)