diff --git a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptGoToDefinitionService.cs b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptGoToDefinitionService.cs index cb8785f71d675..6d162ddd9394c 100644 --- a/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptGoToDefinitionService.cs +++ b/src/EditorFeatures/Core/ExternalAccess/VSTypeScript/Api/IVSTypeScriptGoToDefinitionService.cs @@ -2,12 +2,14 @@ // 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; namespace Microsoft.CodeAnalysis.ExternalAccess.VSTypeScript.Api { + [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 ebfbe1b5a28a5..6f87069485e38 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 for go-to-def. Then let us know.", error: false)] internal interface IVSTypeScriptGoToDefinitionServiceFactoryImplementation { IVSTypeScriptGoToDefinitionService? CreateLanguageService(HostLanguageServices languageServices); 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)); - } - } -} 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),