Skip to content

Commit 20d939f

Browse files
committed
fix: Fixing file resolution and improving project browser performance.
1 parent ab8061b commit 20d939f

File tree

6 files changed

+32
-15
lines changed

6 files changed

+32
-15
lines changed

src/DarkId.Papyrus.DebugAdapterProxy/Program.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ static async Task<Dictionary<ObjectIdentifier, string>> ResolveSources(Options o
105105
var project = await projectLoader.LoadProject(options.ProjectPath);
106106

107107
var programOptions = new ProgramOptionsBuilder().WithProject(project).Build();
108-
return await fileSystem.ResolveSourceFiles(programOptions.Sources);
108+
var includes = await fileSystem.ResolveSourceFileIncludes(programOptions.Sources);
109+
return includes.ResolveSourceFiles();
109110
}
110111
else if (!string.IsNullOrEmpty(options.DefaultScriptSourceFolder) && !string.IsNullOrEmpty(options.DefaultAdditionalImports))
111112
{
@@ -137,7 +138,7 @@ static async Task<Dictionary<ObjectIdentifier, string>> ResolveSources(Options o
137138
loggerFactory.CreateLogger<CreationKitProgramOptionsProvider>());
138139

139140
var programOptions = programOptionsProvider.GetAmbientProgramOptions();
140-
return await fileSystem.ResolveSourceFiles(programOptions.Sources);
141+
return (await fileSystem.ResolveSourceFileIncludes(programOptions.Sources)).ResolveSourceFiles();
141142
}
142143

143144
return new Dictionary<ObjectIdentifier, string>();

src/DarkId.Papyrus.LanguageService/Program/PapyrusProgram.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,10 @@ public Task<string> GetFlagsFilePath()
8282
return _fileSystem.ResolveFlagsFile(_options);
8383
}
8484

85-
public async Task ResolveSources()
85+
public async Task<Dictionary<SourceInclude, Dictionary<ObjectIdentifier, string>>> ResolveSources()
8686
{
87-
var newFiles = await _fileSystem.ResolveSourceFiles(_options.Sources);
87+
var includes = await _fileSystem.ResolveSourceFileIncludes(_options.Sources);
88+
var newFiles = includes.ResolveSourceFiles();
8889

8990
lock (_lock)
9091
{
@@ -111,6 +112,8 @@ public async Task ResolveSources()
111112

112113
Task.WaitAll(fileSyncTask, filePathSyncTask);
113114
}
115+
116+
return includes;
114117
}
115118

116119
public void Dispose()

