Fix inferred error set return types

This commit is contained in:
Luuk de Gram 2021-03-07 18:45:37 +01:00
parent e2f4bbf2f3
commit 53c37765c0
No known key found for this signature in database
GPG Key ID: A002B174963DBB7D
3 changed files with 21 additions and 5 deletions

View File

@ -63,6 +63,7 @@ The following options are currently available.
| `build_runner_cache_path` | `?[]const u8` | `null` | Path to a directroy that will be used as zig's cache when running `zig run build_runner.zig ...`. `null` is equivalent to `${KnownFloders.Cache}/zls` | | `build_runner_cache_path` | `?[]const u8` | `null` | Path to a directroy that will be used as zig's cache when running `zig run build_runner.zig ...`. `null` is equivalent to `${KnownFloders.Cache}/zls` |
| `enable_semantic_tokens` | `bool` | `true` | Enables semantic token support when the client also supports it. | | `enable_semantic_tokens` | `bool` | `true` | Enables semantic token support when the client also supports it. |
| `operator_completions` | `bool` | `true` | Enables `*` and `?` operators in completion lists. | | `operator_completions` | `bool` | `true` | Enables `*` and `?` operators in completion lists. |
| `skip_std_references` | `bool` | `false` | When true, skips searching for references in std. Improves lookup speed for functions in user's code. Renaming and go-to-definition will continue to work as is.
## Features ## Features

View File

@ -467,8 +467,24 @@ pub fn resolveReturnType(
} }
if (fn_decl.ast.return_type == 0) return null; if (fn_decl.ast.return_type == 0) return null;
return ((try resolveTypeOfNodeInternal(store, arena, .{ const return_type = fn_decl.ast.return_type;
.node = fn_decl.ast.return_type,
const is_inferred_error = tree.tokens.items(.tag)[tree.firstToken(return_type) - 1] == .bang;
return if (is_inferred_error) block: {
const child_type = (try resolveTypeOfNodeInternal(store, arena, .{
.node = return_type,
.handle = handle,
}, bound_type_params)) orelse return null;
const child_type_node = switch (child_type.type.data) {
.other => |n| n,
else => return null,
};
break :block TypeWithHandle{
.type = .{ .data = .{ .error_union = child_type_node }, .is_type_val = false },
.handle = child_type.handle,
};
} else ((try resolveTypeOfNodeInternal(store, arena, .{
.node = return_type,
.handle = handle, .handle = handle,
}, bound_type_params)) orelse return null).instanceTypeVal(); }, bound_type_params)) orelse return null).instanceTypeVal();
} }
@ -509,6 +525,7 @@ fn resolveUnwrapErrorType(
}, },
.primitive, .slice, .pointer => return null, .primitive, .slice, .pointer => return null,
}; };
if (rhs.handle.tree.nodes.items(.tag)[rhs_node] == .error_union) { if (rhs.handle.tree.nodes.items(.tag)[rhs_node] == .error_union) {
return ((try resolveTypeOfNodeInternal(store, arena, .{ return ((try resolveTypeOfNodeInternal(store, arena, .{
.node = rhs.handle.tree.nodes.items(.data)[rhs_node].rhs, .node = rhs.handle.tree.nodes.items(.data)[rhs_node].rhs,

View File

@ -366,7 +366,6 @@ fn nodeToCompletion(
.arena = arena, .arena = arena,
.orig_handle = orig_handle, .orig_handle = orig_handle,
}; };
logger.debug("eklafgaef", .{});
try analysis.iterateSymbolsContainer(&document_store, arena, node_handle, orig_handle, declToCompletion, context, !is_type_val); try analysis.iterateSymbolsContainer(&document_store, arena, node_handle, orig_handle, declToCompletion, context, !is_type_val);
} }
@ -623,9 +622,8 @@ fn hoverSymbol(
const first_token = param.first_doc_comment orelse const first_token = param.first_doc_comment orelse
param.comptime_noalias orelse param.comptime_noalias orelse
param.name_token orelse param.name_token orelse
param.anytype_ellipsis3 orelse
tree.firstToken(param.type_expr); tree.firstToken(param.type_expr);
const last_token = tree.lastToken(param.type_expr); const last_token = tree.lastToken(param.anytype_ellipsis3 orelse param.type_expr);
const start = offsets.tokenLocation(tree, first_token).start; const start = offsets.tokenLocation(tree, first_token).start;
const end = offsets.tokenLocation(tree, last_token).end; const end = offsets.tokenLocation(tree, last_token).end;