Skip to content

Commit

Permalink
Merge pull request #70875 from dibarbet/remove_npm
Browse files Browse the repository at this point in the history
Ship Devkit dependencies as a nuget package to support directly including in the C# extension
  • Loading branch information
dibarbet authored Nov 21, 2023
2 parents ce6f532 + d7a1d67 commit d1b2e28
Show file tree
Hide file tree
Showing 18 changed files with 37 additions and 167 deletions.
2 changes: 0 additions & 2 deletions Roslyn.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 0 additions & 15 deletions azure-pipelines-official.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@
<MicrosoftVisualStudioImageCatalogVersion>$(MicrosoftVisualStudioShellPackagesVersion)</MicrosoftVisualStudioImageCatalogVersion>
<MicrosoftVisualStudioImagingVersion>$(MicrosoftVisualStudioShellPackagesVersion)</MicrosoftVisualStudioImagingVersion>
<MicrosoftVisualStudioImagingInterop140DesignTimeVersion>17.8.36726</MicrosoftVisualStudioImagingInterop140DesignTimeVersion>
<MicrosoftVisualStudioInternalMicroBuildNpmPackVersion>2.0.93</MicrosoftVisualStudioInternalMicroBuildNpmPackVersion>
<MicrosoftVisualStudioInteropVersion>17.8.36711</MicrosoftVisualStudioInteropVersion>
<MicrosoftVisualStudioLanguageVersion>$(VisualStudioEditorPackagesVersion)</MicrosoftVisualStudioLanguageVersion>
<MicrosoftVisualStudioLanguageCallHierarchyVersion>15.8.27812-alpha</MicrosoftVisualStudioLanguageCallHierarchyVersion>
Expand Down
11 changes: 0 additions & 11 deletions eng/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,6 @@ function BuildSolution() {

$restoreUseStaticGraphEvaluation = $true

$isNpmAvailable = IsNpmAvailable

try {
MSBuild $toolsetBuildProj `
$bl `
Expand All @@ -282,7 +280,6 @@ function BuildSolution() {
/p:RestoreUseStaticGraphEvaluation=$restoreUseStaticGraphEvaluation `
/p:VisualStudioIbcDrop=$ibcDropName `
/p:VisualStudioDropAccessToken=$officialVisualStudioDropAccessToken `
/p:IsNpmPackable=$isNpmAvailable `
$suppressExtensionDeployment `
$msbuildWarnAsError `
$buildFromSource `
Expand Down Expand Up @@ -713,14 +710,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)"
Expand Down
2 changes: 1 addition & 1 deletion eng/config/PublishData.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 0 additions & 5 deletions eng/publish-assets.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 0 additions & 5 deletions eng/targets/Settings.props
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@
<PublishWindowsPdb>false</PublishWindowsPdb>
<EnforceExtendedAnalyzerRules>false</EnforceExtendedAnalyzerRules>
<EnforceExtendedAnalyzerRules Condition="'$(IsAnalyzer)' == 'true'">true</EnforceExtendedAnalyzerRules>

<!-- NPM packaging settings -->
<NpmPackageOutputPath>$(ArtifactsDir)\packages\$(Configuration)\NPM\</NpmPackageOutputPath>
<!-- By default don't attempt to do npm packaging during pack since it requires NPM to be installed -->
<IsNpmPackable Condition="'$(IsNpmPackable)'==''">false</IsNpmPackable>
</PropertyGroup>

<!--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
-->
<Target Name="_CopyDevKitExtensionFiles" AfterTargets="ResolveProjectReferences">
<MSBuild Projects="..\..\..\VisualStudio\DevKit\Impl\Microsoft.VisualStudio.LanguageServices.DevKit.csproj"
Targets="CollectNpmInputs">
Targets="CollectPackInputs">
<Output TaskParameter="TargetOutputs" ItemName="_DevKitExtensionFile"/>
</MSBuild>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ private static string GetDevKitExtensionPath()
=> Path.Combine(AppContext.BaseDirectory, DevKitExtensionSubdirectory, DevKitAssemblyFileName);

public static Task<ExportProvider> CreateExportProviderAsync(ILoggerFactory loggerFactory, bool includeDevKitComponents)
=> ExportProviderBuilder.CreateExportProviderAsync(extensionAssemblyPaths: includeDevKitComponents ? [GetDevKitExtensionPath()] : Array.Empty<string>(), sharedDependenciesPath: null, loggerFactory);
=> ExportProviderBuilder.CreateExportProviderAsync(extensionAssemblyPaths: includeDevKitComponents ? [GetDevKitExtensionPath()] : Array.Empty<string>(), loggerFactory: loggerFactory);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Microsoft.CodeAnalysis.LanguageServer;

internal sealed class ExportProviderBuilder
{
public static async Task<ExportProvider> CreateExportProviderAsync(IEnumerable<string> extensionAssemblyPaths, string? sharedDependenciesPath, ILoggerFactory loggerFactory)
public static async Task<ExportProvider> CreateExportProviderAsync(IEnumerable<string> extensionAssemblyPaths, ILoggerFactory loggerFactory)
{
var logger = loggerFactory.CreateLogger<ExportProviderBuilder>();

Expand Down Expand Up @@ -48,7 +48,7 @@ public static async Task<ExportProvider> CreateExportProviderAsync(IEnumerable<s

foreach (var extensionAssemblyPath in extensionAssemblyPaths)
{
if (AssemblyLoadContextWrapper.TryLoadExtension(extensionAssemblyPath, sharedDependenciesPath, logger, out var extensionAssembly))
if (AssemblyLoadContextWrapper.TryLoadExtension(extensionAssemblyPath, logger, out var extensionAssembly))
{
assemblies.Add(extensionAssembly);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ static async Task RunAsync(ServerConfiguration serverConfiguration, Cancellation

logger.LogTrace($".NET Runtime Version: {RuntimeInformation.FrameworkDescription}");

using var exportProvider = await ExportProviderBuilder.CreateExportProviderAsync(serverConfiguration.ExtensionAssemblyPaths, serverConfiguration.SharedDependenciesPath, loggerFactory);
using var exportProvider = await ExportProviderBuilder.CreateExportProviderAsync(serverConfiguration.ExtensionAssemblyPaths, loggerFactory);

// The log file directory passed to us by VSCode might not exist yet, though its parent directory is guaranteed to exist.
Directory.CreateDirectory(serverConfiguration.ExtensionLogDirectory);
Expand Down Expand Up @@ -179,12 +179,6 @@ static CliRootCommand CreateCommandLineParser()
Required = false
};

var sharedDependenciesOption = new CliOption<string?>("--sharedDependencies")
{
Description = "Full path of the directory containing shared assemblies (optional).",
Required = false
};

var extensionAssemblyPathsOption = new CliOption<string[]?>("--extension", "--extensions") // TODO: remove plural form
{
Description = "Full paths of extension assemblies to load (optional).",
Expand All @@ -199,7 +193,6 @@ static CliRootCommand CreateCommandLineParser()
starredCompletionsPathOption,
telemetryLevelOption,
sessionIdOption,
sharedDependenciesOption,
extensionAssemblyPathsOption,
extensionLogDirectoryOption
};
Expand All @@ -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<string>();
var extensionLogDirectory = parseResult.GetValue(extensionLogDirectoryOption)!;
Expand All @@ -220,7 +212,6 @@ static CliRootCommand CreateCommandLineParser()
StarredCompletionsPath: starredCompletionsPath,
TelemetryLevel: telemetryLevel,
SessionId: sessionId,
SharedDependenciesPath: sharedDependenciesPath,
ExtensionAssemblyPaths: extensionAssemblyPaths,
ExtensionLogDirectory: extensionLogDirectory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.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);
}
Expand All @@ -47,6 +47,5 @@ internal record class ServerConfiguration(
string? StarredCompletionsPath,
string? TelemetryLevel,
string? SessionId,
string? SharedDependenciesPath,
IEnumerable<string> ExtensionAssemblyPaths,
string ExtensionLogDirectory);
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ namespace Microsoft.CodeAnalysis.LanguageServer.Services
{
internal sealed class AssemblyLoadContextWrapper : IDisposable
{
private static readonly ConcurrentDictionary<AssemblyName, Assembly?> s_loadedSharedAssemblies = new(AssemblyNameComparer.Default);

private AssemblyLoadContext? _assemblyLoadContext;
private readonly ImmutableDictionary<string, Assembly> _loadedAssemblies;
private readonly ILogger? _logger;
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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<string, Assembly>();
foreach (var file in directory.GetFiles("*.dll"))
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 0 additions & 3 deletions src/VisualStudio/DevKit/Impl/.npmrc

This file was deleted.

Loading

0 comments on commit d1b2e28

Please sign in to comment.