From 1e27f6625b5f71f58789c5c803ca215a71e7fcfa Mon Sep 17 00:00:00 2001 From: David Barbet Date: Thu, 16 Nov 2023 17:53:03 -0800 Subject: [PATCH 1/2] Ship Devkit dependencies as a nuget package to support directly including in the C# extension --- Roslyn.sln | 2 - azure-pipelines-official.yml | 15 ---- eng/Versions.props | 1 - eng/build.ps1 | 11 --- eng/config/PublishData.json | 2 +- eng/publish-assets.ps1 | 5 -- eng/targets/Settings.props | 5 -- ...deAnalysis.LanguageServer.UnitTests.csproj | 2 +- .../LanguageServerTestComposition.cs | 2 +- .../ExportProviderBuilder.cs | 4 +- .../Program.cs | 11 +-- .../ServerConfigurationFactory.cs | 5 +- .../Services/AssemblyLoadContextWrapper.cs | 42 ++------- .../StarredCompletionsAssemblyHelper.cs | 2 +- src/VisualStudio/DevKit/Impl/.npmrc | 3 - ...isualStudio.LanguageServices.DevKit.csproj | 87 +++++-------------- src/VisualStudio/DevKit/Impl/package.json | 4 - ...soft.CodeAnalysis.Remote.Workspaces.csproj | 1 + 18 files changed, 37 insertions(+), 167 deletions(-) delete mode 100644 src/VisualStudio/DevKit/Impl/.npmrc delete mode 100644 src/VisualStudio/DevKit/Impl/package.json diff --git a/Roslyn.sln b/Roslyn.sln index 681d3fae1c046..acdafebf61b47 100644 --- a/Roslyn.sln +++ b/Roslyn.sln @@ -1639,8 +1639,6 @@ Global src\Compilers\Server\VBCSCompiler\VBCSCompilerCommandLine.projitems*{9508f118-f62e-4c16-a6f4-7c3b56e166ad}*SharedItemsImports = 5 src\Compilers\VisualBasic\vbc\VbcCommandLine.projitems*{975cd834-45f4-4ea0-a395-cb60dbd0e214}*SharedItemsImports = 5 src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\WorkspaceExtensions.projitems*{99f594b1-3916-471d-a761-a6731fc50e9a}*SharedItemsImports = 13 - src\Dependencies\Collections\Microsoft.CodeAnalysis.Collections.projitems*{9b7ac5c2-293d-438d-b9a2-1eddc2c6bf00}*SharedItemsImports = 5 - src\Dependencies\PooledObjects\Microsoft.CodeAnalysis.PooledObjects.projitems*{9b7ac5c2-293d-438d-b9a2-1eddc2c6bf00}*SharedItemsImports = 5 src\Analyzers\VisualBasic\CodeFixes\VisualBasicCodeFixes.projitems*{9f9ccc78-7487-4127-9d46-db23e501f001}*SharedItemsImports = 13 src\Analyzers\CSharp\CodeFixes\CSharpCodeFixes.projitems*{a07abcf5-bc43-4ee9-8fd8-b2d77fd54d73}*SharedItemsImports = 5 src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\CSharpWorkspaceExtensions.projitems*{a07abcf5-bc43-4ee9-8fd8-b2d77fd54d73}*SharedItemsImports = 5 diff --git a/azure-pipelines-official.yml b/azure-pipelines-official.yml index 6d661e6b13496..5a69351394ca4 100644 --- a/azure-pipelines-official.yml +++ b/azure-pipelines-official.yml @@ -301,21 +301,6 @@ stages: ArtifactName: 'PackageArtifacts' condition: succeeded() - # Publish language server package - - powershell: Write-Host "##vso[task.setvariable variable=NPMFileName]$((ls -file $(Build.SourcesDirectory)\artifacts\packages\Release\NPM\ | select -First 1).FullName)" - displayName: Setting NPM Package Variable - - # Authenticates the .npmrc file for publishing to the internal AzDO feed. - # See: https://learn.microsoft.com/azure/devops/pipelines/tasks/package/npm-authenticate?view=azure-devops - - task: npmAuthenticate@0 - displayName: Authenticate NPM Feed - inputs: - workingFile: $(Build.SourcesDirectory)/src/VisualStudio/DevKit/Impl/.npmrc - customEndpoint: devdiv-vs-green-npm-package-feed - - - script: npm publish --userconfig $(Build.SourcesDirectory)\src\VisualStudio\DevKit\Impl\.npmrc $(NPMFileName) - displayName: Publish Language Server NPM Package - # Publish Asset Manifests for Build Asset Registry job - task: PublishBuildArtifacts@1 displayName: Publish Asset Manifests diff --git a/eng/Versions.props b/eng/Versions.props index 80d1a14816e92..8e98add304de6 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -164,7 +164,6 @@ $(MicrosoftVisualStudioShellPackagesVersion) $(MicrosoftVisualStudioShellPackagesVersion) 17.8.36726 - 2.0.93 17.8.36711 $(VisualStudioEditorPackagesVersion) 15.8.27812-alpha diff --git a/eng/build.ps1 b/eng/build.ps1 index 3995ae41ba368..bfe46f89fadb2 100644 --- a/eng/build.ps1 +++ b/eng/build.ps1 @@ -258,8 +258,6 @@ function BuildSolution() { $restoreUseStaticGraphEvaluation = $true - $isNpmAvailable = IsNpmAvailable - try { MSBuild $toolsetBuildProj ` $bl ` @@ -282,7 +280,6 @@ function BuildSolution() { /p:RestoreUseStaticGraphEvaluation=$restoreUseStaticGraphEvaluation ` /p:VisualStudioIbcDrop=$ibcDropName ` /p:VisualStudioDropAccessToken=$officialVisualStudioDropAccessToken ` - /p:IsNpmPackable=$isNpmAvailable ` $suppressExtensionDeployment ` $msbuildWarnAsError ` $buildFromSource ` @@ -712,14 +709,6 @@ function List-Processes() { Get-Process -Name "devenv" -ErrorAction SilentlyContinue | Out-Host } -function IsNpmAvailable() { - if (Get-Command "npm" -ErrorAction SilentlyContinue) { - return $true - } - - return $false; -} - try { if ($PSVersionTable.PSVersion.Major -lt "5") { Write-Host "PowerShell version must be 5 or greater (version $($PSVersionTable.PSVersion) detected)" diff --git a/eng/config/PublishData.json b/eng/config/PublishData.json index ba0b59eee1f41..90b80cc0bf946 100644 --- a/eng/config/PublishData.json +++ b/eng/config/PublishData.json @@ -45,7 +45,7 @@ "Microsoft.CodeAnalysis.EditorFeatures.Wpf": "vssdk", "Microsoft.CodeAnalysis.EditorFeatures.Cocoa": "vssdk", "Microsoft.VisualStudio.IntegrationTest.Utilities": "vs-impl", - "Microsoft.VisualStudio.LanguageServices.DevKit": "npm", + "Microsoft.VisualStudio.LanguageServices.DevKit": "vs-impl", "Microsoft.CodeAnalysis.LanguageServer": "vs-impl", "Microsoft.CodeAnalysis.LanguageServer.alpine-arm64": "vs-impl", "Microsoft.CodeAnalysis.LanguageServer.alpine-x64": "vs-impl", diff --git a/eng/publish-assets.ps1 b/eng/publish-assets.ps1 index 7cc3a725ea64e..cc8b36f874e67 100644 --- a/eng/publish-assets.ps1 +++ b/eng/publish-assets.ps1 @@ -92,11 +92,6 @@ function Publish-Nuget($publishData, [string]$packageDir) { continue } - if ($feedName.equals("npm")) { - Write-Host "Skipping publishing for $nupkg as it is published in a separate step as an NPM package" - continue - } - # Use the feed name to get the source to upload the package to. if (-not (Get-Member -InputObject $feedData -Name $feedName)) { throw "$feedName has no configured source feed" diff --git a/eng/targets/Settings.props b/eng/targets/Settings.props index 564a19e4f4fd5..e59fb67a8d712 100644 --- a/eng/targets/Settings.props +++ b/eng/targets/Settings.props @@ -51,11 +51,6 @@ false false true - - - $(ArtifactsDir)\packages\$(Configuration)\NPM\ - - false + Targets="CollectPackInputs"> diff --git a/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer.UnitTests/Utilities/LanguageServerTestComposition.cs b/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer.UnitTests/Utilities/LanguageServerTestComposition.cs index c73d434139a73..4d9d66026469a 100644 --- a/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer.UnitTests/Utilities/LanguageServerTestComposition.cs +++ b/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer.UnitTests/Utilities/LanguageServerTestComposition.cs @@ -20,5 +20,5 @@ private static string GetDevKitExtensionPath() => Path.Combine(AppContext.BaseDirectory, DevKitExtensionSubdirectory, DevKitAssemblyFileName); public static Task CreateExportProviderAsync(ILoggerFactory loggerFactory, bool includeDevKitComponents) - => ExportProviderBuilder.CreateExportProviderAsync(extensionAssemblyPaths: includeDevKitComponents ? [GetDevKitExtensionPath()] : Array.Empty(), sharedDependenciesPath: null, loggerFactory); + => ExportProviderBuilder.CreateExportProviderAsync(extensionAssemblyPaths: includeDevKitComponents ? [GetDevKitExtensionPath()] : Array.Empty(), loggerFactory: loggerFactory); } diff --git a/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/ExportProviderBuilder.cs b/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/ExportProviderBuilder.cs index 3afa2dcc69c47..1e7ee9f73dc68 100644 --- a/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/ExportProviderBuilder.cs +++ b/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/ExportProviderBuilder.cs @@ -14,7 +14,7 @@ namespace Microsoft.CodeAnalysis.LanguageServer; internal sealed class ExportProviderBuilder { - public static async Task CreateExportProviderAsync(IEnumerable extensionAssemblyPaths, string? sharedDependenciesPath, ILoggerFactory loggerFactory) + public static async Task CreateExportProviderAsync(IEnumerable extensionAssemblyPaths, ILoggerFactory loggerFactory) { var logger = loggerFactory.CreateLogger(); @@ -48,7 +48,7 @@ public static async Task CreateExportProviderAsync(IEnumerable("--sharedDependencies") - { - Description = "Full path of the directory containing shared assemblies (optional).", - Required = false - }; - var extensionAssemblyPathsOption = new CliOption("--extension", "--extensions") // TODO: remove plural form { Description = "Full paths of extension assemblies to load (optional).", @@ -199,7 +193,6 @@ static CliRootCommand CreateCommandLineParser() starredCompletionsPathOption, telemetryLevelOption, sessionIdOption, - sharedDependenciesOption, extensionAssemblyPathsOption, extensionLogDirectoryOption }; @@ -210,7 +203,6 @@ static CliRootCommand CreateCommandLineParser() var starredCompletionsPath = parseResult.GetValue(starredCompletionsPathOption); var telemetryLevel = parseResult.GetValue(telemetryLevelOption); var sessionId = parseResult.GetValue(sessionIdOption); - var sharedDependenciesPath = parseResult.GetValue(sharedDependenciesOption); var extensionAssemblyPaths = parseResult.GetValue(extensionAssemblyPathsOption) ?? Array.Empty(); var extensionLogDirectory = parseResult.GetValue(extensionLogDirectoryOption)!; @@ -220,7 +212,6 @@ static CliRootCommand CreateCommandLineParser() StarredCompletionsPath: starredCompletionsPath, TelemetryLevel: telemetryLevel, SessionId: sessionId, - SharedDependenciesPath: sharedDependenciesPath, ExtensionAssemblyPaths: extensionAssemblyPaths, ExtensionLogDirectory: extensionLogDirectory); diff --git a/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/ServerConfigurationFactory.cs b/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/ServerConfigurationFactory.cs index 68238e47b3e04..021a4e2d91f3a 100644 --- a/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/ServerConfigurationFactory.cs +++ b/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/ServerConfigurationFactory.cs @@ -34,8 +34,8 @@ public void InitializeConfiguration(ServerConfiguration serverConfiguration) // Update any other global options based on the configuration the server was started with. - // Use the SharedDependenciesPath option as a proxy for whether or not devkit is running. - var isDevkitEnabled = !string.IsNullOrEmpty(serverConfiguration.SharedDependenciesPath); + // Check if the devkit extension is included to see if devkit is enabled. + var isDevkitEnabled = serverConfiguration.ExtensionAssemblyPaths.Contains("Microsoft.VisualStudio.LanguageServices.DevKit.dll"); // Set the standalone option so other features know whether devkit is running. _globalOptionService.SetGlobalOption(LspOptionsStorage.LspUsingDevkitFeatures, isDevkitEnabled); } @@ -47,6 +47,5 @@ internal record class ServerConfiguration( string? StarredCompletionsPath, string? TelemetryLevel, string? SessionId, - string? SharedDependenciesPath, IEnumerable ExtensionAssemblyPaths, string ExtensionLogDirectory); diff --git a/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/Services/AssemblyLoadContextWrapper.cs b/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/Services/AssemblyLoadContextWrapper.cs index d61012c2aafb7..0d963eaf353e7 100644 --- a/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/Services/AssemblyLoadContextWrapper.cs +++ b/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/Services/AssemblyLoadContextWrapper.cs @@ -20,8 +20,6 @@ namespace Microsoft.CodeAnalysis.LanguageServer.Services { internal sealed class AssemblyLoadContextWrapper : IDisposable { - private static readonly ConcurrentDictionary s_loadedSharedAssemblies = new(AssemblyNameComparer.Default); - private AssemblyLoadContext? _assemblyLoadContext; private readonly ImmutableDictionary _loadedAssemblies; private readonly ILogger? _logger; @@ -33,7 +31,7 @@ private AssemblyLoadContextWrapper(AssemblyLoadContext assemblyLoadContext, Immu _logger = logger; } - public static bool TryLoadExtension(string assemblyFilePath, string? sharedDependenciesPath, ILogger? logger, [NotNullWhen(true)] out Assembly? assembly) + public static bool TryLoadExtension(string assemblyFilePath, ILogger? logger, [NotNullWhen(true)] out Assembly? assembly) { var dir = Path.GetDirectoryName(assemblyFilePath); var fileName = Path.GetFileName(assemblyFilePath); @@ -43,7 +41,7 @@ public static bool TryLoadExtension(string assemblyFilePath, string? sharedDepen Contract.ThrowIfNull(fileName); Contract.ThrowIfNull(fileNameNoExt); - var loadContext = TryCreate(fileNameNoExt, dir, sharedDependenciesPath, logger); + var loadContext = TryCreate(fileNameNoExt, dir, logger); if (loadContext != null) { assembly = loadContext.GetAssembly(fileName); @@ -54,11 +52,11 @@ public static bool TryLoadExtension(string assemblyFilePath, string? sharedDepen return false; } - public static AssemblyLoadContextWrapper? TryCreate(string name, string assembliesDirectoryPath, string? sharedDependenciesPath, ILogger? logger) + public static AssemblyLoadContextWrapper? TryCreate(string name, string assembliesDirectoryPath, ILogger? logger) { try { - var loadContext = CreateLoadContext(name, sharedDependenciesPath); + var loadContext = CreateLoadContext(name); var directory = new DirectoryInfo(assembliesDirectoryPath); var builder = new Dictionary(); foreach (var file in directory.GetFiles("*.dll")) @@ -75,39 +73,9 @@ public static bool TryLoadExtension(string assemblyFilePath, string? sharedDepen } } - private static AssemblyLoadContext CreateLoadContext(string name, string? sharedDependenciesPath) + private static AssemblyLoadContext CreateLoadContext(string name) { var loadContext = new AssemblyLoadContext(name); - - if (sharedDependenciesPath != null) - { - loadContext.Resolving += (_, assemblyName) => - { - if (assemblyName.Name is null) - { - return null; - } - - if (s_loadedSharedAssemblies.TryGetValue(assemblyName, out var loadedAssembly)) - { - return loadedAssembly; - } - - var candidatePath = assemblyName.CultureName is not null - ? Path.Combine(sharedDependenciesPath, assemblyName.CultureName, $"{assemblyName.Name}.dll") - : Path.Combine(sharedDependenciesPath, $"{assemblyName.Name}.dll"); - - if (File.Exists(candidatePath)) - { - loadedAssembly = loadContext.LoadFromAssemblyPath(candidatePath); - } - - s_loadedSharedAssemblies.TryAdd(assemblyName, loadedAssembly); - - return s_loadedSharedAssemblies[assemblyName]; - }; - } - return loadContext; } diff --git a/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/Services/StarredCompletions/StarredCompletionsAssemblyHelper.cs b/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/Services/StarredCompletions/StarredCompletionsAssemblyHelper.cs index 03a581634f047..70d7aeda9f716 100644 --- a/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/Services/StarredCompletions/StarredCompletionsAssemblyHelper.cs +++ b/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/Services/StarredCompletions/StarredCompletionsAssemblyHelper.cs @@ -88,7 +88,7 @@ internal static void InitializeInstance(string? completionsAssemblyLocation, ILo try { - var alc = AssemblyLoadContextWrapper.TryCreate(ALCName, s_completionsAssemblyLocation, sharedDependenciesPath: null, s_logger); + var alc = AssemblyLoadContextWrapper.TryCreate(ALCName, s_completionsAssemblyLocation, s_logger); if (alc is null) { s_previousCreationFailed = true; diff --git a/src/VisualStudio/DevKit/Impl/.npmrc b/src/VisualStudio/DevKit/Impl/.npmrc deleted file mode 100644 index 816fed5f83098..0000000000000 --- a/src/VisualStudio/DevKit/Impl/.npmrc +++ /dev/null @@ -1,3 +0,0 @@ -# This must be located directly next to the package.json for compliance. -registry=https://pkgs.dev.azure.com/dnceng/internal/_packaging/dotnet-tools-internal/npm/registry/ -always-auth=true \ No newline at end of file diff --git a/src/VisualStudio/DevKit/Impl/Microsoft.VisualStudio.LanguageServices.DevKit.csproj b/src/VisualStudio/DevKit/Impl/Microsoft.VisualStudio.LanguageServices.DevKit.csproj index 7bae3eb83e73e..74252a98df551 100644 --- a/src/VisualStudio/DevKit/Impl/Microsoft.VisualStudio.LanguageServices.DevKit.csproj +++ b/src/VisualStudio/DevKit/Impl/Microsoft.VisualStudio.LanguageServices.DevKit.csproj @@ -8,97 +8,54 @@ .NET Compiler Platform ("Roslyn") Language Server Protocol internal. - true + true + CollectPackInputs;$(BeforePack) + + + NU5100 - - - - - - - - - - - - - - - DoNotUse - + + + + - - - - - - - - - - - - - - - $(StageForNpmPackDependsOn);CollectNpmInputs - - - - - $(PackageVersion) - - - - - - + + + - - - - - - - - - - + + + + + + - - - diff --git a/src/VisualStudio/DevKit/Impl/package.json b/src/VisualStudio/DevKit/Impl/package.json deleted file mode 100644 index cf3f56c469c13..0000000000000 --- a/src/VisualStudio/DevKit/Impl/package.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "name": "@microsoft/visualstudio-languageservices-devkit", - "version": "0.0.1" -} \ No newline at end of file diff --git a/src/Workspaces/Remote/Core/Microsoft.CodeAnalysis.Remote.Workspaces.csproj b/src/Workspaces/Remote/Core/Microsoft.CodeAnalysis.Remote.Workspaces.csproj index 65661b2402c51..f687db6f14a0a 100644 --- a/src/Workspaces/Remote/Core/Microsoft.CodeAnalysis.Remote.Workspaces.csproj +++ b/src/Workspaces/Remote/Core/Microsoft.CodeAnalysis.Remote.Workspaces.csproj @@ -52,6 +52,7 @@ + From d7a1d67a02feaa72b0efb6fbf8ce0c3396ab233f Mon Sep 17 00:00:00 2001 From: David Barbet Date: Mon, 20 Nov 2023 10:59:20 -0800 Subject: [PATCH 2/2] fix --- .../ServerConfigurationFactory.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/ServerConfigurationFactory.cs b/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/ServerConfigurationFactory.cs index 021a4e2d91f3a..8a4b5fcb2c366 100644 --- a/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/ServerConfigurationFactory.cs +++ b/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/ServerConfigurationFactory.cs @@ -35,7 +35,7 @@ public void InitializeConfiguration(ServerConfiguration serverConfiguration) // Update any other global options based on the configuration the server was started with. // Check if the devkit extension is included to see if devkit is enabled. - var isDevkitEnabled = serverConfiguration.ExtensionAssemblyPaths.Contains("Microsoft.VisualStudio.LanguageServices.DevKit.dll"); + var isDevkitEnabled = serverConfiguration.ExtensionAssemblyPaths.Any(path => Path.GetFileName(path) == "Microsoft.VisualStudio.LanguageServices.DevKit.dll"); // Set the standalone option so other features know whether devkit is running. _globalOptionService.SetGlobalOption(LspOptionsStorage.LspUsingDevkitFeatures, isDevkitEnabled); }