Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch API to immutable-array from params-array #74741

Merged
merged 2 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public async Task CreatingDirectoryWatchRequestsDirectoryWatch()
var tempDirectory = tempRoot.CreateDirectory();

// Try creating a context and ensure we created the registration
var context = lspFileChangeWatcher.CreateContext(new ProjectSystem.WatchedDirectory(tempDirectory.Path, extensionFilter: null));
var context = lspFileChangeWatcher.CreateContext([new ProjectSystem.WatchedDirectory(tempDirectory.Path, extensionFilter: null)]);
await WaitForFileWatcherAsync(testLspServer);

var watcher = GetSingleFileWatcher(dynamicCapabilitiesRpcTarget);
Expand Down Expand Up @@ -92,7 +92,7 @@ public async Task CreatingFileWatchRequestsFileWatch()
var tempDirectory = tempRoot.CreateDirectory();

// Try creating a single file watch and ensure we created the registration
var context = lspFileChangeWatcher.CreateContext();
var context = lspFileChangeWatcher.CreateContext([]);
var watchedFile = context.EnqueueWatchingFile("Z:\\SingleFile.txt");
await WaitForFileWatcherAsync(testLspServer);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Microsoft.Extensions.Logging;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using System.Collections.Immutable;

namespace Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.FileWatching;

Expand Down Expand Up @@ -50,8 +51,6 @@ private IFileChangeWatcher CreateFileWatcher()
}
}

public IFileChangeContext CreateContext(params WatchedDirectory[] watchedDirectories)
{
return _underlyingFileWatcher.Value.CreateContext(watchedDirectories);
}
public IFileChangeContext CreateContext(ImmutableArray<WatchedDirectory> watchedDirectories)
=> _underlyingFileWatcher.Value.CreateContext(watchedDirectories);
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,10 @@ public static bool SupportsLanguageServerHost(LanguageServerHost languageServerH
return clientCapabilitiesProvider.GetClientCapabilities().Workspace?.DidChangeWatchedFiles?.DynamicRegistration ?? false;
}

public IFileChangeContext CreateContext(params WatchedDirectory[] watchedDirectories)
{
return new FileChangeContext([.. watchedDirectories], this);
}
public IFileChangeContext CreateContext(ImmutableArray<WatchedDirectory> watchedDirectories)
=> new FileChangeContext(watchedDirectories, this);

private class FileChangeContext : IFileChangeContext
private sealed class FileChangeContext : IFileChangeContext
{
private readonly ImmutableArray<WatchedDirectory> _watchedDirectories;
private readonly LspFileChangeWatcher _lspFileChangeWatcher;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ namespace Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.FileWatching;
/// </remarks>
internal sealed class SimpleFileChangeWatcher : IFileChangeWatcher
{
public IFileChangeContext CreateContext(params WatchedDirectory[] watchedDirectories)
{
return new FileChangeContext([.. watchedDirectories]);
}
public IFileChangeContext CreateContext(ImmutableArray<WatchedDirectory> watchedDirectories)
=> new FileChangeContext(watchedDirectories);

private class FileChangeContext : IFileChangeContext
private sealed class FileChangeContext : IFileChangeContext
{
private readonly ImmutableArray<WatchedDirectory> _watchedDirectories;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,12 @@ public LoadedProject(ProjectSystemProject projectSystemProject, SolutionServices
// We'll watch the directory for all source file changes
// TODO: we only should listen for add/removals here, but we can't specify such a filter now
var projectDirectory = Path.GetDirectoryName(projectSystemProject.FilePath)!;
var watchedDirectories = new WatchedDirectory[]
{

_fileChangeContext = fileWatcher.CreateContext([
new(projectDirectory, ".cs"),
new(projectDirectory, ".cshtml"),
new(projectDirectory, ".razor")
};

_fileChangeContext = fileWatcher.CreateContext(watchedDirectories);
]);
_fileChangeContext.FileChanged += FileChangedContext_FileChanged;

// Start watching for file changes for the project file as well
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,8 @@ static int FindCombinableRange(ImmutableSegmentedList<WatcherOperation> operatio
}
}

public IFileChangeContext CreateContext(params WatchedDirectory[] watchedDirectories)
{
return new Context(this, watchedDirectories.ToImmutableArray());
}
public IFileChangeContext CreateContext(ImmutableArray<WatchedDirectory> watchedDirectories)
=> new Context(this, watchedDirectories.ToImmutableArray());
CyrusNajmabadi marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Represents an operation to subscribe or unsubscribe from <see cref="IVsAsyncFileChangeEx2"/> events. The
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void InitializeFileTracking(IFileChangeWatcher fileChangeWatcher)
includes = [FilePath];
}

_fileChangeContext = fileChangeWatcher.CreateContext();
_fileChangeContext = fileChangeWatcher.CreateContext([]);
_fileChangeContext.FileChanged += IncludeUpdated;

foreach (var include in includes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public FileWatchedPortableExecutableReferenceFactory(
referenceDirectories.Add(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".nuget", "packages"));
}

var directoriesToWatch = referenceDirectories.Select(static d => new WatchedDirectory(d, ".dll")).ToArray();
var directoriesToWatch = referenceDirectories.SelectAsArray(static d => new WatchedDirectory(d, ".dll"));
var fileReferenceChangeContext = fileChangeWatcher.CreateContext(directoriesToWatch);
fileReferenceChangeContext.FileChanged += FileReferenceChangeContext_FileChanged;
return fileReferenceChangeContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Microsoft.CodeAnalysis.ProjectSystem;

internal interface IFileChangeWatcher
{
IFileChangeContext CreateContext(params WatchedDirectory[] watchedDirectories);
IFileChangeContext CreateContext(ImmutableArray<WatchedDirectory> watchedDirectories);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,18 +204,14 @@ internal ProjectSystemProject(
_documentFileChangeContext = _projectSystemProjectFactory.FileChangeWatcher.CreateContext(watchedDirectories);
_documentFileChangeContext.FileChanged += DocumentFileChangeContext_FileChanged;

static WatchedDirectory[] GetWatchedDirectories(string? language, string? filePath)
static ImmutableArray<WatchedDirectory> GetWatchedDirectories(string? language, string? filePath)
{
if (filePath is null)
{
return [];
}

var rootPath = Path.GetDirectoryName(filePath);
if (rootPath is null)
{
return [];
}

return language switch
{
Expand Down
Loading