Skip to content

Commit

Permalink
chore: enable strict mode in tsconfig.json and fix resulting compile-…
Browse files Browse the repository at this point in the history
…time null/undefined and typing errors.

chore: Improvements to eventToValueObservable handling and typing of undefined.

chore: Removing ancient legacy debug plugin upgrade check.

fix: Ensure that language service status items are updated properly.

feat: Updated welcome message with debugger upgrade info.

fix: Various potential extension errors/crashes in rare circumstances. (Empty config values, etc.)

feat: Update display name for Skyrim to include AE.
  • Loading branch information
joelday committed Jan 16, 2023
1 parent 1d64045 commit 40c647c
Show file tree
Hide file tree
Showing 30 changed files with 379 additions and 325 deletions.
4 changes: 0 additions & 4 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,6 @@ Task("update-bin")
.IsDependentOn("copy-debug-plugin");

Task("build-extension")

This comment has been minimized.

Copy link
@joelday

joelday Jan 16, 2023

Author Owner

I forgot that when I changed this to copy bins, the task was only supposed to be for restarting the debugger after making changes. Since the binaries are in use, this fails when it tries to overwrite them.

.IsDependentOn("npm-clean")
.IsDependentOn("npm-copy-bin")
.IsDependentOn("npm-copy-debug-bin")
.IsDependentOn("copy-debug-plugin")
.IsDependentOn("npm-build");

Task("build-test")
Expand Down
223 changes: 81 additions & 142 deletions src/papyrus-lang-vscode/package-lock.json

Large diffs are not rendered by default.

