From c203110555347469c4eaca133f8088f3fade3e81 Mon Sep 17 00:00:00 2001 From: Techatrix <19954306+Techatrix@users.noreply.github.com> Date: Sat, 11 Mar 2023 18:43:14 +0000 Subject: [PATCH] more tracy calls (#1052) --- src/Server.zig | 9 +++++++++ src/analysis.zig | 13 +++++++++++++ src/diff.zig | 10 ++++++++++ src/folding_range.zig | 7 +++++++ src/inlay_hints.zig | 13 +++++++++++++ src/translate_c.zig | 7 +++++++ 6 files changed, 59 insertions(+) diff --git a/src/Server.zig b/src/Server.zig index ec4a9e6..e9e8e64 100644 --- a/src/Server.zig +++ b/src/Server.zig @@ -3046,6 +3046,15 @@ pub fn processMessage(server: *Server, message: Message) Error!void { const tracy_zone = tracy.trace(@src()); defer tracy_zone.end(); + if (message.method()) |name| { + tracy_zone.setName(name); + } else if (message.id()) |id| { + switch (id) { + .integer => {}, + .string => |name| tracy_zone.setName(name), + } + } + switch (message) { .RequestMessage => |request| { if (!requestMethodExists(request.method)) return error.MethodNotFound; diff --git a/src/analysis.zig b/src/analysis.zig index cdda53f..0847d89 100644 --- a/src/analysis.zig +++ b/src/analysis.zig @@ -6,6 +6,7 @@ const offsets = @import("offsets.zig"); const URI = @import("uri.zig"); const log = std.log.scoped(.zls_analysis); const ast = @import("ast.zig"); +const tracy = @import("tracy.zig"); const ComptimeInterpreter = @import("ComptimeInterpreter.zig"); const InternPool = ComptimeInterpreter.InternPool; @@ -1284,6 +1285,9 @@ pub fn collectImports(allocator: std.mem.Allocator, tree: Ast) error{OutOfMemory /// Collects all `@cImport` nodes /// Caller owns returned memory. pub fn collectCImportNodes(allocator: std.mem.Allocator, tree: Ast) error{OutOfMemory}![]Ast.Node.Index { + const tracy_zone = tracy.trace(@src()); + defer tracy_zone.end(); + var import_nodes = std.ArrayListUnmanaged(Ast.Node.Index){}; errdefer import_nodes.deinit(allocator); @@ -1621,6 +1625,9 @@ pub fn getPositionContext( /// Should we look to the end of the current context? Yes for goto def, no for completions lookahead: bool, ) !PositionContext { + const tracy_zone = tracy.trace(@src()); + defer tracy_zone.end(); + var new_index = doc_index; if (lookahead and new_index < text.len and isSymbolChar(text[new_index])) { new_index += 1; @@ -2612,6 +2619,9 @@ pub const Scope = struct { }; pub fn makeDocumentScope(allocator: std.mem.Allocator, tree: Ast) !DocumentScope { + const tracy_zone = tracy.trace(@src()); + defer tracy_zone.end(); + var document_scope = DocumentScope{ .scopes = .{}, .error_completions = .{}, @@ -2639,6 +2649,9 @@ const ScopeContext = struct { }; fn makeInnerScope(allocator: std.mem.Allocator, context: ScopeContext, node_idx: Ast.Node.Index) error{OutOfMemory}!void { + const tracy_zone = tracy.trace(@src()); + defer tracy_zone.end(); + const scopes = context.scopes; const tree = context.tree; const tags = tree.nodes.items(.tag); diff --git a/src/diff.zig b/src/diff.zig index 749a07e..5da6ced 100644 --- a/src/diff.zig +++ b/src/diff.zig @@ -1,6 +1,7 @@ const std = @import("std"); const types = @import("lsp.zig"); const offsets = @import("offsets.zig"); +const tracy = @import("tracy.zig"); const DiffMatchPatch = @import("diffz"); const dmp = DiffMatchPatch{ @@ -15,6 +16,9 @@ pub fn edits( after: []const u8, encoding: offsets.Encoding, ) Error!std.ArrayListUnmanaged(types.TextEdit) { + const tracy_zone = tracy.trace(@src()); + defer tracy_zone.end(); + var arena = std.heap.ArenaAllocator.init(allocator); defer arena.deinit(); var diffs = try dmp.diff(arena.allocator(), before, after, true); @@ -70,6 +74,9 @@ pub fn applyContentChanges( content_changes: []const types.TextDocumentContentChangeEvent, encoding: offsets.Encoding, ) ![:0]const u8 { + const tracy_zone = tracy.trace(@src()); + defer tracy_zone.end(); + var last_full_text_change: ?usize = null; var i: usize = content_changes.len; while (i > 0) { @@ -111,6 +118,9 @@ pub fn applyTextEdits( text_edits: []const types.TextEdit, encoding: offsets.Encoding, ) ![]const u8 { + const tracy_zone = tracy.trace(@src()); + defer tracy_zone.end(); + var text_edits_sortable = try allocator.alloc(types.TextEdit, text_edits.len); defer allocator.free(text_edits_sortable); diff --git a/src/folding_range.zig b/src/folding_range.zig index 8b95792..b41dc11 100644 --- a/src/folding_range.zig +++ b/src/folding_range.zig @@ -2,6 +2,7 @@ const std = @import("std"); const ast = @import("ast.zig"); const types = @import("lsp.zig"); const offsets = @import("offsets.zig"); +const tracy = @import("tracy.zig"); const Ast = std.zig.Ast; const FoldingRange = struct { @@ -54,6 +55,9 @@ const Builder = struct { } pub fn getRanges(builder: Builder) error{OutOfMemory}![]types.FoldingRange { + const tracy_zone = tracy.trace(@src()); + defer tracy_zone.end(); + var result_locations = try builder.allocator.alloc(types.FoldingRange, builder.locations.items.len); errdefer builder.allocator.free(result_locations); @@ -121,6 +125,9 @@ const Builder = struct { }; pub fn generateFoldingRanges(allocator: std.mem.Allocator, tree: Ast, encoding: offsets.Encoding) error{OutOfMemory}![]types.FoldingRange { + const tracy_zone = tracy.trace(@src()); + defer tracy_zone.end(); + var builder = Builder{ .allocator = allocator, .locations = .{}, diff --git a/src/inlay_hints.zig b/src/inlay_hints.zig index db10792..1e3d308 100644 --- a/src/inlay_hints.zig +++ b/src/inlay_hints.zig @@ -4,6 +4,7 @@ const DocumentStore = @import("DocumentStore.zig"); const analysis = @import("analysis.zig"); const types = @import("lsp.zig"); const offsets = @import("offsets.zig"); +const tracy = @import("tracy.zig"); const Ast = std.zig.Ast; const log = std.log.scoped(.zls_inlay_hint); const ast = @import("ast.zig"); @@ -64,6 +65,9 @@ const Builder = struct { /// `decl_handle` should be a function protototype /// writes parameter hints into `builder.hints` fn writeCallHint(builder: *Builder, call: Ast.full.Call, decl_handle: analysis.DeclWithHandle) !void { + const tracy_zone = tracy.trace(@src()); + defer tracy_zone.end(); + const handle = builder.handle; const tree = handle.tree; @@ -127,6 +131,9 @@ fn writeCallHint(builder: *Builder, call: Ast.full.Call, decl_handle: analysis.D /// takes parameter nodes from the ast and function parameter names from `Builtin.arguments` and writes parameter hints into `builder.hints` fn writeBuiltinHint(builder: *Builder, parameters: []const Ast.Node.Index, arguments: []const []const u8) !void { + const tracy_zone = tracy.trace(@src()); + defer tracy_zone.end(); + const handle = builder.handle; const tree = handle.tree; @@ -162,6 +169,9 @@ fn writeBuiltinHint(builder: *Builder, parameters: []const Ast.Node.Index, argum /// takes a Ast.full.Call (a function call), analysis its function expression, finds its declaration and writes parameter hints into `builder.hints` fn writeCallNodeHint(builder: *Builder, call: Ast.full.Call) !void { + const tracy_zone = tracy.trace(@src()); + defer tracy_zone.end(); + if (call.ast.params.len == 0) return; if (builder.config.inlay_hints_exclude_single_argument and call.ast.params.len == 1) return; @@ -280,6 +290,9 @@ pub fn writeRangeInlayHint( loc: offsets.Loc, hover_kind: types.MarkupKind, ) error{OutOfMemory}![]InlayHint { + const tracy_zone = tracy.trace(@src()); + defer tracy_zone.end(); + var builder: Builder = .{ .arena = arena, .store = store, diff --git a/src/translate_c.zig b/src/translate_c.zig index f45e8a3..97c0182 100644 --- a/src/translate_c.zig +++ b/src/translate_c.zig @@ -3,6 +3,7 @@ const zig_builtin = @import("builtin"); const builtin = @import("builtin"); const Config = @import("Config.zig"); const ast = @import("ast.zig"); +const tracy = @import("tracy.zig"); const Ast = std.zig.Ast; const URI = @import("uri.zig"); const log = std.log.scoped(.zls_translate_c); @@ -24,6 +25,9 @@ const log = std.log.scoped(.zls_translate_c); /// #include "GLFW/glfw3.h" /// ``` pub fn convertCInclude(allocator: std.mem.Allocator, tree: Ast, node: Ast.Node.Index) error{ OutOfMemory, Unsupported }![]const u8 { + const tracy_zone = tracy.trace(@src()); + defer tracy_zone.end(); + const main_tokens = tree.nodes.items(.main_token); std.debug.assert(ast.isBuiltinCall(tree, node)); @@ -130,6 +134,9 @@ pub const Result = union(enum) { /// null indicates a failure which is automatically logged /// Caller owns returned memory. pub fn translate(allocator: std.mem.Allocator, config: Config, include_dirs: []const []const u8, source: []const u8) error{OutOfMemory}!?Result { + const tracy_zone = tracy.trace(@src()); + defer tracy_zone.end(); + const file_path = try std.fs.path.join(allocator, &[_][]const u8{ config.global_cache_path.?, "cimport.h" }); defer allocator.free(file_path);