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

Inline Rename and Find all References fail across projects #3033

Closed
cartermp opened this issue May 11, 2017 · 19 comments
Closed

Inline Rename and Find all References fail across projects #3033

cartermp opened this issue May 11, 2017 · 19 comments
Labels
Area-LangService-API Bug Impact-Medium (Internal MS Team use only) Describes an issue with moderate impact on existing code.
Milestone

Comments

@cartermp
Copy link
Contributor

cartermp commented May 11, 2017

Inline Rename and Find all References fail across projects in cases where you have made incremental updates to the references between projects.

Workaround is to unload/reload your solution.

Repro steps

Provide the steps required to reproduce the problem

  1. Create a Console App and Class Library.

  2. Create anything in the Class Library (class, function, etc.), and use it in the Console app.

  3. In the Class Library, rename a construct that is used in the Console App. Or find all references on it.

Expected behavior

In either case, the action works across projects.

Actual behavior

It fails.

Known workarounds

Unload/reload solution or individual projects after making a change to project references

Related information

VS 15.2 and 15.3. Not fixed with nightlies.

Interestingly enough, Go to Definition and the Go to All features all work perfectly across projects.

Screen captures from @vasily-kirichenko:

Inline Rename:

Find all References:

@cartermp cartermp added this to the VS 2017 Updates milestone May 11, 2017
@vasily-kirichenko
Copy link
Contributor

Were all documents saved to disk? If not, it's a known bug - FCS reads all files from disk, except current one.

@vasily-kirichenko
Copy link
Contributor

I can reproduce it. However, if you close the solution and reopen it, renaming works OK:

1

@vasily-kirichenko
Copy link
Contributor

I've tested it on #3025 and found that it does not fix this bug.

@vasily-kirichenko
Copy link
Contributor

I debugged it seems that this.Solution.GetProjectDependencyGraph().GetProjectsThatDirectlyDependOnThisProject does not return proper results.

@dsyme dsyme added Bug Impact-Medium (Internal MS Team use only) Describes an issue with moderate impact on existing code. Area-LangService-API labels May 12, 2017
@cartermp
Copy link
Contributor Author

Thanks for the investigating work @vasily-kirichenko

@cartermp
Copy link
Contributor Author

From @vasily-kirichenko:

What's more, referencing a symbol in another project breaks renaming it within the project where the symbol is defined.

@vasily-kirichenko
Copy link
Contributor

Adding project reference raises NRE:

1

Stack trace:

 	Microsoft.VisualStudio.LanguageServices.dll!Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.VisualStudioProjectTracker.ContainsProject(Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.AbstractProject project = null)	Unknown
 	Microsoft.VisualStudio.LanguageServices.dll!Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.VisualStudioProjectTracker.WorkspaceHostState.AddToPushListIfNeeded(Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.AbstractProject project = null, System.Collections.Generic.List<Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.AbstractProject> inOrderToPush = Count = 0, System.Collections.Generic.HashSet<Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.AbstractProject> visited = Count = 0)	Unknown
 	Microsoft.VisualStudio.LanguageServices.dll!Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.VisualStudioProjectTracker.WorkspaceHostState.StartPushingToWorkspaceAndNotifyOfOpenDocuments(System.Collections.Generic.IEnumerable<Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.AbstractProject> projects)	Unknown
 	Microsoft.VisualStudio.LanguageServices.dll!Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.VisualStudioProjectTracker.StartPushingToWorkspaceAndNotifyOfOpenDocuments(System.Collections.Generic.IEnumerable<Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.AbstractProject> projects = {Roslyn.Utilities.SpecializedCollections.Singleton.List<Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.AbstractProject>})	Unknown
 	Microsoft.VisualStudio.LanguageServices.dll!Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.AbstractProject.AddProjectReference(Microsoft.CodeAnalysis.ProjectReference projectReference)	Unknown
