Skip to content

Commit

Permalink
Merge pull request #83 from meysamhadeli/chore/update-tree-sitter-to-…
Browse files Browse the repository at this point in the history
…have-full-signiture-body

chore: update tree-sitter to have more details signature body
  • Loading branch information
meysamhadeli authored Nov 17, 2024
2 parents dfdae55 + a57e623 commit b7a9c67
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 59 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ $env:CHAT_API_KEY="your_chat_api_key"
$env:EMBEDDINGS_API_KEY="your_embeddings_api_key" #(Optional, If you want use RAG.)
```
### 🔧 Configuration
`codai` requires a `config.yml` file in the `root of your working directory` or using `environment variables` to set below configs `globally` as a configuration.
`codai` requires a `codai-config.yml` file in the `root of your working directory` or using `environment variables` to set below configs `globally` as a configuration.

The `config` file should be like following example base on your `AI provider`:
The `codai-config` file should be like following example base on your `AI provider`:

**config.yml**
**codai-config.yml**
```yml
ai_provider_config:
provider_name: "openai" # openai | ollama | azure-openai
Expand All @@ -75,11 +75,11 @@ rag: true #(Optional, If you want use RAG.)
> Note: We used the standard integration of [OpenAI APIs](https://platform.openai.com/docs/api-reference/introduction), [Ollama APIs](https://github.com/ollama/ollama/blob/main/docs/api.md) and [Azure Openai](https://learn.microsoft.com/en-us/azure/ai-services/openai/reference) and you can find more details in documentation of each APIs.
If you wish to customize your configuration, you can create your own `config.yml` file and place it in the `root directory` of `each project` you want to analyze with codai. If `no configuration` file is provided, codai will use the `default settings`.
If you wish to customize your configuration, you can create your own `codai-config.yml` file and place it in the `root directory` of `each project` you want to analyze with codai. If `no configuration` file is provided, codai will use the `default settings`.

You can also specify a configuration file from any directory by using the following CLI command:
```bash
codai code --config ./config.yml
codai code --config ./codai-config.yml
```
Additionally, you can pass configuration options directly in the command line. For example:
```bash
Expand Down
22 changes: 19 additions & 3 deletions code_analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,26 @@ func (analyzer *CodeAnalyzer) ProcessFile(filePath string, sourceCode []byte) []

for _, cap := range match.Captures {
element := cap.Node.Content(sourceCode)
// Tag the element with its type (e.g., namespace, class, method, interface)
taggedElement := fmt.Sprintf("%s\n: %s", tag, element)
elements = append(elements, taggedElement)
queryName := query.CaptureNameForId(cap.Index)

if !analyzer.IsRAG {
if strings.HasPrefix(queryName, "definition.") {
lines := strings.Split(element, "\n")
// Get the first line
element = lines[0] // First line from the array
} else {
continue
}
taggedElement := fmt.Sprintf("%s:\n %s", tag, element)
elements = append(elements, taggedElement)
} else {
if !strings.HasPrefix(queryName, "definition.") {
taggedElement := fmt.Sprintf("%s:\n %s", tag, element)
elements = append(elements, taggedElement)
}
}
}

}
}

Expand Down
6 changes: 3 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ func LoadConfigs(rootCmd *cobra.Command, cwd string) *Config {
}
} else {
// Automatically look for 'config.yml' in the working directory if no CLI file is provided
viper.SetConfigName("config") // name of config file (without extension)
viper.SetConfigType("yml") // Required if file extension is not yaml/yml
viper.AddConfigPath(cwd) // Look for config in the current working directory
viper.SetConfigName("codai-config") // name of config file (without extension)
viper.SetConfigType("yml") // Required if file extension is not yaml/yml
viper.AddConfigPath(cwd) // Look for config in the current working directory
}

// Read the configuration file if available
Expand Down
2 changes: 1 addition & 1 deletion embed_data/prompts/rag_context_prompt.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
- Use best practices when coding.
- You NEVER leave comments describing code without implementing it!
- You always COMPLETELY IMPLEMENT the needed code!
- Explain any needed changes.
- Explain any needed changes in code and just don't consider any preamble.


## General Instructions for Code Modifications:
Expand Down
2 changes: 1 addition & 1 deletion embed_data/prompts/summarize_full_context_prompt.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
- Use best practices when coding.
- You NEVER leave comments describing code without implementing it!
- You always COMPLETELY IMPLEMENT the needed code!
- Explain any needed changes.
- Explain any needed changes in code and just don't consider any preamble.


## PRIORITY: Handling Specific Code Context Requests
Expand Down
18 changes: 9 additions & 9 deletions embed_data/tree-sitter/queries/csharp.scm
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"definition.file_scoped_namespace": "(file_scoped_namespace_declaration name: (identifier)? @name.file_scoped_namespace name: (qualified_name)? @name)",
"definition.namespace": "(namespace_declaration name: (qualified_name)? @name.namespace name: (identifier)? @name)",
"definition.class": "(class_declaration name: (identifier) @name)",
"definition.interface": "(interface_declaration name: (identifier) @name)",
"definition.method": "(method_declaration name: (identifier) @name)",
"definition.enum": "(enum_declaration name: (identifier) @name)",
"definition.struct": "(struct_declaration name: (identifier) @name)",
"definition.record": "(record_declaration name: (identifier) @name)",
"definition.property": "(property_declaration name: (identifier) @name)"
"file_scoped_namespace": "(file_scoped_namespace_declaration name: (identifier)? @name.file_scoped_namespace name: (qualified_name)? @name) @definition.file_scoped_namespace",
"namespace": "(namespace_declaration name: (qualified_name)? @name.namespace name: (identifier)? @name) @definition.namespace",
"class": "(class_declaration name: (identifier) @name) @definition.class",
"interface": "(interface_declaration name: (identifier) @name) @definition.interface",
"method": "(method_declaration name: (identifier) @name) @definition.method",
"enum": "(enum_declaration name: (identifier) @name) @definition.enum",
"struct": "(struct_declaration name: (identifier) @name) @definition.struct",
"record": "(record_declaration name: (identifier) @name) @definition.record",
"property": "(property_declaration name: (identifier) @name) @definition.property"
}
10 changes: 5 additions & 5 deletions embed_data/tree-sitter/queries/go.scm
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"definition.package": "(package_clause (package_identifier) @name)",
"definition.function": "(function_declaration name: (identifier) @name)",
"definition.method": "(method_declaration name: (field_identifier) @name)",
"definition.interface": "(type_declaration (type_spec name: (type_identifier) @name type: (interface_type)))",
"definition.struct": "(type_declaration (type_spec name: name: (type_identifier) @name type: (struct_type)))"
"package": "(package_clause (package_identifier) @name) @definition.package",
"function": "(function_declaration name: (identifier) @name) @definition.function",
"method": "(method_declaration name: (field_identifier) @name) @definition.method",
"interface": "(type_declaration (type_spec name: (type_identifier) @name type: (interface_type))) @definition.interface",
"struct": "(type_declaration (type_spec name: name: (type_identifier) @name type: (struct_type))) @definition.struct"
}

10 changes: 5 additions & 5 deletions embed_data/tree-sitter/queries/java.scm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"definition.package": "(package_declaration (scoped_identifier name: (identifier) @name))",
"definition.class": "(class_declaration name: (identifier) @name)",
"definition.interface": "(interface_declaration name: (identifier) @name)",
"definition.method": "(method_declaration name: (identifier) @name)",
"definition.enum": "(enum_declaration name: (identifier) @name)"
"package": "(package_declaration (scoped_identifier name: (identifier) @name)) @definition.package",
"class": "(class_declaration name: (identifier) @name) @definition.class",
"interface": "(interface_declaration name: (identifier) @name) @definition.interface",
"method": "(method_declaration name: (identifier) @name) @definition.method",
"enum": "(enum_declaration name: (identifier) @name) @definition.enum"
}
8 changes: 4 additions & 4 deletions embed_data/tree-sitter/queries/javascript.scm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"definition.class" : "(class_declaration name: (identifier) @name)",
"definition.method": "(method_definition name: (property_identifier) @name)",
"definition.function": "(function_declaration name: (identifier) @name)",
"definition.anonymous_function": "(lexical_declaration(variable_declarator name: (identifier) @name))"
"class" : "(class_declaration name: (identifier) @name) @definition.class",
"method": "(method_definition name: (property_identifier) @name) @definition.method",
"function": "(function_declaration name: (identifier) @name) @definition.function",
"anonymous_function": "(lexical_declaration(variable_declarator name: (identifier) @name)) @definition.anonymous_function"
}

6 changes: 3 additions & 3 deletions embed_data/tree-sitter/queries/python.scm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"definition.class": "(class_definition name: (identifier) @name)",
"definition.function": "(function_definition name: (identifier) @name)",
"definition.decorated" : "(decorated_definition(decorator((identifier) @name)))"
"class": "(class_definition name: (identifier) @name) @definition.class",
"function": "(function_definition name: (identifier) @name) @definition.function",
"decorated" : "(decorated_definition(decorator((identifier) @name))) @definition.decorated"
}
12 changes: 6 additions & 6 deletions embed_data/tree-sitter/queries/typescript.scm
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"definition.class" : "(class_declaration name: ((type_identifier) @name))",
"definition.interface": "(interface_declaration name: ((type_identifier) @name))",
"definition.enum": "(enum_declaration name: ((identifier) @name))",
"definition.method": "(method_definition name: ((property_identifier) @name))",
"definition.function": "(function_declaration name: ((identifier) @name))",
"definition.anonymous_function": "(lexical_declaration(variable_declarator name: (identifier) @name))"
"class" : "(class_declaration name: ((type_identifier) @name)) @definition.class",
"interface": "(interface_declaration name: ((type_identifier) @name)) @definition.interface",
"enum": "(enum_declaration name: ((identifier) @name)) @definition.enum",
"method": "(method_definition name: ((property_identifier) @name)) @definition.method",
"function": "(function_declaration name: ((identifier) @name)) @definition.function",
"anonymous_function": "(lexical_declaration(variable_declarator name: (identifier) @name)) @definition.anonymous_function"
}
15 changes: 1 addition & 14 deletions utils/ignore_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func GetGitignorePatterns() ([]string, error) {
func IsDefaultIgnored(path string) bool {
// Define ignore patterns
ignorePatterns := []string{
"codai-config.yml",
".git",
".svn",
".sum",
Expand All @@ -58,20 +59,6 @@ func IsDefaultIgnored(path string) bool {
"*.dll",
"*.log",
"*.bak",
".mp3",
".wav",
".aac",
".flac",
".ogg",
".jpg",
".jpeg",
".png",
".gif",
".mkv",
".mp4",
".avi",
".mov",
".wmv",
}

// Split the path into parts based on the file separator
Expand Down

0 comments on commit b7a9c67

Please sign in to comment.