Skip to content

Commit

Permalink
fix fences lang
Browse files Browse the repository at this point in the history
  • Loading branch information
rostrovsky committed Aug 20, 2024
1 parent 789746c commit 8da90d4
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 86 deletions.
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 (
Expand Down
166 changes: 82 additions & 84 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 8da90d4

Please sign in to comment.