Skip to content

[feature request] apply quickfix to current file OR a range of text (more general) #7760

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
0x8f701 opened this issue Feb 23, 2021 · 17 comments
Labels
A-diagnostics diagnostics / error reporting C-feature Category: feature request

Comments

@0x8f701
Copy link

0x8f701 commented Feb 23, 2021

sometimes we have many warnings and we would like to apply quick fix, currently it seems that we can only do this one by one. Is it possible to apply quick fix to a range?

image

like the above, it's not effecient at all to apply quick fix one by one

@lnicola
Copy link
Member

lnicola commented Feb 23, 2021

I'd rather we had an "organize imports" action than blindly apply every available quick fix.

@RobertoSnap
Copy link

Looking for the same!

@Veykril
Copy link
Member

Veykril commented Jan 22, 2022

And organize imports assist would sound a lot better. It's rare to want to apply a bunch of quickfixes at once while it also might introduce some bugs due to overlapping text edits resulting from them.

Hence closing as an indirect dupe of #5131

@Veykril Veykril closed this as completed Jan 22, 2022
@jsimmons
Copy link

I don't think this use-case is necessarily rare. Especially for changes like "convert to snake case", it's often useful to be able to bulk apply when you copy paste something from an external source.

@Veykril
Copy link
Member

Veykril commented Jan 28, 2022

Why would that external source use the wrong naming convention?

@jsimmons
Copy link

Why would that external source use the wrong naming convention?

Because it's often not Rust.

@lnicola
Copy link
Member

lnicola commented Jan 28, 2022

Why would that external source use the wrong naming convention?

I just ran into this with a database that uses snake_case and C# code reading from it into camelCase variables 😄.

@Veykril Veykril added the A-diagnostics diagnostics / error reporting label Jan 28, 2022
@Veykril
Copy link
Member

Veykril commented Jan 28, 2022

Because it's often not Rust.

Then I am confused as to how you would even get these kinds of diagnostics if its not rust code.
I'm not trying to come across as hostile towards this idea, I just don't really see a valid reason for as to why this feature would be valuable, hence me asking these question(except for the import fixing which itself should be just an assist in that special case).

@jsimmons
Copy link

jsimmons commented Jan 28, 2022

Then I am confused as to how you would even get these kinds of diagnostics if its not rust code. I'm not trying to come across as hostile towards this idea, I just don't really see a valid reason for as to why this feature would be valuable, hence me asking these question(except for the import fixing which itself should be just an assist in that special case).

Well there's lots of things that you might want to interact with that are defined elsewhere. Often that just means copy pasting some structure / enum / etc from a C header or somewhere else. Then you have a whole bunch of things which don't match rust formatting style, and infinity little "quick fix" buttons to press if you decide to go that route.

For example, you might have something like the following.

