Skip to content

C++ Parser misidentifies functions with std::string parameters as string method #690

@wuhonghui

Description

@wuhonghui

Bug: CodeGraph C++ Parser misidentifies functions with std::string parameters as string method

Summary

CodeGraph's C++ tree-sitter parser incorrectly identifies the function name as string (kind=method) when processing function declarations that contain std::string parameters or return values. This causes functions using std::string to become completely "disconnected" in CodeGraph — unable to search by function name, view callers/callees, or perform impact analysis.

version: 0.9.7

Severity

High

Minimal Reproduction Steps

Step 1: Prepare test code

Create a C++ function containing std::string parameters:

// test_parser.cpp
#include <string>

// CASE 1: Using std::string parameter (will be misparsed)
int deal_command(std::string interfaceName, int flag)
{
    return 0;
}

// CASE 2: Using string parameter without std:: prefix (parsed correctly)
int create_oss_version_node(string& local_ip, string& port)
{
    return 0;
}

// CASE 3: No string parameter (parsed correctly)
int connect_zookeeper()
{
    return 0;
}

Step 2: Let CodeGraph index the file

# Ensure the codegraph daemon is running and index the project
codegraph index 

Step 3: Query the index results

sqlite3 .codegraph/codegraph.db \
  "SELECT name, kind, qualified_name, start_line FROM nodes WHERE file_path='test_parser.cpp' AND kind IN ('function','method') ORDER BY start_line"

Expected Result

deal_command|function|deal_command|4
create_oss_version_node|function|create_oss_version_node|10
connect_zookeeper|function|connect_zookeeper|16

Actual Result

string|method|std::string|5    ← wrong! should be deal_command
create_oss_version_node|function|create_oss_version_node|11
connect_zookeeper|function|connect_zookeeper|17

Step 4: Verify that search/callers/impact are all unavailable

# Searching for deal_command returns no results
> codegraph query deal_command    # → no output

# Searching for string returns大量irrelevant results
> codegraph query string  
Search Results for "string":

method      string (7500%)
  test_parser.cpp:5

import      string (6600%)
  test_parser.cpp:2
  #include <string>

function    connect_zookeeper (-500%)
  test_parser.cpp:17

function    create_oss_version_node (-500%)
  test_parser.cpp:11

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions