File tree Expand file tree Collapse file tree 4 files changed +57
-1
lines changed
Expand file tree Collapse file tree 4 files changed +57
-1
lines changed Original file line number Diff line number Diff line change @@ -156,6 +156,34 @@ function M.add_directory_context(directory_path)
156156 Logger .info (" Directory context added: " .. vim .inspect (context ))
157157end
158158
159+ --- @param url string
160+ function M .add_web_context (url )
161+ Logger .info (" Adding web context: " .. url )
162+ local eca = require (" eca" )
163+
164+ if not eca .server or not eca .server :is_running () then
165+ Logger .notify (" ECA server is not running" , vim .log .levels .ERROR )
166+ return
167+ end
168+
169+ local chat = eca .get ()
170+
171+ if not chat or not chat .mediator then
172+ Logger .notify (" No active ECA Chat to add context" , vim .log .levels .WARN )
173+ return
174+ end
175+
176+ local context = {
177+ type = " web" ,
178+ data = {
179+ path = url ,
180+ },
181+ }
182+
183+ chat .mediator :add_context (context )
184+ Logger .info (" Web context added: " .. vim .inspect (context ))
185+ end
186+
159187function M .add_current_file_context ()
160188 local current_file = vim .api .nvim_buf_get_name (0 )
161189 if current_file and current_file ~= " " then
Original file line number Diff line number Diff line change @@ -107,6 +107,23 @@ function M.setup()
107107 range = true ,
108108 })
109109
110+ vim .api .nvim_create_user_command (" EcaChatAddUrl" , function ()
111+ vim .ui .input ({ prompt = " Enter URL to add as context: " }, function (input )
112+ if not input or input == " " then
113+ return
114+ end
115+
116+ local url = vim .fn .trim (input )
117+ if url == " " then
118+ return
119+ end
120+
121+ require (" eca.api" ).add_web_context (url )
122+ end )
123+ end , {
124+ desc = " Add URL as web context to ECA" ,
125+ })
126+
110127 vim .api .nvim_create_user_command (" EcaListContexts" , function ()
111128 Logger .notify (" EcaListContexts is deprecated. Use EcaChatListContexts instead." , vim .log .levels .WARN )
112129
Original file line number Diff line number Diff line change @@ -66,6 +66,7 @@ M._defaults = {
6666 input = {
6767 prefix = " > " ,
6868 height = 8 , -- Height of the input window
69+ web_context_max_len = 20 , -- Maximum length for web context names in input
6970 },
7071 edit = {
7172 border = " rounded" ,
Original file line number Diff line number Diff line change @@ -706,7 +706,17 @@ function M:_update_input_display(opts)
706706 break
707707 end
708708
709- local name = vim .fn .fnamemodify (path , " :t" )
709+ local name
710+ if context .type == " web" then
711+ name = path
712+ local max_len = (Config .windows and Config .windows .input and Config .windows .input .web_context_max_len ) or 20
713+ if # name > max_len then
714+ name = string.sub (name , 1 , max_len - 3 ) .. " ..."
715+ end
716+ else
717+ name = vim .fn .fnamemodify (path , " :t" )
718+ end
719+
710720 local lines_range = context .data .lines_range
711721
712722 if lines_range and lines_range .line_start and lines_range .line_end then
You can’t perform that action at this time.
0 commit comments