11local uv = vim .uv or vim .loop
22local Utils = require (" eca.utils" )
3- local Config = require (" eca.config" )
43local Logger = require (" eca.logger" )
54
65--- @class eca.PathFinder
@@ -100,7 +99,7 @@ function M:_write_version_file(version)
10099 file :write (version )
101100 file :close ()
102101 else
103- Logger .notify (" Could not write version file: " .. self ._version_file , vim . log . levels . WARN )
102+ Logger .warn (" Could not write version file: " .. self ._version_file )
104103 end
105104end
106105
@@ -136,7 +135,7 @@ function M:_download_latest_server(server_path, version)
136135
137136 local download_path = self ._cache_dir .. " /" .. artifact_name
138137
139- Logger .notify (" Downloading latest ECA server version from: " .. download_url , vim . log . levels . INFO )
138+ Logger .debug (" Downloading latest ECA server version from: " .. download_url )
140139
141140 -- Ensure cache directory exists
142141 vim .fn .mkdir (self ._cache_dir , " p" )
@@ -150,8 +149,7 @@ function M:_download_latest_server(server_path, version)
150149
151150 local download_result = os.execute (download_cmd )
152151 if download_result ~= 0 then
153- Logger .notify (" Failed to download ECA server from: " .. download_url , vim .log .levels .ERROR )
154- return false
152+ error (" Failed to download ECA server from: " .. download_url )
155153 end
156154
157155 -- Extract if it's a zip file
@@ -161,42 +159,38 @@ function M:_download_latest_server(server_path, version)
161159
162160 local extract_result = os.execute (extract_cmd )
163161 if extract_result ~= 0 then
164- Logger .notify (" Failed to extract ECA server" , vim .log .levels .ERROR )
165- return false
162+ error (" Failed to extract ECA server" )
166163 end
167164
168165 -- Remove the zip file after extraction
169166 os.remove (download_path )
170167 end
171168
172169 -- Make executable (if not Windows)
173- if not vim . loop .os_uname ().sysname :lower ():match (" windows" ) then
170+ if not uv .os_uname ().sysname :lower ():match (" windows" ) then
174171 os.execute (" chmod +x " .. vim .fn .shellescape (server_path ))
175172 end
176173
177174 if not Utils .file_exists (server_path ) then
178- Logger .notify (" ECA server binary not found after download and extraction" , vim .log .levels .ERROR )
179- return false
175+ error (" ECA server binary not found after download and extraction" )
180176 end
181177
182178 -- Write version file
183179 self :_write_version_file (version )
184180
185- Logger .notify (" ECA server downloaded successfully" , vim .log .levels .INFO )
181+ Logger .debug (" ECA server downloaded successfully" )
182+
186183 return true
187184end
188185
189186--- @return string
190- function M :find ()
187+ function M :find (custom_path )
191188 -- Check for custom server path first
192- local custom_path = Config .server_path
193189 if custom_path and custom_path :gsub (" %s+" , " " ) ~= " " then
194- if Utils .file_exists (custom_path ) then
195- Logger .debug (" Using custom server path: " .. custom_path )
196- return custom_path
197- else
198- Logger .notify (" Custom server path does not exist: " .. custom_path , vim .log .levels .WARN )
190+ if not Utils .file_exists (custom_path ) then
191+ error (" Custom server path does not exist: " .. custom_path )
199192 end
193+ return custom_path
200194 end
201195
202196 local server_path = self :_get_extension_server_path ()
@@ -215,13 +209,18 @@ function M:find()
215209 -- Download if server doesn't exist or version is outdated
216210 if not server_exists or (latest_version and current_version ~= latest_version ) then
217211 if not latest_version then
218- Logger .notify (" Could not check for latest version, using existing server" , vim . log . levels . WARN )
212+ Logger .warn (" Could not check for latest version, using existing server" )
219213 return server_path
220214 end
221215
222- local success = self :_download_latest_server (server_path , latest_version )
223- if not success then
224- error (" Failed to download ECA server" )
216+ local success
217+
218+ local ok , err = pcall (function ()
219+ success = self :_download_latest_server (server_path , latest_version )
220+ end )
221+
222+ if not ok or not success then
223+ error ((err and tostring (err )) or " Failed to download ECA server" )
225224 end
226225 end
227226
0 commit comments