diff --git a/main.go b/main.go index d9d199e..4955304 100644 --- a/main.go +++ b/main.go @@ -8,8 +8,8 @@ import ( "regexp" "strings" - "github.com/spf13/cobra" u "github.com/rostrovsky/sourceprompt/pkg/utils" + "github.com/spf13/cobra" ) const DEFAULT_PROMPT = `You will be provided with a markdown text (under the "---" separator) containing the contents of a codebase. Each code snippet will be enclosed in code fences, along with the corresponding file name. Your task is to analyze the codebase and gain a comprehensive understanding of its structure, functionality, and key features. @@ -34,7 +34,7 @@ Your analysis should be thorough, insightful, and aimed at enabling AI agents to ` const ( - version = "1.0.3" + version = "1.0.4" ) var ( diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index b704dfb..65a78de 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -50,87 +50,87 @@ func IsMarkdown(filename string) bool { } func DetectLanguage(path string) string { - filename := filepath.Base(path) - ext := strings.ToLower(filepath.Ext(filename)) - - switch ext { - case ".go", ".templ": - return "go" - case ".py": - return "python" - case ".js": - return "javascript" - case ".ts": - return "typescript" - case ".java": - return "java" - case ".c", ".h": - return "c" - case ".cpp", ".cxx", ".cc", ".hpp": - return "cpp" - case ".cs": - return "csharp" - case ".rb": - return "ruby" - case ".php": - return "php" - case ".swift": - return "swift" - case ".kt", ".kts": - return "kotlin" - case ".rs": - return "rust" - case ".html", ".htm", ".gohtml": - return "html" - case ".css": - return "css" - case ".sql": - return "sql" - case ".sh": - return "bash" - case ".pl": - return "perl" - case ".r": - return "r" - case ".m": - return "objectivec" // This could also be MATLAB - case ".vb": - return "vbnet" - case ".scala": - return "scala" - case ".lua": - return "lua" - case ".groovy": - return "groovy" - case ".dart": - return "dart" - case ".md", ".markdown": - return "markdown" - case ".json": - return "json" - case ".xml": - return "xml" - case ".yaml", ".yml": - return "yaml" - case ".tex": - return "tex" - case ".dockerfile", ".df": - return "dockerfile" - case ".ps1": - return "powershell" - case ".scss": - return "scss" - case ".toml": - return "toml" - case ".zig": - return "zig" - case ".nim": - return "nim" - case ".hs": - return "haskell" - default: - return "" - } + filename := filepath.Base(path) + ext := strings.ToLower(filepath.Ext(filename)) + + switch ext { + case ".go", ".templ": + return "go" + case ".py": + return "python" + case ".js": + return "javascript" + case ".ts": + return "typescript" + case ".java": + return "java" + case ".c", ".h": + return "c" + case ".cpp", ".cxx", ".cc", ".hpp": + return "cpp" + case ".cs": + return "csharp" + case ".rb": + return "ruby" + case ".php": + return "php" + case ".swift": + return "swift" + case ".kt", ".kts": + return "kotlin" + case ".rs": + return "rust" + case ".html", ".htm", ".gohtml": + return "html" + case ".css": + return "css" + case ".sql": + return "sql" + case ".sh": + return "bash" + case ".pl": + return "perl" + case ".r": + return "r" + case ".m": + return "objectivec" // This could also be MATLAB + case ".vb": + return "vbnet" + case ".scala": + return "scala" + case ".lua": + return "lua" + case ".groovy": + return "groovy" + case ".dart": + return "dart" + case ".md", ".markdown": + return "markdown" + case ".json": + return "json" + case ".xml": + return "xml" + case ".yaml", ".yml": + return "yaml" + case ".tex": + return "tex" + case ".dockerfile", ".df": + return "dockerfile" + case ".ps1": + return "powershell" + case ".scss": + return "scss" + case ".toml": + return "toml" + case ".zig": + return "zig" + case ".nim": + return "nim" + case ".hs": + return "haskell" + default: + return "" + } } func ProcessPath(path string, prefixToRemove string, include *regexp.Regexp, exclude *regexp.Regexp, stringBuilder *strings.Builder) error { @@ -193,10 +193,8 @@ func ProcessPath(path string, prefixToRemove string, include *regexp.Regexp, exc fences = "````" } - fences += DetectLanguage(filePath) - stringBuilder.WriteString("`" + filePath + "`\n\n") - stringBuilder.WriteString(fences + "\n") + stringBuilder.WriteString(fences + DetectLanguage(filePath) + "\n") stringBuilder.Write(content) if content[len(content)-1] != '\n' { stringBuilder.WriteString("\n")