>	FSharp.Editor.dll!<StartupCode$FSharp-Editor>.$LanguageService.setup@421.Invoke(Microsoft.VisualStudio.FSharp.LanguageService.IProjectSite site = {Microsoft.VisualStudio.FSharp.ProjectSystem.DynamicProjectSite}) Line 462	F#
 	FSharp.Editor.dll!Microsoft.VisualStudio.FSharp.Editor.FSharpLanguageService.SetupProjectFile(Microsoft.VisualStudio.FSharp.LanguageService.IProvideProjectSite siteProvider = Windows Runtime Object, Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.VisualStudioWorkspaceImpl workspace = {Microsoft.VisualStudio.LanguageServices.RoslynVisualStudioWorkspace}, string userOpName = "SetupNewTextView") Line 470	F#
 	FSharp.Editor.dll!Microsoft.VisualStudio.FSharp.Editor.FSharpLanguageService.SetupNewTextView(Microsoft.VisualStudio.TextManager.Interop.IVsTextView textView = {Microsoft.VisualStudio.Editor.Implementation.VsTextViewAdapter}) Line 513	F#
 	Microsoft.VisualStudio.LanguageServices.dll!Microsoft.VisualStudio.LanguageServices.Implementation.LanguageService.AbstractLanguageService<Microsoft.VisualStudio.FSharp.Editor.FSharpPackage, Microsoft.VisualStudio.FSharp.Editor.FSharpLanguageService>.VsCodeWindowManager.AddAdornments()	Unknown
 	Microsoft.VisualStudio.Editor.Implementation.dll!Microsoft.VisualStudio.Editor.Implementation.CompoundTextViewWindow.TextDocData_OnNewLanguageService(ref System.Guid sidLangServiceID)	Unknown
 	Microsoft.VisualStudio.Editor.Implementation.dll!Microsoft.VisualStudio.Editor.Implementation.CompoundTextViewWindow.OnPrimaryView_FullyInitialized()	Unknown
 	Microsoft.VisualStudio.Editor.Implementation.dll!Microsoft.VisualStudio.Editor.Implementation.CompoundTextViewWindow.PrimaryView_TextViewHostUpdated(object sender, System.EventArgs e)	Unknown
 	Microsoft.VisualStudio.Editor.Implementation.dll!Microsoft.VisualStudio.Editor.Implementation.SimpleTextViewWindow.Init_InitializeWpfTextView()	Unknown
 	Microsoft.VisualStudio.Editor.Implementation.dll!Microsoft.VisualStudio.Editor.Implementation.SimpleTextViewWindow.Init_OnActivation()	Unknown
 	Microsoft.VisualStudio.Editor.Implementation.dll!Microsoft.VisualStudio.Editor.Implementation.SimpleTextViewWindow.SetInfo()	Unknown
 	Microsoft.VisualStudio.Editor.Implementation.dll!Microsoft.VisualStudio.Editor.Implementation.CompoundTextViewWindow.SetInfo()	Unknown
 	Microsoft.VisualStudio.Shell.UI.Internal.dll!Microsoft.VisualStudio.PlatformUI.StatusBarService.OnElementValueChanged(uint elementid, object varValueOld, object varValueNew)	Unknown
 	[Native to Managed Transition]	
 	[Managed to Native Transition]	
 	Microsoft.VisualStudio.Platform.WindowManagement.dll!Microsoft.VisualStudio.Platform.WindowManagement.WindowFrame.ConnectSelectionContext()	Unknown
 	Microsoft.VisualStudio.Platform.WindowManagement.dll!Microsoft.VisualStudio.Platform.WindowManagement.WindowFrame.Activate()	Unknown
 	Microsoft.VisualStudio.Platform.WindowManagement.dll!Microsoft.VisualStudio.Platform.WindowManagement.WindowManagerService.viewManager_ActiveViewChanged(object sender, Microsoft.VisualStudio.PlatformUI.Shell.ActiveViewChangedEventArgs e)	Unknown
 	Microsoft.VisualStudio.Utilities.dll!Microsoft.VisualStudio.PlatformUI.ExtensionMethods.RaiseEvent<System.__Canon>(System.EventHandler<System.__Canon> eventHandler, object source, System.__Canon args)	Unknown
 	Microsoft.VisualStudio.Shell.ViewManager.dll!Microsoft.VisualStudio.PlatformUI.Shell.ViewManager.SetActiveView(Microsoft.VisualStudio.PlatformUI.Shell.View view, Microsoft.VisualStudio.PlatformUI.Shell.ActivationType type)	Unknown
 	Microsoft.VisualStudio.Shell.ViewManager.dll!Microsoft.VisualStudio.PlatformUI.Shell.ViewManager.ActiveViewDeferrer.DisposeManagedResources()	Unknown
 	Microsoft.VisualStudio.Utilities.dll!Microsoft.VisualStudio.PlatformUI.DisposableObject.Dispose(bool disposing)	Unknown
 	Microsoft.VisualStudio.Utilities.dll!Microsoft.VisualStudio.PlatformUI.DisposableObject.Dispose()	Unknown
 	Microsoft.VisualStudio.Platform.WindowManagement.dll!Microsoft.VisualStudio.Platform.WindowManagement.SolutionOptions.LoadBinaryDocumentStates.AnonymousMethod__0(Microsoft.VisualStudio.Utilities.VersionedBinaryReader VersionedBinaryReader)	Unknown
 	Microsoft.VisualStudio.Utilities.dll!Microsoft.VisualStudio.Utilities.VersionedBinaryReader.ReadVersioned(int expectedVersion, Microsoft.VisualStudio.Utilities.VersionedBinaryReader.ReadCallback callback, bool throwOnUnexpectedVersion)	Unknown
 	Microsoft.VisualStudio.Platform.WindowManagement.dll!Microsoft.VisualStudio.Platform.WindowManagement.SolutionOptions.LoadBinaryDocumentStates(Microsoft.VisualStudio.Platform.WindowManagement.WindowManagerService windowManager, Microsoft.VisualStudio.OLE.Interop.IStream comStream, bool isExternal)	Unknown
 	Microsoft.VisualStudio.Platform.WindowManagement.dll!Microsoft.VisualStudio.Platform.WindowManagement.SolutionOptions.LoadDocumentStates(Microsoft.VisualStudio.Platform.WindowManagement.WindowManagerService windowManager, Microsoft.VisualStudio.OLE.Interop.IStream comStream, bool isExternal)	Unknown
 	Microsoft.VisualStudio.Platform.WindowManagement.dll!Microsoft.VisualStudio.Platform.WindowManagement.WindowManagerService.LoadDocumentStates.AnonymousMethod__0()	Unknown
 	Microsoft.VisualStudio.Shell.15.0.dll!Microsoft.VisualStudio.ErrorHandler.CallWithCOMConvention(System.Action method, bool reportError = false)	Unknown
 	Microsoft.VisualStudio.Platform.WindowManagement.dll!Microsoft.VisualStudio.Platform.WindowManagement.WindowManagerService.LoadDocumentStates(Microsoft.VisualStudio.OLE.Interop.IStream stream, int fExternal)	Unknown
 	[Native to Managed Transition]	
 	[Managed to Native Transition]	
 	Microsoft.VisualStudio.Shell.UI.Internal.dll!Microsoft.VisualStudio.PlatformUI.Packages.MRU.ExtensionMethods.TryOpenProject(Microsoft.VisualStudio.Shell.Interop.IVsSolution solution, string projectPath, System.Guid projectGuid)	Unknown
 	Microsoft.VisualStudio.Shell.UI.Internal.dll!Microsoft.VisualStudio.PlatformUI.CodeContainerAccessManager.OpenLocalCodeContainer(Microsoft.VisualStudio.Shell.CodeContainerManagement.CodeContainer codeContainer)	Unknown
 	Microsoft.VisualStudio.Shell.UI.Internal.dll!Microsoft.VisualStudio.PlatformUI.CodeContainerAccessManager.OpenAsync(Microsoft.VisualStudio.Shell.CodeContainerManagement.CodeContainer codeContainer)	Unknown
 	mscorlib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<bool>.Start<Microsoft.VisualStudio.PlatformUI.CodeContainerAccessManager.<OpenAsync>d__8>(ref Microsoft.VisualStudio.PlatformUI.CodeContainerAccessManager.<OpenAsync>d__8 stateMachine)	Unknown
 	Microsoft.VisualStudio.Shell.UI.Internal.dll!Microsoft.VisualStudio.PlatformUI.CodeContainerAccessManager.OpenAsync(Microsoft.VisualStudio.Shell.CodeContainerManagement.CodeContainer codeContainer)	Unknown
 	Microsoft.VisualStudio.Shell.UI.Internal.dll!Microsoft.VisualStudio.PlatformUI.CodeContainerListViewModel.OnOpen.AnonymousMethod__0()	Unknown
 	mscorlib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start<Microsoft.VisualStudio.PlatformUI.CodeContainerListViewModel.(ref Microsoft.VisualStudio.PlatformUI.CodeContainerListViewModel.<>c__DisplayClass17_0.<<OnOpen>b__0>d stateMachine)	Unknown
 	Microsoft.VisualStudio.Shell.UI.Internal.dll!Microsoft.VisualStudio.PlatformUI.CodeContainerListViewModel.OnOpen.AnonymousMethod__0()	Unknown
 	Microsoft.VisualStudio.Threading.dll!Microsoft.VisualStudio.Threading.JoinableTaskFactory.RunAsync(System.Func<System.Threading.Tasks.Task> asyncMethod, bool synchronouslyBlocking, Microsoft.VisualStudio.Threading.JoinableTaskCreationOptions creationOptions, System.Delegate entrypointOverride)	Unknown
 	Microsoft.VisualStudio.Shell.UI.Internal.dll!Microsoft.VisualStudio.PlatformUI.CodeContainerListViewModel.OnOpen(Microsoft.VisualStudio.PlatformUI.CodeContainerViewModelBase codeContainerViewModel)	Unknown
 	Microsoft.VisualStudio.Shell.UI.Internal.dll!Microsoft.VisualStudio.PlatformUI.CodeContainerViewModelBase..ctor.AnonymousMethod__0(object o)	Unknown
 	Microsoft.VisualStudio.Utilities.dll!Microsoft.VisualStudio.PlatformUI.DelegateCommand.Execute(object parameter)	Unknown
 	PresentationFramework.dll!MS.Internal.Commands.CommandHelpers.CriticalExecuteCommandSource(System.Windows.Input.ICommandSource commandSource, bool userInitiated)	Unknown
 	PresentationFramework.dll!System.Windows.Controls.Primitives.ButtonBase.OnClick()	Unknown
 	PresentationFramework.dll!System.Windows.Controls.Button.OnClick()	Unknown
 	PresentationFramework.dll!System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(System.Windows.Input.MouseButtonEventArgs e)	Unknown
 	PresentationCore.dll!System.Windows.UIElement.OnMouseLeftButtonUpThunk(object sender, System.Windows.Input.MouseButtonEventArgs e)	Unknown
 	PresentationCore.dll!System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(System.Delegate genericHandler, object genericTarget)	Unknown
 	PresentationCore.dll!System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate handler, object target)	Unknown
 	PresentationCore.dll!System.Windows.RoutedEventHandlerInfo.InvokeHandler(object target, System.Windows.RoutedEventArgs routedEventArgs)	Unknown
 	PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(object source = {System.Windows.Controls.Button}, System.Windows.RoutedEventArgs args = {System.Windows.Input.MouseButtonEventArgs}, bool reRaised = true)	Unknown
 	PresentationCore.dll!System.Windows.UIElement.ReRaiseEventAs(System.Windows.DependencyObject sender = {System.Windows.Controls.Button}, System.Windows.RoutedEventArgs args = {System.Windows.Input.MouseButtonEventArgs}, System.Windows.RoutedEvent newEvent)	Unknown
 	PresentationCore.dll!System.Windows.UIElement.OnMouseUpThunk(object sender, System.Windows.Input.MouseButtonEventArgs e)	Unknown
 	PresentationCore.dll!System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(System.Delegate genericHandler, object genericTarget)	Unknown
 	PresentationCore.dll!System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate handler, object target)	Unknown
 	PresentationCore.dll!System.Windows.RoutedEventHandlerInfo.InvokeHandler(object target, System.Windows.RoutedEventArgs routedEventArgs)	Unknown
 	PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(object source = {System.Windows.Controls.Button}, System.Windows.RoutedEventArgs args = {System.Windows.Input.MouseButtonEventArgs}, bool reRaised = false)	Unknown
 	PresentationCore.dll!System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject sender = {System.Windows.Controls.Button}, System.Windows.RoutedEventArgs args = {System.Windows.Input.MouseButtonEventArgs})	Unknown
 	PresentationCore.dll!System.Windows.UIElement.RaiseTrustedEvent(System.Windows.RoutedEventArgs args = {System.Windows.Input.MouseButtonEventArgs})	Unknown
 	PresentationCore.dll!System.Windows.UIElement.RaiseEvent(System.Windows.RoutedEventArgs args, bool trusted)	Unknown
 	PresentationCore.dll!System.Windows.Input.InputManager.ProcessStagingArea()	Unknown
 	PresentationCore.dll!System.Windows.Input.InputManager.ProcessInput(System.Windows.Input.InputEventArgs input)	Unknown
 	PresentationCore.dll!System.Windows.Input.InputProviderSite.ReportInput(System.Windows.Input.InputReport inputReport)	Unknown
 	PresentationCore.dll!System.Windows.Interop.HwndMouseInputProvider.ReportInput(System.IntPtr hwnd, System.Windows.Input.InputMode mode, int timestamp, System.Windows.Input.RawMouseActions actions, int x, int y, int wheel)	Unknown
 	PresentationCore.dll!System.Windows.Interop.HwndMouseInputProvider.FilterMessage(System.IntPtr hwnd, MS.Internal.Interop.WindowMessage msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled)	Unknown
 	PresentationCore.dll!System.Windows.Interop.HwndSource.InputFilterMessage(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled)	Unknown
 	WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled)	Unknown
 	WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o)	Unknown
 	WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs)	Unknown
 	WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source = {System.Windows.Threading.Dispatcher}, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler = null)	Unknown
 	WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, int numArgs)	Unknown
 	WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam)	Unknown

@vasily-kirichenko
Copy link
Contributor

After that GetDependentProjects returns empty list, hence the features do not work.

@dsyme
Copy link
Contributor

dsyme commented Jul 25, 2017

@Pilchie could you take a look at https://github.com/Microsoft/visualfsharp/blob/master/vsintegration/src/FSharp.Editor/LanguageService/LanguageService.fs#L420 for us? What are we doing wrong here to get a stack like the above?
Particularly:

 	Microsoft.VisualStudio.LanguageServices.dll!Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.VisualStudioProjectTracker.ContainsProject(Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.AbstractProject project = null)	Unknown
 	Microsoft.VisualStudio.LanguageServices.dll!Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.VisualStudioProjectTracker.WorkspaceHostState.AddToPushListIfNeeded(Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.AbstractProject project = null, System.Collections.Generic.List<Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.AbstractProject> inOrderToPush = Count = 0, System.Collections.Generic.HashSet<Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.AbstractProject> visited = Count = 0)	Unknown
 	Microsoft.VisualStudio.LanguageServices.dll!Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.VisualStudioProjectTracker.WorkspaceHostState.StartPushingToWorkspaceAndNotifyOfOpenDocuments(System.Collections.Generic.IEnumerable<Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.AbstractProject> projects)	Unknown
 	Microsoft.VisualStudio.LanguageServices.dll!Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.VisualStudioProjectTracker.StartPushingToWorkspaceAndNotifyOfOpenDocuments(System.Collections.Generic.IEnumerable<Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.AbstractProject> projects = {Roslyn.Utilities.SpecializedCollections.Singleton.List<Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.AbstractProject>})	Unknown
 	Microsoft.VisualStudio.LanguageServices.dll!Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.AbstractProject.AddProjectReference(Microsoft.CodeAnalysis.ProjectReference projectReference)	Unknown
>	FSharp.Editor.dll!<StartupCode$FSharp-Editor>.$LanguageService.setup@421.Invoke(Microsoft.VisualStudio.FSharp.LanguageService.IProjectSite site = {Microsoft.VisualStudio.FSharp.ProjectSystem.DynamicProjectSite}) Line 462	F#
 	FSharp.Editor.dll!Microsoft.VisualStudio.FSharp.Editor.FSharpLanguageService.SetupProjectFile(Microsoft.VisualStudio.FSharp.LanguageService.IProvideProjectSite siteProvider = Windows Runtime Object, Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.VisualStudioWorkspaceImpl workspace = {Microsoft.VisualStudio.LanguageServices.RoslynVisualStudioWorkspace}, string userOpName = "SetupNewTextView") Line 470	F#
 	FSharp.Editor.dll!Microsoft.VisualStudio.FSharp.Editor.FSharpLanguageService.SetupNewTextView(Microsoft.VisualStudio.TextManager.Interop.IVsTextView textView = {Microsoft.VisualStudio.Editor.Implementation.VsTextViewAdapter}) Line 513	F#
 	Microsoft.VisualStudio.LanguageServices.dll!Microsoft.VisualStudio.LanguageServices.Implementation.LanguageService.AbstractLanguageService<Microsoft.VisualStudio.FSharp.Editor.FSharpPackage, Microsoft.VisualStudio.FSharp.Editor.FSharpLanguageService>.VsCodeWindowManager.AddAdornments()	Unknown

@Pilchie
Copy link
Member

Pilchie commented Jul 25, 2017

It looks like what's happening is that you're adding a project reference to a project which has itself not been added to the VisualStudioProjectTracker yet. That causes this code to get null back out here, which we just pass along until we dereference it to get the Id here. Not sure why we don't have the other project in the workspace yet though.

@jasonmalinowski any thoughts?

@dsyme
Copy link
Contributor

dsyme commented Jul 25, 2017

@Pilchie Ugh, yes, all we've done is create a project ID. Likely we should do this:

    let  rec setup (site: IProjectSite) =
            ....
            for referencedSite in referencedProjectSites do
                setup referencedSite                    
                let referencedProjectFileName = referencedSite.ProjectFileName()
                let referencedProjectDisplayName = projectDisplayNameOf referencedProjectFileName
                let referencedProjectId = workspace.ProjectTracker.GetOrCreateProjectIdForPath(referencedProjectFileName, referencedProjectDisplayName)
                project.AddProjectReference(ProjectReference referencedProjectId)

            if not (workspace.ProjectTracker.ContainsProject(project)) then 
                workspace.ProjectTracker.AddProject(project)

rather than

    let  rec setup (site: IProjectSite) =
            ....
            for referencedSite in referencedProjectSites do
                let referencedProjectFileName = referencedSite.ProjectFileName()
                let referencedProjectDisplayName = projectDisplayNameOf referencedProjectFileName
                let referencedProjectId = workspace.ProjectTracker.GetOrCreateProjectIdForPath(referencedProjectFileName, referencedProjectDisplayName)
                project.AddProjectReference(ProjectReference referencedProjectId)

            if not (workspace.ProjectTracker.ContainsProject(project)) then 
                workspace.ProjectTracker.AddProject(project)

            for referencedSite in referencedProjectSites do
                setup referencedSite                    

