From 681446fcee82e6250c09dcea014b8453177a4350 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 5 Dec 2023 10:44:14 -0800 Subject: [PATCH 1/7] Remove uncalled TS api --- .../Api/IVSTypeScriptGoToDefinitionService.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptGoToDefinitionService.cs b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptGoToDefinitionService.cs index cb8785f71d675..afd20052a856e 100644 --- a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptGoToDefinitionService.cs +++ b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptGoToDefinitionService.cs @@ -6,11 +6,9 @@ using System.Threading.Tasks; using System.Collections.Generic; -namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api +namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api; + +internal interface IVSTypeScriptGoToDefinitionService { - internal interface IVSTypeScriptGoToDefinitionService - { - Task?> FindDefinitionsAsync(Document document, int position, CancellationToken cancellationToken); - bool TryGoToDefinition(Document document, int position, CancellationToken cancellationToken); - } + Task?> FindDefinitionsAsync(Document document, int position, CancellationToken cancellationToken); } From 18009b92bad24326da683f62236e9566a77bb1d8 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 5 Dec 2023 10:53:32 -0800 Subject: [PATCH 2/7] Remove impls --- ...eScriptDefinitionLocationServiceFactory.cs | 41 ------------------- ...STypeScriptNavigableItemsServiceFactory.cs | 41 ------------------- 2 files changed, 82 deletions(-) delete mode 100644 src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptDefinitionLocationServiceFactory.cs delete mode 100644 src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptNavigableItemsServiceFactory.cs diff --git a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptDefinitionLocationServiceFactory.cs b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptDefinitionLocationServiceFactory.cs deleted file mode 100644 index 274510b8cabe8..0000000000000 --- a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptDefinitionLocationServiceFactory.cs +++ /dev/null @@ -1,41 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.Collections.Immutable; -using System.Composition; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api; -using Microsoft.CodeAnalysis.Host; -using Microsoft.CodeAnalysis.Host.Mef; -using Microsoft.CodeAnalysis.Navigation; - -namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript; - -[ExportLanguageServiceFactory(typeof(IDefinitionLocationService), InternalLanguageNames.TypeScript), Shared] -[method: ImportingConstructor] -[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] -internal sealed class VSTypeScriptDefinitionLocationServiceFactory(IVSTypeScriptGoToDefinitionServiceFactoryImplementation impl) : ILanguageServiceFactory -{ - public ILanguageService? CreateLanguageService(HostLanguageServices languageServices) - { - var service = impl.CreateLanguageService(languageServices); - return service != null ? new VSTypeScriptDefinitionLocationService(service) : null; - } - - private sealed class VSTypeScriptDefinitionLocationService(IVSTypeScriptGoToDefinitionService service) : IDefinitionLocationService - { - public Task GetDefinitionLocationAsync(Document document, int position, CancellationToken cancellationToken) - => DefinitionLocationServiceHelpers.GetDefinitionLocationFromLegacyImplementationsAsync( - document, position, - async cancellationToken => - { - var items = await service.FindDefinitionsAsync(document, position, cancellationToken).ConfigureAwait(false); - return items?.Select(i => (i.Document, i.SourceSpan)); - }, - cancellationToken); - } -} diff --git a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptNavigableItemsServiceFactory.cs b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptNavigableItemsServiceFactory.cs deleted file mode 100644 index cad50439e66cf..0000000000000 --- a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/VSTypeScriptNavigableItemsServiceFactory.cs +++ /dev/null @@ -1,41 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.Collections.Immutable; -using System.Composition; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api; -using Microsoft.CodeAnalysis.Host; -using Microsoft.CodeAnalysis.Host.Mef; -using Microsoft.CodeAnalysis.Navigation; -using Roslyn.Utilities; - -namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript; - -[ExportLanguageServiceFactory(typeof(INavigableItemsService), InternalLanguageNames.TypeScript), Shared] -[method: ImportingConstructor] -[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] -internal sealed class VSTypeScriptNavigableItemsServiceFactory(IVSTypeScriptGoToDefinitionServiceFactoryImplementation impl) : ILanguageServiceFactory -{ - public ILanguageService? CreateLanguageService(HostLanguageServices languageServices) - { - var service = impl.CreateLanguageService(languageServices); - return service != null ? new VSTypeScriptNavigableItemsService(service) : null; - } - - private sealed class VSTypeScriptNavigableItemsService(IVSTypeScriptGoToDefinitionService service) : INavigableItemsService - { - public async Task> GetNavigableItemsAsync(Document document, int position, CancellationToken cancellationToken) - { - var items = await service.FindDefinitionsAsync(document, position, cancellationToken).ConfigureAwait(false); - if (items is null) - return ImmutableArray.Empty; - - return items.SelectAsArray(i => (INavigableItem)new VSTypeScriptNavigableItemWrapper(i)); - } - } -} From aa62e882ef81bccc869984e6b34b2ef7c329d0d9 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 5 Dec 2023 10:54:33 -0800 Subject: [PATCH 3/7] REvert --- .../Api/IVSTypeScriptGoToDefinitionService.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptGoToDefinitionService.cs b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptGoToDefinitionService.cs index afd20052a856e..cb8785f71d675 100644 --- a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptGoToDefinitionService.cs +++ b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptGoToDefinitionService.cs @@ -6,9 +6,11 @@ using System.Threading.Tasks; using System.Collections.Generic; -namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api; - -internal interface IVSTypeScriptGoToDefinitionService +namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api { - Task?> FindDefinitionsAsync(Document document, int position, CancellationToken cancellationToken); + internal interface IVSTypeScriptGoToDefinitionService + { + Task?> FindDefinitionsAsync(Document document, int position, CancellationToken cancellationToken); + bool TryGoToDefinition(Document document, int position, CancellationToken cancellationToken); + } } From e123b26430b16d1a9a20e19553beded71efed394 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 5 Dec 2023 10:55:51 -0800 Subject: [PATCH 4/7] obsoletE --- .../VSTypeScript/Api/IVSTypeScriptGoToDefinitionService.cs | 2 ++ .../IVSTypeScriptGoToDefinitionServiceFactoryImplementation.cs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptGoToDefinitionService.cs b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptGoToDefinitionService.cs index cb8785f71d675..cbd332ec78c57 100644 --- a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptGoToDefinitionService.cs +++ b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptGoToDefinitionService.cs @@ -5,9 +5,11 @@ using System.Threading; using System.Threading.Tasks; using System.Collections.Generic; +using System; namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api { + [Obsolete("TS, remove your implementation of this type now that you're entirely on LSP. Then let us know.", error: false)] internal interface IVSTypeScriptGoToDefinitionService { Task?> FindDefinitionsAsync(Document document, int position, CancellationToken cancellationToken); diff --git a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptGoToDefinitionServiceFactoryImplementation.cs b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptGoToDefinitionServiceFactoryImplementation.cs index ebfbe1b5a28a5..387034d14167a 100644 --- a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptGoToDefinitionServiceFactoryImplementation.cs +++ b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptGoToDefinitionServiceFactoryImplementation.cs @@ -2,10 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System; using Microsoft.CodeAnalysis.Host; namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api { + [Obsolete("TS, remove your implementation of this type now that you're entirely on LSP. Then let us know.", error: false)] internal interface IVSTypeScriptGoToDefinitionServiceFactoryImplementation { IVSTypeScriptGoToDefinitionService? CreateLanguageService(HostLanguageServices languageServices); From ca358ca1de434b49343af8f38852cd05c78ea493 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 5 Dec 2023 10:56:21 -0800 Subject: [PATCH 5/7] sort --- .../VSTypeScript/Api/IVSTypeScriptGoToDefinitionService.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptGoToDefinitionService.cs b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptGoToDefinitionService.cs index cbd332ec78c57..9744c72021158 100644 --- a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptGoToDefinitionService.cs +++ b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptGoToDefinitionService.cs @@ -2,10 +2,10 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System; +using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; -using System.Collections.Generic; -using System; namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api { From f50ed04466b6a83eeafea8d9491134c6313e2073 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 5 Dec 2023 10:56:54 -0800 Subject: [PATCH 6/7] text --- .../VSTypeScript/Api/IVSTypeScriptGoToDefinitionService.cs | 2 +- .../IVSTypeScriptGoToDefinitionServiceFactoryImplementation.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptGoToDefinitionService.cs b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptGoToDefinitionService.cs index 9744c72021158..6d162ddd9394c 100644 --- a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptGoToDefinitionService.cs +++ b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptGoToDefinitionService.cs @@ -9,7 +9,7 @@ namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api { - [Obsolete("TS, remove your implementation of this type now that you're entirely on LSP. Then let us know.", error: false)] + [Obsolete("TS, remove your implementation of this type now that you're entirely on LSP for go-to-def. Then let us know.", error: false)] internal interface IVSTypeScriptGoToDefinitionService { Task?> FindDefinitionsAsync(Document document, int position, CancellationToken cancellationToken); diff --git a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptGoToDefinitionServiceFactoryImplementation.cs b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptGoToDefinitionServiceFactoryImplementation.cs index 387034d14167a..6f87069485e38 100644 --- a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptGoToDefinitionServiceFactoryImplementation.cs +++ b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptGoToDefinitionServiceFactoryImplementation.cs @@ -7,7 +7,7 @@ namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api { - [Obsolete("TS, remove your implementation of this type now that you're entirely on LSP. Then let us know.", error: false)] + [Obsolete("TS, remove your implementation of this type now that you're entirely on LSP for go-to-def. Then let us know.", error: false)] internal interface IVSTypeScriptGoToDefinitionServiceFactoryImplementation { IVSTypeScriptGoToDefinitionService? CreateLanguageService(HostLanguageServices languageServices); From 8ffa18a973f225d493dcc9a7d52293450c5311a0 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 5 Dec 2023 10:58:40 -0800 Subject: [PATCH 7/7] Be resilient to missing service --- .../Handler/Definitions/AbstractGoToDefinitionHandler.cs | 4 +++- .../GoToDefinition/OmniSharpFindDefinitionService.cs | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Features/LanguageServer/Protocol/Handler/Definitions/AbstractGoToDefinitionHandler.cs b/src/Features/LanguageServer/Protocol/Handler/Definitions/AbstractGoToDefinitionHandler.cs index 680da2eb1b8b0..7751bd2fe113a 100644 --- a/src/Features/LanguageServer/Protocol/Handler/Definitions/AbstractGoToDefinitionHandler.cs +++ b/src/Features/LanguageServer/Protocol/Handler/Definitions/AbstractGoToDefinitionHandler.cs @@ -46,7 +46,9 @@ public AbstractGoToDefinitionHandler(IMetadataAsSourceFileService metadataAsSour var locations = ArrayBuilder.GetInstance(); var position = await document.GetPositionFromLinePositionAsync(ProtocolConversions.PositionToLinePosition(request.Position), cancellationToken).ConfigureAwait(false); - var service = document.GetRequiredLanguageService(); + var service = document.GetLanguageService(); + if (service is null) + return null; var definitions = await service.GetNavigableItemsAsync(document, position, cancellationToken).ConfigureAwait(false); if (definitions.Length > 0) diff --git a/src/Tools/ExternalAccess/OmniSharp/GoToDefinition/OmniSharpFindDefinitionService.cs b/src/Tools/ExternalAccess/OmniSharp/GoToDefinition/OmniSharpFindDefinitionService.cs index 043f497b1562f..0d6dfff851a26 100644 --- a/src/Tools/ExternalAccess/OmniSharp/GoToDefinition/OmniSharpFindDefinitionService.cs +++ b/src/Tools/ExternalAccess/OmniSharp/GoToDefinition/OmniSharpFindDefinitionService.cs @@ -15,7 +15,10 @@ internal static class OmniSharpFindDefinitionService { internal static async Task> FindDefinitionsAsync(Document document, int position, CancellationToken cancellationToken) { - var service = document.GetRequiredLanguageService(); + var service = document.GetLanguageService(); + if (service is null) + return ImmutableArray.Empty; + var result = await service.GetNavigableItemsAsync(document, position, cancellationToken).ConfigureAwait(false); return await result.NullToEmpty().SelectAsArrayAsync( async (original, solution, cancellationToken) => new OmniSharpNavigableItem(original.DisplayTaggedParts, await original.Document.GetRequiredDocumentAsync(solution, cancellationToken).ConfigureAwait(false), original.SourceSpan),