Files
herolib/lib/develop/heroprompt/heroprompt_child.v
Mahmoud-Emad cc93081b15 feat: Add workspace selection synchronization
- Create `codewalker` module with file system utilities
- Refactor `Workspace` file operations to use `codewalker`
- Add `include_tree` flag to `HeropromptChild` struct
- Implement new `/selection` API endpoint for workspace
- Sync frontend selection state to backend via new API
2025-08-24 12:58:09 +03:00

67 lines
1.7 KiB
V

module heroprompt
import freeflowuniverse.herolib.core.pathlib
import os
pub struct HeropromptChild {
pub mut:
content string
path pathlib.Path
name string
include_tree bool // when true and this child is a dir, include full subtree in maps/contents
}
// Utility function to get file extension with special handling for common files
pub fn get_file_extension(filename string) string {
// Handle special cases for common files without extensions
special_files := {
'dockerfile': 'dockerfile'
'makefile': 'makefile'
'license': 'license'
'readme': 'readme'
'changelog': 'changelog'
'authors': 'authors'
'contributors': 'contributors'
'copying': 'copying'
'install': 'install'
'news': 'news'
'todo': 'todo'
'version': 'version'
'manifest': 'manifest'
'gemfile': 'gemfile'
'rakefile': 'rakefile'
'procfile': 'procfile'
'vagrantfile': 'vagrantfile'
}
lower_filename := filename.to_lower()
if lower_filename in special_files {
return special_files[lower_filename]
}
if filename.starts_with('.') && !filename.starts_with('..') {
if filename.contains('.') && filename.len > 1 {
parts := filename[1..].split('.')
if parts.len >= 2 {
return parts[parts.len - 1]
} else {
return filename[1..]
}
} else {
return filename[1..]
}
}
parts := filename.split('.')
if parts.len < 2 {
return ''
}
return parts[parts.len - 1]
}
// Read the file content
pub fn (chl HeropromptChild) read() !string {
if chl.path.cat != .file {
return error('cannot read content of a directory')
}
content := os.read_file(chl.path.path)!
return content
}