al-codeactions icon indicating copy to clipboard operation
al-codeactions copied to clipboard

Extract procedure for duplicate code (request)

Open PeterBizz opened this issue 2 years ago • 3 comments

Often the extract procedure function is used to eliminate duplicate code.

What about the following ideas:

  • Extract procedure automatically matches the generated procedure with an existing procedure and suggests to use this already existing procedure. or ( I think this might be harder to realise) when the procedure NewProcedure is renamed to the name of the same procedure with the same signature the NewProcedure is not created ( duplicate )

  • allow multiple cursor feature to select multiple occurences of the same lines that can be extracted to one NewProcedure which is called multiple times.

PeterBizz avatar Jan 23 '23 11:01 PeterBizz

Hi Peter, I understand the requirements, but have to see what I can do for you. Currently I rarely find time to develop, so no promises, but I'll have it in mind next time I look into it.

DavidFeldhoff avatar Jan 27 '23 15:01 DavidFeldhoff

What would be if after the first extraction a pop up would show up telling you that there are more occurences of exactly the same code and asks you if they should be replaced as well (Yes/No)? If no code could be found that is exactly the same, then of course the pop pu wouldn't show up.

DavidFeldhoff avatar Feb 25 '23 17:02 DavidFeldhoff

May be the other way around? If the extracted procedure would duplicate an existing procedure you could pop up a question if the existing procedure needs to be re-used? (so option 1) . This seems to be less work for you.

Otherwise your suggestion is ok

PeterBizz avatar Feb 27 '23 07:02 PeterBizz