diff --git a/src/analysis.zig b/src/analysis.zig index ba53a93..f290cec 100644 --- a/src/analysis.zig +++ b/src/analysis.zig @@ -399,11 +399,20 @@ pub fn resolveTypeOfNode(analysis_ctx: *AnalysisContext, node: *ast.Node) ?*ast. }, .Call => { const call = node.cast(ast.Node.Call).?; + const previous_tree = analysis_ctx.tree(); + const decl = resolveTypeOfNode(analysis_ctx, call.lhs) orelse return null; if (decl.cast(ast.Node.FnProto)) |fn_decl| { + if (previous_tree != analysis_ctx.tree()) { + return resolveReturnType(analysis_ctx, fn_decl); + } + // Add type param values to the scope nodes const param_len = std.math.min(call.params_len, fn_decl.params_len); + var scope_nodes = std.ArrayList(*ast.Node).fromOwnedSlice(&analysis_ctx.arena.allocator, analysis_ctx.scope_nodes); + var analysis_ctx_clone = analysis_ctx.clone() catch return null; for (fn_decl.paramsConst()) |decl_param, param_idx| { + if (param_idx >= param_len) break; if (decl_param.name_token == null) continue; // @TODO @@ -420,9 +429,10 @@ pub fn resolveTypeOfNode(analysis_ctx: *AnalysisContext, node: *ast.Node) ?*ast. // TODO This may invalidate the analysis context so we copy it. // However, if the argument hits an import we just ignore it for now. // Once we return our own types instead of directly using nodes we can fix this. - var analysis_ctx_clone = analysis_ctx.clone() catch return null; + std.debug.warn("Arg {} of fn {}\n", .{param_idx, analysis_ctx.tree().tokenSlice(fn_decl.name_token.?)}); const call_param_type = resolveTypeOfNode(&analysis_ctx_clone, call.paramsConst()[param_idx]) orelse continue; if (analysis_ctx_clone.handle != analysis_ctx.handle) { + analysis_ctx_clone = analysis_ctx.clone() catch return null; continue; } @@ -444,7 +454,6 @@ pub fn resolveTypeOfNode(analysis_ctx: *AnalysisContext, node: *ast.Node) ?*ast. .semicolon_token = decl_param.name_token.?, }; - var scope_nodes = std.ArrayList(*ast.Node).fromOwnedSlice(&analysis_ctx.arena.allocator, analysis_ctx.scope_nodes); scope_nodes.append(&var_decl_node.base) catch return null; analysis_ctx.scope_nodes = scope_nodes.items; } diff --git a/src/main.zig b/src/main.zig index 48a23c8..f986dcb 100644 --- a/src/main.zig +++ b/src/main.zig @@ -25,7 +25,7 @@ const ClientCapabilities = struct { var client_capabilities = ClientCapabilities{}; const initialize_response = - \\,"result":{"capabilities":{"signatureHelpProvider":{"triggerCharacters":["(",","]},"textDocumentSync":1,"completionProvider":{"resolveProvider":false,"triggerCharacters":[".",":","@"]},"documentHighlightProvider":false,"hoverProvider":true,"codeActionProvider":false,"declarationProvider":true,"definitionProvider":true,"typeDefinitionProvider":true,"implementationProvider":false,"referencesProvider":false,"documentSymbolProvider":true,"colorProvider":false,"documentFormattingProvider":false,"documentRangeFormattingProvider":false,"foldingRangeProvider":false,"selectionRangeProvider":false,"workspaceSymbolProvider":false,"workspace":{"workspaceFolders":{"supported":true,"changeNotifications":true}}}}} + \\,"result":{"capabilities":{"signatureHelpProvider":{"triggerCharacters":["(",","]},"textDocumentSync":1,"completionProvider":{"resolveProvider":false,"triggerCharacters":[".",":","@"]},"documentHighlightProvider":false,"hoverProvider":true,"codeActionProvider":false,"declarationProvider":true,"definitionProvider":true,"typeDefinitionProvider":true,"implementationProvider":false,"referencesProvider":false,"documentSymbolProvider":true,"colorProvider":false,"documentFormattingProvider":false,"documentRangeFormattingProvider":false,"foldingRangeProvider":false,"selectionRangeProvider":false,"workspaceSymbolProvider":false,"semanticTokensProvider":{"legend":{"tokenTypes":["type","struct","enum","parameter","variable","enumMember","function","member","keyword","modifier","comment","string","number","operator"],"tokenModifiers":["definition","async","documentation"]},"rangeProvider":false,"documentProvider":true},"workspace":{"workspaceFolders":{"supported":true,"changeNotifications":true}}}}} ; const not_implemented_response = @@ -744,6 +744,11 @@ fn processJsonRpc(parser: *std.json.Parser, json: []const u8, config: Config) !v document_store.closeDocument(uri); } + // Semantic highlighting + else if (std.mem.eql(u8, method, "textDocument/semanticTokens")) { + // @TODO Implement this (we dont get here from vscode atm even when we get the client capab.) + return try respondGeneric(id, empty_array_response); + } // Autocomplete / Signatures else if (std.mem.eql(u8, method, "textDocument/completion")) { const text_document = params.getValue("textDocument").?.Object;