28 changes: 15 additions & 13 deletions src/papyrus-lang-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
}
},
{
"label": "Papyrus: Skyrim Special Edition",
"label": "Papyrus: Skyrim Special Edition/Anniversary Edition",
"body": {
"name": "Skyrim",
"type": "papyrus",
Expand All @@ -99,9 +99,9 @@
}
},
{
"label": "Papyrus: Skyrim Special Edition (with .ppj)",
"label": "Papyrus: Skyrim Special Editio/Anniversary Editionn (with .ppj)",
"body": {
"name": "Skyrim Special Edition Project",
"name": "Skyrim Special Edition/Anniversary Edition Project",
"type": "papyrus",
"request": "attach",
"game": "skyrimSpecialEdition",
Expand Down Expand Up @@ -240,7 +240,7 @@
"papyrus.skyrim.enabled": {
"default": true,
"type": "boolean",
"description": "Enable support for Skyrim LE (\"Oldrim\"). This is not for Skyrim Special Edition!"
"description": "Enable support for Skyrim LE (\"Oldrim\"). This is not for Skyrim Special Edition/Anniversary Edition!"
},
"papyrus.skyrim.creationKitIniFiles": {
"default": [
Expand All @@ -260,7 +260,7 @@
"papyrus.skyrimSpecialEdition.enabled": {
"default": true,
"type": "boolean",
"markdownDescription": "Enable support for **Skyrim Special Edition**. Use the [Generate Project Files](command:papyrus.skyrimSpecialEdition.generateProject) command to set up the language server and builds."
"markdownDescription": "Enable support for **Skyrim Special Edition/Anniversary Edition**. Use the [Generate Project Files](command:papyrus.skyrimSpecialEdition.generateProject) command to set up the language server and builds."
},
"papyrus.skyrimSpecialEdition.creationKitIniFiles": {
"default": [
Expand All @@ -271,22 +271,22 @@
"items": {
"type": "string"
},
"description": "INI Files for the Skyrim Special Edition version of the Creation Kit."
"description": "INI Files for the Skyrim Special Edition/Anniversary Edition version of the Creation Kit."
},
"papyrus.skyrimSpecialEdition.installPath": {
"default": "C:\\Program Files (x86)\\Steam\\steamapps\\common\\Skyrim Special Edition\\",
"type": "string",
"description": "Pathname of the directory where Skyrim Special Edition is installed."
"description": "Pathname of the directory where Skyrim Special Edition/Anniversary Edition is installed."
},
"papyrus.skyrimSpecialEdition.ignoreDebuggerVersion": {
"default": false,
"type": "boolean",
"description": "Allow using old version of the debugger script extender plugin with Skyrim Special Edition."
"description": "Allow using old version of the debugger script extender plugin with Skyrim Special Edition/Anniversary Edition."
},
"papyrus.skyrimSpecialEdition.modDirectoryPath": {
"default": "",
"type": "string",
"description": "If you want to use a mod manager to manage the debugger plugin as a mod, set this to the path of the directory where installed mods for Skyrim SE are kept. Otherwise it will be installed in the game directory."
"description": "If you want to use a mod manager to manage the debugger plugin as a mod, set this to the path of the directory where installed mods for Skyrim SE/AE are kept. Otherwise it will be installed in the game directory."
}
},
"title": "Papyrus",
Expand Down Expand Up @@ -369,12 +369,12 @@
{
"category": "Papyrus",
"command": "papyrus.skyrimSpecialEdition.installDebuggerSupport",
"title": "Install Papyrus debugging support for Skyrim Special Edition"
"title": "Install Papyrus debugging support for Skyrim Special Edition/Anniversary Edition"
},
{
"category": "Debug",
"command": "papyrus.skyrimSpecialEdition.attachDebugger",
"title": "Attach to Skyrim Special Edition"
"title": "Attach to Skyrim Special Edition/Anniversary Edition"
},
{
"category": "Papyrus",
Expand All @@ -384,7 +384,7 @@
{
"category": "Papyrus",
"command": "papyrus.skyrimSpecialEdition.generateProject",
"title": "Generate Skyrim Special Edition Project Files"
"title": "Generate Skyrim Special Edition/Anniversary Edition Project Files"
},
{
"category": "Papyrus",
Expand Down Expand Up @@ -515,14 +515,15 @@
"dependencies": {
"@semantic-release/exec": "^6.0.3",
"@types/semantic-release": "^17.2.4",
"reflect-metadata": "^0.1.13",
"deepmerge": "^4.2.2",
"fast-deep-equal": "^3.1.3",
"ini": "^3.0.1",
"inversify": "^6.0.1",
"md5-file": "^5.0.0",
"ps-list": "^6.3.0",
"reflect-metadata": "^0.1.13",
"rxjs": "^6.6.7",
"semver": "^7.3.8",
"vscode-debugprotocol": "^1.37.0",
"vscode-languageclient": "^5.2.1",
"winreg": "^1.2.4",
Expand All @@ -535,6 +536,7 @@
"@types/ini": "^1.3.31",
"@types/mocha": "^10.0.1",
"@types/node": "^18.11.18",
"@types/semver": "^7.3.13",
"@types/vscode": "^1.74.0",
"@types/winreg": "^1.2.31",
"@vscode/test-electron": "2.2.0",
Expand Down
4 changes: 2 additions & 2 deletions src/papyrus-lang-vscode/resources/sse/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"version": "0.2.0",
"configurations": [
{
"name": "Skyrim SE",
"name": "Skyrim SE/AE",
"type": "papyrus",
"request": "attach",
"game": "skyrimSpecialEdition"
}
]
}
}
16 changes: 8 additions & 8 deletions src/papyrus-lang-vscode/resources/welcome/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ Now all you need to do is launch the game and start up the debugger again. Break

At this point all features are supported for all games _except_ debugging is not supported for Skyrim LE.

| Feature | Skyrim LE | Skyrim SE | Fallout 4 |
| --------------------------------------------------------------------------------------- | --------- | --------- | --------- |
| [Language Definition](https://github.com/joelday/papyrus-lang/wiki/Language-Definition) | Yes | Yes | Yes |
| [Static Analysis](https://github.com/joelday/papyrus-lang/wiki/Static-Analysis) | Yes | Yes | Yes |
| [IntelliSense](https://github.com/joelday/papyrus-lang/wiki/IntelliSense) | Yes | Yes | Yes |
| [Refactoring](https://github.com/joelday/papyrus-lang/wiki/Refactoring) | Yes | Yes | Yes |
| [Compilation](https://github.com/joelday/papyrus-lang/wiki/Compilation) | Yes | Yes | Yes |
| [Debugging](https://github.com/joelday/papyrus-lang/wiki/Debugging) | No | Yes | Yes |
| Feature | Skyrim LE | Skyrim SE/AE | Fallout 4 |
| --------------------------------------------------------------------------------------- | --------- | ------------ | --------- |
| [Language Definition](https://github.com/joelday/papyrus-lang/wiki/Language-Definition) | Yes | Yes | Yes |
| [Static Analysis](https://github.com/joelday/papyrus-lang/wiki/Static-Analysis) | Yes | Yes | Yes |
| [IntelliSense](https://github.com/joelday/papyrus-lang/wiki/IntelliSense) | Yes | Yes | Yes |
| [Refactoring](https://github.com/joelday/papyrus-lang/wiki/Refactoring) | Yes | Yes | Yes |
| [Compilation](https://github.com/joelday/papyrus-lang/wiki/Compilation) | Yes | Yes | Yes |
| [Debugging](https://github.com/joelday/papyrus-lang/wiki/Debugging) | No | Yes | Yes |

## Further Resources

Expand Down
12 changes: 6 additions & 6 deletions src/papyrus-lang-vscode/src/CreationKitInfoProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ const readFile = promisify(fs.readFile);
const exists = promisify(fs.exists);

export interface ICreationKitInfo {
resolvedInstallPath: string;
resolvedCompilerPath: string;
resolvedInstallPath: string | null;
resolvedCompilerPath: string | null;
config: ICreationKitConfig;
}

Expand Down Expand Up @@ -111,7 +111,7 @@ export class CreationKitInfoProvider {
);

const parsedInis = iniTexts.pipe(
map((iniTexts) => iniTexts.filter((iniText) => iniText !== null).map((iniText) => ini.parse(iniText)))
map((iniTexts) => iniTexts.filter((iniText) => iniText !== null).map((iniText) => ini.parse(iniText!)))
);

const mergedIni = parsedInis.pipe(
Expand All @@ -133,23 +133,23 @@ export class CreationKitInfoProvider {

return combineLatest(resolvedInstallPath, mergedIni).pipe(
mergeMap(async ([resolvedInstallPath, mergedIni]) => {
const compilerPath = resolvedInstallPath
const compilerPath = resolvedInstallPath && mergedIni.Papyrus?.sCompilerFolder
? path.resolve(resolvedInstallPath, mergedIni.Papyrus.sCompilerFolder)
: null;

const resolvedCompilerPath =
compilerPath && (await exists(compilerPath))
? compilerPath
: inDevelopmentEnvironment() && game !== PapyrusGame.skyrim
? path.resolve(resolvedInstallPath, getDevelopmentCompilerFolderForGame(game))
? path.resolve(resolvedInstallPath!, getDevelopmentCompilerFolderForGame(game))
: null;

return {
resolvedInstallPath,
resolvedCompilerPath:
inDevelopmentEnvironment() &&
game !== PapyrusGame.skyrim &&
!(await exists(resolvedCompilerPath))
(!resolvedCompilerPath || !(await exists(resolvedCompilerPath)))
? null
: resolvedCompilerPath,
config: mergedIni,
Expand Down
3 changes: 2 additions & 1 deletion src/papyrus-lang-vscode/src/ExtensionConfigProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { injectable, interfaces } from 'inversify';
import { workspace, Disposable } from 'vscode';
import { eventToValueObservable } from './common/vscode/reactive/Events';
import { Observable } from 'rxjs';
import { filter } from 'rxjs/operators';

export interface IGameConfig {
readonly enabled: boolean;
Expand Down Expand Up @@ -30,7 +31,7 @@ export class ExtensionConfigProvider implements IExtensionConfigProvider {
private readonly _config = eventToValueObservable(
workspace.onDidChangeConfiguration,
() => getPapyrusConfig(),
(e) => (e.affectsConfiguration('papyrus') ? getPapyrusConfig() : undefined)

This comment has been minimized.

Copy link
@joelday

joelday Jan 16, 2023

Author Owner

Nit: trailing comma, but I'll deal with this when I set up eslint and prettier.

(e) => (e.affectsConfiguration('papyrus') ? getPapyrusConfig() : undefined),
);

get config() {
Expand Down
2 changes: 0 additions & 2 deletions src/papyrus-lang-vscode/src/PapyrusExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ class PapyrusExtension implements Disposable {

this._showWelcomeCommand = this._serviceContainer.resolve(ShowWelcomeCommand);

// Show the getting started document if there's no previous version (new install)
// At some point we might want a "what's new" so I included both version numbers.
void showWelcome(papyrusVersion, previousVersion);
context.globalState.update(GlobalState.PapyrusVersion, papyrusVersion);
}
Expand Down
31 changes: 20 additions & 11 deletions src/papyrus-lang-vscode/src/PapyrusGame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export enum PapyrusGame {
const displayNames = new Map([
[PapyrusGame.fallout4, 'Fallout 4'],
[PapyrusGame.skyrim, 'Skyrim'],
[PapyrusGame.skyrimSpecialEdition, 'Skyrim Special Edition'],
[PapyrusGame.skyrimSpecialEdition, 'Skyrim Special Edition/Anniversary Edition'],
]);

export function getDisplayNameForGame(game: PapyrusGame) {
Expand All @@ -28,7 +28,7 @@ export function getDisplayNameForGame(game: PapyrusGame) {
const shortDisplayNames = new Map([
[PapyrusGame.fallout4, 'Fallout 4'],
[PapyrusGame.skyrim, 'Skyrim'],
[PapyrusGame.skyrimSpecialEdition, 'Skyrim SE'],
[PapyrusGame.skyrimSpecialEdition, 'Skyrim SE/AE'],
]);

const scriptExtenderNames = new Map([[PapyrusGame.fallout4, 'F4SE'], [PapyrusGame.skyrimSpecialEdition, 'SKSE']]);
Expand All @@ -43,41 +43,50 @@ const scriptExtenderUrls = new Map([
]);

export function getScriptExtenderUrl(game: PapyrusGame) {
return scriptExtenderUrls.get(game);
return scriptExtenderUrls.get(game)!;
}

export function getShortDisplayNameForGame(game: PapyrusGame) {
return shortDisplayNames.get(game);
export function getShortDisplayNameForGame(game: PapyrusGame): string {
return shortDisplayNames.get(game)!;
}

export function getGames(): PapyrusGame[] {
return Object.keys(PapyrusGame).map((k) => PapyrusGame[k]);
return (Object.keys(PapyrusGame) as (keyof typeof PapyrusGame)[]).map((k) => PapyrusGame[k]);
}

export async function getWorkspaceGameFromProjects(ppjFiles: Uri[]): Promise<PapyrusGame | undefined> {
let game: string = undefined;
let game: string | undefined = undefined;
if (!ppjFiles) {
return undefined;
}

for (let ppjFile of ppjFiles) {
game = await getWorkspaceGameFromProjectFile(ppjFile.fsPath);
if (game) {
break;
}
}
if (!game) {

if (!game || !PyroGameToPapyrusGame[game as keyof typeof PyroGameToPapyrusGame]) {
return undefined;
}
return PyroGameToPapyrusGame[game];

return PyroGameToPapyrusGame[game as keyof typeof PyroGameToPapyrusGame] as unknown as PapyrusGame;
}

export async function getWorkspaceGameFromProjectFile(projectFile: string): Promise<PapyrusGame | undefined> {
let xml = await readFile(projectFile, { encoding: 'utf-8' });
let results = xml2js(xml, { compact: true, trim: true });
const xml = await readFile(projectFile, { encoding: 'utf-8' });
// TODO: Annoying type cast here:
const results = xml2js(xml, { compact: true, trim: true }) as Record<string, any>;

return results['PapyrusProject']['_attributes']['Game'];
}

export async function getWorkspaceGame(): Promise<PapyrusGame | undefined> {
if (!workspace.workspaceFolders) {
return undefined;
}

const ppjFiles: Uri[] = await workspace.findFiles(new RelativePattern(workspace.workspaceFolders[0], "**/*.ppj"));
return getWorkspaceGameFromProjects(ppjFiles);
}
Loading

0 comments on commit 40c647c

Please sign in to comment.