Skip to content

Commit df19e79

Browse files
committed
Feature: Add Python and JavaScript support to language options
1 parent 0121420 commit df19e79

File tree

4 files changed

+67
-13
lines changed

4 files changed

+67
-13
lines changed

CodeIngest.Desktop/MainViewModel.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public class MainViewModel : ViewModelBase
3434
private bool m_excludeImports = Settings.Instance.ExcludeImports;
3535
private bool m_useFullPaths = Settings.Instance.UseFullPaths;
3636
private bool m_excludeComments = Settings.Instance.ExcludeComments;
37+
private bool m_isPython = Settings.Instance.IsPython;
38+
private bool m_isJavaScript = Settings.Instance.IsJavaScript;
3739
private int? m_previewFileCount;
3840
private long? m_previewFileSize;
3941
private bool m_isGeneratingPreview;
@@ -90,6 +92,32 @@ public bool IsCppWithHeaders
9092
}
9193
}
9294

95+
public bool IsPython
96+
{
97+
get => m_isPython;
98+
set
99+
{
100+
if (SetField(ref m_isPython, value))
101+
{
102+
Settings.Instance.IsPython = value;
103+
InvalidatePreviewStats();
104+
}
105+
}
106+
}
107+
108+
public bool IsJavaScript
109+
{
110+
get => m_isJavaScript;
111+
set
112+
{
113+
if (SetField(ref m_isJavaScript, value))
114+
{
115+
Settings.Instance.IsJavaScript = value;
116+
InvalidatePreviewStats();
117+
}
118+
}
119+
}
120+
93121
public bool ExcludeImports
94122
{
95123
get => m_excludeImports;
@@ -197,6 +225,10 @@ public async Task RunIngest()
197225
filterExtensions = [".cpp"];
198226
else if (IsCppWithHeaders)
199227
filterExtensions = [".cpp", ".h"];
228+
else if (IsPython)
229+
filterExtensions = [".py"];
230+
else if (IsJavaScript)
231+
filterExtensions = [".js"];
200232
else
201233
filterExtensions = [".cs"];
202234

CodeIngest.Desktop/Settings.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,26 @@ public bool UseFullPaths
6767
set => Set(value);
6868
}
6969

70+
public bool IsPython
71+
{
72+
get => Get<bool>();
73+
set => Set(value);
74+
}
75+
76+
public bool IsJavaScript
77+
{
78+
get => Get<bool>();
79+
set => Set(value);
80+
}
81+
7082
protected override void ApplyDefaults()
7183
{
7284
RootFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments).ToDir();
7385
IsCSharp = true;
7486
IsCppNoHeaders = false;
7587
IsCppWithHeaders = false;
88+
IsPython = false;
89+
IsJavaScript = false;
7690
ExcludeImports = true;
7791
ExcludeComments = true;
7892
IncludeMarkdown = false;

CodeIngest.Desktop/Views/MainWindow.axaml

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,21 +97,26 @@
9797
<Border Grid.Row="1" BorderThickness="1" Margin="0,16,0,0">
9898
<StackPanel>
9999
<!-- ReSharper disable once Xaml.StyleClassNotFound -->
100-
<TextBlock Text="Options" Classes="Overline" Margin="4"/>
101-
<StackPanel Margin="8">
102-
<CheckBox Content="Export Full Paths" IsChecked="{Binding UseFullPaths}"/>
103-
104-
<RadioButton Content="C#" Margin="0,16,0,0" IsChecked="{Binding IsCSharp}"/>
105-
<RadioButton Content="C/C++ (No Headers)" IsChecked="{Binding IsCppNoHeaders}" Margin="0,4"/>
106-
<RadioButton Content="C/C++ (With Headers)" IsChecked="{Binding IsCppWithHeaders}" />
100+
<TextBlock Text="Languages" Classes="Overline" Margin="4"/>
101+
<StackPanel Margin="8,4">
102+
<RadioButton Content="C#" IsChecked="{Binding IsCSharp}"/>
103+
<RadioButton Content="C/C++ (No Headers)" IsChecked="{Binding IsCppNoHeaders}" Margin="0,4,0,0"/>
104+
<RadioButton Content="C/C++ (With Headers)" IsChecked="{Binding IsCppWithHeaders}" Margin="0,4,0,0"/>
105+
<RadioButton Content="Python" IsChecked="{Binding IsPython}" Margin="0,4,0,0"/>
106+
<RadioButton Content="JavaScript" IsChecked="{Binding IsJavaScript}" Margin="0,4,0,0"/>
107+
</StackPanel>
107108

108-
<CheckBox Content="Exclude Imports" Margin="0,16,0,0"
109+
<TextBlock Text="Options" Classes="Overline" Margin="4,16,4,4"/>
110+
<StackPanel Margin="8,4">
111+
<CheckBox Content="Exclude Imports"
109112
ToolTip.Tip="Remove using/#include/etc statements from the output."
110113
IsChecked="{Binding ExcludeImports}" />
111-
<CheckBox Content="Exclude comments" Margin="0,4"
114+
<CheckBox Content="Exclude comments" Margin="0,4,0,0"
112115
ToolTip.Tip="Remove // and /*-style comments from the output."
113116
IsChecked="{Binding ExcludeComments}" />
114-
<CheckBox Content="Include Markdown"
117+
<CheckBox Content="Include Full Paths" Margin="0,4,0,0"
118+
IsChecked="{Binding UseFullPaths}"/>
119+
<CheckBox Content="Include Markdown" Margin="0,4,0,0"
115120
ToolTip.Tip="Include .md files in the output."
116121
IsChecked="{Binding IncludeMarkdown}" />
117122
</StackPanel>

CodeIngestLib/Ingester.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,15 @@ private static bool ShouldIncludeSourceLine(string s, IngestOptions options)
121121
return false;
122122
var trimmed = s.Trim();
123123

124-
if (options.ExcludeImports && s.StartsWith("using") || s.StartsWith("#include") || s.StartsWith("#pragma") || trimmed.StartsWith("namespace"))
125-
return false;
124+
if (options.ExcludeImports)
125+
{
126+
if (trimmed.StartsWith("using") || trimmed.StartsWith("#include") || trimmed.StartsWith("#pragma") || trimmed.StartsWith("namespace") || trimmed.StartsWith("import") || trimmed.StartsWith("from "))
127+
return false;
128+
}
126129

127130
if (options.StripComments)
128131
{
129-
if (trimmed.StartsWith("//"))
132+
if (trimmed.StartsWith("//") || trimmed.StartsWith("# "))
130133
return false;
131134
if (trimmed.StartsWith("/*") && trimmed.EndsWith("*/"))
132135
return false;

0 commit comments

Comments
 (0)