@dsyme
Copy link
Contributor

dsyme commented Jul 25, 2017

@Pilchie @cartermp @vasily-kirichenko Here's that potential fix if you get to give it a go on the repro and other cases #3387

@vasily-kirichenko
Copy link
Contributor

#3387 seems to fix "Find all references", but not Inline Rename.

@vasily-kirichenko
Copy link
Contributor

But loading VFT solution raises this assert (twice):

image


Assertion Failed: Abort=Quit, Retry=Debug, Ignore=Continue

Could not retrive referenced project guidproject file

at Microsoft.VisualStudio.FSharp.ProjectSystem.ProjectReferenceNode..ctor(ProjectNode root, ProjectElement element)

at Microsoft.VisualStudio.FSharp.ProjectSystem.FSharpProjectReferenceNode..ctor(ProjectNode root, ProjectElement element)

at Microsoft.VisualStudio.FSharp.ProjectSystem.FSharpReferenceContainerNode.CreateProjectReferenceNode(ProjectElement element)

at Microsoft.VisualStudio.FSharp.ProjectSystem.ReferenceContainerNode.CreateReferenceNode(String referenceType, ProjectElement element, BuildResult buildResult)

at Microsoft.VisualStudio.FSharp.ProjectSystem.ReferenceContainerNode.LoadReferencesFromBuildProject(Project buildProject)

at Microsoft.VisualStudio.FSharp.ProjectSystem.ProjectNode.ProcessReferences()

at Microsoft.VisualStudio.FSharp.ProjectSystem.ProjectNode.Reload()

at Microsoft.VisualStudio.FSharp.ProjectSystem.FSharpProjectNode.Reload()

at Microsoft.VisualStudio.FSharp.ProjectSystem.ProjectNode.......

--------------------------- Abort Retry Ignore ---------------------------

@dsyme
Copy link
Contributor

dsyme commented Aug 17, 2017

@cartermp I can confirm this is not fixed in latest nightly for the case where you create a project and library and then rename. I can confirm it does work for the case where you restart VS, i.e. the solution and project are already created.

The underlying bug feels like it must either be

  1. the project options/references are not being kept up-to-date in the face of add/remove references between projects, or
  2. something is cached using the previous options/references

I suppose the problem is likely to be that, in the incremental case, project.AddProjectReference is never being called, in LanguageService.Fs. That's only being called in the initial setup code.

That's also partially confirmed by the fact the unload/reload project is now a workaround

@dsyme
Copy link
Contributor

dsyme commented Aug 17, 2017

Here's my analysis - @KevinRansom, @brettfo, @Pilchie please read. I will submit the content below as documentation, but I really need you guys to fully understand how this code works and fix the bugs in it, to make sure we don't have any further massive snafus :)

