From 88be93f3211b6da8cfb178b018905eae67f40984 Mon Sep 17 00:00:00 2001 From: Joel Day Date: Fri, 22 Mar 2019 12:59:56 -0700 Subject: [PATCH] fix: project script resolution issues (#21) * .ppj fix progress. * Always add ambient program, regardless of presence of workspaces with projects. * fix: project script elements and script file resolution bugs. --- .vscode/launch.json | 79 +------------------ .../Program/ProgramExtensions.cs | 3 +- .../Program/ProgramOptions.cs | 4 +- .../Projects/PapyrusProject.cs | 8 +- .../Projects/ProgramExtensions.cs | 23 +++++- src/DarkId.Papyrus.Server/ProjectManager.cs | 2 +- .../ProjectProgramOptionsProvider.cs | 21 +---- .../scripts/.vscode/settings.json | 2 +- src/DarkId.Papyrus.Test/scripts/Fallout4.ini | 2 +- src/DarkId.Papyrus.Test/scripts/Skyrim.ini | 2 +- .../scripts/Skyrim/Skyrim_1.ppj | 11 +++ .../Skyrim/{Skyrim.ppj => Skyrim_2.ppj} | 0 src/papyrus-lang-vscode/package-lock.json | 6 +- .../src/server/LanguageClientHost.ts | 25 +++--- 14 files changed, 68 insertions(+), 120 deletions(-) create mode 100644 src/DarkId.Papyrus.Test/scripts/Skyrim/Skyrim_1.ppj rename src/DarkId.Papyrus.Test/scripts/Skyrim/{Skyrim.ppj => Skyrim_2.ppj} (100%) diff --git a/.vscode/launch.json b/.vscode/launch.json index 7c490464..754a74ba 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -5,78 +5,7 @@ "version": "0.2.0", "configurations": [ { - "name": "Launch Host (Mono)", - "type": "mono", - "request": "launch", - "program": "${workspaceRoot}/src/DarkId.Papyrus.Host/bin/Debug/net461/DarkId.Papyrus.Host.exe", - "cwd": "${workspaceRoot}", - "console": "integratedTerminal" - }, - { - "name": "Attach to Host (Mono)", - "type": "mono", - "request": "attach", - "port": 2077, - "address": "localhost" - }, - { - "name": "Launch (Full Build)", - "type": "extensionHost", - "request": "launch", - "runtimeExecutable": "${execPath}", - "preLaunchTask": "build", - "args": [ - "--extensionDevelopmentPath=${workspaceFolder}/src/papyrus-lang-vscode" - ], - "outFiles": ["${workspaceFolder}/src/papyrus-lang-vscode/out/**/*.js"], - "env": { - "PAPYRUS_EXTENSION_DEBUG": "1" - } - }, - { - "name": "Launch (Build Bin Only)", - "type": "extensionHost", - "request": "launch", - "runtimeExecutable": "${execPath}", - "preLaunchTask": "updateBin", - "args": [ - "--extensionDevelopmentPath=${workspaceFolder}/src/papyrus-lang-vscode" - ], - "outFiles": ["${workspaceFolder}/src/papyrus-lang-vscode/out/**/*.js"], - "env": { - "PAPYRUS_EXTENSION_DEBUG": "1" - } - }, - { - "name": "Launch (Build TS Only)", - "type": "extensionHost", - "request": "launch", - "runtimeExecutable": "${execPath}", - "preLaunchTask": "buildExtension", - "args": [ - "--extensionDevelopmentPath=${workspaceFolder}/src/papyrus-lang-vscode" - ], - "outFiles": ["${workspaceFolder}/src/papyrus-lang-vscode/out/**/*.js"], - "env": { - "PAPYRUS_EXTENSION_DEBUG": "1" - }, - "internalConsoleOptions": "openOnFirstSessionStart" - }, - { - "name": "Launch (No Build)", - "type": "extensionHost", - "request": "launch", - "runtimeExecutable": "${execPath}", - "args": [ - "--extensionDevelopmentPath=${workspaceFolder}/src/papyrus-lang-vscode" - ], - "outFiles": ["${workspaceFolder}/src/papyrus-lang-vscode/out/**/*.js"], - "env": { - "PAPYRUS_EXTENSION_DEBUG": "1" - } - }, - { - "name": "Launch (Full, No Debug)", + "name": "Launch (Full build)", "type": "extensionHost", "request": "launch", "runtimeExecutable": "${execPath}", @@ -87,7 +16,7 @@ "outFiles": ["${workspaceFolder}/src/papyrus-lang-vscode/out/**/*.js"] }, { - "name": "Launch (Bin, No Debug)", + "name": "Launch (Copy binaries only)", "type": "extensionHost", "request": "launch", "runtimeExecutable": "${execPath}", @@ -98,7 +27,7 @@ "outFiles": ["${workspaceFolder}/src/papyrus-lang-vscode/out/**/*.js"] }, { - "name": "Launch (TS, No Debug)", + "name": "Launch (Build extension only)", "type": "extensionHost", "request": "launch", "runtimeExecutable": "${execPath}", @@ -109,7 +38,7 @@ "outFiles": ["${workspaceFolder}/src/papyrus-lang-vscode/out/**/*.js"] }, { - "name": "Launch (No Build, No Debug)", + "name": "Launch (No build)", "type": "extensionHost", "request": "launch", "runtimeExecutable": "${execPath}", diff --git a/src/DarkId.Papyrus.LanguageService/Program/ProgramExtensions.cs b/src/DarkId.Papyrus.LanguageService/Program/ProgramExtensions.cs index 4193742b..a458e80f 100644 --- a/src/DarkId.Papyrus.LanguageService/Program/ProgramExtensions.cs +++ b/src/DarkId.Papyrus.LanguageService/Program/ProgramExtensions.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Threading.Tasks; using DarkId.Papyrus.Common; @@ -48,7 +49,7 @@ public static async Task> ResolveSourceFile return new Tuple>(include, new string[] { }); } - var files = await fileSystem.FindFiles(include.Path, "*.psc", include.Recursive); + var files = include.Scripts.Count > 0 ? include.Scripts.ToList() : await fileSystem.FindFiles(include.Path, "*.psc", include.Recursive); return new Tuple>(include, files); }) .ToArray()); diff --git a/src/DarkId.Papyrus.LanguageService/Program/ProgramOptions.cs b/src/DarkId.Papyrus.LanguageService/Program/ProgramOptions.cs index edd8946b..9c0aee73 100644 --- a/src/DarkId.Papyrus.LanguageService/Program/ProgramOptions.cs +++ b/src/DarkId.Papyrus.LanguageService/Program/ProgramOptions.cs @@ -21,7 +21,8 @@ public ProgramOptions Clone() Includes = Sources.Includes.Select(include => new SourceInclude() { Path = include.Path, - Recursive = include.Recursive + Recursive = include.Recursive, + Scripts = include.Scripts }).ToList() } }; @@ -42,5 +43,6 @@ public class SourceInclude { public string Path { get; set; } public bool Recursive { get; set; } = true; + public List Scripts { get; set; } = new List(); } } \ No newline at end of file diff --git a/src/DarkId.Papyrus.LanguageService/Projects/PapyrusProject.cs b/src/DarkId.Papyrus.LanguageService/Projects/PapyrusProject.cs index e3237c5d..d66ccefd 100644 --- a/src/DarkId.Papyrus.LanguageService/Projects/PapyrusProject.cs +++ b/src/DarkId.Papyrus.LanguageService/Projects/PapyrusProject.cs @@ -6,7 +6,7 @@ namespace DarkId.Papyrus.LanguageService.Projects [System.Diagnostics.DebuggerStepThroughAttribute()] [System.ComponentModel.DesignerCategoryAttribute("code")] [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "PapyrusProject.xsd")] - [System.Xml.Serialization.XmlRootAttribute(Namespace = "PapyrusProject.xsd", IsNullable = false)] + [System.Xml.Serialization.XmlRootAttribute(Namespace = "PapyrusProject.xsd")] public class PapyrusProject { @@ -37,7 +37,7 @@ public class PapyrusProject private bool finalFieldSpecified; /// - [System.Xml.Serialization.XmlArrayItemAttribute("Import", IsNullable = false)] + [System.Xml.Serialization.XmlArrayItemAttribute("Import")] public string[] Imports { get @@ -51,7 +51,7 @@ public string[] Imports } /// - [System.Xml.Serialization.XmlArrayItemAttribute("Folder", IsNullable = false)] + [System.Xml.Serialization.XmlArrayItemAttribute("Folder")] public FolderType[] Folders { get @@ -65,7 +65,7 @@ public FolderType[] Folders } /// - [System.Xml.Serialization.XmlArrayItemAttribute("Script", IsNullable = false)] + [System.Xml.Serialization.XmlArrayItemAttribute("Script")] public string[] Scripts { get diff --git a/src/DarkId.Papyrus.LanguageService/Projects/ProgramExtensions.cs b/src/DarkId.Papyrus.LanguageService/Projects/ProgramExtensions.cs index e2e23b8c..858fba62 100644 --- a/src/DarkId.Papyrus.LanguageService/Projects/ProgramExtensions.cs +++ b/src/DarkId.Papyrus.LanguageService/Projects/ProgramExtensions.cs @@ -12,22 +12,39 @@ public static class ProgramExtensions { public static ProgramOptionsBuilder WithProject(this ProgramOptionsBuilder builder, PapyrusProjectInfo projectInfo) { + var projectFileDirectory = Path.GetDirectoryName(PathUtilities.Normalize(projectInfo.ProjectFile)); + builder.WithName(Path.GetFileNameWithoutExtension(projectInfo.ProjectFile)) .WithFlagsFileName(projectInfo.Project.Flags) .WithSourceIncludes(projectInfo.Project.Imports.Select(import => new SourceInclude() { - Path = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(PathUtilities.Normalize(projectInfo.ProjectFile)), PathUtilities.Normalize(import))) + Path = Path.GetFullPath(Path.Combine(projectFileDirectory, PathUtilities.Normalize(import))) })); - if (projectInfo.Project.Folders.Length > 0) + if (projectInfo.Project.Folders != null && projectInfo.Project.Folders.Length > 0) { var folder = projectInfo.Project.Folders[0]; builder.WithSourceIncludes(new SourceInclude() { - Path = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(PathUtilities.Normalize(projectInfo.ProjectFile)), PathUtilities.Normalize(folder.Value))), + Path = Path.GetFullPath(Path.Combine(projectFileDirectory, PathUtilities.Normalize(folder.Value))), Recursive = !folder.NoRecurse }); } + else if (projectInfo.Project.Scripts != null && projectInfo.Project.Scripts.Length > 0) + { + var scriptsInclude = new SourceInclude() + { + Path = projectFileDirectory + }; + + foreach (var script in projectInfo.Project.Scripts) + { + var scriptWithExtension = Path.HasExtension(script) ? script : script + ".psc"; + scriptsInclude.Scripts.Add(Path.GetFullPath(Path.Combine(projectFileDirectory, PathUtilities.Normalize(scriptWithExtension)))); + } + + builder.WithSourceIncludes(scriptsInclude); + } return builder; } diff --git a/src/DarkId.Papyrus.Server/ProjectManager.cs b/src/DarkId.Papyrus.Server/ProjectManager.cs index 13025de5..f60e6cc6 100644 --- a/src/DarkId.Papyrus.Server/ProjectManager.cs +++ b/src/DarkId.Papyrus.Server/ProjectManager.cs @@ -59,7 +59,7 @@ public IEnumerable Projects public ScriptFile GetScriptForFilePath(string filePath) { - return _projectHosts.Values.Select(p => p.Program.GetScriptForFilePath(filePath)).FirstOrDefault(); + return _projectHosts.Values.Select(p => p.Program.GetScriptForFilePath(filePath)).WhereNotNull().FirstOrDefault(); } public Task PublishDiagnosticsForFilePath(string filePath) diff --git a/src/DarkId.Papyrus.Server/ProjectProgramOptionsProvider.cs b/src/DarkId.Papyrus.Server/ProjectProgramOptionsProvider.cs index fb0408bf..403bcbd6 100644 --- a/src/DarkId.Papyrus.Server/ProjectProgramOptionsProvider.cs +++ b/src/DarkId.Papyrus.Server/ProjectProgramOptionsProvider.cs @@ -73,25 +73,8 @@ public async Task> GetProgramOptions() .Where(p => p.Item2.FlagsFileName.CaseInsensitiveEquals(_projectFlagsFileName)) .ToDictionary(p => p.Item1, p => p.Item2); - var workspacesWithoutProjects = workspaceProjectFiles.Where(p => p.Value.Count() == 0).Select(p => p.Key); - if (workspacesWithoutProjects.Any()) - { - // var ambientOptions = _ambientOptionsProvider.GetAmbientProgramOptions(); - // foreach (var ambientWorkspacePath in workspacesWithoutProjects) - // { - // var workspaceAmbientOptions = ambientOptions.Clone(); - // workspaceAmbientOptions.Name = Path.GetFileName(ambientWorkspacePath); - // workspaceAmbientOptions.Sources.Includes.Insert(0, new SourceInclude() - // { - // Path = ambientWorkspacePath - // }); - - // options.Add(ambientWorkspacePath, workspaceAmbientOptions); - // } - - var ambientOptions = _ambientOptionsProvider.GetAmbientProgramOptions(); - options.Add(ambientOptions.Name, ambientOptions); - } + var ambientOptions = _ambientOptionsProvider.GetAmbientProgramOptions(); + options.Add(ambientOptions.Name, ambientOptions); return options; } diff --git a/src/DarkId.Papyrus.Test/scripts/.vscode/settings.json b/src/DarkId.Papyrus.Test/scripts/.vscode/settings.json index 20a4e56b..625e5abf 100644 --- a/src/DarkId.Papyrus.Test/scripts/.vscode/settings.json +++ b/src/DarkId.Papyrus.Test/scripts/.vscode/settings.json @@ -1,3 +1,3 @@ { - "search.useIgnoreFiles": false, + "search.useIgnoreFiles": false } diff --git a/src/DarkId.Papyrus.Test/scripts/Fallout4.ini b/src/DarkId.Papyrus.Test/scripts/Fallout4.ini index 176668f9..5260e0e7 100644 --- a/src/DarkId.Papyrus.Test/scripts/Fallout4.ini +++ b/src/DarkId.Papyrus.Test/scripts/Fallout4.ini @@ -1,2 +1,2 @@ [Papyrus] -sScriptSourceFolder="Fallout 4" +sScriptSourceFolder="Fallout 4" \ No newline at end of file diff --git a/src/DarkId.Papyrus.Test/scripts/Skyrim.ini b/src/DarkId.Papyrus.Test/scripts/Skyrim.ini index ae069cd3..c75c8bca 100644 --- a/src/DarkId.Papyrus.Test/scripts/Skyrim.ini +++ b/src/DarkId.Papyrus.Test/scripts/Skyrim.ini @@ -1,2 +1,2 @@ [Papyrus] -sScriptSourceFolder="Skyrim" +sScriptSourceFolder="Skyrim" \ No newline at end of file diff --git a/src/DarkId.Papyrus.Test/scripts/Skyrim/Skyrim_1.ppj b/src/DarkId.Papyrus.Test/scripts/Skyrim/Skyrim_1.ppj new file mode 100644 index 00000000..7d13cfe9 --- /dev/null +++ b/src/DarkId.Papyrus.Test/scripts/Skyrim/Skyrim_1.ppj @@ -0,0 +1,11 @@ + + + + + + + + + + \ No newline at end of file diff --git a/src/DarkId.Papyrus.Test/scripts/Skyrim/Skyrim.ppj b/src/DarkId.Papyrus.Test/scripts/Skyrim/Skyrim_2.ppj similarity index 100% rename from src/DarkId.Papyrus.Test/scripts/Skyrim/Skyrim.ppj rename to src/DarkId.Papyrus.Test/scripts/Skyrim/Skyrim_2.ppj diff --git a/src/papyrus-lang-vscode/package-lock.json b/src/papyrus-lang-vscode/package-lock.json index 1995d9d9..12b4cd98 100644 --- a/src/papyrus-lang-vscode/package-lock.json +++ b/src/papyrus-lang-vscode/package-lock.json @@ -246,9 +246,9 @@ "dev": true }, "@types/node": { - "version": "11.9.4", - "resolved": "https://registry.npmjs.org/@types/node/-/node-11.9.4.tgz", - "integrity": "sha512-Zl8dGvAcEmadgs1tmSPcvwzO1YRsz38bVJQvH1RvRqSR9/5n61Q1ktcDL0ht3FXWR+ZpVmXVwN1LuH4Ax23NsA==", + "version": "11.11.4", + "resolved": "https://registry.npmjs.org/@types/node/-/node-11.11.4.tgz", + "integrity": "sha512-02tIL+QIi/RW4E5xILdoAMjeJ9kYq5t5S2vciUdFPXv/ikFTb0zK8q9vXkg4+WAJuYXGiVT1H28AkD2C+IkXVw==", "dev": true }, "@types/winreg": { diff --git a/src/papyrus-lang-vscode/src/server/LanguageClientHost.ts b/src/papyrus-lang-vscode/src/server/LanguageClientHost.ts index a4bae3f8..8e567b9e 100644 --- a/src/papyrus-lang-vscode/src/server/LanguageClientHost.ts +++ b/src/papyrus-lang-vscode/src/server/LanguageClientHost.ts @@ -1,6 +1,6 @@ import { Disposable, ExtensionContext, OutputChannel, window, TextDocument } from 'vscode'; -import { LanguageClient, ILanguageClient } from './LanguageClient'; +import { LanguageClient, ILanguageClient, IToolArguments } from './LanguageClient'; import { PapyrusGame, getShortDisplayNameForGame } from '../PapyrusGame'; import { IGameConfig } from '../ExtensionConfigProvider'; import { Observable, BehaviorSubject } from 'rxjs'; @@ -98,19 +98,24 @@ export class LanguageClientHost implements ILanguageClientHost, Disposable { return; } + const toolArguments: IToolArguments = { + compilerAssemblyPath: this._creationKitInfo.resolvedCompilerPath, + creationKitInstallPath: this._creationKitInfo.resolvedInstallPath, + relativeIniPaths: this._config.creationKitIniFiles, + flagsFileName: getDefaultFlagsFileNameForGame(this._game), + ambientProjectName: `${getShortDisplayNameForGame(this._game)} Creation Kit`, + defaultScriptSourceFolder: this._creationKitInfo.config.Papyrus.sScriptSourceFolder, + defaultAdditionalImports: this._creationKitInfo.config.Papyrus.sAdditionalImports, + }; + + this._outputChannel.appendLine(`Creating Language Client instance with options:`); + this._outputChannel.appendLine(JSON.stringify(toolArguments)); + this._client = new LanguageClient({ game: this._game, toolPath: this._context.asAbsolutePath(getToolPath(this._game)), outputChannel: this._outputChannel, - toolArguments: { - compilerAssemblyPath: this._creationKitInfo.resolvedCompilerPath, - creationKitInstallPath: this._creationKitInfo.resolvedInstallPath, - relativeIniPaths: this._config.creationKitIniFiles, - flagsFileName: getDefaultFlagsFileNameForGame(this._game), - ambientProjectName: `${getShortDisplayNameForGame(this._game)} Creation Kit`, - defaultScriptSourceFolder: this._creationKitInfo.config.Papyrus.sScriptSourceFolder, - defaultAdditionalImports: this._creationKitInfo.config.Papyrus.sAdditionalImports, - }, + toolArguments, }); this._status.next(ClientHostStatus.starting);