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

Implement inline rename #1932

Merged
merged 28 commits into from
Dec 16, 2016
Merged

Conversation

vasily-kirichenko
Copy link
Contributor

This is early WIP of implementing Roslyn-powered Inline Rename.

@dsyme
Copy link
Contributor

dsyme commented Dec 4, 2016

Wow. Fantastic to see this in progress!

@forki
Copy link
Contributor

forki commented Dec 4, 2016

💋

@vasily-kirichenko
Copy link
Contributor Author

@forki :) But it's not a small task, as it's turned out...

@forki
Copy link
Contributor

forki commented Dec 4, 2016

@vasily-kirichenko I know. that's why you are doing it ;-)

@vasily-kirichenko
Copy link
Contributor Author

I've stuck with this a bit. That's how it works at the moment:

1

What I think about it:

  • The (green) tags are calculated properly - they are shifted and increased in size as they should.
  • Tags and their content is not the same as real Document content because
    • Old code is not shifted (look at the + sign, for example)
    • Preview dialog says "No changes"
  • I think C#/VB editor modify AST directly, which then automatically reflected visually on documents.

If this is all true, I'm afraid we have to modify Documents manually, which raises other questions:

@Pilchie
Copy link
Member

Pilchie commented Dec 4, 2016

Tagging @jasonmalinowski and @dpoeschl for comments about how this works.

@vladima
Copy link
Contributor

vladima commented Dec 6, 2016

I'll try to take a look today

@vasily-kirichenko
Copy link
Contributor Author

BIG thanks to @vladima for fixing this!

It works like this now:

1

What I have to finish:

  • add some validation, like we have in VFPT
  • add tests

@vasily-kirichenko
Copy link
Contributor Author

@vladima I found an interesting bug:

1

@dsyme
Copy link
Contributor

dsyme commented Dec 7, 2016

@vasily-kirichenko Looks like there are quite a few unrelated changes in this branch? Or do you need to merge with master? thx

@vasily-kirichenko
Copy link
Contributor Author

@dsyme You are right. Done.

I will investigate the bug later.

@dsyme
Copy link
Contributor

dsyme commented Dec 8, 2016

~28 failures, e.g.

 1) Failed : Microsoft.VisualStudio.FSharp.Editor.Tests.Roslyn.ColorizationServiceTests.InactiveCode("Inactive Code1*)le","excluded code")

@vasily-kirichenko
Copy link
Contributor Author

I've reverted the tryClassifyAtPosition fix, all should be green now.

@vasily-kirichenko
Copy link
Contributor Author

The bug is a tricky one. If there are no text in the file after the renaming symbol, it pops up immediately, after deleting single character:

image

If there is text after it, then it appears later, depending on the length of trailing text:

image

image

I've compared our implementation to XAML one http://source.roslyn.io/#Microsoft.VisualStudio.LanguageServices.Xaml/Features/InlineRename/XamlEditorInlineRenameService.cs and found no differences. I've tested renaming in XAML editor, it works OK.

Any ideas?

@dsyme
Copy link
Contributor

dsyme commented Dec 8, 2016

@vasily-kirichenko This looks wrong (rename on a property e.Message replaces all text of the expression)

capture17
capture18

@vasily-kirichenko
Copy link
Contributor Author

@dsyme yes, it's because FCS returns wrong ranges for qualified symbols. I had to work it around in Document Highlight service as well (it was copied from VFPT) and @vladima did something similar in this PR, too.

I think it would be really great to fix it at FSC level.

@cartermp
Copy link
Contributor

cartermp commented Dec 8, 2016

I think it would be really great to fix it at FSC level.

Agreed, since this is cropping up in more than one feature area

@vasily-kirichenko
Copy link
Contributor Author

@dsyme could you comment on this? I mean is it by design:

  • System|.DateTime.Now => System
  • System.DateTime|.Now => DateTime
  • System.DateTime.Now| => System.DateTime.Now

?

@cartermp
Copy link
Contributor

cartermp commented Dec 9, 2016

@vasily-kirichenko Something to consider either for this PR or a future one is how to deal with conflicts and preventing bad renames.

For example:

let getFirstFromTwople (t: int*int) = t |> fst
let getFirstFromThreeple (t: int*int*int) = t |> fst
let getFirstFromFourple (t: int*int*int*int) = t |> fst

I can currently inline rename fst to FST, which would result in a compile error, assuming FST either doesn't exist or isn't an inlined function which works for tuples up to a certain size.

Another thing to consider is the Big Scary Warning Text for renaming something into something else in scope which has the same name, like in C#/VB:

screen shot 2016-12-09 at 1 50 53 pm

As an aside, I've been playing with this today and showing it off to people in the office. It's really, really great work. Kudos 😄

@vasily-kirichenko
Copy link
Contributor Author

@cartermp yes, I already thought about this. We have quite good non scope aware name validation in VFPT, but it requires porting significant amount of code, including our own higher level wrapper over the lever for nicer qualified names parsing (or maybe not and we can use classifyAtPosition). What about name conflicts in same scope, I don't know how to get all names for current one. Never done this.

However, I'd prefer to fix the bug (I have absolutely no idea how to do it) and make it solution wide (for all F# projects, making it work with other project types is a different unexplored area, however, the Xamarin guys have done it somehow, so we must be able to do it, too).

@cartermp
Copy link
Contributor

@vasily-kirichenko Makes sense.

Vasily Kirichenko and others added 7 commits December 14, 2016 14:57
Conflicts:
	vsintegration/src/FSharp.Editor/CommonHelpers.fs
Conflicts:
	vsintegration/packages.config
Conflicts:
	vsintegration/src/FSharp.Editor/CommonHelpers.fs
	vsintegration/src/FSharp.Editor/CommonRoslynHelpers.fs
@KevinRansom KevinRansom merged commit 1d65544 into dotnet:master Dec 16, 2016
nosami pushed a commit to xamarin/visualfsharp that referenced this pull request Jan 26, 2022
* add InlineRenameService skeleton

* implement IEditorInlineRenameService instead of inheriting AbstractEditorInlineRenameService, which is roslyn-AST bound

* add some real logic into InlineRenameService

* everything in place, but does not work yet

* TryOnBefore/AfterGlobalSymbolRename should return `true`

* some progress

* port comments

* add RenamedSpansTracker

* trying to adjust span positions

* fixes

* do not check whole project in renamed symbol is local for file

* update inline rename implementation

* remove RenamedSpansTracker

* fixed: CommonHelpers.tryClassifyAtPosition return wrong result at the end position

* do not fix spans for now

* Revert "fixed: CommonHelpers.tryClassifyAtPosition return wrong result at the end position"

This reverts commit af81683.

* refactoring

* refactoring

* use Async.Cache instead of mutable Task reference to emulate a non auto-starting promise

* solution wide Inline Rename (wip)

* fix after merge

* update Microsoft.CodeAnalysis.xxx packages to 2.0.0-rc

* fix after merge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants