Skip to main content
Glama
index.html32.4 kB
<!doctype html> <html lang="en" class="no-js"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1"> <link rel="prev" href="../contributing/"> <link rel="next" href="../troubleshooting/"> <link rel="icon" href="../assets/images/favicon.png"> <meta name="generator" content="mkdocs-1.6.1, mkdocs-material-9.6.21"> <title>Adding New Languages - CodeGraphContext</title> <link rel="stylesheet" href="../assets/stylesheets/main.2a3383ac.min.css"> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,700,700i%7CRoboto+Mono:400,400i,700,700i&display=fallback"> <style>:root{--md-text-font:"Roboto";--md-code-font:"Roboto Mono"}</style> <script>__md_scope=new URL("..",location),__md_hash=e=>[...e].reduce(((e,_)=>(e<<5)-e+_.charCodeAt(0)),0),__md_get=(e,_=localStorage,t=__md_scope)=>JSON.parse(_.getItem(t.pathname+"."+e)),__md_set=(e,_,t=localStorage,a=__md_scope)=>{try{t.setItem(a.pathname+"."+e,JSON.stringify(_))}catch(e){}}</script> </head> <body dir="ltr"> <input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off"> <input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off"> <label class="md-overlay" for="__drawer"></label> <div data-md-component="skip"> <a href="#contributing-new-language-support-to-codegraphcontext" class="md-skip"> Skip to content </a> </div> <div data-md-component="announce"> </div> <header class="md-header md-header--shadow" data-md-component="header"> <nav class="md-header__inner md-grid" aria-label="Header"> <a href=".." title="CodeGraphContext" class="md-header__button md-logo" aria-label="CodeGraphContext" data-md-component="logo"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54"/></svg> </a> <label class="md-header__button md-icon" for="__drawer"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3zm0 5h18v2H3zm0 5h18v2H3z"/></svg> </label> <div class="md-header__title" data-md-component="header-title"> <div class="md-header__ellipsis"> <div class="md-header__topic"> <span class="md-ellipsis"> CodeGraphContext </span> </div> <div class="md-header__topic" data-md-component="header-topic"> <span class="md-ellipsis"> Adding New Languages </span> </div> </div> </div> <script>var palette=__md_get("__palette");if(palette&&palette.color){if("(prefers-color-scheme)"===palette.color.media){var media=matchMedia("(prefers-color-scheme: light)"),input=document.querySelector(media.matches?"[data-md-color-media='(prefers-color-scheme: light)']":"[data-md-color-media='(prefers-color-scheme: dark)']");palette.color.media=input.getAttribute("data-md-color-media"),palette.color.scheme=input.getAttribute("data-md-color-scheme"),palette.color.primary=input.getAttribute("data-md-color-primary"),palette.color.accent=input.getAttribute("data-md-color-accent")}for(var[key,value]of Object.entries(palette.color))document.body.setAttribute("data-md-color-"+key,value)}</script> <label class="md-header__button md-icon" for="__search"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.52 6.52 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5"/></svg> </label> <div class="md-search" data-md-component="search" role="dialog"> <label class="md-search__overlay" for="__search"></label> <div class="md-search__inner" role="search"> <form class="md-search__form" name="search"> <input type="text" class="md-search__input" name="query" aria-label="Search" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="search-query" required> <label class="md-search__icon md-icon" for="__search"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.52 6.52 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5"/></svg> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11z"/></svg> </label> <nav class="md-search__options" aria-label="Search"> <button type="reset" class="md-search__icon md-icon" title="Clear" aria-label="Clear" tabindex="-1"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"/></svg> </button> </nav> </form> <div class="md-search__output"> <div class="md-search__scrollwrap" tabindex="0" data-md-scrollfix> <div class="md-search-result" data-md-component="search-result"> <div class="md-search-result__meta"> Initializing search </div> <ol class="md-search-result__list" role="presentation"></ol> </div> </div> </div> </div> </div> </nav> </header> <div class="md-container" data-md-component="container"> <main class="md-main" data-md-component="main"> <div class="md-main__inner md-grid"> <div class="md-sidebar md-sidebar--primary" data-md-component="sidebar" data-md-type="navigation" > <div class="md-sidebar__scrollwrap"> <div class="md-sidebar__inner"> <nav class="md-nav md-nav--primary" aria-label="Navigation" data-md-level="0"> <label class="md-nav__title" for="__drawer"> <a href=".." title="CodeGraphContext" class="md-nav__button md-logo" aria-label="CodeGraphContext" data-md-component="logo"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54"/></svg> </a> CodeGraphContext </label> <ul class="md-nav__list" data-md-scrollfix> <li class="md-nav__item"> <a href=".." class="md-nav__link"> <span class="md-ellipsis"> Home </span> </a> </li> <li class="md-nav__item"> <a href="../installation/" class="md-nav__link"> <span class="md-ellipsis"> Installation </span> </a> </li> <li class="md-nav__item"> <a href="../use_cases/" class="md-nav__link"> <span class="md-ellipsis"> Use Cases </span> </a> </li> <li class="md-nav__item"> <a href="../architecture/" class="md-nav__link"> <span class="md-ellipsis"> Architecture </span> </a> </li> <li class="md-nav__item"> <a href="../cli/" class="md-nav__link"> <span class="md-ellipsis"> CLI Reference </span> </a> </li> <li class="md-nav__item"> <a href="../server/" class="md-nav__link"> <span class="md-ellipsis"> Server </span> </a> </li> <li class="md-nav__item"> <a href="../core/" class="md-nav__link"> <span class="md-ellipsis"> Core Concepts </span> </a> </li> <li class="md-nav__item"> <a href="../tools/" class="md-nav__link"> <span class="md-ellipsis"> Tools </span> </a> </li> <li class="md-nav__item"> <a href="../cookbook/" class="md-nav__link"> <span class="md-ellipsis"> Cookbook </span> </a> </li> <li class="md-nav__item md-nav__item--active md-nav__item--nested"> <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_10" checked> <label class="md-nav__link" for="__nav_10" id="__nav_10_label" tabindex="0"> <span class="md-ellipsis"> Contributing </span> <span class="md-nav__icon md-icon"></span> </label> <nav class="md-nav" data-md-level="1" aria-labelledby="__nav_10_label" aria-expanded="true"> <label class="md-nav__title" for="__nav_10"> <span class="md-nav__icon md-icon"></span> Contributing </label> <ul class="md-nav__list" data-md-scrollfix> <li class="md-nav__item"> <a href="../contributing/" class="md-nav__link"> <span class="md-ellipsis"> Overview </span> </a> </li> <li class="md-nav__item md-nav__item--active"> <input class="md-nav__toggle md-toggle" type="checkbox" id="__toc"> <label class="md-nav__link md-nav__link--active" for="__toc"> <span class="md-ellipsis"> Adding New Languages </span> <span class="md-nav__icon md-icon"></span> </label> <a href="./" class="md-nav__link md-nav__link--active"> <span class="md-ellipsis"> Adding New Languages </span> </a> <nav class="md-nav md-nav--secondary" aria-label="Table of contents"> <label class="md-nav__title" for="__toc"> <span class="md-nav__icon md-icon"></span> Table of contents </label> <ul class="md-nav__list" data-md-component="toc" data-md-scrollfix> <li class="md-nav__item"> <a href="#1-understanding-the-architecture" class="md-nav__link"> <span class="md-ellipsis"> 1. Understanding the Architecture </span> </a> </li> <li class="md-nav__item"> <a href="#2-steps-to-add-a-new-language-eg-typescript-ts" class="md-nav__link"> <span class="md-ellipsis"> 2. Steps to Add a New Language (e.g., TypeScript - .ts) </span> </a> <nav class="md-nav" aria-label="2. Steps to Add a New Language (e.g., TypeScript - .ts)"> <ul class="md-nav__list"> <li class="md-nav__item"> <a href="#step-21-create-the-language-module-file" class="md-nav__link"> <span class="md-ellipsis"> Step 2.1: Create the Language Module File </span> </a> </li> <li class="md-nav__item"> <a href="#step-22-define-tree-sitter-queries-ts_queries" class="md-nav__link"> <span class="md-ellipsis"> Step 2.2: Define Tree-sitter Queries (TS_QUERIES) </span> </a> </li> <li class="md-nav__item"> <a href="#step-23-implement-langtreesitterparser-class" class="md-nav__link"> <span class="md-ellipsis"> Step 2.3: Implement &lt;Lang&gt;TreeSitterParser Class </span> </a> </li> <li class="md-nav__item"> <a href="#step-24-implement-pre_scan_lang-function" class="md-nav__link"> <span class="md-ellipsis"> Step 2.4: Implement pre_scan_&lt;lang&gt; Function </span> </a> </li> <li class="md-nav__item"> <a href="#step-25-integrate-into-graph_builderpy" class="md-nav__link"> <span class="md-ellipsis"> Step 2.5: Integrate into graph_builder.py </span> </a> </li> </ul> </nav> </li> <li class="md-nav__item"> <a href="#3-verification-and-debugging-using-neo4j" class="md-nav__link"> <span class="md-ellipsis"> 3. Verification and Debugging using Neo4j </span> </a> <nav class="md-nav" aria-label="3. Verification and Debugging using Neo4j"> <ul class="md-nav__list"> <li class="md-nav__item"> <a href="#step-31-prepare-a-sample-project" class="md-nav__link"> <span class="md-ellipsis"> Step 3.1: Prepare a Sample Project </span> </a> </li> <li class="md-nav__item"> <a href="#step-32-index-the-sample-project" class="md-nav__link"> <span class="md-ellipsis"> Step 3.2: Index the Sample Project </span> </a> </li> <li class="md-nav__item"> <a href="#step-33-query-the-neo4j-graph" class="md-nav__link"> <span class="md-ellipsis"> Step 3.3: Query the Neo4j Graph </span> </a> </li> <li class="md-nav__item"> <a href="#step-34-debugging-common-issues" class="md-nav__link"> <span class="md-ellipsis"> Step 3.4: Debugging Common Issues </span> </a> </li> </ul> </nav> </li> </ul> </nav> </li> </ul> </nav> </li> <li class="md-nav__item"> <a href="../troubleshooting/" class="md-nav__link"> <span class="md-ellipsis"> Troubleshooting </span> </a> </li> <li class="md-nav__item"> <a href="../future_work/" class="md-nav__link"> <span class="md-ellipsis"> Future Work </span> </a> </li> <li class="md-nav__item"> <a href="../license/" class="md-nav__link"> <span class="md-ellipsis"> License </span> </a> </li> </ul> </nav> </div> </div> </div> <div class="md-sidebar md-sidebar--secondary" data-md-component="sidebar" data-md-type="toc" > <div class="md-sidebar__scrollwrap"> <div class="md-sidebar__inner"> <nav class="md-nav md-nav--secondary" aria-label="Table of contents"> <label class="md-nav__title" for="__toc"> <span class="md-nav__icon md-icon"></span> Table of contents </label> <ul class="md-nav__list" data-md-component="toc" data-md-scrollfix> <li class="md-nav__item"> <a href="#1-understanding-the-architecture" class="md-nav__link"> <span class="md-ellipsis"> 1. Understanding the Architecture </span> </a> </li> <li class="md-nav__item"> <a href="#2-steps-to-add-a-new-language-eg-typescript-ts" class="md-nav__link"> <span class="md-ellipsis"> 2. Steps to Add a New Language (e.g., TypeScript - .ts) </span> </a> <nav class="md-nav" aria-label="2. Steps to Add a New Language (e.g., TypeScript - .ts)"> <ul class="md-nav__list"> <li class="md-nav__item"> <a href="#step-21-create-the-language-module-file" class="md-nav__link"> <span class="md-ellipsis"> Step 2.1: Create the Language Module File </span> </a> </li> <li class="md-nav__item"> <a href="#step-22-define-tree-sitter-queries-ts_queries" class="md-nav__link"> <span class="md-ellipsis"> Step 2.2: Define Tree-sitter Queries (TS_QUERIES) </span> </a> </li> <li class="md-nav__item"> <a href="#step-23-implement-langtreesitterparser-class" class="md-nav__link"> <span class="md-ellipsis"> Step 2.3: Implement &lt;Lang&gt;TreeSitterParser Class </span> </a> </li> <li class="md-nav__item"> <a href="#step-24-implement-pre_scan_lang-function" class="md-nav__link"> <span class="md-ellipsis"> Step 2.4: Implement pre_scan_&lt;lang&gt; Function </span> </a> </li> <li class="md-nav__item"> <a href="#step-25-integrate-into-graph_builderpy" class="md-nav__link"> <span class="md-ellipsis"> Step 2.5: Integrate into graph_builder.py </span> </a> </li> </ul> </nav> </li> <li class="md-nav__item"> <a href="#3-verification-and-debugging-using-neo4j" class="md-nav__link"> <span class="md-ellipsis"> 3. Verification and Debugging using Neo4j </span> </a> <nav class="md-nav" aria-label="3. Verification and Debugging using Neo4j"> <ul class="md-nav__list"> <li class="md-nav__item"> <a href="#step-31-prepare-a-sample-project" class="md-nav__link"> <span class="md-ellipsis"> Step 3.1: Prepare a Sample Project </span> </a> </li> <li class="md-nav__item"> <a href="#step-32-index-the-sample-project" class="md-nav__link"> <span class="md-ellipsis"> Step 3.2: Index the Sample Project </span> </a> </li> <li class="md-nav__item"> <a href="#step-33-query-the-neo4j-graph" class="md-nav__link"> <span class="md-ellipsis"> Step 3.3: Query the Neo4j Graph </span> </a> </li> <li class="md-nav__item"> <a href="#step-34-debugging-common-issues" class="md-nav__link"> <span class="md-ellipsis"> Step 3.4: Debugging Common Issues </span> </a> </li> </ul> </nav> </li> </ul> </nav> </div> </div> </div> <div class="md-content" data-md-component="content"> <article class="md-content__inner md-typeset"> <h1 id="contributing-new-language-support-to-codegraphcontext">Contributing New Language Support to CodeGraphContext</h1> <p>This document outlines the steps and best practices for adding support for a new programming language to CodeGraphContext. By following this guide, contributors can efficiently integrate new languages and leverage the Neo4j graph for verification.</p> <h2 id="1-understanding-the-architecture">1. Understanding the Architecture</h2> <p>CodeGraphContext uses a modular architecture for multi-language support:</p> <ul> <li><strong>Generic <code>TreeSitterParser</code> (in <code>graph_builder.py</code>):</strong> This acts as a wrapper, dispatching parsing tasks to language-specific implementations.</li> <li><strong>Language-Specific Parser Modules (in <code>src/codegraphcontext/tools/languages/</code>):</strong> Each language (e.g., Python, JavaScript) has its own module (e.g., <code>python.py</code>, <code>javascript.py</code>) containing:<ul> <li>Tree-sitter queries (<code>&lt;LANG&gt;_QUERIES</code>).</li> <li>A <code>&lt;Lang&gt;TreeSitterParser</code> class that encapsulates language-specific parsing logic.</li> <li>A <code>pre_scan_&lt;lang&gt;</code> function for initial symbol mapping.</li> </ul> </li> <li><strong><code>GraphBuilder</code> (in <code>graph_builder.py</code>):</strong> Manages the overall graph building process, including file discovery, pre-scanning, and dispatching to the correct language parser.</li> </ul> <h2 id="2-steps-to-add-a-new-language-eg-typescript-ts">2. Steps to Add a New Language (e.g., TypeScript - <code>.ts</code>)</h2> <h3 id="step-21-create-the-language-module-file">Step 2.1: Create the Language Module File</h3> <ol> <li>Create a new file: <code>src/codegraphcontext/tools/languages/typescript.py</code>.</li> <li>Add the necessary imports: <code>from pathlib import Path</code>, <code>from typing import Any, Dict, Optional, Tuple</code>, <code>import logging</code>, <code>import ast</code> (if needed for AST manipulation).</li> <li>Define <code>TS_QUERIES</code> (Tree-sitter queries for TypeScript).</li> <li>Create a <code>TypescriptTreeSitterParser</code> class.</li> <li>Create a <code>pre_scan_typescript</code> function.</li> </ol> <h3 id="step-22-define-tree-sitter-queries-ts_queries">Step 2.2: Define Tree-sitter Queries (<code>TS_QUERIES</code>)</h3> <p>This is the most critical and often iterative step. You'll need to define queries for:</p> <ul> <li><strong><code>functions</code></strong>: Function declarations, arrow functions, methods.</li> <li><strong><code>classes</code></strong>: Class declarations, class expressions.</li> <li><strong><code>imports</code></strong>: ES6 imports (<code>import ... from ...</code>), CommonJS <code>require()</code>.</li> <li><strong><code>calls</code></strong>: Function calls, method calls.</li> <li><strong><code>variables</code></strong>: Variable declarations (<code>let</code>, <code>const</code>, <code>var</code>).</li> <li><strong><code>docstrings</code></strong>: (Optional) How documentation comments are identified.</li> <li><strong><code>lambda_assignments</code></strong>: (Optional, Python-specific) If the language has similar constructs.</li> </ul> <p><strong>Tips for Query Writing:</strong> * <strong>Consult Tree-sitter Grammars:</strong> Find the <code>node-types.json</code> or grammar definition for your language (e.g., <code>tree-sitter-typescript</code>). * <strong>Use <code>tree-sitter parse</code>:</strong> Use the <code>tree-sitter parse</code> command-line tool to inspect the AST of sample code snippets. This is invaluable for identifying correct node types and field names. * <strong>Start Simple:</strong> Begin with basic queries and gradually add complexity. * <strong>Test Iteratively:</strong> After each query, test it with sample code.</p> <h3 id="step-23-implement-langtreesitterparser-class">Step 2.3: Implement <code>&lt;Lang&gt;TreeSitterParser</code> Class</h3> <p>This class (e.g., <code>TypescriptTreeSitterParser</code>) will encapsulate the language-specific logic.</p> <ol> <li><strong><code>__init__(self, generic_parser_wrapper)</code></strong>:<ul> <li>Store <code>generic_parser_wrapper</code>, <code>language_name</code>, <code>language</code>, <code>parser</code> from the generic wrapper.</li> <li>Load <code>TS_QUERIES</code> using <code>self.language.query(query_str)</code>.</li> </ul> </li> <li><strong>Helper Methods</strong>:<ul> <li><code>_get_node_text(self, node)</code>: Extracts text from a tree-sitter node.</li> <li><code>_get_parent_context(self, node, types=...)</code>: (Language-specific node types for context).</li> <li><code>_calculate_complexity(self, node)</code>: (Language-specific complexity nodes).</li> <li><code>_get_docstring(self, body_node)</code>: (Language-specific docstring extraction).</li> </ul> </li> <li><strong><code>parse(self, file_path: Path, is_dependency: bool = False) -&gt; Dict</code></strong>:<ul> <li>Reads the file, parses it with <code>self.parser</code>.</li> <li>Calls its own <code>_find_*</code> methods (<code>_find_functions</code>, <code>_find_classes</code>, etc.).</li> <li>Returns a standardized dictionary format (as seen in <code>python.py</code> and <code>javascript.py</code>).</li> </ul> </li> <li><strong><code>_find_*</code> Methods</strong>: Implement these for each query type, extracting data from the AST and populating the standardized dictionary.</li> </ol> <h3 id="step-24-implement-pre_scan_lang-function">Step 2.4: Implement <code>pre_scan_&lt;lang&gt;</code> Function</h3> <p>This function (e.g., <code>pre_scan_typescript</code>) will quickly scan files to build an initial <code>imports_map</code>.</p> <ol> <li>It takes <code>files: list[Path]</code> and <code>parser_wrapper</code> (an instance of <code>TreeSitterParser</code>).</li> <li>Uses a simplified query (e.g., for <code>class_declaration</code> and <code>function_declaration</code>) to quickly find definitions.</li> <li>Returns a dictionary mapping symbol names to file paths.</li> </ol> <h3 id="step-25-integrate-into-graph_builderpy">Step 2.5: Integrate into <code>graph_builder.py</code></h3> <ol> <li><strong><code>GraphBuilder.__init__</code></strong>:<ul> <li>Add <code>'.ts': TreeSitterParser('typescript')</code> to <code>self.parsers</code>.</li> </ul> </li> <li><strong><code>TreeSitterParser.__init__</code></strong>:<ul> <li>Add an <code>elif self.language_name == 'typescript':</code> block to initialize <code>self.language_specific_parser</code> with <code>TypescriptTreeSitterParser(self)</code>.</li> </ul> </li> <li><strong><code>GraphBuilder._pre_scan_for_imports</code></strong>:<ul> <li>Add an <code>elif '.ts' in files_by_lang:</code> block to import <code>pre_scan_typescript</code> and call it.</li> </ul> </li> </ol> <h2 id="3-verification-and-debugging-using-neo4j">3. Verification and Debugging using Neo4j</h2> <p>After implementing support for a new language, it's crucial to verify that the graph is being built correctly.</p> <h3 id="step-31-prepare-a-sample-project">Step 3.1: Prepare a Sample Project</h3> <p>Create a small sample project for your new language (e.g., <code>tests/sample_project_typescript/</code>) with: * Function declarations. * Class declarations (including inheritance). * Various import types (if applicable). * Function calls. * Variable declarations.</p> <h3 id="step-32-index-the-sample-project">Step 3.2: Index the Sample Project</h3> <ol> <li><strong>Delete existing data (if any):</strong> ```bash # Replace with your sample project path <tool_code>print(default_api.delete_repository(repo_path='/path/to/your/sample_project'))</tool_code></li> <li><strong>Index the project:</strong> ```bash # Replace with your sample project path <tool_code>print(default_api.add_code_to_graph(path='/path/to/your/sample_project'))</tool_code></li> <li><strong>Monitor job status:</strong> ```bash # Use the job_id returned by add_code_to_graph <tool_code>print(default_api.check_job_status(job_id='<your_job_id>'))</tool_code></li> </ol> <h3 id="step-33-query-the-neo4j-graph">Step 3.3: Query the Neo4j Graph</h3> <p>Use Cypher queries to inspect the generated graph.</p> <ul> <li> <p><strong>Check for Files and Language Tags:</strong> <code>cypher MATCH (f:File) WHERE f.path STARTS WITH '/path/to/your/sample_project' RETURN f.name, f.path, f.lang</code> <em>Expected:</em> All files from your sample project should be listed with the correct <code>lang</code> tag.</p> </li> <li> <p><strong>Check for Functions:</strong> <code>cypher MATCH (f:File)-[:CONTAINS]-&gt;(fn:Function) WHERE f.path STARTS WITH '/path/to/your/sample_project' AND fn.lang = '&lt;your_language_name&gt;' RETURN f.name AS FileName, fn.name AS FunctionName, fn.line_number AS Line</code> <em>Expected:</em> All functions from your sample project should be listed.</p> </li> <li> <p><strong>Check for Classes:</strong> <code>cypher MATCH (f:File)-[:CONTAINS]-&gt;(c:Class) WHERE f.path STARTS WITH '/path/to/your/sample_project' AND c.lang = '&lt;your_language_name&gt;' RETURN f.name AS FileName, c.name AS ClassName, c.line_number AS Line</code> <em>Expected:</em> All classes from your sample project should be listed.</p> </li> <li> <p><strong>Check for Imports (Module-level):</strong> <code>cypher MATCH (f:File)-[:IMPORTS]-&gt;(m:Module) WHERE f.path STARTS WITH '/path/to/your/sample_project' AND f.lang = '&lt;your_language_name&gt;' RETURN f.name AS FileName, m.name AS ImportedModule, m.full_import_name AS FullImportName</code> <em>Expected:</em> All module-level imports should be listed.</p> </li> <li> <p><strong>Check for Function Calls:</strong> <code>cypher MATCH (caller:Function)-[:CALLS]-&gt;(callee:Function) WHERE caller.file_path STARTS WITH '/path/to/your/sample_project' AND caller.lang = '&lt;your_language_name&gt;' RETURN caller.name AS Caller, callee.name AS Callee, caller.file_path AS CallerFile, callee.file_path AS CalleeFile</code> <em>Expected:</em> All function calls should be correctly linked.</p> </li> <li> <p><strong>Check for Class Inheritance:</strong> <code>cypher MATCH (child:Class)-[:INHERITS]-&gt;(parent:Class) WHERE child.file_path STARTS WITH '/path/to/your/sample_project' AND child.lang = '&lt;your_language_name&gt;' RETURN child.name AS ChildClass, parent.name AS ParentClass, child.file_path AS ChildFile, parent.file_path AS ParentFile</code> <em>Expected:</em> All inheritance relationships should be correctly linked.</p> </li> </ul> <h3 id="step-34-debugging-common-issues">Step 3.4: Debugging Common Issues</h3> <ul> <li><strong><code>NameError: Invalid node type ...</code></strong>: Your tree-sitter query is using a node type that doesn't exist in the language's grammar. Use <code>tree-sitter parse</code> to inspect the AST.</li> <li><strong>Missing Relationships (e.g., <code>CALLS</code>, <code>IMPORTS</code>)</strong>:<ul> <li><strong>Check <code>_find_*</code> methods</strong>: Ensure your <code>_find_*</code> methods are correctly extracting the necessary data.</li> <li><strong>Check <code>imports_map</code></strong>: Verify that the <code>pre_scan_&lt;lang&gt;</code> function is correctly populating the <code>imports_map</code>.</li> <li><strong>Check <code>local_imports</code> map</strong>: Ensure the <code>local_imports</code> map (built in <code>_create_function_calls</code> and <code>_create_inheritance_links</code>) is correctly resolving symbols.</li> </ul> </li> <li><strong>Incorrect <code>lang</code> tags</strong>: Ensure <code>self.language_name</code> is correctly passed and stored.</li> </ul> <p>By following these steps, contributors can effectively add and verify new language support.</p> </article> </div> <script>var target=document.getElementById(location.hash.slice(1));target&&target.name&&(target.checked=target.name.startsWith("__tabbed_"))</script> </div> </main> <footer class="md-footer"> <div class="md-footer-meta md-typeset"> <div class="md-footer-meta__inner md-grid"> <div class="md-copyright"> Made with <a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener"> Material for MkDocs </a> </div> </div> </div> </footer> </div> <div class="md-dialog" data-md-component="dialog"> <div class="md-dialog__inner md-typeset"></div> </div> <script id="__config" type="application/json">{"base": "..", "features": [], "search": "../assets/javascripts/workers/search.973d3a69.min.js", "tags": null, "translations": {"clipboard.copied": "Copied to clipboard", "clipboard.copy": "Copy to clipboard", "search.result.more.one": "1 more on this page", "search.result.more.other": "# more on this page", "search.result.none": "No matching documents", "search.result.one": "1 matching document", "search.result.other": "# matching documents", "search.result.placeholder": "Type to start searching", "search.result.term.missing": "Missing", "select.version": "Select version"}, "version": null}</script> <script src="../assets/javascripts/bundle.f55a23d4.min.js"></script> </body> </html>

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Shashankss1205/CodeGraphContext'

If you have feedback or need assistance with the MCP directory API, please join our Discord server