[LS][TypeScript] replace_symbol_body still corrupts top-level exported const declarations by duplicating export const
Summary
replace_symbol_body can still corrupt a simple top-level exported TypeScript const declaration by duplicating the declaration prefix.
The tool returns OK, but the resulting source is syntactically invalid.
This appears related to #1029 / #1030, but the reproducer here is a simple top-level exported const, not a nested TSX symbol.
Minimal reproduction
Create a TypeScript file:
export const twice = (n: number): number => n * 2;
Call find_symbol for twice with include_body=true.
The returned symbol body is:
twice = (n: number): number => n * 2
Notably, the returned body/range does not include:
Then call replace_symbol_body for twice with the full replacement definition, following the documented body contract:
export const twice = (n: number): number => n * 3;
The tool returns:
But the resulting file becomes:
export const export const twice = (n: number): number => n * 3;;
TypeScript diagnostics then report a syntax error such as:
'export' is not allowed as a variable declaration name.
Additional observation
If the replacement body is instead shaped exactly like the body returned by find_symbol:
twice = (n: number): number => n * 4
the resulting source is valid:
export const twice = (n: number): number => n * 4;
This suggests that the language-server symbol range begins at the identifier rather than at the declaration prefix, while replace_symbol_body accepts/recommends a complete symbol definition.
Expected behavior
Given:
export const twice = (n: number): number => n * 2;
and replacement:
export const twice = (n: number): number => n * 3;
the result should be:
export const twice = (n: number): number => n * 3;
At minimum, replace_symbol_body should not return OK after producing syntactically invalid source.
Relation to previous issues
This looks closely related to:
The notable difference is that this reproduces on a simple top-level TypeScript export const declaration after the earlier TypeScript fix.
Environment
Serena is being used through its MCP find_symbol and replace_symbol_body tools with the TypeScript language server.
I can provide the exact Serena version and language-server version if needed.
[LS][TypeScript] replace_symbol_body still corrupts top-level exported const declarations by duplicating
export constSummary
replace_symbol_bodycan still corrupt a simple top-level exported TypeScriptconstdeclaration by duplicating the declaration prefix.The tool returns
OK, but the resulting source is syntactically invalid.This appears related to #1029 / #1030, but the reproducer here is a simple top-level exported
const, not a nested TSX symbol.Minimal reproduction
Create a TypeScript file:
Call
find_symbolfortwicewithinclude_body=true.The returned symbol body is:
Notably, the returned body/range does not include:
Then call
replace_symbol_bodyfortwicewith the full replacement definition, following the documentedbodycontract:The tool returns:
But the resulting file becomes:
TypeScript diagnostics then report a syntax error such as:
Additional observation
If the replacement body is instead shaped exactly like the body returned by
find_symbol:the resulting source is valid:
This suggests that the language-server symbol range begins at the identifier rather than at the declaration prefix, while
replace_symbol_bodyaccepts/recommends a complete symbol definition.Expected behavior
Given:
and replacement:
the result should be:
At minimum,
replace_symbol_bodyshould not returnOKafter producing syntactically invalid source.Relation to previous issues
This looks closely related to:
replace_symbol_bodycorruption caused by symbol replacement boundariestype/var/constThe notable difference is that this reproduces on a simple top-level TypeScript
export constdeclaration after the earlier TypeScript fix.Environment
Serena is being used through its MCP
find_symbolandreplace_symbol_bodytools with the TypeScript language server.I can provide the exact Serena version and language-server version if needed.