microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.17k stars 12.38k forks source link

VS 2019 can't rename anything exported. #42171

Open Griffork opened 3 years ago

Griffork commented 3 years ago

Bug Report

πŸ”Ž Search Terms

InlineRename, can't rename.

πŸ•— Version & Regression Information

Visual Studio Version: 16.8.3 TypeScript Tools: 16.0.21016.2001 TypeScript Version (installed in npm): 3.9.7 Project type GUIDs: {3AF33F2E-1136-4D97-BBB7-1795711AC8B8};{349c5851-65df-11da-9384-00065b846f21};{9092AA53-FB77-4645-B42D-1CCCA6BD08BD}

I noticed this bug when I created a new project in VS2019. It doesn't appear to happen in my old project.

πŸ’» The problem:

Trying to rename any class, interface or variable that is exported from one file and used in any other file works (in that you can type out the new name) but fails to apply. An error shows at the top of the window and the edited property reverts to it's original name with an extra newline inserted where the cursor was.

e.g.

export class RenderOrganiser {
    //... other code
}

When I try to use rename to edit it to be:

export class RenderOrganiserABAB {
    //... other code
}

It instead becomes:

export class RenderOrganiser
 {
    //... other code
}

And the following error occurs in the log:

System.Runtime.InteropServices.COMException (0x80004005): Error HRESULT E_FAIL has been returned from a call to a COM component. at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo) at Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.InvisibleEditor..ctor(IServiceProvider serviceProvider, String filePath, IVsHierarchy hierarchy, Boolean needsSave, Boolean needsUndoDisabled) at Microsoft.VisualStudio.LanguageServices.RoslynVisualStudioWorkspace.OpenInvisibleEditor(DocumentId documentId) at Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.VisualStudioWorkspaceImpl.ApplyTextDocumentChange(DocumentId documentId, SourceText newText) at Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.VisualStudioWorkspaceImpl.ApplyDocumentTextChanged(DocumentId documentId, SourceText newText) at Microsoft.CodeAnalysis.Workspace.ApplyChangedDocument(ProjectChanges projectChanges, DocumentId documentId) at Microsoft.CodeAnalysis.Workspace.ApplyProjectChanges(ProjectChanges projectChanges) at Microsoft.CodeAnalysis.Workspace.TryApplyChanges(Solution newSolution, IProgressTracker progressTracker) at Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.VisualStudioWorkspaceImpl.TryApplyChanges(Solution newSolution, IProgressTracker progressTracker) at Microsoft.CodeAnalysis.Workspace.TryApplyChanges(Solution newSolution) at Microsoft.CodeAnalysis.Editor.Implementation.InlineRename.InlineRenameSession.ApplyRename(Solution newSolution, IWaitContext waitContext) at Microsoft.CodeAnalysis.Editor.Implementation.InlineRename.InlineRenameSession.CommitCore(IWaitContext waitContext, Boolean previewChanges) at Microsoft.CodeAnalysis.Editor.Implementation.InlineRename.InlineRenameSession.<>cDisplayClass78_0.b0(IWaitContext waitContext) at Microsoft.VisualStudio.LanguageServices.Implementation.Utilities.VisualStudioWaitIndicator.Wait(String title, String message, Boolean allowCancel, Boolean showProgress, Action`1 action) at Microsoft.CodeAnalysis.Editor.Implementation.InlineRename.InlineRenameSession.CommitWorker(Boolean previewChanges) at Microsoft.CodeAnalysis.Editor.Implementation.InlineRename.RenameCommandHandler.ExecuteCommand(ReturnKeyCommandArgs args, CommandExecutionContext context) at Microsoft.VisualStudio.UI.Text.Commanding.Implementation.EditorCommandHandlerService.<>cDisplayClass14_1`1.b0() at Microsoft.VisualStudio.Text.Utilities.GuardedOperations.CallExtensionPoint(Object errorSource, Action call, Predicate`1 exceptionFilter) --- End of stack trace from previous location where exception was thrown --- at Microsoft.VisualStudio.Telemetry.WindowsErrorReporting.WatsonReport.GetClrWatsonExceptionInfo(Exception exceptionObject)

DanielRosenwasser commented 3 years ago

I'll wait on @minestarks to verify whether this has already been fixed. If so, I believe you can expect a fix in an upcoming update of Visual Studio 2019.

Griffork commented 3 years ago

Not sure if related but now renames are causing the names to be doubled up, so:

Renaming getTopLevelElement in the following code:

export abstract class UIComponent {
    abstract visible: KnockoutObservable<boolean>;
    abstract getTopLevelElement(): HTMLElement;
}

to:

export abstract class UIComponent {
    abstract visible: KnockoutObservable<boolean>;
    abstract getRootElement(): HTMLElement;
}

becomes:

export abstract class UIComponent {
    abstract visible: KnockoutObservable<boolean>;
    abstract getRootElementgetRootElement(): HTMLElement;
}
uniqueiniquity commented 3 years ago

Hi @Griffork! I'm not able to repro either issue in either Visual Studio 2019 version 16.10.1 or version 16.11 Preview 1, in both cases with TypeScript version 3.9.7.

Could you please confirm that you're still able to observe the issues in one of these versions? Are you still using TS 3.9.7?

If so, could you please report this using the "Report A Problem" functionality in Visual Studio? By doing so and using the "Record your actions" functionality, that will provide us with logs to help us further investigate the issue.

Thank you!

Griffork commented 3 years ago

I can confirm that I am still getting the problem. If I restart a bunch occasionally it won't happen and if it doesn't happen it's good for the entire session (and then the problem reappears when I restart after that).

I'm using 16.10.1 and Typescript version 4.2.

I've done a recording and submitted it. I'll have a link to it soon and post it here.