Skip to content

Commit

Permalink
fix: project script resolution issues (#21)
Browse files Browse the repository at this point in the history
* .ppj fix progress.

* Always add ambient program, regardless of presence of workspaces with projects.

* fix: project script elements and script file resolution bugs.
  • Loading branch information
joelday authored Mar 22, 2019
1 parent cb44cfe commit 88be93f
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 120 deletions.
79 changes: 4 additions & 75 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand All @@ -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}",
Expand All @@ -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}",
Expand All @@ -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}",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using DarkId.Papyrus.Common;
Expand Down Expand Up @@ -48,7 +49,7 @@ public static async Task<Dictionary<ObjectIdentifier, string>> ResolveSourceFile
return new Tuple<SourceInclude, IEnumerable<string>>(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<SourceInclude, IEnumerable<string>>(include, files);
})
.ToArray());
Expand Down
4 changes: 3 additions & 1 deletion src/DarkId.Papyrus.LanguageService/Program/ProgramOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
};
Expand All @@ -42,5 +43,6 @@ public class SourceInclude
{
public string Path { get; set; }
public bool Recursive { get; set; } = true;
public List<string> Scripts { get; set; } = new List<string>();
}
}
8 changes: 4 additions & 4 deletions src/DarkId.Papyrus.LanguageService/Projects/PapyrusProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{

Expand Down Expand Up @@ -37,7 +37,7 @@ public class PapyrusProject
private bool finalFieldSpecified;

/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("Import", IsNullable = false)]
[System.Xml.Serialization.XmlArrayItemAttribute("Import")]
public string[] Imports
{
get
Expand All @@ -51,7 +51,7 @@ public string[] Imports
}

/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("Folder", IsNullable = false)]
[System.Xml.Serialization.XmlArrayItemAttribute("Folder")]
public FolderType[] Folders
{
get
Expand All @@ -65,7 +65,7 @@ public FolderType[] Folders
}

/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("Script", IsNullable = false)]
[System.Xml.Serialization.XmlArrayItemAttribute("Script")]
public string[] Scripts
{
get
Expand Down
23 changes: 20 additions & 3 deletions src/DarkId.Papyrus.LanguageService/Projects/ProgramExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/DarkId.Papyrus.Server/ProjectManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public IEnumerable<ProjectHost> 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)
Expand Down
21 changes: 2 additions & 19 deletions src/DarkId.Papyrus.Server/ProjectProgramOptionsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,25 +73,8 @@ public async Task<Dictionary<string, ProgramOptions>> 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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/DarkId.Papyrus.Test/scripts/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"search.useIgnoreFiles": false,
"search.useIgnoreFiles": false
}
2 changes: 1 addition & 1 deletion src/DarkId.Papyrus.Test/scripts/Fallout4.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[Papyrus]
sScriptSourceFolder="Fallout 4"
sScriptSourceFolder="Fallout 4"
2 changes: 1 addition & 1 deletion src/DarkId.Papyrus.Test/scripts/Skyrim.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[Papyrus]
sScriptSourceFolder="Skyrim"
sScriptSourceFolder="Skyrim"
11 changes: 11 additions & 0 deletions src/DarkId.Papyrus.Test/scripts/Skyrim/Skyrim_1.ppj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version='1.0'?>
<PapyrusProject xmlns="PapyrusProject.xsd"
Flags="TESV_Papyrus_Flags.flg">
<Imports>
</Imports>

<Scripts>
<Script>BaseScript.psc</Script>
<Script>ScriptObject</Script>
</Scripts>
</PapyrusProject>
6 changes: 3 additions & 3 deletions src/papyrus-lang-vscode/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 15 additions & 10 deletions src/papyrus-lang-vscode/src/server/LanguageClientHost.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 88be93f

Please sign in to comment.