Merge pull request #69 from alexnask/master

Small fixes
This commit is contained in:
Auguste Rame 2020-05-21 09:12:30 -04:00 committed by GitHub
commit 584a441327
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 6 deletions

View File

@ -47,8 +47,8 @@ The following options are currently available.
| Option | Type | Default value | What it Does | | 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). | | `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, used to analyze std library imports. | | `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 | | `warn_style` | `bool` | `false` | Enables warnings for style *guideline* mismatches |
## Usage ## Usage

View File

@ -298,7 +298,6 @@ pub fn resolveTypeOfNode(analysis_ctx: *AnalysisContext, node: *ast.Node) ?*ast.
}, },
.Identifier => { .Identifier => {
if (getChildOfSlice(analysis_ctx.tree, analysis_ctx.scope_nodes, analysis_ctx.tree.getNodeSource(node))) |child| { 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); return resolveTypeOfNode(analysis_ctx, child);
} else return null; } else return null;
}, },

View File

@ -284,6 +284,7 @@ fn nodeToCompletion(list: *std.ArrayList(types.CompletionItem), analysis_ctx: *D
fn identifierFromPosition(pos_index: usize, handle: DocumentStore.Handle) []const u8 { fn identifierFromPosition(pos_index: usize, handle: DocumentStore.Handle) []const u8 {
var start_idx = pos_index; var start_idx = pos_index;
while (start_idx > 0 and while (start_idx > 0 and
(std.ascii.isAlNum(handle.document.text[start_idx]) or handle.document.text[start_idx] == '_')) : (start_idx -= 1) (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(); defer tree.deinit();
const name = identifierFromPosition(pos_index, handle); const name = identifierFromPosition(pos_index, handle);
if (name.len == 0) return try respondGeneric(id, null_result_response);
var arena = std.heap.ArenaAllocator.init(allocator); var arena = std.heap.ArenaAllocator.init(allocator);
defer arena.deinit(); defer arena.deinit();
@ -328,15 +331,16 @@ fn gotoDefinitionFieldAccess(
line_start_idx: usize, line_start_idx: usize,
config: Config, config: Config,
) !void { ) !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); var arena = std.heap.ArenaAllocator.init(allocator);
defer arena.deinit(); defer arena.deinit();
var analysis_ctx = try document_store.analysisContext(handle, &arena, position, config.zig_lib_path); var analysis_ctx = try document_store.analysisContext(handle, &arena, position, config.zig_lib_path);
defer analysis_ctx.deinit(); 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)); const line = try handle.document.getLine(@intCast(usize, position.line));
var tokenizer = std.zig.Tokenizer.init(line[line_start_idx..]); var tokenizer = std.zig.Tokenizer.init(line[line_start_idx..]);