src/DarkId.Papyrus.LanguageService/Program/ProgramExtensions.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,11 @@ public static async Task<Dictionary<SourceInclude, Dictionary<ObjectIdentifier,
6565
foreach (var include in includedFiles)
6666
{
6767
var filePaths = new Dictionary<ObjectIdentifier, string>();
68+
var includePath = Path.GetFullPath(include.Item1.Path);
6869

6970
foreach (var fullPath in include.Item2)
7071
{
71-
var relativePath = fullPath.Substring(include.Item1.Path.Length + 1);
72+
var relativePath = fullPath.Substring(includePath.Length + 1);
7273
var identifier = ObjectIdentifier.FromScriptFilePath(relativePath);
7374

7475
filePaths.Add(identifier, fullPath);
@@ -80,15 +81,23 @@ public static async Task<Dictionary<SourceInclude, Dictionary<ObjectIdentifier,
8081
return results;
8182
}
8283

83-
public static async Task<Dictionary<ObjectIdentifier, string>> ResolveSourceFiles(this IFileSystem fileSystem, ProgramSources sources)
84+
public static Dictionary<ObjectIdentifier, string> ResolveSourceFiles(this Dictionary<SourceInclude, Dictionary<ObjectIdentifier, string>> includes)
8485
{
8586
var results = new Dictionary<ObjectIdentifier, string>();
87+
var fileIdentifiers = new Dictionary<string, ObjectIdentifier>();
8688

87-
foreach (var include in await fileSystem.ResolveSourceFileIncludes(sources))
89+
foreach (var include in includes)
8890
{
8991
foreach (var identifierFile in include.Value)
9092
{
93+
if (fileIdentifiers.ContainsKey(identifierFile.Value))
94+
{
95+
results.Remove(identifierFile.Key);
96+
fileIdentifiers.Remove(identifierFile.Value);
97+
}
98+
9199
results[identifierFile.Key] = identifierFile.Value;
100+
fileIdentifiers[identifierFile.Value] = identifierFile.Key;
92101
}
93102
}
94103

src/DarkId.Papyrus.Server/Features/ProjectInfosHandler.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,29 @@ namespace DarkId.Papyrus.Server.Features
2121
public class ProjectInfosHandler : IProjectInfosHandler
2222
{
2323
private readonly ProjectManager _projectManager;
24-
private readonly IFileSystem _fileSystem;
2524
private readonly ILogger _logger;
2625

27-
public ProjectInfosHandler(ProjectManager projectManager, IFileSystem fileSystem, ILogger<ProjectInfosHandler> logger)
26+
public ProjectInfosHandler(ProjectManager projectManager, ILogger<ProjectInfosHandler> logger)
2827
{
2928
_projectManager = projectManager;
30-
_fileSystem = fileSystem;
3129
_logger = logger;
3230
}
3331

3432
public Task<ProjectInfos> Handle(ProjectInfosParams request, CancellationToken cancellationToken)
3533
{
3634
return Task.FromResult(new ProjectInfos()
3735
{
38-
Projects = new Container<ProjectInfo>(_projectManager.Projects.Select(p =>
36+
Projects = new Container<ProjectInfo>(_projectManager.Projects.AsParallel().AsOrdered().Select(p =>
3937
{
38+
if (p.Sources == null)
39+
{
40+
p.ResolveSources();
41+
}
42+
4043
return new ProjectInfo()
4144
{
4245
Name = p.Name,
43-
SourceIncludes = new Container<ProjectInfoSourceInclude>(_fileSystem.ResolveSourceFileIncludes(p.Program.Options.Sources).WaitForResult().Select(include =>
46+
SourceIncludes = new Container<ProjectInfoSourceInclude>(p.Sources != null ? p.Sources.Select(include =>
4447
{
4548
var name = !string.IsNullOrEmpty(include.Key.Path) ? Path.GetFileName(include.Key.Path) : "Scripts";
4649

@@ -55,7 +58,7 @@ public Task<ProjectInfos> Handle(ProjectInfosParams request, CancellationToken c
5558
FilePath = script.Value
5659
}))
5760
};
58-
}))
61+
}) : Enumerable.Empty<ProjectInfoSourceInclude>())
5962
};
6063
}))
6164
});

src/DarkId.Papyrus.Server/ProjectHost.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ private void HandleScriptFileChanged(object sender, ScriptFileChangedEventArgs e
5555
}
5656

5757
public string Name => _name;
58+
public Dictionary<SourceInclude, Dictionary<ObjectIdentifier, string>> Sources { get; private set; }
5859

5960
public PapyrusProgram Program
6061
{
@@ -72,7 +73,7 @@ public void ResolveSources()
7273
lock (_lock)
7374
{
7475
_logger.LogInformation("Resolving script files for {0}...", Name);
75-
_program.ResolveSources().Wait();
76+
Sources = _program.ResolveSources().WaitForResult();
7677

7778
_logger.LogInformation("Done");
7879
}

src/papyrus-lang-vscode/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@
203203
"papyrus-views": [
204204
{
205205
"id": "papyrus-projects",
206-
"name": "Project Browser"
206+
"name": "Project Explorer"
207207
}
208208
]
209209
}

0 commit comments

Comments
 (0)