typedef struct VkPhysicalDeviceFeatures {
    VkBool32    robustBufferAccess;
    VkBool32    fullDrawIndexUint32;
    VkBool32    imageCubeArray;
    VkBool32    independentBlend;
    VkBool32    geometryShader;
    VkBool32    tessellationShader;
    VkBool32    sampleRateShading;
    VkBool32    dualSrcBlend;
    VkBool32    logicOp;
    VkBool32    multiDrawIndirect;
    VkBool32    drawIndirectFirstInstance;
    VkBool32    depthClamp;
    VkBool32    depthBiasClamp;
    VkBool32    fillModeNonSolid;
    VkBool32    depthBounds;
    VkBool32    wideLines;
    VkBool32    largePoints;
    VkBool32    alphaToOne;
    VkBool32    multiViewport;
    VkBool32    samplerAnisotropy;
    VkBool32    textureCompressionETC2;
    VkBool32    textureCompressionASTC_LDR;
    VkBool32    textureCompressionBC;
    VkBool32    occlusionQueryPrecise;
    VkBool32    pipelineStatisticsQuery;
    VkBool32    vertexPipelineStoresAndAtomics;
    VkBool32    fragmentStoresAndAtomics;
    VkBool32    shaderTessellationAndGeometryPointSize;
    VkBool32    shaderImageGatherExtended;
    VkBool32    shaderStorageImageExtendedFormats;
    VkBool32    shaderStorageImageMultisample;
    VkBool32    shaderStorageImageReadWithoutFormat;
    VkBool32    shaderStorageImageWriteWithoutFormat;
    VkBool32    shaderUniformBufferArrayDynamicIndexing;
    VkBool32    shaderSampledImageArrayDynamicIndexing;
    VkBool32    shaderStorageBufferArrayDynamicIndexing;
    VkBool32    shaderStorageImageArrayDynamicIndexing;
    VkBool32    shaderClipDistance;
    VkBool32    shaderCullDistance;
    VkBool32    shaderFloat64;
    VkBool32    shaderInt64;
    VkBool32    shaderInt16;
    VkBool32    shaderResourceResidency;
    VkBool32    shaderResourceMinLod;
    VkBool32    sparseBinding;
    VkBool32    sparseResidencyBuffer;
    VkBool32    sparseResidencyImage2D;
    VkBool32    sparseResidencyImage3D;
    VkBool32    sparseResidency2Samples;
    VkBool32    sparseResidency4Samples;
    VkBool32    sparseResidency8Samples;
    VkBool32    sparseResidency16Samples;
    VkBool32    sparseResidencyAliased;
    VkBool32    variableMultisampleRate;
    VkBool32    inheritedQueries;
} VkPhysicalDeviceFeatures;

It's not a huge issue of course, but it does annoy me personally, I found this bug looking to see if there was a way to bulk apply suggestions.

@Veykril
Copy link
Member

Veykril commented Jan 29, 2022

Hm, I mean in this case, bulk changing the case of something I personally would use my IDE's tooling for that(VSCode allows me to just that), but that is obviously client specific.
I'll reopen this for now, but I personally am a bit skeptic to the usefulness of this overall.

@Veykril Veykril reopened this Jan 29, 2022
@jsimmons
Copy link

Hm, I mean in this case, bulk changing the case of something I personally would use my IDE's tooling for that(VSCode allows me to just that), but that is obviously client specific. I'll reopen this for now, but I personally am a bit skeptic to the usefulness of this overall.

I was using vscode, so I'm not really sure what you mean? You can't select a whole range and apply fixes. At least, unless I'm missing something? But you're right that it might be better handled by the editor rather than rust-analyzer itself.

@Veykril
Copy link
Member

Veykril commented Jan 29, 2022

I meant putting a cursor on every identifier in your case, then doing the VSCode action for changing the identifier casing
Code_d70rDMQJBu

@jsimmons
Copy link

Ah I had no idea that was a built-in feature. That's a lot easier than what I was doing! :)

@flodiebold
Copy link
Member

The Dart analysis server usually has an "apply this fix to every instance in this file" action for most quickfixes, IIRC. We could do something similar.

@starwolfy
Copy link

Can confirm that this would have saved me a lot of time worth of work. Especially when I am re-organizing the usage of creates in my project and I have to re-import all the content of the crates with new use statements. However over the problem, apply the suggestion, next. Sometimes many hundreds of times.

@nielsle
Copy link

nielsle commented Sep 14, 2022

It looks like the original poster wanted to remove unused imports. You can use 'cargo machete' for this

https://github.com/bnjbvr/cargo-machete

@Veykril Veykril added the C-feature Category: feature request label Feb 13, 2023
@PoignardAzur
Copy link
Contributor

PoignardAzur commented Feb 17, 2025

I have a similar use case in my codebase: by using sed-like refactoring tools I ended up with a bunch of crate::Foobar::method() paths in my code, which I'd like to replace with top-level use crate::Foobar imports.

A tool that would let me apply a given assist throughout a project would be super useful to me.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-diagnostics diagnostics / error reporting C-feature Category: feature request
Projects
None yet
Development

No branches or pull requests

9 participants