From 4acb77f09e8379954e944a6bc5c05c4979cc64fc Mon Sep 17 00:00:00 2001 From: Alexandros Naskos Date: Thu, 21 May 2020 14:36:14 +0300 Subject: [PATCH] enable_snippets is false by default, fix it in README. Small fixes to goto def/decl --- README.md | 4 ++-- src/analysis.zig | 1 - src/main.zig | 10 +++++++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index a1b3bc3..432a1b5 100644 --- a/README.md +++ b/README.md @@ -47,8 +47,8 @@ The following options are currently available. | Option | Type | Default value | What it Does | | --- | --- | --- | --- | -| `enable_snippets` | `bool` | `true` | Enables snippet completion, set to false for compatibility with language clients that do not support snippets (such as ale). | -| `zig_lib_path` | `?[]const u8` | `null` | zig library path, used to analyze std library imports. | +| `enable_snippets` | `bool` | `false` | Enables snippet completion, set to false for compatibility with language clients that do not support snippets (such as ale). | +| `zig_lib_path` | `?[]const u8` | `null` | zig library path, e.g. `/path/to/zig/lib/zig`, used to analyze std library imports. | | `warn_style` | `bool` | `false` | Enables warnings for style *guideline* mismatches | ## Usage diff --git a/src/analysis.zig b/src/analysis.zig index 9a19487..10bc4f0 100644 --- a/src/analysis.zig +++ b/src/analysis.zig @@ -298,7 +298,6 @@ pub fn resolveTypeOfNode(analysis_ctx: *AnalysisContext, node: *ast.Node) ?*ast. }, .Identifier => { if (getChildOfSlice(analysis_ctx.tree, analysis_ctx.scope_nodes, analysis_ctx.tree.getNodeSource(node))) |child| { - std.debug.warn("Found node {}\n", .{child}); return resolveTypeOfNode(analysis_ctx, child); } else return null; }, diff --git a/src/main.zig b/src/main.zig index 971fc92..c4c7a76 100644 --- a/src/main.zig +++ b/src/main.zig @@ -284,6 +284,7 @@ fn nodeToCompletion(list: *std.ArrayList(types.CompletionItem), analysis_ctx: *D fn identifierFromPosition(pos_index: usize, handle: DocumentStore.Handle) []const u8 { var start_idx = pos_index; + while (start_idx > 0 and (std.ascii.isAlNum(handle.document.text[start_idx]) or handle.document.text[start_idx] == '_')) : (start_idx -= 1) {} @@ -301,6 +302,8 @@ fn gotoDefinitionGlobal(id: i64, pos_index: usize, handle: DocumentStore.Handle) defer tree.deinit(); const name = identifierFromPosition(pos_index, handle); + if (name.len == 0) return try respondGeneric(id, null_result_response); + var arena = std.heap.ArenaAllocator.init(allocator); defer arena.deinit(); @@ -328,15 +331,16 @@ fn gotoDefinitionFieldAccess( line_start_idx: usize, config: Config, ) !void { + const pos_index = try handle.document.positionToIndex(position); + var name = identifierFromPosition(pos_index, handle.*); + if (name.len == 0) return try respondGeneric(id, null_result_response); + var arena = std.heap.ArenaAllocator.init(allocator); defer arena.deinit(); var analysis_ctx = try document_store.analysisContext(handle, &arena, position, config.zig_lib_path); defer analysis_ctx.deinit(); - const pos_index = try handle.document.positionToIndex(position); - var name = identifierFromPosition(pos_index, handle.*); - const line = try handle.document.getLine(@intCast(usize, position.line)); var tokenizer = std.zig.Tokenizer.init(line[line_start_idx..]);