vscode-cpptools
vscode-cpptools copied to clipboard
Add support for the Extract Variable refactoring
I've filed a VS request at https://developercommunity.visualstudio.com/t/C:-Add-Extract-Variable-refactoring/10357919
"Extract to constant (field)" or "Extract to constexpr (field)" might be possibilities in the future too (not sure if those would need to be tracked separately though).
Our previous issue is at https://github.com/microsoft/vscode-cpptools/issues/1162, but that got changed to track only Extract Function/Method.
Related on Stack Overflow (I'll update the answer post with progress updates): VS Code "Extract Method" and "Extract Variable" not in context menu for C++.
Is this feature still an ongoing effort?
Is this fixed?
@yhyu13 @ashishpawar517 It is not fixed and there is not currently being worked on. The extract variable feature can be done by using GitHub Copilot, but since it's driven by AI, the results might be inconsistent and your prompt has to be specific on the details of how you want it extracted.
****
Instead of using Copilot, I wanted to have a similar refactoring option that we have as an extract function.
Could you guide me towards relevant code files? I can work on this.
@ashishpawar517 It would require modifications to our closed source cpptools/cpptools-srv process.
Is there any other workaround then? Maybe changing language server or similar?
@ashishpawar517 There is no other workaround. Changing the language server would be implementing the feature. You could potentially install another extension that implements the feature (I don't know of one).
Well, it might be possible to implement it in the open source TypeScript via making a call to the existing Extract to Function call and then applying post-processing to turn the function into a variable, however, I don't know how reliable that approach would be or if it would require more complicated C++ parsing than what is available in the Typescript part.