Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/extraction/grammars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const WASM_GRAMMAR_FILES: Record<GrammarLanguage, string> = {
r: 'tree-sitter-r.wasm',
luau: 'tree-sitter-luau.wasm',
objc: 'tree-sitter-objc.wasm',
odin: 'tree-sitter-odin.wasm',
};

/**
Expand Down Expand Up @@ -115,6 +116,7 @@ export const EXTENSION_MAP: Record<string, Language> = {
// shape as the `.yml` variants — the YAML/properties extractor emits one node
// per leaf key, and the Spring resolver links `@Value("${k}")` references.
'.properties': 'properties',
'.odin': 'odin',
};

/**
Expand Down Expand Up @@ -221,7 +223,7 @@ export async function loadGrammarsForLanguages(languages: Language[]): Promise<v
// `class Foo(...)` as an ERROR that swallows the whole class (#237); we
// vendor the upstream ABI-15 tree-sitter-c-sharp 0.23.5 wasm, which parses
// primary constructors natively.
const wasmPath = (lang === 'pascal' || lang === 'scala' || lang === 'lua' || lang === 'luau' || lang === 'csharp' || lang === 'r')
const wasmPath = (lang === 'pascal' || lang === 'scala' || lang === 'lua' || lang === 'luau' || lang === 'csharp' || lang === 'r' || lang === 'odin')
? path.join(__dirname, 'wasm', wasmFile)
: require.resolve(`tree-sitter-wasms/out/${wasmFile}`);
const language = await WasmLanguage.load(wasmPath);
Expand Down Expand Up @@ -436,6 +438,7 @@ export function getLanguageDisplayName(language: Language): string {
twig: 'Twig',
xml: 'XML',
properties: 'Java properties',
odin: 'Odin',
unknown: 'Unknown',
};
return names[language] || language;
Expand Down
2 changes: 2 additions & 0 deletions src/extraction/languages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { luaExtractor } from './lua';
import { rExtractor } from './r';
import { luauExtractor } from './luau';
import { objcExtractor } from './objc';
import { odinExtractor } from './odin';

export const EXTRACTORS: Partial<Record<Language, LanguageExtractor>> = {
typescript: typescriptExtractor,
Expand All @@ -51,4 +52,5 @@ export const EXTRACTORS: Partial<Record<Language, LanguageExtractor>> = {
r: rExtractor,
luau: luauExtractor,
objc: objcExtractor,
odin: odinExtractor,
};
77 changes: 77 additions & 0 deletions src/extraction/languages/odin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import type { Node as SyntaxNode } from 'web-tree-sitter';
import type { LanguageExtractor } from '../tree-sitter-types';

export const odinExtractor: LanguageExtractor = {
functionTypes: ['procedure_declaration', 'overloaded_procedure_declaration'],
classTypes: [], // Odin has no classes
methodTypes: [], // Procedures are not attached to classes/objects
interfaceTypes: [], // Odin has no interfaces/traits
structTypes: ['struct_declaration', 'union_declaration', 'bit_field_declaration'],
enumTypes: ['enum_declaration'],
enumMemberTypes: ['identifier'], // Enum values are identifiers
typeAliasTypes: [],
importTypes: ['import_declaration'],
callTypes: ['call_expression', 'selector_call_expression'],
variableTypes: ['variable_declaration', 'var_declaration', 'const_declaration', 'const_type_declaration'],
fieldTypes: ['field'], // Struct fields

nameField: 'name',
bodyField: 'body',
paramsField: 'parameters',

resolveName: (node: SyntaxNode, source: string) => {
// In Odin, declarations are structured as: name :: definition or name : type := definition
// The LHS name (an identifier or expression) is the first named child.
const first = node.firstNamedChild;
if (first) {
return source.substring(first.startIndex, first.endIndex).trim();
}
return undefined;
},

resolveBody: (node: SyntaxNode, _bodyField: string) => {
if (node.type === 'procedure_declaration') {
const procNode = node.namedChildren.find(c => c.type === 'procedure');
if (procNode) {
const block = procNode.namedChildren.find(c => c.type === 'block');
if (block) return block;
}
} else if (
node.type === 'struct_declaration' ||
node.type === 'union_declaration' ||
node.type === 'bit_field_declaration' ||
node.type === 'enum_declaration'
) {
// The struct/enum fields are direct children of the declaration node.
// Returning the node itself allows the core extractor to visit its children.
return node;
}
return null;
},

getSignature: (node: SyntaxNode, source: string) => {
const procNode = node.namedChildren.find(c => c.type === 'procedure' || c.type === 'overloaded_procedure');
if (procNode) {
return source.substring(procNode.startIndex, procNode.endIndex).trim();
}
return undefined;
},

extractImport: (node: SyntaxNode, source: string) => {
const pathNode = node.childForFieldName('path');
if (!pathNode) return null;

let modulePath = source.substring(pathNode.startIndex, pathNode.endIndex).trim();
// Strip string quotes
if ((modulePath.startsWith('"') && modulePath.endsWith('"')) ||
(modulePath.startsWith('`') && modulePath.endsWith('`'))) {
modulePath = modulePath.slice(1, -1);
}

const signature = source.substring(node.startIndex, node.endIndex).trim();
return {
moduleName: modulePath,
signature: signature,
};
},
};
3 changes: 2 additions & 1 deletion src/extraction/tree-sitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1682,7 +1682,8 @@ export class TreeSitterExtractor {
// Skip forward declarations and type references (no body = not a definition)
// — EXCEPT C# positional records (`record struct M(decimal Amount);`),
// complete definitions with no body block. (#831)
const body = getChildByField(node, this.extractor.bodyField);
const body = this.extractor.resolveBody?.(node, this.extractor.bodyField)
?? getChildByField(node, this.extractor.bodyField);
if (!body && node.type !== 'record_declaration') return;

const name = extractName(node, this.source, this.extractor);
Expand Down
Binary file added src/extraction/wasm/tree-sitter-odin.wasm
Binary file not shown.
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export const LANGUAGES = [
'twig',
'xml',
'properties',
'odin',
'unknown',
] as const;

Expand Down