claude-code-emacs-mcp-server
Version:
MCP server for Claude Code Emacs integration
65 lines • 2.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleGetDefinition = handleGetDefinition;
async function handleGetDefinition(bridge, args) {
if (!bridge.isConnected()) {
return {
content: [{
type: 'text',
text: 'Error: Emacs is not connected'
}],
definitions: [],
isError: true
};
}
try {
const result = await bridge.request('getDefinition', args);
if (!result.definitions || result.definitions.length === 0) {
return {
content: [{
type: 'text',
text: `No definition found for ${args.symbol}`
}],
definitions: []
};
}
// Format the response
const definitionCount = result.definitions.length;
const plural = definitionCount > 1 ? 's' : '';
let output = `Found ${definitionCount} definition${plural} using ${result.method}:\n\n`;
result.definitions.forEach((def, index) => {
output += `## Definition ${index + 1}\n`;
output += `**File**: ${def.file}\n`;
output += `**Location**: Line ${def.range.start.line + 1}, Column ${def.range.start.character + 1}\n`;
if (def.preview) {
output += '\n```\n' + def.preview + '\n```\n';
}
output += '\n';
});
// Transform definitions to match schema structure
const structuredDefinitions = result.definitions.map(def => ({
file: def.file,
line: def.range.start.line + 1, // Convert to 1-based
column: def.range.start.character + 1, // Convert to 1-based
preview: def.preview
}));
return {
content: [{
type: 'text',
text: output.trim()
}],
definitions: structuredDefinitions
};
}
catch (error) {
return {
content: [{
type: 'text',
text: `Error getting definition: ${error instanceof Error ? error.message : 'Unknown error'}`
}],
definitions: [],
isError: true
};
}
}
//# sourceMappingURL=definition-tools.js.map