@@ -62,71 +62,21 @@ pub fn generate_prompt(current_profile: Option<&str>) -> String {
62
62
"> " . to_string ( )
63
63
}
64
64
65
- /// Categorized path context patterns for better organization and maintainability
66
- pub struct PathContextPatterns {
67
- /// File operation commands (cat, ls, etc.)
68
- pub file_commands : & ' static [ & ' static str ] ,
69
- /// Words indicating file operations (open, read, etc.)
70
- pub file_operations : & ' static [ & ' static str ] ,
71
- /// Path-related terms (file, path, directory, etc.)
72
- pub path_terms : & ' static [ & ' static str ] ,
73
- /// Special commands that work with files
74
- pub special_commands : & ' static [ & ' static str ] ,
75
- }
76
-
77
- impl Default for PathContextPatterns {
78
- fn default ( ) -> Self {
79
- Self {
80
- file_commands : & [ "cat " , "ls " , "cd " , "vim " , "nano " , "less " , "more " , "grep " ] ,
81
- file_operations : & [ "open " , "read " , "write " , "edit " , "create " , "delete " , "remove " ] ,
82
- path_terms : & [ "file " , "path " , "directory " , "folder " , "location " ] ,
83
- special_commands : & [ "/context add" , "/context rm" ] ,
84
- }
85
- }
86
- }
87
-
88
65
/// A wrapper around FilenameCompleter that provides enhanced path detection
89
66
/// and completion capabilities for the chat interface.
90
67
pub struct PathCompleter {
91
68
/// The underlying filename completer from rustyline
92
69
filename_completer : FilenameCompleter ,
93
- path_patterns : PathContextPatterns ,
94
70
}
95
71
96
72
impl PathCompleter {
97
73
/// Creates a new PathCompleter instance
98
74
pub fn new ( ) -> Self {
99
75
Self {
100
76
filename_completer : FilenameCompleter :: new ( ) ,
101
- path_patterns : PathContextPatterns :: default ( ) ,
102
77
}
103
78
}
104
79
105
- /// Check if the input might be referring to a file path based on context clues
106
- fn is_path_context ( & self , line : & str ) -> bool {
107
- // Check for file commands
108
- let has_file_command = self . path_patterns . file_commands
109
- . iter ( )
110
- . any ( |& cmd| line. contains ( cmd) ) ;
111
-
112
- // Check for file operations
113
- let has_file_operation = self . path_patterns . file_operations
114
- . iter ( )
115
- . any ( |& op| line. contains ( op) ) ;
116
-
117
- // Check for path terms
118
- let has_path_term = self . path_patterns . path_terms
119
- . iter ( )
120
- . any ( |& term| line. contains ( term) ) ;
121
-
122
- // Check for special commands
123
- let has_special_command = self . path_patterns . special_commands
124
- . iter ( )
125
- . any ( |& cmd| line. contains ( cmd) ) ;
126
-
127
- has_file_command || has_file_operation || has_path_term || has_special_command
128
- }
129
-
130
80
/// Attempts to complete a file path at the given position in the line
131
81
pub fn complete_path (
132
82
& self ,
@@ -149,11 +99,6 @@ impl PathCompleter {
149
99
Err ( err) => Err ( err) ,
150
100
}
151
101
}
152
-
153
- /// Checks if the word appears to be a file path based on its syntax
154
- pub fn is_path_syntax ( & self , word : & str ) -> bool {
155
- word. contains ( '/' ) || word. starts_with ( '~' ) || word. starts_with ( '.' )
156
- }
157
102
}
158
103
159
104
pub struct ChatCompleter {
@@ -197,12 +142,10 @@ impl Completer for ChatCompleter {
197
142
return Ok ( self . complete_command ( word, start) ) ;
198
143
}
199
144
200
- // Handle file path completion if the word contains path separators or context suggests file paths
201
- if self . path_completer . is_path_syntax ( word) || self . path_completer . is_path_context ( line) {
202
- if let Ok ( ( pos, completions) ) = self . path_completer . complete_path ( line, pos, _ctx) {
203
- if !completions. is_empty ( ) {
204
- return Ok ( ( pos, completions) ) ;
205
- }
145
+ // Handle file path completion as fallback
146
+ if let Ok ( ( pos, completions) ) = self . path_completer . complete_path ( line, pos, _ctx) {
147
+ if !completions. is_empty ( ) {
148
+ return Ok ( ( pos, completions) ) ;
206
149
}
207
150
}
208
151
@@ -322,26 +265,4 @@ mod tests {
322
265
// Verify no completions are returned for regular text
323
266
assert ! ( completions. is_empty( ) ) ;
324
267
}
325
-
326
- #[ test]
327
- fn test_is_path_context ( ) {
328
- let completer = PathCompleter :: new ( ) ;
329
-
330
- // Test positive cases
331
- assert ! ( completer. is_path_context( "Please read file test.txt" ) ) ;
332
- assert ! ( completer. is_path_context( "Show me the path to config" ) ) ;
333
- assert ! ( completer. is_path_context( "List the directory contents" ) ) ;
334
- assert ! ( completer. is_path_context( "/context add ./myfile.txt" ) ) ;
335
- assert ! ( completer. is_path_context( "/context rm ./myfile.txt" ) ) ;
336
- assert ! ( completer. is_path_context( "Can you open this file?" ) ) ;
337
- assert ! ( completer. is_path_context( "Please read this for me" ) ) ;
338
- assert ! ( completer. is_path_context( "cat my_file.txt" ) ) ;
339
- assert ! ( completer. is_path_context( "ls -la" ) ) ;
340
- assert ! ( completer. is_path_context( "cd /usr/local" ) ) ;
341
-
342
- // Test negative cases
343
- assert ! ( !completer. is_path_context( "Hello world" ) ) ;
344
- assert ! ( !completer. is_path_context( "What is the weather today?" ) ) ;
345
- assert ! ( !completer. is_path_context( "How do I upload data using s3 cli" ) ) ;
346
- }
347
268
}
0 commit comments