Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Smart Rename: Provide additional context for renamed symbol #73873

Merged
merged 55 commits into from
Jul 17, 2024

Conversation

AmadeusW
Copy link
Contributor

@AmadeusW AmadeusW commented Jun 6, 2024

Provide references, definitions and documentation of renamed symbol in Smart Rename. The purpose is to improve quality of suggestions, and ultimately remove the need to provide the entire document.

The feature is gated behind a feature flag, visible to MSFT internal users:
image

When feature flag is set, additional data is collected and attached to the prompt, for example:

Your task is to help a software developer improve the identifier name indicated by [NameThisIdentifier]. The existing identifier name is ShowMarkdownPreviewKey
Use the following information as context:

[BEGIN-DEFINITION]
        internal static readonly EditorOptionKey<bool> ShowMarkdownPreviewKey = new EditorOptionKey<bool>(ShowMarkdownPreviewOptionId);

[END-DEFINITION]

[BEGIN-REFERENCE]
        internal static bool GetDefaultShowMarkdownPreview(this ITextView textView)
        {
            return textView.Options.GlobalOptions.GetOptionValue(MarkdownOptions.ShowMarkdownPreviewKey);
        }

[END-REFERENCE]

[BEGIN-REFERENCE]
        internal static void SetPerViewShowMarkdownPreview(this ITextView textView, bool showPreview)
        {
            textView.Options.SetOptionValue(MarkdownOptions.ShowMarkdownPreviewKey, showPreview);
        }

[END-REFERENCE]

[BEGIN-REFERENCE]
        internal static bool GetPerViewShowMarkdownPreview(this ITextView textView)
        {
            return textView.Options.GetOptionValue(MarkdownOptions.ShowMarkdownPreviewKey);
        }

[END-REFERENCE]

[BEGIN-REFERENCE]
        internal static void SetDefaultShowMarkdownPreview(this ITextView textView, bool showPreview)
        {
            textView.Options.GlobalOptions.SetOptionValue(MarkdownOptions.ShowMarkdownPreviewKey, showPreview);
        }

[END-REFERENCE]

[BEGIN-REFERENCE]
            public override EditorOptionKey<bool> Key => ShowMarkdownPreviewKey;

[END-REFERENCE]

[BEGIN-DOCUMENTATION]
<member name="F:Microsoft.VisualStudio.Markdown.MarkdownOptions.ShowMarkdownPreviewKey">
    <summary>
    Whether Markdown preview should be visible.
    When set in <see cref="P:Microsoft.VisualStudio.Text.Editor.IEditorOptions.GlobalOptions" />, influences default behavior for newly opened views.
    A specific view may override this value in its <see cref="P:Microsoft.VisualStudio.Text.Editor.ITextView.Options" />.
    </summary>
</member>

[END-DOCUMENTATION]

@AmadeusW AmadeusW requested a review from a team as a code owner June 6, 2024 17:26
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Jun 6, 2024
@dotnet-policy-service dotnet-policy-service bot added the Community The pull request was submitted by a contributor who is not a Microsoft employee. label Jun 6, 2024
Copy link
Member

@CyrusNajmabadi CyrusNajmabadi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be reworked to be async. needs to work for any roslyn language.

@Cosifne
Copy link
Member

Cosifne commented Jul 9, 2024

Even though there might be a few places need to be refactored, the general status LGTM,

Copy link
Member

@CyrusNajmabadi CyrusNajmabadi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tentatively signing off to unblock. though i'm a bit wary about a few things. also, we'venoticed the rename dialog automatically dismissing when brought up when people type. i worry that the complex mix of sync/async processing will add to that issue.

@AmadeusW
Copy link
Contributor Author

@Cosifne it's ready, can you please complete the PR?

@Cosifne Cosifne merged commit 30edd04 into dotnet:main Jul 17, 2024
25 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Jul 17, 2024
Cosifne added a commit to Cosifne/roslyn that referenced this pull request Jul 23, 2024
…3873)

* work in progress on getting context and almost passing it to smart rename

* pass context to SmartRenameSession

* attempt to set PromptOverride through Lightup

* reflection refinement

* Fix CreatePropertySetter in LightupHelpers

* Find definitions and references and add them to the context

* also capture snippet of surrounding method

* simplify

* fix GetRequiredLanguageService

* undo code cleanup artifacts

* use ImmutableArray throughout Roslyn's interfaces

* fixup

* refactor to get context only if smart rename is active

* revert the now unnecessary change

* restore CreateFunctionAccessor with 2 parameters

* Dont duplicate work of getting rename locations

* use interface in the method declarations

* fix warning

* remove IInlineRenameSession from the API

* cleanup

* refactor getting doccomments

* fixup

* PR feedback

* Add IEditorInlineRenameService.IsRenameContextSupported

* revert unnecessary change

* remove unnecessary changes

* doc comments

* expose TriggerDocument instead of creating a property that returns a field

* add feature flag to control whether we're getting context

* improve event handler name

* fix Correctness_Analyzers warnings

* update Feature Flag look

* fix Freeing Twice assert

* add 'requires restart' to the FF name

* cleanup usings

* extract constants

* remove unused code

* NumberOfContextLines const

* GetRenameContextCoreAsync doc comments

* pr feedback on CSharpEditorInlineRenameService

* override fixes

* enforce hard limits on amount of symbols we traverse

* Get context off UI thread, respond to property changed on UI thread

* undo unwanted file

* Remove CSharpRenameContextHelper; improve the provided context

* modifiers and doc comments

* remove never taken branch

* Remove IsRenameContextSupported

* PR feedback to move TryGetSurroundingNodeSpanAsync to parent class

* use CompletesAsyncOperation pattern for SessionPropertyChanged

* Create IAsynchronousOperationListener in the constructor

* improve algorithm that provides context snippet

---------

Co-authored-by: Shen Chen <shech@microsoft.com>
arkalyanms added a commit that referenced this pull request Jul 23, 2024
@RikkiGibson RikkiGibson modified the milestones: Next, 17.12 P1 Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Community The pull request was submitted by a contributor who is not a Microsoft employee. untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants