Skip to content

[LS][TypeScript] replace_symbol_body still corrupts top-level exported const declarations by duplicating export const #1956

Description

@tonyzhu

[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:

export const

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:

OK

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions