feat: add DSH IDE open-file references
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Prophet.CoopWithDsh
|
||||
{
|
||||
internal sealed class OpenDocument
|
||||
{
|
||||
[JsonProperty("path")] public string Path { get; set; } = string.Empty;
|
||||
[JsonProperty("label")] public string Label { get; set; } = string.Empty;
|
||||
[JsonProperty("dirty")] public bool Dirty { get; set; }
|
||||
}
|
||||
|
||||
internal sealed class OpenFileSnapshot
|
||||
{
|
||||
[JsonProperty("version")] public int Version { get; set; } = 1;
|
||||
[JsonProperty("instanceId")] public string InstanceId { get; set; } = string.Empty;
|
||||
[JsonProperty("ide")] public string Ide { get; set; } = "visualstudio";
|
||||
[JsonProperty("processId")] public int ProcessId { get; set; }
|
||||
[JsonProperty("workspace", NullValueHandling = NullValueHandling.Ignore)] public string? Workspace { get; set; }
|
||||
[JsonProperty("updatedAt")] public string UpdatedAt { get; set; } = string.Empty;
|
||||
[JsonProperty("documents")] public IReadOnlyList<OpenDocument> Documents { get; set; } = Array.Empty<OpenDocument>();
|
||||
}
|
||||
|
||||
internal static class SnapshotModel
|
||||
{
|
||||
internal static OpenFileSnapshot Create(string instanceId, int processId, string? workspace, IEnumerable<OpenDocument> documents, DateTimeOffset now)
|
||||
{
|
||||
var deduplicated = new Dictionary<string, OpenDocument>(StringComparer.OrdinalIgnoreCase);
|
||||
foreach (var document in documents.Where(d => !string.IsNullOrWhiteSpace(d.Path) && Path.IsPathRooted(d.Path)))
|
||||
{
|
||||
if (!deduplicated.TryGetValue(document.Path, out var current) || (!current.Dirty && document.Dirty))
|
||||
deduplicated[document.Path] = document;
|
||||
}
|
||||
return new OpenFileSnapshot
|
||||
{
|
||||
InstanceId = instanceId,
|
||||
ProcessId = processId,
|
||||
Workspace = string.IsNullOrWhiteSpace(workspace) ? null : workspace,
|
||||
UpdatedAt = now.UtcDateTime.ToString("O"),
|
||||
Documents = deduplicated.Values.OrderBy(d => d.Label, StringComparer.OrdinalIgnoreCase).ThenBy(d => d.Path, StringComparer.OrdinalIgnoreCase).ToArray(),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user