Implement usingnamespace and fix function snippets
This commit is contained in:
		
							parent
							
								
									7495aab28b
								
							
						
					
					
						commit
						a80e9b262e
					
				
							
								
								
									
										100
									
								
								src/analysis.zig
									
									
									
									
									
								
							
							
						
						
									
										100
									
								
								src/analysis.zig
									
									
									
									
									
								
							| @ -18,7 +18,7 @@ pub fn getDocCommentTokenIndex(tree: ast.Tree, node: ast.Node.Index) ?ast.TokenI | |||||||
|             idx -= 1; |             idx -= 1; | ||||||
|             if (tokens[idx] == .keyword_extern and idx > 0) |             if (tokens[idx] == .keyword_extern and idx > 0) | ||||||
|                 idx -= 1; |                 idx -= 1; | ||||||
|             if (tokens[idx] == .keyword_pub and idx < 0) |             if (tokens[idx] == .keyword_pub and idx > 0) | ||||||
|                 idx -= 1; |                 idx -= 1; | ||||||
|         }, |         }, | ||||||
|         .local_var_decl, .global_var_decl, .aligned_var_decl, .simple_var_decl => { |         .local_var_decl, .global_var_decl, .aligned_var_decl, .simple_var_decl => { | ||||||
| @ -118,10 +118,10 @@ pub fn getFunctionSnippet(allocator: *std.mem.Allocator, tree: ast.Tree, func: a | |||||||
| 
 | 
 | ||||||
|     var it = func.iterate(tree); |     var it = func.iterate(tree); | ||||||
|     while (it.next()) |param| { |     while (it.next()) |param| { | ||||||
|         if (skip_self_param and it.param_i == 0) continue; |         if (skip_self_param and it.param_i -1 == 0) continue; | ||||||
|         if (it.param_i != @boolToInt(skip_self_param)) try buffer.appendSlice(", ${") else try buffer.appendSlice("${"); |         if (it.param_i -1 != @boolToInt(skip_self_param)) try buffer.appendSlice(", ${") else try buffer.appendSlice("${"); | ||||||
| 
 | 
 | ||||||
|         try buf_stream.print("{d}", .{it.param_i + 1}); |         try buf_stream.print("{d}:", .{it.param_i}); | ||||||
| 
 | 
 | ||||||
|         if (param.comptime_noalias) |token_index| { |         if (param.comptime_noalias) |token_index| { | ||||||
|             if (token_tags[token_index] == .keyword_comptime) |             if (token_tags[token_index] == .keyword_comptime) | ||||||
| @ -141,8 +141,8 @@ pub fn getFunctionSnippet(allocator: *std.mem.Allocator, tree: ast.Tree, func: a | |||||||
|             else |             else | ||||||
|                 try buffer.appendSlice("..."); |                 try buffer.appendSlice("..."); | ||||||
|         } else { |         } else { | ||||||
|             var curr_token = param.type_expr; |             var curr_token = tree.firstToken(param.type_expr); | ||||||
|             var end_token = tree.lastToken(func.ast.params[it.param_i]); |             var end_token = tree.lastToken(param.type_expr); | ||||||
|             while (curr_token <= end_token) : (curr_token += 1) { |             while (curr_token <= end_token) : (curr_token += 1) { | ||||||
|                 const tag = token_tags[curr_token]; |                 const tag = token_tags[curr_token]; | ||||||
|                 const is_comma = tag == .comma; |                 const is_comma = tag == .comma; | ||||||
| @ -1989,18 +1989,20 @@ fn iterateSymbolsContainerInternal( | |||||||
|             try callback(context, decl); |             try callback(context, decl); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         // for (container_scope.uses) |use| { |         for (container_scope.uses) |use| { | ||||||
|         //     if (handle != orig_handle and use.visib_token == null) continue; |             const use_token = tree.nodes.items(.main_token)[use]; | ||||||
|         //     if (std.mem.indexOfScalar(*ast.Node.Use, use_trail.items, use) != null) continue; |             const is_pub = use_token > 0 and token_tags[use_token - 1] == .keyword_pub; | ||||||
|         //     try use_trail.append(use); |             if (handle != orig_handle and !is_pub) continue; | ||||||
|  |             if (std.mem.indexOfScalar(ast.Node.Index, use_trail.items, use) != null) continue; | ||||||
|  |             try use_trail.append(use); | ||||||
| 
 | 
 | ||||||
|         //     const use_expr = (try resolveTypeOfNode(store, arena, .{ .node = use.expr, .handle = handle })) orelse continue; |             const use_expr = (try resolveTypeOfNode(store, arena, .{ .node = tree.nodes.items(.data)[use].rhs, .handle = handle })) orelse continue; | ||||||
|         //     const use_expr_node = switch (use_expr.type.data) { |             const use_expr_node = switch (use_expr.type.data) { | ||||||
|         //         .other => |n| n, |                 .other => |n| n, | ||||||
|         //         else => continue, |                 else => continue, | ||||||
|         //     }; |             }; | ||||||
|         //     try iterateSymbolsContainerInternal(store, arena, .{ .node = use_expr_node, .handle = use_expr.handle }, orig_handle, callback, context, false, use_trail); |             try iterateSymbolsContainerInternal(store, arena, .{ .node = use_expr_node, .handle = use_expr.handle }, orig_handle, callback, context, false, use_trail); | ||||||
|         // } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -2056,17 +2058,17 @@ fn iterateSymbolsGlobalInternal( | |||||||
|                 try callback(context, DeclWithHandle{ .decl = &entry.value, .handle = handle }); |                 try callback(context, DeclWithHandle{ .decl = &entry.value, .handle = handle }); | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             // for (Index) |use| { |             for (scope.uses) |use| { | ||||||
|             //     if (std.mem.indexOfScalar(*ast.Node.Use, use_trail.items, use) != null) continue; |                 if (std.mem.indexOfScalar(ast.Node.Index, use_trail.items, use) != null) continue; | ||||||
|             //     try use_trail.append(use); |                 try use_trail.append(use); | ||||||
| 
 | 
 | ||||||
|             //     const use_expr = (try resolveTypeOfNode(store, arena, .{ .node = use.expr, .handle = handle })) orelse continue; |                 const use_expr = (try resolveTypeOfNode(store, arena, .{ .node = handle.tree.nodes.items(.data)[use].lhs, .handle = handle })) orelse continue; | ||||||
|             //     const use_expr_node = switch (use_expr.type.data) { |                 const use_expr_node = switch (use_expr.type.data) { | ||||||
|             //         .other => |n| n, |                     .other => |n| n, | ||||||
|             //         else => continue, |                     else => continue, | ||||||
|             //     }; |                 }; | ||||||
|             //     try iterateSymbolsContainerInternal(store, arena, .{ .node = use_expr_node, .handle = use_expr.handle }, handle, callback, context, false, use_trail); |                 try iterateSymbolsContainerInternal(store, arena, .{ .node = use_expr_node, .handle = use_expr.handle }, handle, callback, context, false, use_trail); | ||||||
|             // } |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         if (scope.range.start >= source_index) return; |         if (scope.range.start >= source_index) return; | ||||||
| @ -2104,27 +2106,27 @@ pub fn innermostContainer(handle: *DocumentStore.Handle, source_index: usize) Ty | |||||||
| fn resolveUse( | fn resolveUse( | ||||||
|     store: *DocumentStore, |     store: *DocumentStore, | ||||||
|     arena: *std.heap.ArenaAllocator, |     arena: *std.heap.ArenaAllocator, | ||||||
|     // uses: []const *ast.Node.Use, |     uses: []const ast.Node.Index, | ||||||
|     symbol: []const u8, |     symbol: []const u8, | ||||||
|     handle: *DocumentStore.Handle, |     handle: *DocumentStore.Handle, | ||||||
|     use_trail: *std.ArrayList(*ast.Node.Use), |     use_trail: *std.ArrayList(ast.Node.Index), | ||||||
| ) error{OutOfMemory}!?DeclWithHandle { | ) error{OutOfMemory}!?DeclWithHandle { | ||||||
|     // for (uses) |use| { |     for (uses) |use| { | ||||||
|     //     if (std.mem.indexOfScalar(*ast.Node.Use, use_trail.items, use) != null) continue; |         if (std.mem.indexOfScalar(ast.Node.Index, use_trail.items, use) != null) continue; | ||||||
|     //     try use_trail.append(use); |         try use_trail.append(use); | ||||||
| 
 | 
 | ||||||
|     //     const use_expr = (try resolveTypeOfNode(store, arena, .{ .node = use.expr, .handle = handle })) orelse continue; |         const use_expr = (try resolveTypeOfNode(store, arena, .{ .node = handle.tree.nodes.items(.data)[use].lhs, .handle = handle })) orelse continue; | ||||||
|     //     const use_expr_node = switch (use_expr.type.data) { |         const use_expr_node = switch (use_expr.type.data) { | ||||||
|     //         .other => |n| n, |             .other => |n| n, | ||||||
|     //         else => continue, |             else => continue, | ||||||
|     //     }; |         }; | ||||||
|     //     if (try lookupSymbolContainerInternal(store, arena, .{ .node = use_expr_node, .handle = use_expr.handle }, symbol, false, use_trail)) |candidate| { |         if (try lookupSymbolContainerInternal(store, arena, .{ .node = use_expr_node, .handle = use_expr.handle }, symbol, false, use_trail)) |candidate| { | ||||||
|     //         if (candidate.handle != handle and !candidate.isPublic()) { |             if (candidate.handle != handle and !candidate.isPublic()) { | ||||||
|     //             continue; |                 continue; | ||||||
|     //         } |             } | ||||||
|     //         return candidate; |             return candidate; | ||||||
|     //     } |         } | ||||||
|     // } |     } | ||||||
|     return null; |     return null; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -2160,7 +2162,6 @@ fn lookupSymbolGlobalInternal( | |||||||
|     use_trail: *std.ArrayList(ast.Node.Index), |     use_trail: *std.ArrayList(ast.Node.Index), | ||||||
| ) error{OutOfMemory}!?DeclWithHandle { | ) error{OutOfMemory}!?DeclWithHandle { | ||||||
|     for (handle.document_scope.scopes) |scope| { |     for (handle.document_scope.scopes) |scope| { | ||||||
|         // @TODO: Fix scope positions |  | ||||||
|         if (source_index >= scope.range.start and source_index < scope.range.end) { |         if (source_index >= scope.range.start and source_index < scope.range.end) { | ||||||
|             if (scope.decls.getEntry(symbol)) |candidate| { |             if (scope.decls.getEntry(symbol)) |candidate| { | ||||||
|                 switch (candidate.value) { |                 switch (candidate.value) { | ||||||
| @ -2176,7 +2177,7 @@ fn lookupSymbolGlobalInternal( | |||||||
|                 }; |                 }; | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             // if (try resolveUse(store, arena, scope.uses, symbol, handle, use_trail)) |result| return result; |             if (try resolveUse(store, arena, scope.uses, symbol, handle, use_trail)) |result| return result; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         if (scope.range.start > source_index) return null; |         if (scope.range.start > source_index) return null; | ||||||
| @ -2233,7 +2234,7 @@ fn lookupSymbolContainerInternal( | |||||||
|             return DeclWithHandle{ .decl = &candidate.value, .handle = handle }; |             return DeclWithHandle{ .decl = &candidate.value, .handle = handle }; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         // if (try resolveUse(store, arena, container_scope.uses, symbol, handle, use_trail)) |result| return result; |         if (try resolveUse(store, arena, container_scope.uses, symbol, handle, use_trail)) |result| return result; | ||||||
|         return null; |         return null; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -2262,14 +2263,13 @@ pub const DocumentScope = struct { | |||||||
|         for (self.scopes) |scope| { |         for (self.scopes) |scope| { | ||||||
|             log.debug( |             log.debug( | ||||||
|                 \\-------------------------- |                 \\-------------------------- | ||||||
|                 \\Scope {}, range: [{}, {}) |                 \\Scope {}, range: [{d}, {d}) | ||||||
|                 \\ {} usingnamespaces |                 \\ {d} usingnamespaces | ||||||
|                 \\Decls:  |                 \\Decls:  | ||||||
|             , .{ |             , .{ | ||||||
|                 scope.data, |                 scope.data, | ||||||
|                 scope.range.start, |                 scope.range.start, | ||||||
|                 scope.range.end, |                 scope.range.end, | ||||||
|                 {}, |  | ||||||
|                 scope.uses.len, |                 scope.uses.len, | ||||||
|             }); |             }); | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user