In LanguageService.fs we are trying to keep several versions of project information in sync. Here's how I believe this works:

  • For the old F# project system (Which is what we are dealing with here), the authoritative view of the project information is maintained by Project.fs. This information is conveyed to the rest of the implementation via an IProjectSite interface (an unfortunate name given that Site has other meanings in VS?).

  • For the new F# project system my limited understanding is that it manages the project information using a Roslyn project in the workspace. This means a lot of the stuff below is irrelevant in that case.

  • For most purposes, an IProjectSite has to provide three main things: the source files, the compilation options, and the assembly references. Project.fs collects the first two from MSBuild. For the third - assembly references - it looks through the nodes of the hierarchy for the F# project, e.g. here. This looks for AssemblyReferenceNode nodes in the hierarchy and extracts out their referenced path. (There seems to be an essentially duplicated version of this code in ProjectSitesAndFiles which walks over the IProjectSite using cruddy VS APIs to again collect referenced project nodes as further IProjectSite references. We can probably get rid of this duplication easily enough.)

  • In our LanguageService.fs, we use this IProjectSite information to incrementally maintain a corresponding F# CompilerService FSharpProjectOptions value. I think that is working correctly at the moment, which is why features like file checking, autocomplete and goto-definition are working.

  • In our LanguageService.fs, we also use this IProjectSite information to maintain a corresponding Roslyn project in the workspace. This is done by SetupProjectFile and SyncProject by making various calls to add/remove methods on both project: AbstractProject and projectContext: IWorkspaceProjectContext. (These are actually the same object but are two interfaces to it, something that's not entirely clear to me).

    The calls we currently make in SyncProject and SetupProjectFile are

    • On incremental project sync SyncProject we variously call projectContext.AddSourceFile, projectContext.RemoveSourceFile, projectContext.AddMetadataReference, projectContext.RemoveMetadataReference based on a diff to the list.

    • On initial project setup, we call SyncProject then also call project.AddProjectReference(..) for each referenced project (after setting up each referenced project). This is only done on initial setup, which is the bug. Note that during initial setup we call both project.AddProjectReference and projectContext.AddMetadataReference. I don't think the AbstractProject implementation knows that these are related, though I'm not sure it matters

So one fix might be to call project.AddProjectReference and project.RemoveProjectReference in SyncProject. However Roslyn only makes project.AddProjectReference available - project.RemoveProjectReference is protected. So that approach won't work without a Roslyn change

However, looking at the Roslyn CPS project code, it seems to me that Roslyn's CPSProject/AbstractProject implementation is probably meant to convert the metadata references managed by AddMetadataReference and RemoveMetadataReference to be project references, using Roslyn's "ProjectReferenceConversion" internal feature. That is, from what I see here this should be happening. However I haven't checked under the debugger. I expect it is not happening correctly, since otherwise we wouldn't have this bug.

@Pilchie
Copy link
Member

Pilchie commented Aug 17, 2017

Good analysis @dsyme.

I think it's worth checking to see what happens in the project conversion - it is tied to the output path of the projects, and only does the conversion if the incoming metadata reference path matches a project's output path. This is doubly complicated by the fact that most projects actually have two output paths. The compiler is generally told to build to the obj path, and then MSBuild copies the resulting binary to the bin directory. It's this bin directory that is normally passed to other projects as a reference. My hunch is that the paths aren't lining up quite right.

For reference: the split between AbstractProject and IWorkspaceProjectContext is basically between what grew up organically to support the old C# project system, and what we'd like to expose publicly for CPS based projects going forward. We should over time be working toward making it so that F# doesn't need to deal with AbstractProject at all if possible.

Also tagging @jasonmalinowski.

@dsyme
Copy link
Contributor

dsyme commented Aug 17, 2017

My hunch is that the paths aren't lining up quite right.

@Pilchie Thanks, great. Yes, it's possible they aren't. We need to debug into the roslyn code to be sure

@cartermp
Copy link
Contributor Author

cartermp commented Jan 7, 2018

This is now fixed as of 15.6 Preview 1.1. I suspect that the work @KevinRansom did in the relevant files (LanguageService.fs and ProjectSitesAndFiles.fs) to clean things up and enable .NET Standard and .NET Core support is what has fixed this.

@cartermp cartermp closed this as completed Jan 7, 2018
@cartermp cartermp modified the milestones: VS 2017 Updates, 15.6 Jun 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-LangService-API Bug Impact-Medium (Internal MS Team use only) Describes an issue with moderate impact on existing code.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants