Missing `error.` completions for `imported.f() catch |err| switch (err) { error.`, and irrelevant for `return error.` for fns with known Error (Set(s))
ZLS: 0.16.0-dev.26+8b2754ad
Given a f() catch |err| switch (err) { error.* or return error. the server has enough context to figure out if the fn has a non-IES and present only the relevant entries.
(*) This is the more so important when the fn is in a different file (currently the server only present errors defined in the current file).
const std = @import("std");
const FnMainErr = error{ A, B, C };
const FnFooErr = error{ L, M, N };
const UnrelatedErr = error{ X, Y, Z };
fn foo() FnFooErr!void {}
pub fn main() FnMainErr!void {
foo() catch |err| switch (err) {
error. // Show only: L M N
};
std.Uri.parseAfterScheme() catch |err| switch (err) {
error. // Missing: InvalidFormat, InvalidPort, UnexpectedCharacter
};
return error. // Show only: A B C
}
Having the same problem.
I have code like this:
const std = @import("std");
pub fn main() !void {
const allocator = std.heap.page_allocator;
var client = std.http.Client{ .allocator = allocator };
const result = client.fetch(.{ .location = .{ .url = "http://google.com" } }) catch |err| {
switch (err) {
error.ConnectionRefused => {
std.debug.print("Connection refused by the server.\n", .{});
std.process.exit(4);
},
else => {},
}
std.debug.print("Fetch failed: {}\n", .{err});
std.process.exit(1);
};
std.debug.print("Status code: {}\n", .{@intFromEnum(result.status)});
std.process.exit(3);
}
And inside switch statement there is no autocomplete for the possible cases, even though on hover I see that err is:
(error{UnexpectedCharacter,InvalidFormat,InvalidPort,OutOfMemory,ConnectionRefused,NetworkUnreachable,ConnectionTimedOut,ConnectionResetByPeer,TemporaryNameServerFailure,NameServerFailure,UnknownHostName,HostLacksNetworkAddresses,UnexpectedConnectFailure,TlsInitializationFailed,UnsupportedUriScheme,UriMissingHost,UriHostTooLong,CertificateBundleLoadFailure,HttpHeadersOversize,HttpRequestTruncated,HttpConnectionClosing,ReadFailed,HttpHeadersInvalid,TooManyHttpRedirects,RedirectRequiresResend,HttpRedirectLocationMissing,HttpRedirectLocationOversize,HttpRedirectLocationInvalid,HttpContentEncodingUnsupported,HttpChunkInvalid,HttpChunkTruncated,WriteFailed,StreamTooLong,UnsupportedCompressionMethod})
I expect lsp should be able figure out those cases for autocomplete since it already knows them and show on hover
This is also the case for std lib errors. I remember this was the same back in the 0.13.0 days.
I'm using the latest ZLS (LspInfo: 0.16.0-dev.64+e8e542a2) and the Zig master branch (zig version: 0.16.0-dev.1582+7f36c4c7d).
Would be really nice to have the auto completions. This would've pushed me to tinker with the possible errors and quickly fill switches with something useful ;')